lezu 0.0.41 → 0.0.42

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 DELETED
@@ -1,784 +0,0 @@
1
- import {
2
- createLoadCommand
3
- } from "./chunk-4LVALDII.js";
4
- import {
5
- createGetCommand
6
- } from "./chunk-NQBVD6F7.js";
7
- import {
8
- loadConfig,
9
- validateConfig
10
- } from "./chunk-EDQCBUBB.js";
11
- import {
12
- LezuApiClient
13
- } from "./chunk-HFRJAE6K.js";
14
-
15
- // src/index.ts
16
- import { program } from "commander";
17
- import chalk4 from "chalk";
18
-
19
- // src/commands/add.ts
20
- import { Command } from "commander";
21
- import chalk from "chalk";
22
- import ora from "ora";
23
- function createAddCommand() {
24
- const command = new Command("add").description("Add a new translation key with values").requiredOption("-k, --key <key>", 'Translation key (e.g., "common.save")').option("-v, --value <value>", "Value for the source language").option("--en <value>", "English translation").option("--es <value>", "Spanish translation").option("--fr <value>", "French translation").option("--de <value>", "German translation").option("--nl <value>", "Dutch translation").option("--it <value>", "Italian translation").option("--pt <value>", "Portuguese translation").option("--ru <value>", "Russian translation").option("--ja <value>", "Japanese translation").option("--ko <value>", "Korean translation").option("--zh <value>", "Chinese translation").option("--ar <value>", "Arabic translation").option("-d, --description <desc>", "Description for the translation key").option("-p, --project <id>", "Project ID").option("-a, --api-key <key>", "API key").option("--api-url <url>", "API URL", "https://api.lezu.app").option("--auto", "Auto-translate to all enabled languages").action(async (options) => {
25
- try {
26
- const config = loadConfig(options);
27
- const errors = validateConfig(config);
28
- if (errors.length > 0) {
29
- console.error(chalk.red("Configuration errors:"));
30
- errors.forEach((error) => console.error(chalk.red(` - ${error}`)));
31
- process.exit(1);
32
- }
33
- const translations = {};
34
- const languageOptions = ["en", "es", "fr", "de", "nl", "it", "pt", "ru", "ja", "ko", "zh", "ar"];
35
- languageOptions.forEach((lang) => {
36
- if (options[lang]) {
37
- translations[lang] = options[lang];
38
- }
39
- });
40
- if (options.value && Object.keys(translations).length === 0) {
41
- const spinner2 = ora("Getting project information...").start();
42
- const client = new LezuApiClient(config);
43
- try {
44
- const { project } = await client.getProject();
45
- const sourceLanguage = project.source_language || "en";
46
- translations[sourceLanguage] = options.value;
47
- spinner2.succeed(`Using ${sourceLanguage} as source language`);
48
- } catch (error) {
49
- spinner2.fail("Failed to get project information");
50
- translations["en"] = options.value;
51
- }
52
- }
53
- await addTranslationKey(config, {
54
- key: options.key,
55
- description: options.description,
56
- translations,
57
- auto: options.auto
58
- });
59
- } catch (error) {
60
- console.error(chalk.red("\n[Error]"), error instanceof Error ? error.message : error);
61
- process.exit(1);
62
- }
63
- });
64
- return command;
65
- }
66
- async function addTranslationKey(config, options) {
67
- const spinner2 = ora("Adding translation key...").start();
68
- try {
69
- const client = new LezuApiClient(config);
70
- const response = await client.addTranslationKey(options.key, options.translations);
71
- spinner2.succeed("Translation key added successfully!");
72
- console.log(chalk.green("\n[Success] Key added:"));
73
- console.log(chalk.gray(` - Key: ${options.key}`));
74
- if (options.description) {
75
- console.log(chalk.gray(` - Description: ${options.description}`));
76
- }
77
- console.log(chalk.gray(` - Languages: ${Object.keys(options.translations).join(", ")}`));
78
- if (Object.keys(options.translations).length > 0) {
79
- console.log(chalk.gray("\n Translations:"));
80
- Object.entries(options.translations).forEach(([lang, value]) => {
81
- console.log(chalk.gray(` ${lang}: "${value}"`));
82
- });
83
- }
84
- if (options.auto) {
85
- console.log(chalk.cyan("\n[AI] Auto-translation was enabled. Check the dashboard to review AI-generated translations."));
86
- }
87
- } catch (error) {
88
- spinner2.fail("Failed to add translation key");
89
- throw error;
90
- }
91
- }
92
-
93
- // src/commands/release.ts
94
- import { Command as Command2 } from "commander";
95
- import chalk2 from "chalk";
96
- import ora2 from "ora";
97
- function createReleaseCommand() {
98
- const command = new Command2("release").description("Manage releases");
99
- command.command("create").alias("new").description("Create a new release").option("-r, --release-version <version>", 'Release version (e.g., "1.0.0")').option("-n, --name <name>", "Release name").option("-d, --description <desc>", "Release description").option("-e, --environment <env>", "Environment", "production").option("-p, --project <id>", "Project ID").option("-a, --api-key <key>", "API key").option("--api-url <url>", "API URL", "https://api.lezu.app").option("--reviewed-only", "Include only reviewed translations").option("--set-current", "Set this release as the current release").option("--timestamp <iso>", "Specific timestamp for the release (ISO format)").option("--languages <langs>", "Comma-separated list of languages to include").option("--json", "Output as JSON").action(async (options) => {
100
- try {
101
- const config = loadConfig(options);
102
- const errors = validateConfig(config);
103
- if (errors.length > 0) {
104
- console.error(chalk2.red("Configuration errors:"));
105
- errors.forEach((error) => console.error(chalk2.red(` - ${error}`)));
106
- process.exit(1);
107
- }
108
- await createRelease(config, options);
109
- } catch (error) {
110
- console.error(chalk2.red("\n[Error]"), error instanceof Error ? error.message : error);
111
- process.exit(1);
112
- }
113
- });
114
- command.command("current <releaseId>").description("Set a release as current").option("-p, --project <id>", "Project ID").option("-a, --api-key <key>", "API key").option("--api-url <url>", "API URL", "https://api.lezu.app").option("--json", "Output as JSON").action(async (releaseId, options) => {
115
- try {
116
- const config = loadConfig(options);
117
- const errors = validateConfig(config);
118
- if (errors.length > 0) {
119
- console.error(chalk2.red("Configuration errors:"));
120
- errors.forEach((error) => console.error(chalk2.red(` - ${error}`)));
121
- process.exit(1);
122
- }
123
- await setCurrentRelease(config, releaseId, options);
124
- } catch (error) {
125
- console.error(chalk2.red("\n[Error]"), error instanceof Error ? error.message : error);
126
- process.exit(1);
127
- }
128
- });
129
- command.command("list").alias("ls").description("List all releases").option("-p, --project <id>", "Project ID").option("-a, --api-key <key>", "API key").option("--api-url <url>", "API URL", "https://api.lezu.app").option("-e, --environment <env>", "Environment", "production").option("--json", "Output as JSON").option("--limit <n>", "Limit number of results", "10").action(async (options) => {
130
- try {
131
- const config = loadConfig(options);
132
- const errors = validateConfig(config);
133
- if (errors.length > 0) {
134
- console.error(chalk2.red("Configuration errors:"));
135
- errors.forEach((error) => console.error(chalk2.red(` - ${error}`)));
136
- process.exit(1);
137
- }
138
- const { getReleases } = await import("./get-2SEC6NXW.js");
139
- await getReleases(config, options);
140
- } catch (error) {
141
- console.error(chalk2.red("\n[Error]"), error instanceof Error ? error.message : error);
142
- process.exit(1);
143
- }
144
- });
145
- return command;
146
- }
147
- async function createRelease(config, options) {
148
- const spinner2 = ora2("Creating release...").start();
149
- try {
150
- const client = new LezuApiClient(config);
151
- const languages = options.languages ? options.languages.split(",").map((l) => l.trim()) : void 0;
152
- let timestamp;
153
- if (options.timestamp) {
154
- try {
155
- timestamp = new Date(options.timestamp).toISOString();
156
- } catch (error) {
157
- throw new Error("Invalid timestamp format. Use ISO format (e.g., 2023-12-01T10:00:00Z)");
158
- }
159
- }
160
- const releaseData = {
161
- environment: options.environment,
162
- version: options.releaseVersion,
163
- name: options.name,
164
- description: options.description,
165
- reviewedOnly: options.reviewedOnly || false,
166
- setAsCurrent: options.setCurrent || false,
167
- timestamp,
168
- languages
169
- };
170
- spinner2.text = "Creating release and generating bundles...";
171
- const response = await client.createRelease(releaseData);
172
- spinner2.succeed("Release created successfully!");
173
- if (options.json) {
174
- console.log(JSON.stringify(response, null, 2));
175
- return;
176
- }
177
- console.log(chalk2.green("\n[Release Created]"));
178
- console.log(` ID: ${response.release.id}`);
179
- console.log(` Version: ${response.release.version}`);
180
- if (response.release.name) {
181
- console.log(` Name: ${response.release.name}`);
182
- }
183
- if (response.release.description) {
184
- console.log(` Description: ${response.release.description}`);
185
- }
186
- console.log(` Environment: ${response.release.environment?.name || options.environment}`);
187
- console.log(` Reviewed Only: ${response.release.reviewed_only ? "Yes" : "No"}`);
188
- console.log(` Is Current: ${response.release.is_current ? "Yes" : "No"}`);
189
- console.log(` Created: ${new Date(response.release.created_at).toLocaleString()}`);
190
- if (response.release.artifacts && response.release.artifacts.length > 0) {
191
- console.log(chalk2.green("\n[Bundles Generated]"));
192
- response.release.artifacts.forEach((artifact) => {
193
- const sizeKB = Math.round(artifact.file_size / 1024);
194
- console.log(` - ${artifact.language_code}: ${sizeKB}KB`);
195
- });
196
- console.log(chalk2.gray(`
197
- Total: ${response.release.artifacts.length} language bundles`));
198
- }
199
- console.log(chalk2.cyan("\n[Tip] You can now use this release with:"));
200
- console.log(chalk2.gray(` npx lezu load --release ${response.release.id}`));
201
- if (response.release.is_current) {
202
- console.log(chalk2.green("\n[Success] This release is now set as current!"));
203
- }
204
- } catch (error) {
205
- spinner2.fail("Failed to create release");
206
- throw error;
207
- }
208
- }
209
- async function setCurrentRelease(config, releaseId, options) {
210
- const spinner2 = ora2("Setting release as current...").start();
211
- try {
212
- const response = await fetch(`${config.apiUrl}/v1/releases/${releaseId}/current`, {
213
- method: "PUT",
214
- headers: {
215
- "Authorization": `Bearer ${config.apiKey}`,
216
- "Content-Type": "application/json"
217
- }
218
- });
219
- if (!response.ok) {
220
- const error = await response.text();
221
- throw new Error(`Failed to set current release: ${response.status} ${response.statusText}
222
- ${error}`);
223
- }
224
- const data = await response.json();
225
- spinner2.succeed("Release set as current!");
226
- if (options.json) {
227
- console.log(JSON.stringify(data, null, 2));
228
- return;
229
- }
230
- console.log(chalk2.green("\n[Release Updated]"));
231
- console.log(` Release ID: ${releaseId}`);
232
- console.log(" Status: Now set as current release");
233
- console.log(chalk2.cyan("\n[Info] All new bundle requests will now use this release"));
234
- } catch (error) {
235
- spinner2.fail("Failed to set release as current");
236
- throw error;
237
- }
238
- }
239
-
240
- // src/interactive.ts
241
- import { intro, outro, select, text, confirm, spinner, cancel, isCancel } from "@clack/prompts";
242
- import chalk3 from "chalk";
243
- async function interactiveMode(initialConfig) {
244
- intro(chalk3.cyan("Welcome to Lezu CLI!"));
245
- try {
246
- const command = await select({
247
- message: "What would you like to do?",
248
- options: [
249
- { value: "load", label: "Load translation files" },
250
- { value: "add", label: "Add a new translation key" },
251
- { value: "get", label: "Get project information" },
252
- { value: "release", label: "Manage releases" }
253
- ]
254
- });
255
- if (isCancel(command)) {
256
- cancel("Operation cancelled");
257
- process.exit(0);
258
- }
259
- const projectId = await text({
260
- message: "Project ID",
261
- placeholder: "Enter your project ID",
262
- initialValue: initialConfig.projectId || "",
263
- validate: (value) => {
264
- if (!value) return "Project ID is required";
265
- }
266
- });
267
- if (isCancel(projectId)) {
268
- cancel("Operation cancelled");
269
- process.exit(0);
270
- }
271
- const apiKey = await text({
272
- message: "API Key",
273
- placeholder: "Enter your API key",
274
- initialValue: initialConfig.apiKey || "",
275
- validate: (value) => {
276
- if (!value) return "API Key is required";
277
- }
278
- });
279
- if (isCancel(apiKey)) {
280
- cancel("Operation cancelled");
281
- process.exit(0);
282
- }
283
- const config = loadConfig({ projectId, apiKey, ...initialConfig });
284
- const validationSpinner = spinner();
285
- validationSpinner.start("Validating credentials...");
286
- try {
287
- const { LezuApiClient: LezuApiClient2 } = await import("./api-G2AOOTDN.js");
288
- const client = new LezuApiClient2(config);
289
- await client.validateCredentials();
290
- validationSpinner.stop("Credentials validated!");
291
- } catch (error) {
292
- if (error instanceof Error) {
293
- validationSpinner.stop("Invalid credentials");
294
- outro(chalk3.red(error.message));
295
- } else {
296
- validationSpinner.stop("Failed to validate credentials");
297
- outro(chalk3.red("Could not connect to Lezu API"));
298
- }
299
- process.exit(1);
300
- }
301
- switch (command) {
302
- case "load":
303
- await configureLoadCommand(config);
304
- break;
305
- case "add":
306
- await configureAddCommand(config);
307
- break;
308
- case "get":
309
- await configureGetCommand(config);
310
- break;
311
- case "release":
312
- await configureReleaseCommand(config);
313
- break;
314
- }
315
- outro(chalk3.green("Done!"));
316
- } catch (error) {
317
- if (error instanceof Error) {
318
- outro(chalk3.red(error.message));
319
- } else {
320
- outro(chalk3.red("An unexpected error occurred"));
321
- }
322
- process.exit(1);
323
- }
324
- }
325
- async function configureLoadCommand(config) {
326
- const { LezuApiClient: LezuApiClient2 } = await import("./api-G2AOOTDN.js");
327
- const client = new LezuApiClient2(config);
328
- const releaseSpinner = spinner();
329
- releaseSpinner.start("Fetching releases...");
330
- let selectedRelease;
331
- let availableLanguages = [];
332
- try {
333
- const releasesResponse = await client.getReleases();
334
- releaseSpinner.stop();
335
- if (releasesResponse.releases && releasesResponse.releases.length > 0) {
336
- const releaseChoice = await select({
337
- message: "Select a release",
338
- options: [
339
- { value: "latest", label: "\u{1F4E6} Latest release (recommended)" },
340
- ...releasesResponse.releases.map((release) => ({
341
- value: release.id,
342
- label: `${release.version}${release.is_current ? " \u2B50\uFE0F (current)" : ""}${release.name ? ` - ${release.name}` : ""}`
343
- }))
344
- ]
345
- });
346
- if (isCancel(releaseChoice)) {
347
- cancel("Operation cancelled");
348
- process.exit(0);
349
- }
350
- if (releaseChoice === "latest") {
351
- selectedRelease = releasesResponse.releases[0].id;
352
- const release = releasesResponse.releases[0];
353
- availableLanguages = release.languages || [];
354
- } else {
355
- selectedRelease = releaseChoice;
356
- const release = releasesResponse.releases.find((r) => r.id === releaseChoice);
357
- availableLanguages = release?.languages || [];
358
- }
359
- } else {
360
- releaseSpinner2.stop();
361
- console.log(chalk3.yellow("\n\u26A0\uFE0F No releases found for this project."));
362
- console.log(chalk3.gray("Releases are required for downloading translations."));
363
- console.log(chalk3.gray("They provide cached, versioned snapshots that are fast and efficient."));
364
- const shouldCreateRelease = await confirm({
365
- message: "Create a release now?",
366
- initialValue: true
367
- });
368
- if (isCancel(shouldCreateRelease) || !shouldCreateRelease) {
369
- console.log(chalk3.red("\n\u2716 A release is required to download translations"));
370
- console.log(chalk3.gray("Create a release through the dashboard or API first."));
371
- process.exit(0);
372
- }
373
- const version2 = await text({
374
- message: "Version",
375
- placeholder: (/* @__PURE__ */ new Date()).toISOString().split("T")[0].replace(/-/g, "."),
376
- initialValue: (/* @__PURE__ */ new Date()).toISOString().split("T")[0].replace(/-/g, ".")
377
- });
378
- if (isCancel(version2)) {
379
- cancel("Operation cancelled");
380
- process.exit(0);
381
- }
382
- const releaseSpinner2 = spinner();
383
- releaseSpinner2.start("Creating release...");
384
- try {
385
- const release = await client.createRelease({
386
- version: version2,
387
- name: "Initial Release",
388
- description: "Created by Lezu CLI"
389
- });
390
- selectedRelease = release.release.id;
391
- availableLanguages = release.release.languages || [];
392
- releaseSpinner2.stop(`Created release v${release.release.version}`);
393
- } catch (error) {
394
- releaseSpinner2.stop();
395
- console.log(chalk3.red("Failed to create release"));
396
- console.log(chalk3.red("\n\u2716 Cannot continue without a release"));
397
- console.log(chalk3.gray("Please check your permissions or try again later."));
398
- process.exit(1);
399
- }
400
- }
401
- } catch (error) {
402
- releaseSpinner.stop();
403
- console.log(chalk3.yellow("\n\u26A0\uFE0F Could not fetch releases."));
404
- console.log(chalk3.gray("This might be due to no releases existing yet."));
405
- const shouldCreateRelease = await confirm({
406
- message: "Would you like to create a release now?",
407
- initialValue: true
408
- });
409
- if (isCancel(shouldCreateRelease) || !shouldCreateRelease) {
410
- console.log(chalk3.red("\n\u2716 A release is required to download translations"));
411
- console.log(chalk3.gray("Releases provide cached, versioned snapshots that are fast and efficient."));
412
- process.exit(0);
413
- }
414
- const version2 = await text({
415
- message: "Version",
416
- placeholder: (/* @__PURE__ */ new Date()).toISOString().split("T")[0].replace(/-/g, "."),
417
- initialValue: (/* @__PURE__ */ new Date()).toISOString().split("T")[0].replace(/-/g, ".")
418
- });
419
- if (isCancel(version2)) {
420
- cancel("Operation cancelled");
421
- process.exit(0);
422
- }
423
- const createReleaseSpinner = spinner();
424
- createReleaseSpinner.start("Creating release...");
425
- try {
426
- const release = await client.createRelease({
427
- version: version2,
428
- name: "Initial Release",
429
- description: "Created by Lezu CLI"
430
- });
431
- selectedRelease = release.release.id;
432
- availableLanguages = release.release.languages || [];
433
- createReleaseSpinner.stop(`Created release v${release.release.version}`);
434
- } catch (createError) {
435
- createReleaseSpinner.stop();
436
- console.log(chalk3.red("Failed to create release"));
437
- console.log(chalk3.red("\n\u2716 Cannot continue without a release"));
438
- console.log(chalk3.gray("Please check your permissions or try again later."));
439
- process.exit(1);
440
- }
441
- }
442
- if (availableLanguages.length === 0) {
443
- try {
444
- const projectData = await client.getProject();
445
- availableLanguages = projectData.project.languages || ["en"];
446
- } catch {
447
- availableLanguages = ["en"];
448
- }
449
- }
450
- const dest = await text({
451
- message: "Destination folder",
452
- placeholder: "./src/i18n",
453
- initialValue: config.dest || "./src/i18n"
454
- });
455
- if (isCancel(dest)) {
456
- cancel("Operation cancelled");
457
- process.exit(0);
458
- }
459
- const format = await select({
460
- message: "Output format",
461
- options: [
462
- { value: "json", label: "JSON" },
463
- { value: "js", label: "JavaScript (ES modules)" },
464
- { value: "ts", label: "TypeScript" },
465
- { value: "yaml", label: "YAML" }
466
- ]
467
- });
468
- if (isCancel(format)) {
469
- cancel("Operation cancelled");
470
- process.exit(0);
471
- }
472
- const languageChoice = await select({
473
- message: "Which languages to download?",
474
- options: [
475
- { value: "all", label: `All languages (${availableLanguages.join(", ")})` },
476
- { value: "specific", label: "Select specific languages" }
477
- ]
478
- });
479
- if (isCancel(languageChoice)) {
480
- cancel("Operation cancelled");
481
- process.exit(0);
482
- }
483
- let languages;
484
- if (languageChoice === "specific") {
485
- const languageInput = await text({
486
- message: "Enter languages (comma-separated)",
487
- placeholder: availableLanguages.slice(0, 3).join(","),
488
- validate: (value) => {
489
- if (!value) return "At least one language is required";
490
- const langs = value.split(",").map((l) => l.trim());
491
- const invalid = langs.filter((l) => !availableLanguages.includes(l));
492
- if (invalid.length > 0) {
493
- return `Invalid languages: ${invalid.join(", ")}. Available: ${availableLanguages.join(", ")}`;
494
- }
495
- }
496
- });
497
- if (isCancel(languageInput)) {
498
- cancel("Operation cancelled");
499
- process.exit(0);
500
- }
501
- languages = languageInput.split(",").map((l) => l.trim());
502
- }
503
- const finalConfig = {
504
- ...config,
505
- dest,
506
- format,
507
- release: selectedRelease,
508
- languages
509
- };
510
- const s = spinner();
511
- s.start("Syncing translations...");
512
- try {
513
- const { syncTranslations } = await import("./load-M6IQJOQZ.js");
514
- await syncTranslations(finalConfig);
515
- s.stop("Translations synced successfully!");
516
- } catch (error) {
517
- if (error instanceof Error) {
518
- s.stop(`Failed: ${error.message}`);
519
- } else {
520
- s.stop("Failed to sync translations");
521
- }
522
- throw error;
523
- }
524
- }
525
- async function configureAddCommand(config) {
526
- const key = await text({
527
- message: "Translation key",
528
- placeholder: "common.save",
529
- validate: (value) => {
530
- if (!value) return "Translation key is required";
531
- }
532
- });
533
- if (isCancel(key)) {
534
- cancel("Operation cancelled");
535
- process.exit(0);
536
- }
537
- const description = await text({
538
- message: "Description (optional)",
539
- placeholder: "Save button text"
540
- });
541
- if (isCancel(description)) {
542
- cancel("Operation cancelled");
543
- process.exit(0);
544
- }
545
- const translationMethod = await select({
546
- message: "How would you like to provide translations?",
547
- options: [
548
- { value: "manual", label: "Provide translations manually" },
549
- { value: "auto", label: "Auto-translate from source language" }
550
- ]
551
- });
552
- if (isCancel(translationMethod)) {
553
- cancel("Operation cancelled");
554
- process.exit(0);
555
- }
556
- let translations = {};
557
- let auto = false;
558
- if (translationMethod === "auto") {
559
- auto = true;
560
- const sourceValue = await text({
561
- message: "Source language value",
562
- placeholder: "Save",
563
- validate: (value) => {
564
- if (!value) return "Source value is required for auto-translation";
565
- }
566
- });
567
- if (isCancel(sourceValue)) {
568
- cancel("Operation cancelled");
569
- process.exit(0);
570
- }
571
- translations.en = sourceValue;
572
- } else {
573
- const languages = ["en", "es", "fr", "de", "nl"];
574
- for (const lang of languages) {
575
- const value = await text({
576
- message: `Translation for ${lang} (optional)`,
577
- placeholder: `Enter ${lang} translation`
578
- });
579
- if (isCancel(value)) {
580
- cancel("Operation cancelled");
581
- process.exit(0);
582
- }
583
- if (value) {
584
- translations[lang] = value;
585
- }
586
- }
587
- }
588
- const s = spinner();
589
- s.start("Adding translation key...");
590
- try {
591
- const { LezuApiClient: LezuApiClient2 } = await import("./api-G2AOOTDN.js");
592
- const client = new LezuApiClient2(config);
593
- await client.addTranslationKey(key, translations);
594
- s.stop("Translation key added successfully!");
595
- if (auto) {
596
- console.log(chalk3.cyan("\n[AI] Auto-translation was enabled. Check the dashboard to review AI-generated translations."));
597
- }
598
- } catch (error) {
599
- if (error instanceof Error) {
600
- s.stop(`Failed: ${error.message}`);
601
- } else {
602
- s.stop("Failed to add translation key");
603
- }
604
- throw error;
605
- }
606
- }
607
- async function configureGetCommand(config) {
608
- const infoType = await select({
609
- message: "What information would you like to get?",
610
- options: [
611
- { value: "project", label: "Project information" },
612
- { value: "languages", label: "Languages" },
613
- { value: "releases", label: "Releases" }
614
- ]
615
- });
616
- if (isCancel(infoType)) {
617
- cancel("Operation cancelled");
618
- process.exit(0);
619
- }
620
- const s = spinner();
621
- s.start("Fetching information...");
622
- try {
623
- const { LezuApiClient: LezuApiClient2 } = await import("./api-G2AOOTDN.js");
624
- const client = new LezuApiClient2(config);
625
- switch (infoType) {
626
- case "project":
627
- const project = await client.getProject();
628
- s.stop("Project information:");
629
- console.log(` Name: ${project.project.name}`);
630
- console.log(` Key: ${project.project.key}`);
631
- console.log(` Source Language: ${project.project.source_language}`);
632
- break;
633
- case "languages":
634
- const languages = await client.getLanguages();
635
- s.stop("Languages:");
636
- languages.languages?.forEach((lang) => {
637
- const status = lang.enabled ? chalk3.green("[ON]") : chalk3.gray("[OFF]");
638
- console.log(` ${status} ${lang.language?.name || lang.language_code}`);
639
- });
640
- break;
641
- case "releases":
642
- const releases = await client.getReleases();
643
- s.stop("Recent releases:");
644
- releases.releases?.slice(0, 10).forEach((release) => {
645
- const current = release.is_current ? chalk3.green(" [CURRENT]") : "";
646
- console.log(` ${release.version}${current}`);
647
- });
648
- break;
649
- }
650
- } catch (error) {
651
- if (error instanceof Error) {
652
- s.stop(`Failed: ${error.message}`);
653
- } else {
654
- s.stop("Failed to fetch information");
655
- }
656
- throw error;
657
- }
658
- }
659
- async function configureReleaseCommand(config) {
660
- const action = await select({
661
- message: "Release management",
662
- options: [
663
- { value: "create", label: "Create new release" },
664
- { value: "list", label: "List releases" }
665
- ]
666
- });
667
- if (isCancel(action)) {
668
- cancel("Operation cancelled");
669
- process.exit(0);
670
- }
671
- const { LezuApiClient: LezuApiClient2 } = await import("./api-G2AOOTDN.js");
672
- const client = new LezuApiClient2(config);
673
- if (action === "create") {
674
- const version2 = await text({
675
- message: "Version",
676
- placeholder: "1.0.0",
677
- validate: (value) => {
678
- if (!value) return "Version is required";
679
- }
680
- });
681
- if (isCancel(version2)) {
682
- cancel("Operation cancelled");
683
- process.exit(0);
684
- }
685
- const name = await text({
686
- message: "Name (optional)",
687
- placeholder: "Production Release"
688
- });
689
- if (isCancel(name)) {
690
- cancel("Operation cancelled");
691
- process.exit(0);
692
- }
693
- const description = await text({
694
- message: "Description (optional)",
695
- placeholder: "Added new features..."
696
- });
697
- if (isCancel(description)) {
698
- cancel("Operation cancelled");
699
- process.exit(0);
700
- }
701
- const setCurrent = await confirm({
702
- message: "Set as current release?"
703
- });
704
- if (isCancel(setCurrent)) {
705
- cancel("Operation cancelled");
706
- process.exit(0);
707
- }
708
- const s = spinner();
709
- s.start("Creating release...");
710
- try {
711
- const release = await client.createRelease({
712
- version: version2,
713
- name: name || void 0,
714
- description: description || void 0,
715
- reviewedOnly: false
716
- });
717
- if (setCurrent) {
718
- await fetch(`${config.apiUrl}/v1/releases/${release.release.id}/current`, {
719
- method: "PUT",
720
- headers: {
721
- "Authorization": `Bearer ${config.apiKey}`
722
- }
723
- });
724
- }
725
- s.stop("Release created successfully!");
726
- console.log(` ID: ${release.release.id}`);
727
- console.log(` Version: ${release.release.version}`);
728
- } catch (error) {
729
- if (error instanceof Error) {
730
- s.stop(`Failed: ${error.message}`);
731
- } else {
732
- s.stop("Failed to create release");
733
- }
734
- throw error;
735
- }
736
- } else {
737
- const s = spinner();
738
- s.start("Fetching releases...");
739
- try {
740
- const releases = await client.getReleases();
741
- s.stop("Releases:");
742
- releases.releases?.forEach((release, index) => {
743
- const current = release.is_current ? chalk3.green(" [CURRENT]") : "";
744
- console.log(` ${index + 1}. ${release.version}${current}`);
745
- });
746
- } catch (error) {
747
- if (error instanceof Error) {
748
- s.stop(`Failed: ${error.message}`);
749
- } else {
750
- s.stop("Failed to list releases");
751
- }
752
- throw error;
753
- }
754
- }
755
- }
756
-
757
- // src/index.ts
758
- var version = "0.0.41";
759
- program.name("lezu").description("CLI tool for managing translations with Lezu").version(version);
760
- program.addCommand(createLoadCommand());
761
- program.addCommand(createAddCommand());
762
- program.addCommand(createGetCommand());
763
- program.addCommand(createReleaseCommand());
764
- if (process.argv.length <= 2) {
765
- ;
766
- (async () => {
767
- console.log(chalk4.blue("Welcome to Lezu CLI!"));
768
- console.log();
769
- try {
770
- const config = loadConfig({});
771
- await interactiveMode(config);
772
- } catch (error) {
773
- if (error instanceof Error) {
774
- console.error(chalk4.red("\nError:"), error.message);
775
- } else {
776
- console.error(chalk4.red("\nError:"), error);
777
- }
778
- process.exit(1);
779
- }
780
- })();
781
- } else {
782
- program.parse();
783
- }
784
- //# sourceMappingURL=index.js.map