Skip to content

chore(jp): migrate script to mjs #3481

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions scripts/api-ja.js → scripts/api-ja.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const fetch = require('node-fetch');
const fs = require('fs');
const path = require('path');
const { api: apiOverrides } = require('./data/meta-override.json');
const utils = require('./utils');
import { resolve, join } from 'node:path';
import fetch from 'node-fetch';
import { existsSync, writeFileSync } from 'fs';
import overrides from './data/meta-override.json' assert { type: 'json' };
import * as utils from './utils.mjs';

const DEMOS_PATH = path.resolve('static/demos');
const apiOverrides = overrides.api;

const DEMOS_PATH = resolve('static/demos');
let COMPONENT_LINK_REGEXP;

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

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

function renderFrontmatter({ tag }) {
Expand All @@ -46,7 +48,7 @@ function renderFrontmatter({ tag }) {
};

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

function renderReadme({ readme, encapsulation }) {
if (!readme) {
return `
import EncapsulationPill from '@components/page/api/EncapsulationPill';

${encapsulation !== 'none' ? `<EncapsulationPill type="${encapsulation}" />` : ''}


`;
} else {
}
const endIndex = readme.indexOf('\n');

const title = readme.substring(0, endIndex);
Expand Down
2 changes: 1 addition & 1 deletion scripts/i18n.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ set -o nounset
mkdir -p i18n/ja/docusaurus-plugin-content-docs/current/
curl -fsSL https://github.com/ionic-team/ionic-docs/archive/refs/heads/translation/jp.tar.gz |
tar -zxf - -C i18n/ja/docusaurus-plugin-content-docs/current/ --strip-components 2 ionic-docs-translation-jp/docs
node scripts/api-ja.js
node scripts/api-ja.mjs