diff --git a/.node-version b/.node-version
index c818c7b005..975215f459 100644
--- a/.node-version
+++ b/.node-version
@@ -1 +1 @@
-16.15.0
\ No newline at end of file
+16.17.0
\ No newline at end of file
diff --git a/aio-ja/tools/transforms/templates/error/error.template.html b/aio-ja/tools/transforms/templates/error/error.template.html
index d055009d69..0f06500b26 100644
--- a/aio-ja/tools/transforms/templates/error/error.template.html
+++ b/aio-ja/tools/transforms/templates/error/error.template.html
@@ -20,14 +20,14 @@
{$ doc.code $}: {$ doc.shortDescription $}
{% if doc.videoCaption %}{$ doc.videoCaption | marked $}{% endif%}
-
説明
+ Description
{$ doc.description | marked $}
-
エラーのデバッグ
+ Debugging the error
{$ doc.debugging | marked $}
diff --git a/package.json b/package.json
index 3615ae2835..5cfb89eb87 100644
--- a/package.json
+++ b/package.json
@@ -7,18 +7,16 @@
"license": "MIT",
"private": true,
"scripts": {
- "build": "zx tools/build.mjs",
- "lint": "yarn ~~textlint",
- "lint:fix": "yarn ~~textlint --fix",
"start": "zx tools/watch.mjs",
+ "build": "zx tools/build.mjs",
+ "lint": "yarn ~textlint",
+ "~textlint": "textlint 'aio-ja/**/!(*.en).md'",
"test": "npm run lint && yarn test:patch",
- "test:patch": "git apply -v --check --directory origin ./scripts/git-patch/*.patch",
- "update-origin": "./update-origin.sh",
- "~~textlint": "textlint 'aio-ja/**/!(*.en).md'"
+ "test:patch": "git apply -v --check --directory origin ./tools/git-patch/*.patch",
+ "update-origin": "zx tools/update-origin.mjs"
},
"devDependencies": {
"chokidar": "3.5.3",
- "glob": "^8.0.3",
"prh-rules": "prh/rules",
"textlint": "^12.2.1",
"textlint-filter-rule-comments": "^1.2.2",
diff --git a/scripts/sync-origin.js b/scripts/sync-origin.js
deleted file mode 100644
index 9285a371d8..0000000000
--- a/scripts/sync-origin.js
+++ /dev/null
@@ -1,56 +0,0 @@
-const fs = require('fs');
-const path = require('path');
-const glob = require('glob');
-const { promisify } = require('util');
-
-const copyTargets = [
- 'content/cli/**/*.md',
- 'content/guide/**/*.md',
- 'content/errors/**/*.md',
- 'content/marketing/**/*',
- 'content/start/**/*.md',
- 'content/tutorial/**/*.md',
- 'content/navigation.json',
- 'content/examples/toh-pt6/src/app/hero-search/hero-search.component.ts',
- 'content/examples/toh-pt6/src/app/heroes/heroes.component.html',
- 'content/examples/toh-pt6/src/app/hero.service.ts',
- 'tools/transforms/templates/error/error.template.html',
-];
-
-const promiseGlob = promisify(glob);
-
-async function main() {
- const aioOriginDir = 'origin/aio';
- const aioJaDir = 'aio-ja';
-
- const searchFiles = async () => {
- const globResults = await Promise.all(copyTargets.map(target => {
- return promiseGlob(path.resolve(aioOriginDir, target), {});
- }));
- return globResults.reduce((files, result) => [...files, ...(result.map(file => path.relative(aioOriginDir, file)))], []);
- }
-
- const files = await searchFiles();
-
- const copy = (file) => {
- const ext = path.extname(file);
- const enFilePath = file.replace(`${ext}`, `.en${ext}`);
- const src = fs.readFileSync(path.resolve(aioOriginDir, file), { encoding: 'utf8' });
-
- let isTranslated = false;
- try {
- fs.accessSync(path.resolve(aioJaDir, enFilePath));
- isTranslated = true;
- } catch (err) { }
-
- fs.writeFileSync(path.resolve(aioJaDir, isTranslated ? enFilePath : file), src, { encoding: 'utf8' });
- };
- files.forEach(copy);
-}
-
-
-main().catch(err => {
- console.error(err);
- process.exit(1);
-});
-
diff --git a/tools/build.mjs b/tools/build.mjs
index 2c8ef4502b..ee217dd459 100644
--- a/tools/build.mjs
+++ b/tools/build.mjs
@@ -18,7 +18,7 @@ try {
}
async function setup() {
- await resetBuildDir();
+ await resetBuildDir({ removeExisting: true });
}
async function preBuild() {
diff --git a/scripts/git-patch/add-japanese-font.patch b/tools/git-patch/add-japanese-font.patch
similarity index 100%
rename from scripts/git-patch/add-japanese-font.patch
rename to tools/git-patch/add-japanese-font.patch
diff --git a/scripts/git-patch/add-japanese-search.patch b/tools/git-patch/add-japanese-search.patch
similarity index 100%
rename from scripts/git-patch/add-japanese-search.patch
rename to tools/git-patch/add-japanese-search.patch
diff --git a/scripts/git-patch/add-translated-icon.patch b/tools/git-patch/add-translated-icon.patch
similarity index 100%
rename from scripts/git-patch/add-translated-icon.patch
rename to tools/git-patch/add-translated-icon.patch
diff --git a/scripts/git-patch/change-analytics-id.patch b/tools/git-patch/change-analytics-id.patch
similarity index 100%
rename from scripts/git-patch/change-analytics-id.patch
rename to tools/git-patch/change-analytics-id.patch
diff --git a/scripts/git-patch/change-document-title.patch b/tools/git-patch/change-document-title.patch
similarity index 100%
rename from scripts/git-patch/change-document-title.patch
rename to tools/git-patch/change-document-title.patch
diff --git a/scripts/git-patch/change-github-links.patch b/tools/git-patch/change-github-links.patch
similarity index 100%
rename from scripts/git-patch/change-github-links.patch
rename to tools/git-patch/change-github-links.patch
diff --git a/scripts/git-patch/disable-service-worker.patch b/tools/git-patch/disable-service-worker.patch
similarity index 100%
rename from scripts/git-patch/disable-service-worker.patch
rename to tools/git-patch/disable-service-worker.patch
diff --git a/tools/lib/common.mjs b/tools/lib/common.mjs
index d73ed4d4c9..93627a8a22 100644
--- a/tools/lib/common.mjs
+++ b/tools/lib/common.mjs
@@ -1,7 +1,7 @@
import { watch } from 'chokidar';
import { resolve } from 'node:path';
import { $, cd, glob, within } from 'zx';
-import { clearDir, cpRf, sed } from './fileutils.mjs';
+import { initDir, cpRf, exists, sed } from './fileutils.mjs';
const rootDir = resolve(__dirname, '../');
const aiojaDir = resolve(rootDir, 'aio-ja');
@@ -11,8 +11,11 @@ const outDir = resolve(rootDir, 'build');
// https://github.com/google/zx/blob/main/src/util.ts#L31
$.quote = (s) => s;
-export async function resetBuildDir() {
- await clearDir(outDir);
+export async function resetBuildDir({ removeExisting = false }) {
+ const buildDirExists = await exists(outDir);
+ if (!buildDirExists || removeExisting) {
+ await initDir(outDir);
+ }
await cpRf(resolve(rootDir, 'origin'), outDir);
}
@@ -66,7 +69,7 @@ export async function watchLocalizedFiles(signal) {
export async function applyPatches() {
await within(async () => {
cd(outDir);
- const patches = await glob('scripts/git-patch/*.patch', { cwd: rootDir });
+ const patches = await glob('tools/git-patch/*.patch', { cwd: rootDir });
for (const patch of patches) {
const path = resolve(rootDir, patch);
await $`git apply -p1 --ignore-whitespace ${path}`;
diff --git a/tools/lib/fileutils.mjs b/tools/lib/fileutils.mjs
index 8c668a1ecc..ebf2f99ea2 100644
--- a/tools/lib/fileutils.mjs
+++ b/tools/lib/fileutils.mjs
@@ -1,4 +1,4 @@
-import { cp, mkdir, readFile, rm, writeFile } from 'node:fs/promises';
+import { access, cp, mkdir, readFile, rm, writeFile } from 'node:fs/promises';
export async function rmrf(path) {
try {
@@ -6,7 +6,13 @@ export async function rmrf(path) {
} catch {}
}
-export async function clearDir(path) {
+export async function exists(path) {
+ return await access(path)
+ .then(() => true)
+ .catch(() => false);
+}
+
+export async function initDir(path) {
await rmrf(path);
await mkdir(path, { recursive: true });
}
diff --git a/tools/update-origin.mjs b/tools/update-origin.mjs
new file mode 100644
index 0000000000..f8680c748e
--- /dev/null
+++ b/tools/update-origin.mjs
@@ -0,0 +1,65 @@
+import { access, copyFile } from 'node:fs/promises';
+import { extname, resolve } from 'node:path';
+import { $, argv, chalk, glob } from 'zx';
+
+const copyTargets = [
+ // Text contents
+ 'content/cli/**/*.md',
+ 'content/guide/**/*.md',
+ 'content/errors/**/*.md',
+ 'content/marketing/**/*',
+ 'content/start/**/*.md',
+ 'content/tutorial/**/*.md',
+ 'content/navigation.json',
+ // AIO source code files
+ 'content/examples/toh-pt6/src/app/hero-search/hero-search.component.ts',
+ 'content/examples/toh-pt6/src/app/heroes/heroes.component.html',
+ 'content/examples/toh-pt6/src/app/hero.service.ts',
+ 'tools/transforms/templates/error/error.template.html',
+];
+
+try {
+ console.log(chalk.cyan('Checking aio changes in origin...'));
+
+ const [aioHash] = argv._;
+ if (aioHash == null) {
+ console.log('No aio origin SHA is provided.');
+ process.exit(1);
+ }
+ console.log(chalk.green('aio origin SHA: ' + aioHash));
+
+ await resetOriginHead(aioHash);
+ await copyOriginFiles();
+
+ console.log(chalk.cyan('Done.'));
+} catch (err) {
+ console.error(chalk.red(err));
+ process.exit(1);
+}
+
+async function resetOriginHead(hash) {
+ await $`git -C origin fetch --all`;
+ await $`git -C origin reset ${hash} --hard`;
+}
+
+async function copyOriginFiles() {
+ const aioOriginDir = 'origin/aio';
+ const aioJaDir = 'aio-ja';
+
+ const files = await glob(copyTargets, { cwd: aioOriginDir });
+
+ for (const file of files) {
+ const src = resolve(aioOriginDir, file);
+ const ext = extname(file);
+ const enFilePath = file.replace(`${ext}`, `.en${ext}`);
+
+ let isTranslated = false;
+ try {
+ await access(resolve(aioJaDir, enFilePath));
+ isTranslated = true;
+ } catch {}
+ const dest = resolve(aioJaDir, isTranslated ? enFilePath : file);
+
+ await copyFile(src, dest);
+ }
+}
diff --git a/tools/watch.mjs b/tools/watch.mjs
index 4d4bd50695..77b90606a0 100644
--- a/tools/watch.mjs
+++ b/tools/watch.mjs
@@ -1,11 +1,13 @@
#!/usr/bin/env zx
-import { chalk } from 'zx';
+import { argv, chalk } from 'zx';
import { applyPatches, copyLocalizedFiles, resetBuildDir, watchAIO, watchLocalizedFiles } from './lib/common.mjs';
try {
+ const { 'clear-cache': clearCache = false } = argv;
+
console.log(chalk.green('==== setup ===='));
- await setup();
+ await setup({ clearCache });
console.log(chalk.green('==== preWatch ===='));
await preWatch();
console.log(chalk.green('==== watch ===='));
@@ -15,11 +17,16 @@ try {
process.exit(1);
}
-async function setup() {
+async function setup({ clearCache }) {
console.log('');
console.log(chalk.yellow('変更監視の対象は、aio-ja 内のファイル と build/aio 内のソースコードです。'));
+ if (clearCache) {
+ console.log(chalk.yellow('build ディレクトリを初期化し、キャッシュを破棄します。'));
+ } else {
+ console.log(chalk.yellow('build ディレクトリを初期化するには --clear-cache オプションを指定してください。'));
+ }
console.log('');
- await resetBuildDir();
+ await resetBuildDir({ removeExisting: clearCache });
}
async function preWatch() {
diff --git a/update-origin.sh b/update-origin.sh
deleted file mode 100755
index 7dd6d4416c..0000000000
--- a/update-origin.sh
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/bin/bash -eux
-
-echo "Checking aio changes in origin..."
-
-aioHash="$1"
-
-if [ -z "${aioHash}" ]; then
- echo "No aio origin SHA is provided.";
- exit 1;
-fi
-
-
-git -C origin fetch --all
-git -C origin reset ${aioHash} --hard
-
-node scripts/sync-origin.js
-
-echo "Finished!"
diff --git a/yarn.lock b/yarn.lock
index 09d5cddef0..507e528f72 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -284,13 +284,6 @@ brace-expansion@^1.1.7:
balanced-match "^1.0.0"
concat-map "0.0.1"
-brace-expansion@^2.0.1:
- version "2.0.1"
- resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-2.0.1.tgz#1edc459e0f0c548486ecf9fc99f2221364b9a0ae"
- integrity sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==
- dependencies:
- balanced-match "^1.0.0"
-
braces@^3.0.2, braces@~3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.2.tgz#3454e1a462ee8d599e236df336cd9ea4f8afe107"
@@ -638,17 +631,6 @@ glob@^7.1.3, glob@^7.2.3:
once "^1.3.0"
path-is-absolute "^1.0.0"
-glob@^8.0.3:
- version "8.0.3"
- resolved "https://registry.yarnpkg.com/glob/-/glob-8.0.3.tgz#415c6eb2deed9e502c68fa44a272e6da6eeca42e"
- integrity sha512-ull455NHSHI/Y1FqGaaYFaLGkNMMJbavMrEGFXG/PGrg6y7sutWHUHrz6gy6WEBH6akM1M414dWKCNs+IhKdiQ==
- dependencies:
- fs.realpath "^1.0.0"
- inflight "^1.0.4"
- inherits "2"
- minimatch "^5.0.1"
- once "^1.3.0"
-
globby@^13.1.2:
version "13.1.2"
resolved "https://registry.yarnpkg.com/globby/-/globby-13.1.2.tgz#29047105582427ab6eca4f905200667b056da515"
@@ -1114,13 +1096,6 @@ minimatch@^3.1.1:
dependencies:
brace-expansion "^1.1.7"
-minimatch@^5.0.1:
- version "5.1.0"
- resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-5.1.0.tgz#1717b464f4971b144f6aabe8f2d0b8e4511e09c7"
- integrity sha512-9TPBGGak4nHfGZsPBohm9AWg6NoT7QTCehS3BIJABslyZbzxfV78QM2Y6+i741OPZIafFAaiiEMh5OyIrJPgtg==
- dependencies:
- brace-expansion "^2.0.1"
-
minimist@^1.2.6:
version "1.2.6"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.6.tgz#8637a5b759ea0d6e98702cfb3a9283323c93af44"