From f0ec0b53580ebe16a4dce44655e5e1a86bdbd839 Mon Sep 17 00:00:00 2001 From: Nat Alison <1278991+tesseralis@users.noreply.github.com> Date: Thu, 9 Apr 2020 06:15:59 -0700 Subject: [PATCH] maintenance (scripts/i18n) Create run-all i18n script (#22873) * Create run-all i18n script * error checking * add more documentation --- scripts/i18n/README.md | 10 ++++++++++ scripts/i18n/package.json | 1 + scripts/i18n/run-all.js | 21 +++++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 scripts/i18n/run-all.js diff --git a/scripts/i18n/README.md b/scripts/i18n/README.md index 6b7654ccce566..8211f63214653 100644 --- a/scripts/i18n/README.md +++ b/scripts/i18n/README.md @@ -70,3 +70,13 @@ When run, the script will: - Pulls the latest version of `gatsby-i18n-source`. - Creates a "sync" pull request that updates all files that do not contain conflicts from the merge. - Creates a "conflicts" pull request that contains all merge conflicts, with instructions on how to resolve them. + +### `run-all` + +Usage: + +```shell +yarn run-all [script name] +``` + +The `run-all` script runs the script provided in the argument across all languages for which there are translations of gatbyjs.org, listed in /www/src/i18n.json. diff --git a/scripts/i18n/package.json b/scripts/i18n/package.json index b8795edc8fef0..1c60f22081e4f 100644 --- a/scripts/i18n/package.json +++ b/scripts/i18n/package.json @@ -4,6 +4,7 @@ "description": "Scripts for gatsby internationalization", "scripts": { "create": "node ./create.js", + "run-all": "node ./run-all.js", "sync": "node ./sync.js", "update-source": "node ./update-source.js" }, diff --git a/scripts/i18n/run-all.js b/scripts/i18n/run-all.js new file mode 100644 index 0000000000000..3cac7e235ac4a --- /dev/null +++ b/scripts/i18n/run-all.js @@ -0,0 +1,21 @@ +// Run the provided script on all valid repos +const fs = require(`fs`) +const log4js = require(`log4js`) +const shell = require(`shelljs`) +let logger = log4js.getLogger(`run-all`) + +require(`dotenv`).config() + +function runAll(script) { + if (!script) { + logger.error(`Usage: yarn run-all `) + process.exit(1) + } + const langs = JSON.parse(fs.readFileSync(`../../www/i18n.json`)) + for (const { code } of langs) { + shell.exec(`yarn ${script} ${code}`) + } +} + +const [script] = process.argv.slice(2) +runAll(script)