@localess/cli 0.0.1-dev.20260216111227 → 0.0.1-dev.20260216155349

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 CHANGED
@@ -24,7 +24,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
24
24
  ));
25
25
 
26
26
  // src/program.ts
27
- var import_commander4 = require("commander");
27
+ var import_commander6 = require("commander");
28
28
 
29
29
  // src/commands/login/index.ts
30
30
  var import_commander = require("commander");
@@ -336,7 +336,7 @@ var process2 = __toESM(require("process"));
336
336
  var import_promises = require("fs/promises");
337
337
  var import_node_path = require("path");
338
338
  var DEFAULT_CONFIG_DIR = ".localess";
339
- async function writeToFile(filePath, data, option) {
339
+ async function writeFile(filePath, data, option) {
340
340
  const resolvedPath = (0, import_node_path.parse)(filePath).dir;
341
341
  try {
342
342
  await (0, import_promises.mkdir)(resolvedPath, { recursive: true });
@@ -348,6 +348,9 @@ async function writeToFile(filePath, data, option) {
348
348
  } catch (writeError) {
349
349
  }
350
350
  }
351
+ async function readFile(filePath) {
352
+ return (0, import_promises.readFile)(filePath, "utf-8");
353
+ }
351
354
 
352
355
  // src/session.ts
353
356
  var CREDENTIALS_PATH = (0, import_node_path2.join)(process2.cwd(), DEFAULT_CONFIG_DIR, "credentials.json");
@@ -391,7 +394,7 @@ async function getSession() {
391
394
  }
392
395
  async function persistSession(data) {
393
396
  if (data.origin && data.token && data.space) {
394
- await writeToFile(CREDENTIALS_PATH, JSON.stringify(data, null, 2), { mode: 384 });
397
+ await writeFile(CREDENTIALS_PATH, JSON.stringify(data, null, 2), { mode: 384 });
395
398
  console.log("Add session credentials to file system.");
396
399
  console.log("Add .localess to .gitignore to avoid committing them to your repository.");
397
400
  } else {
@@ -401,7 +404,7 @@ async function persistSession(data) {
401
404
  async function clearSession() {
402
405
  try {
403
406
  await (0, import_promises2.access)(CREDENTIALS_PATH);
404
- await writeToFile(CREDENTIALS_PATH, "{}", { mode: 384 });
407
+ await writeFile(CREDENTIALS_PATH, "{}", { mode: 384 });
405
408
  } catch (error) {
406
409
  throw new Error("Failed to clear session credentials.");
407
410
  }
@@ -491,18 +494,79 @@ var typesCommand = new import_commander3.Command("types").description("Generate
491
494
  };
492
495
  const ast = await (0, import_openapi_typescript.default)(minimalSpec, { exportType: true, rootTypes: true, rootTypesNoSchemaPrefix: true });
493
496
  const contents = (0, import_openapi_typescript.astToString)(ast);
494
- await writeToFile(TYPES_PATH, contents);
497
+ await writeFile(TYPES_PATH, contents);
495
498
  console.log(`Types generated successfully at ${TYPES_PATH}`);
496
499
  } catch (e) {
497
500
  console.error(e);
498
501
  }
499
502
  });
500
503
 
504
+ // src/commands/translations/index.ts
505
+ var import_commander5 = require("commander");
506
+
507
+ // src/commands/translations/push/index.ts
508
+ var import_commander4 = require("commander");
509
+
510
+ // src/models/translations.ts
511
+ var TranslationUpdateType = /* @__PURE__ */ ((TranslationUpdateType2) => {
512
+ TranslationUpdateType2["ADD_MISSING"] = "add-missing";
513
+ TranslationUpdateType2["UPDATE_EXISTING"] = "update-existing";
514
+ return TranslationUpdateType2;
515
+ })(TranslationUpdateType || {});
516
+ function isTranslationUpdateType(value) {
517
+ return value in TranslationUpdateType;
518
+ }
519
+
520
+ // src/models/translation.zod.ts
521
+ var import_zod = require("zod");
522
+ var zLocaleTranslationsSchema = import_zod.z.record(import_zod.z.string(), import_zod.z.string());
523
+ var zTranslationUpdateTypeSchema = import_zod.z.enum(["add-missing", "update-existing"]);
524
+ var zTranslationUpdateSchema = import_zod.z.object({
525
+ type: zTranslationUpdateTypeSchema,
526
+ values: zLocaleTranslationsSchema
527
+ });
528
+
529
+ // src/commands/translations/push/index.ts
530
+ var translationsPushCommand = new import_commander4.Command("push").argument("<locale>", "Locale to push").description("Push locale translations to Localess").requiredOption("-f, --file <path>", "Path to the translations file to push").option("-t, --type <type>", `Push type. Possible values are : ${Object.values(TranslationUpdateType)}`, "add-missing" /* ADD_MISSING */).action(async (locale, options) => {
531
+ console.log("Pushing translations with arguments:", locale);
532
+ console.log("Pushing translations with options:", options);
533
+ if (!isTranslationUpdateType(options.type)) {
534
+ console.error("Invalid type provided. Possible values are :", Object.values(TranslationUpdateType));
535
+ return;
536
+ }
537
+ const session = await getSession();
538
+ if (!session.isLoggedIn) {
539
+ console.error("Not logged in");
540
+ console.error('Please log in first using "localess login" command');
541
+ return;
542
+ }
543
+ const client = localessClient({
544
+ origin: session.origin,
545
+ spaceId: session.space,
546
+ token: session.token
547
+ });
548
+ console.log("Reading translations file from:", options.file);
549
+ const fileContent = await readFile(options.file);
550
+ const translationValues = JSON.parse(fileContent);
551
+ const pResult = zLocaleTranslationsSchema.safeParse(translationValues);
552
+ if (!pResult.success) {
553
+ console.error("Invalid translations file format:", pResult.error);
554
+ return;
555
+ }
556
+ console.log("Pushing translations to Localess with locale:", locale, "and type:", options.type);
557
+ await client.updateTranslations(locale, options.type, translationValues);
558
+ console.log("Successfully pushed translations to Localess");
559
+ });
560
+
561
+ // src/commands/translations/index.ts
562
+ var translationsCommand = new import_commander5.Command("translations").description("Manage translations").addCommand(translationsPushCommand);
563
+
501
564
  // src/program.ts
502
- var program = new import_commander4.Command();
565
+ var program = new import_commander6.Command();
503
566
  program.name("Localess CLI").description("CLI tool for Localess platform management").version("0.0.1");
504
567
  program.addCommand(loginCommand);
505
568
  program.addCommand(logoutCommand);
569
+ program.addCommand(translationsCommand);
506
570
  program.addCommand(typesCommand);
507
571
 
508
572
  // src/index.ts
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/program.ts
4
- import { Command as Command4 } from "commander";
4
+ import { Command as Command6 } from "commander";
5
5
 
6
6
  // src/commands/login/index.ts
7
7
  import { Command } from "commander";
@@ -305,15 +305,15 @@ function localessClient(options) {
305
305
  }
306
306
 
307
307
  // src/session.ts
308
- import { access as access2, readFile } from "fs/promises";
308
+ import { access as access2, readFile as readFile2 } from "fs/promises";
309
309
  import { join } from "path";
310
310
  import * as process2 from "process";
311
311
 
312
312
  // src/file.ts
313
- import { access, constants, mkdir, writeFile } from "fs/promises";
313
+ import { access, constants, mkdir, writeFile as nodeWriteFile, readFile as nodeReadFile } from "fs/promises";
314
314
  import { parse } from "path";
315
315
  var DEFAULT_CONFIG_DIR = ".localess";
316
- async function writeToFile(filePath, data, option) {
316
+ async function writeFile(filePath, data, option) {
317
317
  const resolvedPath = parse(filePath).dir;
318
318
  try {
319
319
  await mkdir(resolvedPath, { recursive: true });
@@ -321,10 +321,13 @@ async function writeToFile(filePath, data, option) {
321
321
  return;
322
322
  }
323
323
  try {
324
- await writeFile(filePath, data, option);
324
+ await nodeWriteFile(filePath, data, option);
325
325
  } catch (writeError) {
326
326
  }
327
327
  }
328
+ async function readFile(filePath) {
329
+ return nodeReadFile(filePath, "utf-8");
330
+ }
328
331
 
329
332
  // src/session.ts
330
333
  var CREDENTIALS_PATH = join(process2.cwd(), DEFAULT_CONFIG_DIR, "credentials.json");
@@ -347,7 +350,7 @@ async function getSession() {
347
350
  }
348
351
  try {
349
352
  await access2(CREDENTIALS_PATH);
350
- const content = await readFile(CREDENTIALS_PATH, "utf8");
353
+ const content = await readFile2(CREDENTIALS_PATH, "utf8");
351
354
  const parsedContent = JSON.parse(content);
352
355
  if (Object.keys(parsedContent).length === 0) {
353
356
  return session;
@@ -368,7 +371,7 @@ async function getSession() {
368
371
  }
369
372
  async function persistSession(data) {
370
373
  if (data.origin && data.token && data.space) {
371
- await writeToFile(CREDENTIALS_PATH, JSON.stringify(data, null, 2), { mode: 384 });
374
+ await writeFile(CREDENTIALS_PATH, JSON.stringify(data, null, 2), { mode: 384 });
372
375
  console.log("Add session credentials to file system.");
373
376
  console.log("Add .localess to .gitignore to avoid committing them to your repository.");
374
377
  } else {
@@ -378,7 +381,7 @@ async function persistSession(data) {
378
381
  async function clearSession() {
379
382
  try {
380
383
  await access2(CREDENTIALS_PATH);
381
- await writeToFile(CREDENTIALS_PATH, "{}", { mode: 384 });
384
+ await writeFile(CREDENTIALS_PATH, "{}", { mode: 384 });
382
385
  } catch (error) {
383
386
  throw new Error("Failed to clear session credentials.");
384
387
  }
@@ -468,18 +471,79 @@ var typesCommand = new Command3("types").description("Generate types for your sc
468
471
  };
469
472
  const ast = await openapiTS(minimalSpec, { exportType: true, rootTypes: true, rootTypesNoSchemaPrefix: true });
470
473
  const contents = astToString(ast);
471
- await writeToFile(TYPES_PATH, contents);
474
+ await writeFile(TYPES_PATH, contents);
472
475
  console.log(`Types generated successfully at ${TYPES_PATH}`);
473
476
  } catch (e) {
474
477
  console.error(e);
475
478
  }
476
479
  });
477
480
 
481
+ // src/commands/translations/index.ts
482
+ import { Command as Command5 } from "commander";
483
+
484
+ // src/commands/translations/push/index.ts
485
+ import { Command as Command4 } from "commander";
486
+
487
+ // src/models/translations.ts
488
+ var TranslationUpdateType = /* @__PURE__ */ ((TranslationUpdateType2) => {
489
+ TranslationUpdateType2["ADD_MISSING"] = "add-missing";
490
+ TranslationUpdateType2["UPDATE_EXISTING"] = "update-existing";
491
+ return TranslationUpdateType2;
492
+ })(TranslationUpdateType || {});
493
+ function isTranslationUpdateType(value) {
494
+ return value in TranslationUpdateType;
495
+ }
496
+
497
+ // src/models/translation.zod.ts
498
+ import { z } from "zod";
499
+ var zLocaleTranslationsSchema = z.record(z.string(), z.string());
500
+ var zTranslationUpdateTypeSchema = z.enum(["add-missing", "update-existing"]);
501
+ var zTranslationUpdateSchema = z.object({
502
+ type: zTranslationUpdateTypeSchema,
503
+ values: zLocaleTranslationsSchema
504
+ });
505
+
506
+ // src/commands/translations/push/index.ts
507
+ var translationsPushCommand = new Command4("push").argument("<locale>", "Locale to push").description("Push locale translations to Localess").requiredOption("-f, --file <path>", "Path to the translations file to push").option("-t, --type <type>", `Push type. Possible values are : ${Object.values(TranslationUpdateType)}`, "add-missing" /* ADD_MISSING */).action(async (locale, options) => {
508
+ console.log("Pushing translations with arguments:", locale);
509
+ console.log("Pushing translations with options:", options);
510
+ if (!isTranslationUpdateType(options.type)) {
511
+ console.error("Invalid type provided. Possible values are :", Object.values(TranslationUpdateType));
512
+ return;
513
+ }
514
+ const session = await getSession();
515
+ if (!session.isLoggedIn) {
516
+ console.error("Not logged in");
517
+ console.error('Please log in first using "localess login" command');
518
+ return;
519
+ }
520
+ const client = localessClient({
521
+ origin: session.origin,
522
+ spaceId: session.space,
523
+ token: session.token
524
+ });
525
+ console.log("Reading translations file from:", options.file);
526
+ const fileContent = await readFile(options.file);
527
+ const translationValues = JSON.parse(fileContent);
528
+ const pResult = zLocaleTranslationsSchema.safeParse(translationValues);
529
+ if (!pResult.success) {
530
+ console.error("Invalid translations file format:", pResult.error);
531
+ return;
532
+ }
533
+ console.log("Pushing translations to Localess with locale:", locale, "and type:", options.type);
534
+ await client.updateTranslations(locale, options.type, translationValues);
535
+ console.log("Successfully pushed translations to Localess");
536
+ });
537
+
538
+ // src/commands/translations/index.ts
539
+ var translationsCommand = new Command5("translations").description("Manage translations").addCommand(translationsPushCommand);
540
+
478
541
  // src/program.ts
479
- var program = new Command4();
542
+ var program = new Command6();
480
543
  program.name("Localess CLI").description("CLI tool for Localess platform management").version("0.0.1");
481
544
  program.addCommand(loginCommand);
482
545
  program.addCommand(logoutCommand);
546
+ program.addCommand(translationsCommand);
483
547
  program.addCommand(typesCommand);
484
548
 
485
549
  // src/index.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@localess/cli",
3
- "version": "0.0.1-dev.20260216111227",
3
+ "version": "0.0.1-dev.20260216155349",
4
4
  "description": "Localess Command Line.",
5
5
  "keywords": [
6
6
  "localess",
@@ -42,7 +42,8 @@
42
42
  "dependencies": {
43
43
  "commander": "^14.0.3",
44
44
  "chalk": "^5.6.2",
45
- "openapi-typescript": "^7.12.0"
45
+ "openapi-typescript": "^7.12.0",
46
+ "zod": "^4.3.6"
46
47
  },
47
48
  "devDependencies": {
48
49
  "@types/node": "^20",