@kununu/phraseapp-cli 4.0.0-beta.0 → 4.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,22 +1,15 @@
1
- //import { readFileSync, writeFileSync, unlinkSync, existsSync } from 'fs';
2
- //import { sync } from 'glob';
3
- //import { parse } from '@babel/parser';
4
- //import traverse from '@babel/traverse';
5
-
6
- const { readFileSync, writeFileSync, unlinkSync, existsSync } = require('fs');
1
+ const { readFileSync, writeFileSync, unlinkSync, existsSync, mkdirSync } = require('fs');
7
2
  const {sync} = require('glob');
8
3
  const {parse} = require('@babel/parser');
9
4
  const traverse = require('@babel/traverse');
10
5
 
11
-
12
- // const TRANSLATIONS_FILE = `${process.cwd()}/translations/de_AT.json`;
13
- const DYNAMIC_KEYS_FILE = `${process.cwd()}/dynamic_keys.json`;
14
- const UNUSED_KEYS_FILE = 'not_used_keys.json';
15
- const MISSING_KEYS_FILE = 'missing_keys.json';
16
- const POSSIBLE_DYNAMIC_KEYS_FILE = 'possible_dynamic_keys.json';
6
+ const FOLDER_REPORT_CHECK_TRANSLATIONS = `${process.cwd()}/report-check-translations`;
7
+ const UNUSED_KEYS_FILE = `${FOLDER_REPORT_CHECK_TRANSLATIONS}/not_used_keys.json`;
8
+ const MISSING_KEYS_FILE = `${FOLDER_REPORT_CHECK_TRANSLATIONS}/missing_keys.json`;
9
+ const POSSIBLE_DYNAMIC_KEYS_FILE = `${FOLDER_REPORT_CHECK_TRANSLATIONS}/possible_dynamic_keys.json`;
17
10
 
18
11
  function extractTranslationKeys() {
19
- const files = sync(`${process.env.SOURCE_DIR}/**/**/*.{js,jsx,ts,tsx}`);
12
+ const files = sync(`${process.cwd()}/${process.env.SOURCE_DIR}/**/**/*.{js,jsx,ts,tsx}`);
20
13
  const keys = new Set();
21
14
  const possibleDynamicKeys = {};
22
15
 
@@ -55,7 +48,7 @@ function extractTranslationKeys() {
55
48
  });
56
49
 
57
50
  if (Object.keys(possibleDynamicKeys).length > 0) {
58
- console.log(`${Object.keys(possibleDynamicKeys).length} files contain possible dynamic keys.`);
51
+ console.log(`${Object.keys(possibleDynamicKeys).length} files contain possible dynamic keys were saved in ${POSSIBLE_DYNAMIC_KEYS_FILE}`);
59
52
  writeFileSync(POSSIBLE_DYNAMIC_KEYS_FILE, JSON.stringify(possibleDynamicKeys, null, 2));
60
53
  } else if (existsSync(POSSIBLE_DYNAMIC_KEYS_FILE)) {
61
54
  unlinkSync(POSSIBLE_DYNAMIC_KEYS_FILE);
@@ -66,13 +59,17 @@ function extractTranslationKeys() {
66
59
  }
67
60
 
68
61
  function compareKeys() {
62
+ // create folder for report
63
+ if (!existsSync(FOLDER_REPORT_CHECK_TRANSLATIONS)) {
64
+ mkdirSync(FOLDER_REPORT_CHECK_TRANSLATIONS, { recursive: true });
65
+ }
69
66
  const configPath = `${process.cwd()}/.phraseapp.json`;
70
67
  const appKeys = extractTranslationKeys();
71
68
 
72
69
  try {
73
- const phrase = JSON.parse(fs.readFileSync(configPath));
70
+ const phrase = JSON.parse(readFileSync(configPath));
74
71
  const translations = JSON.parse(readFileSync(`${phrase.path}/de_AT.json`, 'utf8'));
75
- const dynamicKeys = JSON.parse(readFileSync(phrase.dynamicKeys, 'utf8'));
72
+ const dynamicKeys = phrase.dynamicKeys || [];
76
73
 
77
74
  const allValidKeys = new Set(Object.keys(translations));
78
75
 
@@ -108,8 +105,8 @@ function compareKeys() {
108
105
  console.log(`${UNUSED_KEYS_FILE} was deleted as there are no missing keys.`);
109
106
  }
110
107
  } catch (error) {
111
- console.error(`Error processing ${file}:`, error);
108
+ console.error(error);
112
109
  }
113
110
  }
114
111
 
115
- compareKeys();
112
+ compareKeys();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kununu/phraseapp-cli",
3
- "version": "4.0.0-beta.0",
3
+ "version": "4.0.0-beta.2",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "author": "kununu",