Skip to content

Commit 5922a9e

Browse files
authored
chore(jp): migrate script to mjs (#3481)
1 parent 70db0de commit 5922a9e

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

scripts/api-ja.js renamed to scripts/api-ja.mjs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
const fetch = require('node-fetch');
2-
const fs = require('fs');
3-
const path = require('path');
4-
const { api: apiOverrides } = require('./data/meta-override.json');
5-
const utils = require('./utils');
1+
import { resolve, join } from 'node:path';
2+
import fetch from 'node-fetch';
3+
import { existsSync, writeFileSync } from 'fs';
4+
import overrides from './data/meta-override.json' with { type: 'json' };
5+
import * as utils from './utils.mjs';
66

7-
const DEMOS_PATH = path.resolve('static/demos');
7+
const apiOverrides = overrides.api;
8+
9+
const DEMOS_PATH = resolve('static/demos');
810
let COMPONENT_LINK_REGEXP;
911

1012
(async function () {
@@ -37,7 +39,7 @@ function writePage(page) {
3739
data = data.replace(COMPONENT_LINK_REGEXP, '($1.md$2)');
3840

3941
const path = `i18n/ja/docusaurus-plugin-content-docs/current/api/${page.tag.slice(4)}.md`;
40-
fs.writeFileSync(path, data);
42+
writeFileSync(path, data);
4143
}
4244

4345
function renderFrontmatter({ tag }) {
@@ -46,7 +48,7 @@ function renderFrontmatter({ tag }) {
4648
};
4749

4850
const demoPath = `api/${tag.slice(4)}/index.html`;
49-
if (fs.existsSync(path.join(DEMOS_PATH, demoPath))) {
51+
if (existsSync(join(DEMOS_PATH, demoPath))) {
5052
frontmatter.demoUrl = `/docs/demos/${demoPath}`;
5153
frontmatter.demoSourceUrl = `https://github.com/ionic-team/ionic-docs/tree/main/static/demos/${demoPath}`;
5254
}
@@ -64,6 +66,16 @@ ${utils.getHeadTag(apiOverrides[tag])}
6466
}
6567

6668
function renderReadme({ readme, encapsulation }) {
69+
if (!readme) {
70+
return `
71+
import EncapsulationPill from '@components/page/api/EncapsulationPill';
72+
73+
${encapsulation !== 'none' ? `<EncapsulationPill type="${encapsulation}" />` : ''}
74+
75+
76+
`;
77+
}
78+
6779
const endIndex = readme.indexOf('\n');
6880

6981
const title = readme.substring(0, endIndex);

scripts/i18n.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ set -o nounset
55
mkdir -p i18n/ja/docusaurus-plugin-content-docs/current/
66
curl -fsSL https://github.com/ionic-team/ionic-docs/archive/refs/heads/translation/jp.tar.gz |
77
tar -zxf - -C i18n/ja/docusaurus-plugin-content-docs/current/ --strip-components 2 ionic-docs-translation-jp/docs
8-
node scripts/api-ja.js
8+
node scripts/api-ja.mjs

0 commit comments

Comments
 (0)