build: auto check language files for json errors

This commit is contained in:
Johannes Millan 2023-01-05 15:06:55 +01:00
parent 4e3226bdfc
commit b36405817f
2 changed files with 29 additions and 1 deletions

View File

@ -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": [

27
tools/test-lng-files.js Normal file
View File

@ -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);
}
});
});
});