@kopynator/cli 1.0.12 ā 1.0.13
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/dist/index.js +26 -20
- package/package.json +3 -2
- package/src/commands/sync.ts +31 -23
package/dist/index.js
CHANGED
|
@@ -205,6 +205,7 @@ var import_chalk3 = __toESM(require("chalk"));
|
|
|
205
205
|
var import_fs3 = __toESM(require("fs"));
|
|
206
206
|
var import_path3 = __toESM(require("path"));
|
|
207
207
|
var import_inquirer2 = __toESM(require("inquirer"));
|
|
208
|
+
var import_ora = __toESM(require("ora"));
|
|
208
209
|
function detectFramework() {
|
|
209
210
|
const angularJson = import_path3.default.join(process.cwd(), "angular.json");
|
|
210
211
|
const packageJson = import_path3.default.join(process.cwd(), "package.json");
|
|
@@ -334,44 +335,49 @@ async function syncCommand() {
|
|
|
334
335
|
const syncConfig = await getSyncConfig();
|
|
335
336
|
const baseUrl = config.baseUrl || "http://localhost:7300/api/tokens";
|
|
336
337
|
const token = config.apiKey;
|
|
338
|
+
const spinner = (0, import_ora.default)("\u{1F4E1} Connecting to Kopynator Cloud...").start();
|
|
337
339
|
try {
|
|
338
|
-
|
|
340
|
+
spinner.text = "\u{1F4E1} Fetching available languages...";
|
|
339
341
|
const languagesUrl = `${baseUrl}/languages?token=${token}`;
|
|
340
342
|
const languagesResponse = await fetch(languagesUrl);
|
|
341
343
|
if (!languagesResponse.ok) {
|
|
342
|
-
|
|
344
|
+
spinner.fail(`Failed to fetch languages: ${languagesResponse.status} ${languagesResponse.statusText}`);
|
|
343
345
|
return;
|
|
344
346
|
}
|
|
345
347
|
const languages = await languagesResponse.json();
|
|
346
|
-
|
|
348
|
+
spinner.succeed(`Found ${languages.length} language(s): ${languages.join(", ")}`);
|
|
347
349
|
const i18nDir = getTranslationDir(framework);
|
|
348
350
|
if (!import_fs3.default.existsSync(i18nDir)) {
|
|
349
351
|
import_fs3.default.mkdirSync(i18nDir, { recursive: true });
|
|
350
352
|
console.log(import_chalk3.default.blue(`\u{1F4C1} Created directory: ${i18nDir}`));
|
|
351
353
|
}
|
|
352
354
|
for (const locale of languages) {
|
|
353
|
-
|
|
355
|
+
const downloadSpinner = (0, import_ora.default)(`\u2B07\uFE0F Downloading ${locale}...`).start();
|
|
354
356
|
const fetchUrl = `${baseUrl}/fetch?token=${token}&langs=${locale}&nested=${syncConfig.nested}&includeLangKey=${syncConfig.includeLangKey}&pretty=${syncConfig.pretty}&indent=${syncConfig.indent}`;
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
357
|
+
try {
|
|
358
|
+
const translationResponse = await fetch(fetchUrl);
|
|
359
|
+
if (!translationResponse.ok) {
|
|
360
|
+
downloadSpinner.warn(`Failed to fetch ${locale}: ${translationResponse.status}`);
|
|
361
|
+
continue;
|
|
362
|
+
}
|
|
363
|
+
const translationData = await translationResponse.json();
|
|
364
|
+
const outputPath = import_path3.default.join(i18nDir, `${locale}.json`);
|
|
365
|
+
let jsonString;
|
|
366
|
+
if (syncConfig.pretty) {
|
|
367
|
+
const indentValue = syncConfig.indent === "tab" ? " " : Number(syncConfig.indent);
|
|
368
|
+
jsonString = JSON.stringify(translationData, null, indentValue);
|
|
369
|
+
} else {
|
|
370
|
+
jsonString = JSON.stringify(translationData);
|
|
371
|
+
}
|
|
372
|
+
import_fs3.default.writeFileSync(outputPath, jsonString);
|
|
373
|
+
downloadSpinner.succeed(`Saved ${locale}.json`);
|
|
374
|
+
} catch (err) {
|
|
375
|
+
downloadSpinner.fail(`Error downloading ${locale}: ${err instanceof Error ? err.message : "Unknown error"}`);
|
|
368
376
|
}
|
|
369
|
-
import_fs3.default.writeFileSync(outputPath, jsonString);
|
|
370
|
-
console.log(import_chalk3.default.green(`\u2705 Saved ${locale}.json`));
|
|
371
377
|
}
|
|
372
378
|
console.log(import_chalk3.default.bold.green("\n\u{1F389} Sync completed successfully!\n"));
|
|
373
379
|
} catch (error) {
|
|
374
|
-
|
|
380
|
+
spinner.fail(`Sync failed: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
375
381
|
}
|
|
376
382
|
}
|
|
377
383
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kopynator/cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.13",
|
|
4
4
|
"description": "CLI tool for Kopynator - The i18n management solution",
|
|
5
5
|
"bin": {
|
|
6
6
|
"kopynator": "dist/index.js"
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"chalk": "^4.1.2",
|
|
26
26
|
"commander": "^11.1.0",
|
|
27
|
-
"inquirer": "^8.2.6"
|
|
27
|
+
"inquirer": "^8.2.6",
|
|
28
|
+
"ora": "^5.4.1"
|
|
28
29
|
},
|
|
29
30
|
"devDependencies": {
|
|
30
31
|
"@types/inquirer": "^9.0.7",
|
package/src/commands/sync.ts
CHANGED
|
@@ -2,6 +2,7 @@ import chalk from 'chalk';
|
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import inquirer from 'inquirer';
|
|
5
|
+
import ora from 'ora';
|
|
5
6
|
|
|
6
7
|
interface KopyConfig {
|
|
7
8
|
apiKey: string;
|
|
@@ -195,19 +196,21 @@ export async function syncCommand() {
|
|
|
195
196
|
const baseUrl = config.baseUrl || 'http://localhost:7300/api/tokens';
|
|
196
197
|
const token = config.apiKey;
|
|
197
198
|
|
|
199
|
+
const spinner = ora('š” Connecting to Kopynator Cloud...').start();
|
|
200
|
+
|
|
198
201
|
try {
|
|
199
202
|
// 1. Fetch available languages
|
|
200
|
-
|
|
203
|
+
spinner.text = 'š” Fetching available languages...';
|
|
201
204
|
const languagesUrl = `${baseUrl}/languages?token=${token}`;
|
|
202
205
|
const languagesResponse = await fetch(languagesUrl);
|
|
203
206
|
|
|
204
207
|
if (!languagesResponse.ok) {
|
|
205
|
-
|
|
208
|
+
spinner.fail(`Failed to fetch languages: ${languagesResponse.status} ${languagesResponse.statusText}`);
|
|
206
209
|
return;
|
|
207
210
|
}
|
|
208
211
|
|
|
209
212
|
const languages = await languagesResponse.json() as string[];
|
|
210
|
-
|
|
213
|
+
spinner.succeed(`Found ${languages.length} language(s): ${languages.join(', ')}`);
|
|
211
214
|
|
|
212
215
|
// 2. Get translation directory based on framework
|
|
213
216
|
const i18nDir = getTranslationDir(framework);
|
|
@@ -218,33 +221,38 @@ export async function syncCommand() {
|
|
|
218
221
|
|
|
219
222
|
// 3. Download translations for each language
|
|
220
223
|
for (const locale of languages) {
|
|
221
|
-
|
|
224
|
+
const downloadSpinner = ora(`ā¬ļø Downloading ${locale}...`).start();
|
|
222
225
|
const fetchUrl = `${baseUrl}/fetch?token=${token}&langs=${locale}&nested=${syncConfig.nested}&includeLangKey=${syncConfig.includeLangKey}&pretty=${syncConfig.pretty}&indent=${syncConfig.indent}`;
|
|
223
|
-
|
|
226
|
+
|
|
227
|
+
try {
|
|
228
|
+
const translationResponse = await fetch(fetchUrl);
|
|
224
229
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
230
|
+
if (!translationResponse.ok) {
|
|
231
|
+
downloadSpinner.warn(`Failed to fetch ${locale}: ${translationResponse.status}`);
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
229
234
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
235
|
+
const translationData = await translationResponse.json();
|
|
236
|
+
const outputPath = path.join(i18nDir, `${locale}.json`);
|
|
237
|
+
|
|
238
|
+
// Format based on config
|
|
239
|
+
let jsonString: string;
|
|
240
|
+
if (syncConfig.pretty) {
|
|
241
|
+
const indentValue = syncConfig.indent === 'tab' ? '\t' : Number(syncConfig.indent);
|
|
242
|
+
jsonString = JSON.stringify(translationData, null, indentValue);
|
|
243
|
+
} else {
|
|
244
|
+
jsonString = JSON.stringify(translationData);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
fs.writeFileSync(outputPath, jsonString);
|
|
248
|
+
downloadSpinner.succeed(`Saved ${locale}.json`);
|
|
249
|
+
} catch (err) {
|
|
250
|
+
downloadSpinner.fail(`Error downloading ${locale}: ${err instanceof Error ? err.message : 'Unknown error'}`);
|
|
240
251
|
}
|
|
241
|
-
|
|
242
|
-
fs.writeFileSync(outputPath, jsonString);
|
|
243
|
-
console.log(chalk.green(`ā
Saved ${locale}.json`));
|
|
244
252
|
}
|
|
245
253
|
|
|
246
254
|
console.log(chalk.bold.green('\nš Sync completed successfully!\n'));
|
|
247
255
|
} catch (error) {
|
|
248
|
-
|
|
256
|
+
spinner.fail(`Sync failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
249
257
|
}
|
|
250
258
|
}
|