From b36405817f0e90da0376a686efcba185105f05d0 Mon Sep 17 00:00:00 2001 From: Johannes Millan Date: Thu, 5 Jan 2023 15:06:55 +0100 Subject: [PATCH] build: auto check language files for json errors --- package.json | 3 ++- tools/test-lng-files.js | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 tools/test-lng-files.js diff --git a/package.json b/package.json index a37faddab..dacd73a16 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "test:watch": "cross-env TZ='Europe/Berlin' ng test --browsers ChromeHeadless", "lint": "ng lint", "prebuild": "node ./tools/git-version.js", - "preCheck": "npm run lint && npm run test && npm run e2e", + "preCheck": "npm run lint && npm run test & npm run int:test && npm run e2e", "e2e": "cross-env TZ='' DETECT_CHROMEDRIVER_VERSION=true SKIP_POST_INSTALL=true npm i -D chromedriver --legacy-peer-deps && tsc --project e2e/tsconfig.e2e.json && start-server-and-test 'ng serve --no-live-reload' 4200 'nightwatch -c ./e2e/nightwatch.conf.js --suiteRetries 1 --retries 0'", "e2e:tag": "killall chromedriver; rm -R ./out-tsc; tsc --project e2e/tsconfig.e2e.json && nightwatch -c ./e2e/nightwatch.conf.js --suiteRetries 0 --retries 0 --tag ", "electron": "NODE_ENV=PROD electron .", @@ -94,6 +94,7 @@ "int:watch": "node ./tools/extract-i18n-watch.js", "int:find": "ngx-translate-extract --input ./src --output ./src/assets/i18n/*.json --sort --format namespaced-json --marker _", "int:clean": "ngx-translate-extract --input ./src --output ./src/assets/i18n/*.json --clean --sort --format namespaced-json --marker _", + "int:test": "node ./tools/test-lng-files.js", "postinstall": "cross-env-shell node ./tools/is-skip-postinstall.js --env.SKIP_POST_INSTALL=$SKIP_POST_INSTALL || ngcc --tsconfig src/tsconfig.app.json" }, "publish": [ diff --git a/tools/test-lng-files.js b/tools/test-lng-files.js new file mode 100644 index 000000000..4599bb1f9 --- /dev/null +++ b/tools/test-lng-files.js @@ -0,0 +1,27 @@ +/* eslint-env es6 */ +const { readdir, readFile } = require('fs'); +const BASE_PATH = 'src/assets/i18n'; +readdir(BASE_PATH, (err, files) => { + //handling error + if (err) { + console.log('Unable to scan directory: ' + err); + process.exit(12345); + } + //listing all files using forEach + files.forEach((file) => { + // Do whatever you want to do with the file + readFile(BASE_PATH + '/' + file, (err, data) => { + if (err) { + console.error(err); + process.exit(12345); + } + try { + JSON.parse(data.toString()); + } catch (e) { + console.log(BASE_PATH + '/' + file); + console.error(e); + process.exit(12345); + } + }); + }); +});