poly-lexis 0.2.0 → 0.2.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.
- package/README.md +40 -0
- package/dist/cli/translations.js +27 -19
- package/dist/cli/translations.js.map +1 -1
- package/dist/index.d.ts +5 -4
- package/dist/index.js +15 -11
- package/dist/index.js.map +1 -1
- package/dist/scripts/verify-translations.js +470 -0
- package/dist/scripts/verify-translations.js.map +1 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -79,6 +79,46 @@ poly-lexis add --namespace common --key HELLO --value "Hello"
|
|
|
79
79
|
poly-lexis add -n common -k WELCOME -v "Welcome" --auto-fill
|
|
80
80
|
```
|
|
81
81
|
|
|
82
|
+
### Verify Translations (CI/CD)
|
|
83
|
+
|
|
84
|
+
For CI/CD pipelines, you can validate translations and fail the build if any are missing:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
# In your project that uses poly-lexis
|
|
88
|
+
npx poly-lexis --skip-types # Validates translations, exits with code 1 if invalid
|
|
89
|
+
|
|
90
|
+
# Or create a script in your package.json:
|
|
91
|
+
{
|
|
92
|
+
"scripts": {
|
|
93
|
+
"verify-translations": "poly-lexis --skip-types"
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
# Then run in your CI/CD pipeline:
|
|
98
|
+
npm run verify-translations
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
The command will:
|
|
102
|
+
- ✅ Exit with code 0 if all translations are valid
|
|
103
|
+
- ❌ Exit with code 1 if any translations are missing or empty
|
|
104
|
+
|
|
105
|
+
This makes it perfect for CI/CD checks to prevent incomplete translations from being deployed.
|
|
106
|
+
|
|
107
|
+
**Example CI/CD workflow (GitHub Actions):**
|
|
108
|
+
|
|
109
|
+
```yaml
|
|
110
|
+
name: Verify Translations
|
|
111
|
+
on: [push, pull_request]
|
|
112
|
+
jobs:
|
|
113
|
+
verify:
|
|
114
|
+
runs-on: ubuntu-latest
|
|
115
|
+
steps:
|
|
116
|
+
- uses: actions/checkout@v3
|
|
117
|
+
- uses: actions/setup-node@v3
|
|
118
|
+
- run: npm install
|
|
119
|
+
- run: npx poly-lexis --skip-types
|
|
120
|
+
```
|
|
121
|
+
|
|
82
122
|
### CLI Options
|
|
83
123
|
|
|
84
124
|
**Smart Mode:**
|
package/dist/cli/translations.js
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
5
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
6
|
-
}) : x)(function(x) {
|
|
7
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
8
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
9
|
-
});
|
|
10
4
|
var __esm = (fn, res) => function __init() {
|
|
11
5
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
12
6
|
};
|
|
@@ -149,6 +143,8 @@ var init_schema = __esm({
|
|
|
149
143
|
// Chinese (Simplified) - alternative format
|
|
150
144
|
"zh_tw",
|
|
151
145
|
// Chinese (Traditional)
|
|
146
|
+
"zh_hk",
|
|
147
|
+
// Chinese (Hong Kong)
|
|
152
148
|
"co",
|
|
153
149
|
// Corsican
|
|
154
150
|
"hr",
|
|
@@ -183,6 +179,8 @@ var init_schema = __esm({
|
|
|
183
179
|
// Georgian
|
|
184
180
|
"de",
|
|
185
181
|
// German
|
|
182
|
+
"de_at",
|
|
183
|
+
// German (Austria)
|
|
186
184
|
"el",
|
|
187
185
|
// Greek
|
|
188
186
|
"gn",
|
|
@@ -546,7 +544,7 @@ __export(generate_types_exports, {
|
|
|
546
544
|
generateTranslationTypes: () => generateTranslationTypes
|
|
547
545
|
});
|
|
548
546
|
import { execSync } from "child_process";
|
|
549
|
-
import * as
|
|
547
|
+
import * as fs4 from "fs";
|
|
550
548
|
import * as path8 from "path";
|
|
551
549
|
function generateTranslationTypes(projectRoot = process.cwd()) {
|
|
552
550
|
console.log("=====");
|
|
@@ -558,7 +556,7 @@ function generateTranslationTypes(projectRoot = process.cwd()) {
|
|
|
558
556
|
const sourceLanguage = config.sourceLanguage;
|
|
559
557
|
const outputFilePath = path8.join(projectRoot, config.typesOutputPath);
|
|
560
558
|
const dirPath = path8.join(translationsPath, sourceLanguage);
|
|
561
|
-
if (!
|
|
559
|
+
if (!fs4.existsSync(dirPath)) {
|
|
562
560
|
throw new Error(`Source language directory not found: ${dirPath}`);
|
|
563
561
|
}
|
|
564
562
|
const namespaces = getNamespaces(translationsPath, sourceLanguage);
|
|
@@ -572,11 +570,11 @@ function generateTranslationTypes(projectRoot = process.cwd()) {
|
|
|
572
570
|
allKeys = allKeys.concat(keys);
|
|
573
571
|
}
|
|
574
572
|
const outputDir = path8.dirname(outputFilePath);
|
|
575
|
-
if (!
|
|
576
|
-
|
|
573
|
+
if (!fs4.existsSync(outputDir)) {
|
|
574
|
+
fs4.mkdirSync(outputDir, { recursive: true });
|
|
577
575
|
}
|
|
578
576
|
const typeString = typeTemplate(allKeys, namespaces);
|
|
579
|
-
|
|
577
|
+
fs4.writeFileSync(outputFilePath, typeString, "utf8");
|
|
580
578
|
console.log(`Generated types with ${allKeys.length} keys and ${namespaces.length} namespaces`);
|
|
581
579
|
console.log(`Output: ${outputFilePath}`);
|
|
582
580
|
try {
|
|
@@ -610,7 +608,7 @@ var init_generate_types = __esm({
|
|
|
610
608
|
// src/cli/translations.ts
|
|
611
609
|
init_esm_shims();
|
|
612
610
|
import "dotenv/config";
|
|
613
|
-
import * as
|
|
611
|
+
import * as fs6 from "fs";
|
|
614
612
|
import * as path10 from "path";
|
|
615
613
|
import { parseArgs } from "util";
|
|
616
614
|
import { confirm as confirm2, input as input2, select } from "@inquirer/prompts";
|
|
@@ -792,12 +790,13 @@ init_esm_shims();
|
|
|
792
790
|
init_schema();
|
|
793
791
|
init_types();
|
|
794
792
|
init_init();
|
|
793
|
+
import * as fs3 from "fs";
|
|
795
794
|
import * as path5 from "path";
|
|
796
795
|
import { checkbox, confirm, input } from "@inquirer/prompts";
|
|
797
796
|
async function initTranslationsInteractive(projectRoot = process.cwd()) {
|
|
798
797
|
console.log("\n\u{1F30D} Translation System Setup\n");
|
|
799
798
|
const configPath = path5.join(projectRoot, ".translationsrc.json");
|
|
800
|
-
const alreadyExists =
|
|
799
|
+
const alreadyExists = fs3.existsSync(configPath);
|
|
801
800
|
if (alreadyExists) {
|
|
802
801
|
console.log("\u26A0\uFE0F Configuration file already exists at .translationsrc.json\n");
|
|
803
802
|
const shouldOverwrite = await confirm({
|
|
@@ -947,7 +946,7 @@ function getLanguageName(code) {
|
|
|
947
946
|
|
|
948
947
|
// src/translations/cli/manage.ts
|
|
949
948
|
init_esm_shims();
|
|
950
|
-
import * as
|
|
949
|
+
import * as fs5 from "fs";
|
|
951
950
|
import * as path9 from "path";
|
|
952
951
|
|
|
953
952
|
// src/translations/cli/auto-fill.ts
|
|
@@ -1119,7 +1118,7 @@ async function manageTranslations(projectRoot = process.cwd(), options = {}) {
|
|
|
1119
1118
|
console.log("Translation Management");
|
|
1120
1119
|
console.log("=====");
|
|
1121
1120
|
const configPath = path9.join(projectRoot, ".translationsrc.json");
|
|
1122
|
-
const isInitialized =
|
|
1121
|
+
const isInitialized = fs5.existsSync(configPath);
|
|
1123
1122
|
if (!isInitialized) {
|
|
1124
1123
|
console.log("\u{1F4C1} No translation configuration found. Initializing...\n");
|
|
1125
1124
|
initTranslations(projectRoot);
|
|
@@ -1130,10 +1129,10 @@ async function manageTranslations(projectRoot = process.cwd(), options = {}) {
|
|
|
1130
1129
|
const config = loadConfig(projectRoot);
|
|
1131
1130
|
const translationsPath = path9.join(projectRoot, config.translationsPath);
|
|
1132
1131
|
const sourceLangPath = path9.join(translationsPath, config.sourceLanguage);
|
|
1133
|
-
if (!
|
|
1132
|
+
if (!fs5.existsSync(sourceLangPath)) {
|
|
1134
1133
|
console.log(`\u26A0\uFE0F Source language directory not found: ${sourceLangPath}`);
|
|
1135
1134
|
console.log("Please add translation files to the source language directory.\n");
|
|
1136
|
-
return;
|
|
1135
|
+
return false;
|
|
1137
1136
|
}
|
|
1138
1137
|
console.log("\u{1F50D} Validating translations...\n");
|
|
1139
1138
|
const validationResult = validateTranslations(projectRoot);
|
|
@@ -1197,6 +1196,11 @@ async function manageTranslations(projectRoot = process.cwd(), options = {}) {
|
|
|
1197
1196
|
console.log("\n\u2705 All systems ready!");
|
|
1198
1197
|
}
|
|
1199
1198
|
console.log("=====\n");
|
|
1199
|
+
if (autoFill && !dryRun && apiKey) {
|
|
1200
|
+
const finalValidation = validateTranslations(projectRoot);
|
|
1201
|
+
return finalValidation.valid;
|
|
1202
|
+
}
|
|
1203
|
+
return validationResult.valid;
|
|
1200
1204
|
}
|
|
1201
1205
|
|
|
1202
1206
|
// src/cli/translations.ts
|
|
@@ -1314,7 +1318,7 @@ if (command === "add") {
|
|
|
1314
1318
|
try {
|
|
1315
1319
|
console.log("\n\u2728 Add a new translation key\n");
|
|
1316
1320
|
const configPath = path10.join(process.cwd(), ".translationsrc.json");
|
|
1317
|
-
const isInitialized =
|
|
1321
|
+
const isInitialized = fs6.existsSync(configPath);
|
|
1318
1322
|
if (!isInitialized) {
|
|
1319
1323
|
console.log("\u26A0\uFE0F Translation structure not initialized.");
|
|
1320
1324
|
const shouldInit = await confirm2({
|
|
@@ -1458,6 +1462,10 @@ if (command === "add") {
|
|
|
1458
1462
|
language: values.language,
|
|
1459
1463
|
skipTypes: values["skip-types"],
|
|
1460
1464
|
dryRun: values["dry-run"]
|
|
1465
|
+
}).then((isValid) => {
|
|
1466
|
+
if (!isValid) {
|
|
1467
|
+
process.exit(1);
|
|
1468
|
+
}
|
|
1461
1469
|
}).catch((error) => {
|
|
1462
1470
|
console.error("Error:", error instanceof Error ? error.message : error);
|
|
1463
1471
|
process.exit(1);
|
|
@@ -1466,7 +1474,7 @@ if (command === "add") {
|
|
|
1466
1474
|
(async () => {
|
|
1467
1475
|
try {
|
|
1468
1476
|
const configPath = path10.join(process.cwd(), ".translationsrc.json");
|
|
1469
|
-
const isInitialized =
|
|
1477
|
+
const isInitialized = fs6.existsSync(configPath);
|
|
1470
1478
|
console.log("\n\u{1F30D} Translation Management\n");
|
|
1471
1479
|
const action = await select({
|
|
1472
1480
|
message: "What would you like to do?",
|