@localess/cli 0.0.1-dev.20260216101417 → 0.0.1-dev.20260216154305
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 +70 -9
- package/dist/index.mjs +74 -13
- package/package.json +3 -2
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
|
|
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
|
|
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");
|
|
@@ -386,14 +389,12 @@ async function getSession() {
|
|
|
386
389
|
};
|
|
387
390
|
}
|
|
388
391
|
} catch (e) {
|
|
389
|
-
console.error('No credentials found. Please log in using the "localess login" command.');
|
|
390
392
|
}
|
|
391
|
-
console.debug("Not logged in.");
|
|
392
393
|
return session;
|
|
393
394
|
}
|
|
394
395
|
async function persistSession(data) {
|
|
395
396
|
if (data.origin && data.token && data.space) {
|
|
396
|
-
await
|
|
397
|
+
await writeFile(CREDENTIALS_PATH, JSON.stringify(data, null, 2), { mode: 384 });
|
|
397
398
|
console.log("Add session credentials to file system.");
|
|
398
399
|
console.log("Add .localess to .gitignore to avoid committing them to your repository.");
|
|
399
400
|
} else {
|
|
@@ -403,7 +404,7 @@ async function persistSession(data) {
|
|
|
403
404
|
async function clearSession() {
|
|
404
405
|
try {
|
|
405
406
|
await (0, import_promises2.access)(CREDENTIALS_PATH);
|
|
406
|
-
await
|
|
407
|
+
await writeFile(CREDENTIALS_PATH, "{}", { mode: 384 });
|
|
407
408
|
} catch (error) {
|
|
408
409
|
throw new Error("Failed to clear session credentials.");
|
|
409
410
|
}
|
|
@@ -411,7 +412,6 @@ async function clearSession() {
|
|
|
411
412
|
|
|
412
413
|
// src/commands/login/index.ts
|
|
413
414
|
var loginCommand = new import_commander.Command("login").description("Login to Localess CLI").option("-t, --token <token>", "Token to login to Localess CLI").option("-s, --space <space>", "Space ID to login to").option("-o, --origin <origin>", "Origin of the Localess instance").action(async (options) => {
|
|
414
|
-
console.log("Logging in with options:", options);
|
|
415
415
|
const session = await getSession();
|
|
416
416
|
if (session.isLoggedIn && session.method === "file") {
|
|
417
417
|
console.log('Already logged in. If you want to log in with different credentials, please log out first using "localess logout" command.');
|
|
@@ -494,18 +494,79 @@ var typesCommand = new import_commander3.Command("types").description("Generate
|
|
|
494
494
|
};
|
|
495
495
|
const ast = await (0, import_openapi_typescript.default)(minimalSpec, { exportType: true, rootTypes: true, rootTypesNoSchemaPrefix: true });
|
|
496
496
|
const contents = (0, import_openapi_typescript.astToString)(ast);
|
|
497
|
-
await
|
|
497
|
+
await writeFile(TYPES_PATH, contents);
|
|
498
498
|
console.log(`Types generated successfully at ${TYPES_PATH}`);
|
|
499
499
|
} catch (e) {
|
|
500
500
|
console.error(e);
|
|
501
501
|
}
|
|
502
502
|
});
|
|
503
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 [locale]").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
|
+
|
|
504
564
|
// src/program.ts
|
|
505
|
-
var program = new
|
|
565
|
+
var program = new import_commander6.Command();
|
|
506
566
|
program.name("Localess CLI").description("CLI tool for Localess platform management").version("0.0.1");
|
|
507
567
|
program.addCommand(loginCommand);
|
|
508
568
|
program.addCommand(logoutCommand);
|
|
569
|
+
program.addCommand(translationsCommand);
|
|
509
570
|
program.addCommand(typesCommand);
|
|
510
571
|
|
|
511
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
|
|
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
|
|
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
|
|
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
|
|
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;
|
|
@@ -363,14 +366,12 @@ async function getSession() {
|
|
|
363
366
|
};
|
|
364
367
|
}
|
|
365
368
|
} catch (e) {
|
|
366
|
-
console.error('No credentials found. Please log in using the "localess login" command.');
|
|
367
369
|
}
|
|
368
|
-
console.debug("Not logged in.");
|
|
369
370
|
return session;
|
|
370
371
|
}
|
|
371
372
|
async function persistSession(data) {
|
|
372
373
|
if (data.origin && data.token && data.space) {
|
|
373
|
-
await
|
|
374
|
+
await writeFile(CREDENTIALS_PATH, JSON.stringify(data, null, 2), { mode: 384 });
|
|
374
375
|
console.log("Add session credentials to file system.");
|
|
375
376
|
console.log("Add .localess to .gitignore to avoid committing them to your repository.");
|
|
376
377
|
} else {
|
|
@@ -380,7 +381,7 @@ async function persistSession(data) {
|
|
|
380
381
|
async function clearSession() {
|
|
381
382
|
try {
|
|
382
383
|
await access2(CREDENTIALS_PATH);
|
|
383
|
-
await
|
|
384
|
+
await writeFile(CREDENTIALS_PATH, "{}", { mode: 384 });
|
|
384
385
|
} catch (error) {
|
|
385
386
|
throw new Error("Failed to clear session credentials.");
|
|
386
387
|
}
|
|
@@ -388,7 +389,6 @@ async function clearSession() {
|
|
|
388
389
|
|
|
389
390
|
// src/commands/login/index.ts
|
|
390
391
|
var loginCommand = new Command("login").description("Login to Localess CLI").option("-t, --token <token>", "Token to login to Localess CLI").option("-s, --space <space>", "Space ID to login to").option("-o, --origin <origin>", "Origin of the Localess instance").action(async (options) => {
|
|
391
|
-
console.log("Logging in with options:", options);
|
|
392
392
|
const session = await getSession();
|
|
393
393
|
if (session.isLoggedIn && session.method === "file") {
|
|
394
394
|
console.log('Already logged in. If you want to log in with different credentials, please log out first using "localess logout" command.');
|
|
@@ -471,18 +471,79 @@ var typesCommand = new Command3("types").description("Generate types for your sc
|
|
|
471
471
|
};
|
|
472
472
|
const ast = await openapiTS(minimalSpec, { exportType: true, rootTypes: true, rootTypesNoSchemaPrefix: true });
|
|
473
473
|
const contents = astToString(ast);
|
|
474
|
-
await
|
|
474
|
+
await writeFile(TYPES_PATH, contents);
|
|
475
475
|
console.log(`Types generated successfully at ${TYPES_PATH}`);
|
|
476
476
|
} catch (e) {
|
|
477
477
|
console.error(e);
|
|
478
478
|
}
|
|
479
479
|
});
|
|
480
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 [locale]").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
|
+
|
|
481
541
|
// src/program.ts
|
|
482
|
-
var program = new
|
|
542
|
+
var program = new Command6();
|
|
483
543
|
program.name("Localess CLI").description("CLI tool for Localess platform management").version("0.0.1");
|
|
484
544
|
program.addCommand(loginCommand);
|
|
485
545
|
program.addCommand(logoutCommand);
|
|
546
|
+
program.addCommand(translationsCommand);
|
|
486
547
|
program.addCommand(typesCommand);
|
|
487
548
|
|
|
488
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.
|
|
3
|
+
"version": "0.0.1-dev.20260216154305",
|
|
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",
|