@kununu/phraseapp-cli 4.0.1 → 4.0.3-beta.1
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.
- package/check-translations.js +14 -11
- package/index.js +0 -2
- package/package.json +1 -1
package/check-translations.js
CHANGED
|
@@ -10,6 +10,8 @@ const {parse} = require('@babel/parser');
|
|
|
10
10
|
const traverse = require('@babel/traverse');
|
|
11
11
|
const {sync} = require('glob');
|
|
12
12
|
|
|
13
|
+
const colors = require('colors'); // eslint-disable-line no-unused-vars
|
|
14
|
+
|
|
13
15
|
const FOLDER_REPORT_CHECK_TRANSLATIONS = `${process.cwd()}/report-check-translations`;
|
|
14
16
|
const UNUSED_KEYS_FILE = `${FOLDER_REPORT_CHECK_TRANSLATIONS}/not_used_keys.json`;
|
|
15
17
|
const MISSING_KEYS_FILE = `${FOLDER_REPORT_CHECK_TRANSLATIONS}/missing_keys.json`;
|
|
@@ -80,7 +82,7 @@ function extractTranslationKeys() {
|
|
|
80
82
|
|
|
81
83
|
if (Object.keys(possibleDynamicKeys).length > 0) {
|
|
82
84
|
console.log(
|
|
83
|
-
`${Object.keys(possibleDynamicKeys).length} files contain possible dynamic keys were saved in ${POSSIBLE_DYNAMIC_KEYS_FILE}
|
|
85
|
+
`${Object.keys(possibleDynamicKeys).length} files contain possible dynamic keys were saved in ${POSSIBLE_DYNAMIC_KEYS_FILE}`.yellow.bold,
|
|
84
86
|
);
|
|
85
87
|
writeFileSync(
|
|
86
88
|
POSSIBLE_DYNAMIC_KEYS_FILE,
|
|
@@ -89,7 +91,7 @@ function extractTranslationKeys() {
|
|
|
89
91
|
} else if (existsSync(POSSIBLE_DYNAMIC_KEYS_FILE)) {
|
|
90
92
|
unlinkSync(POSSIBLE_DYNAMIC_KEYS_FILE);
|
|
91
93
|
console.log(
|
|
92
|
-
`${POSSIBLE_DYNAMIC_KEYS_FILE} was deleted as there are no possible dynamic keys
|
|
94
|
+
`${POSSIBLE_DYNAMIC_KEYS_FILE} was deleted as there are no possible dynamic keys.`.green.bold,
|
|
93
95
|
);
|
|
94
96
|
}
|
|
95
97
|
|
|
@@ -113,9 +115,8 @@ function compareKeys() {
|
|
|
113
115
|
|
|
114
116
|
const allValidKeys = new Set(Object.keys(translations));
|
|
115
117
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
missingKeys = missingKeys.filter(key => key != null && key !== undefined);
|
|
118
|
+
const missingKeys = [...appKeys].filter(key => !allValidKeys.has(key))
|
|
119
|
+
.filter(key => key != null && key !== undefined);
|
|
119
120
|
|
|
120
121
|
// Check if there are keys in dynamicKeys that are missing from allValidKeys.
|
|
121
122
|
dynamicKeys.forEach(key => {
|
|
@@ -131,29 +132,31 @@ function compareKeys() {
|
|
|
131
132
|
|
|
132
133
|
if (missingKeys.length > 0) {
|
|
133
134
|
writeFileSync(MISSING_KEYS_FILE, JSON.stringify(missingKeys, null, 2));
|
|
134
|
-
console.
|
|
135
|
-
`${missingKeys.length} missing keys were
|
|
135
|
+
console.error(
|
|
136
|
+
`${missingKeys.length} missing keys were found. Please check ${MISSING_KEYS_FILE} for details.`.red.bold,
|
|
136
137
|
);
|
|
138
|
+
process.exit(1);
|
|
137
139
|
} else if (existsSync(MISSING_KEYS_FILE)) {
|
|
138
140
|
unlinkSync(MISSING_KEYS_FILE);
|
|
139
141
|
console.log(
|
|
140
|
-
`${MISSING_KEYS_FILE} was deleted as there are no missing keys
|
|
142
|
+
`${MISSING_KEYS_FILE} was deleted as there are no missing keys.`.green.bold,
|
|
141
143
|
);
|
|
142
144
|
}
|
|
143
145
|
|
|
144
146
|
if (unusedKeys.length > 0) {
|
|
145
147
|
writeFileSync(UNUSED_KEYS_FILE, JSON.stringify(unusedKeys, null, 2));
|
|
146
148
|
console.log(
|
|
147
|
-
`${unusedKeys.length} unused keys were saved in ${UNUSED_KEYS_FILE}
|
|
149
|
+
`${unusedKeys.length} unused keys were saved in ${UNUSED_KEYS_FILE}`.yellow.bold,
|
|
148
150
|
);
|
|
149
151
|
} else if (existsSync(UNUSED_KEYS_FILE)) {
|
|
150
152
|
unlinkSync(UNUSED_KEYS_FILE);
|
|
151
153
|
console.log(
|
|
152
|
-
`${UNUSED_KEYS_FILE} was deleted as there are no
|
|
154
|
+
`${UNUSED_KEYS_FILE} was deleted as there are no unused keys.`.green.bold,
|
|
153
155
|
);
|
|
154
156
|
}
|
|
155
157
|
} catch (error) {
|
|
156
|
-
console.error(error);
|
|
158
|
+
console.error(`Error: ${error.message}`.red.bold);
|
|
159
|
+
process.exit(1);
|
|
157
160
|
}
|
|
158
161
|
}
|
|
159
162
|
|
package/index.js
CHANGED