@vocoder/cli 0.15.0 → 0.16.1
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/bin.mjs +1996 -1980
- package/dist/bin.mjs.map +1 -1
- package/dist/{chunk-62KCB6C6.mjs → chunk-2JERZ6DL.mjs} +79 -237
- package/dist/chunk-2JERZ6DL.mjs.map +1 -0
- package/dist/lib.d.mts +7 -7
- package/dist/lib.mjs +159 -2
- package/dist/lib.mjs.map +1 -1
- package/package.json +3 -3
- package/dist/chunk-62KCB6C6.mjs.map +0 -1
|
@@ -43572,7 +43572,7 @@ var require_brace_expansion = __commonJS({
|
|
|
43572
43572
|
function computeStringsHash(input) {
|
|
43573
43573
|
const { createHash: createHash2 } = __require("crypto");
|
|
43574
43574
|
const sorted = [...input.keys].sort();
|
|
43575
|
-
return createHash2("sha256").update(JSON.stringify({ strings: sorted,
|
|
43575
|
+
return createHash2("sha256").update(JSON.stringify({ strings: sorted, industry: input.industry ?? null })).digest("hex");
|
|
43576
43576
|
}
|
|
43577
43577
|
function isLimitErrorResponse(value) {
|
|
43578
43578
|
if (!value || typeof value !== "object") {
|
|
@@ -43727,7 +43727,7 @@ var VocoderAPI = class {
|
|
|
43727
43727
|
async submitTranslation(branch, entries, targetLocales, options, repoIdentity) {
|
|
43728
43728
|
const allEntries = this.normalizeStringEntries(entries);
|
|
43729
43729
|
const stringEntries = allEntries.filter((e) => e.text != null);
|
|
43730
|
-
const stringsHash = computeStringsHash({ keys: allEntries.map((e) => e.key),
|
|
43730
|
+
const stringsHash = computeStringsHash({ keys: allEntries.map((e) => e.key), industry: options?.industry ?? null });
|
|
43731
43731
|
return this.request(
|
|
43732
43732
|
"/api/cli/sync",
|
|
43733
43733
|
{
|
|
@@ -43746,7 +43746,7 @@ var VocoderAPI = class {
|
|
|
43746
43746
|
...repoIdentity?.repoCanonical ? { repoCanonical: repoIdentity.repoCanonical } : {},
|
|
43747
43747
|
...repoIdentity?.repoAppDir !== void 0 ? { repoAppDir: repoIdentity.repoAppDir } : {},
|
|
43748
43748
|
...repoIdentity?.commitSha ? { commitSha: repoIdentity.commitSha } : {},
|
|
43749
|
-
...options?.
|
|
43749
|
+
...options?.industry ? { industry: options.industry } : {}
|
|
43750
43750
|
})
|
|
43751
43751
|
},
|
|
43752
43752
|
"Translation submission failed"
|
|
@@ -44298,9 +44298,65 @@ var VocoderAPI = class {
|
|
|
44298
44298
|
}
|
|
44299
44299
|
};
|
|
44300
44300
|
|
|
44301
|
+
// src/utils/auth-store.ts
|
|
44302
|
+
import { mkdirSync, readFileSync, unlinkSync, writeFileSync } from "fs";
|
|
44303
|
+
import { homedir } from "os";
|
|
44304
|
+
import { dirname, join } from "path";
|
|
44305
|
+
function getAuthFilePath() {
|
|
44306
|
+
return join(homedir(), ".vocoder", "auth.json");
|
|
44307
|
+
}
|
|
44308
|
+
function readAuthData() {
|
|
44309
|
+
const filePath = getAuthFilePath();
|
|
44310
|
+
try {
|
|
44311
|
+
const raw = readFileSync(filePath, "utf8");
|
|
44312
|
+
const parsed = JSON.parse(raw);
|
|
44313
|
+
if (!parsed || typeof parsed !== "object") return null;
|
|
44314
|
+
const data = parsed;
|
|
44315
|
+
if (typeof data.token !== "string" || typeof data.userId !== "string" || typeof data.email !== "string" || typeof data.createdAt !== "string") {
|
|
44316
|
+
return null;
|
|
44317
|
+
}
|
|
44318
|
+
return {
|
|
44319
|
+
token: data.token,
|
|
44320
|
+
userId: data.userId,
|
|
44321
|
+
email: data.email,
|
|
44322
|
+
name: typeof data.name === "string" ? data.name : null,
|
|
44323
|
+
createdAt: data.createdAt
|
|
44324
|
+
};
|
|
44325
|
+
} catch {
|
|
44326
|
+
return null;
|
|
44327
|
+
}
|
|
44328
|
+
}
|
|
44329
|
+
function writeAuthData(data) {
|
|
44330
|
+
const filePath = getAuthFilePath();
|
|
44331
|
+
const dir = dirname(filePath);
|
|
44332
|
+
mkdirSync(dir, { recursive: true, mode: 448 });
|
|
44333
|
+
writeFileSync(filePath, JSON.stringify(data, null, 2), { mode: 384 });
|
|
44334
|
+
}
|
|
44335
|
+
async function verifyStoredAuth(api) {
|
|
44336
|
+
const stored = readAuthData();
|
|
44337
|
+
if (!stored) return { status: "none" };
|
|
44338
|
+
try {
|
|
44339
|
+
const userInfo = await api.getCliUserInfo(stored.token);
|
|
44340
|
+
return { status: "valid", token: stored.token, ...userInfo };
|
|
44341
|
+
} catch (err) {
|
|
44342
|
+
clearAuthData();
|
|
44343
|
+
if (err instanceof VocoderAPIError && err.status === 404) {
|
|
44344
|
+
return { status: "gone" };
|
|
44345
|
+
}
|
|
44346
|
+
return { status: "expired" };
|
|
44347
|
+
}
|
|
44348
|
+
}
|
|
44349
|
+
function clearAuthData() {
|
|
44350
|
+
const filePath = getAuthFilePath();
|
|
44351
|
+
try {
|
|
44352
|
+
unlinkSync(filePath);
|
|
44353
|
+
} catch {
|
|
44354
|
+
}
|
|
44355
|
+
}
|
|
44356
|
+
|
|
44301
44357
|
// src/utils/detect-local.ts
|
|
44302
|
-
import { existsSync, readFileSync } from "fs";
|
|
44303
|
-
import { join } from "path";
|
|
44358
|
+
import { existsSync, readFileSync as readFileSync2 } from "fs";
|
|
44359
|
+
import { join as join2 } from "path";
|
|
44304
44360
|
function detectLocalEcosystem(cwd = process.cwd()) {
|
|
44305
44361
|
const packageManager = detectPackageManager(cwd);
|
|
44306
44362
|
const pkg = readPackageJson(cwd);
|
|
@@ -44315,7 +44371,7 @@ function detectLocalEcosystem(cwd = process.cwd()) {
|
|
|
44315
44371
|
hasConfig: false,
|
|
44316
44372
|
hasUiPackage: false,
|
|
44317
44373
|
sourceLocale: null,
|
|
44318
|
-
isTypeScript: existsSync(
|
|
44374
|
+
isTypeScript: existsSync(join2(cwd, "tsconfig.json"))
|
|
44319
44375
|
};
|
|
44320
44376
|
}
|
|
44321
44377
|
const allDeps = {
|
|
@@ -44325,7 +44381,7 @@ function detectLocalEcosystem(cwd = process.cwd()) {
|
|
|
44325
44381
|
const hasUnplugin = "@vocoder/plugin" in allDeps;
|
|
44326
44382
|
const hasExtractor = "@vocoder/extractor" in allDeps;
|
|
44327
44383
|
const hasConfig = "@vocoder/config" in allDeps;
|
|
44328
|
-
const isTypeScript = existsSync(
|
|
44384
|
+
const isTypeScript = existsSync(join2(cwd, "tsconfig.json")) || "typescript" in allDeps;
|
|
44329
44385
|
const { ecosystem, framework, uiPackage } = detectFromDeps(allDeps, cwd);
|
|
44330
44386
|
const hasUiPackage = uiPackage !== null && uiPackage in allDeps;
|
|
44331
44387
|
return {
|
|
@@ -44342,17 +44398,17 @@ function detectLocalEcosystem(cwd = process.cwd()) {
|
|
|
44342
44398
|
};
|
|
44343
44399
|
}
|
|
44344
44400
|
function detectPackageManager(cwd) {
|
|
44345
|
-
if (existsSync(
|
|
44346
|
-
if (existsSync(
|
|
44401
|
+
if (existsSync(join2(cwd, "pnpm-lock.yaml"))) return "pnpm";
|
|
44402
|
+
if (existsSync(join2(cwd, "bun.lockb")) || existsSync(join2(cwd, "bun.lock")))
|
|
44347
44403
|
return "bun";
|
|
44348
|
-
if (existsSync(
|
|
44404
|
+
if (existsSync(join2(cwd, "yarn.lock"))) return "yarn";
|
|
44349
44405
|
return "npm";
|
|
44350
44406
|
}
|
|
44351
44407
|
function readPackageJson(cwd) {
|
|
44352
|
-
const pkgPath =
|
|
44408
|
+
const pkgPath = join2(cwd, "package.json");
|
|
44353
44409
|
if (!existsSync(pkgPath)) return null;
|
|
44354
44410
|
try {
|
|
44355
|
-
return JSON.parse(
|
|
44411
|
+
return JSON.parse(readFileSync2(pkgPath, "utf-8"));
|
|
44356
44412
|
} catch {
|
|
44357
44413
|
return null;
|
|
44358
44414
|
}
|
|
@@ -44366,7 +44422,7 @@ function detectFromDeps(allDeps, cwd) {
|
|
|
44366
44422
|
const framework = "@sveltejs/kit" in allDeps ? "sveltekit" : null;
|
|
44367
44423
|
return { ecosystem: "svelte", framework, uiPackage: "@vocoder/svelte" };
|
|
44368
44424
|
}
|
|
44369
|
-
if ("@angular/core" in allDeps || existsSync(
|
|
44425
|
+
if ("@angular/core" in allDeps || existsSync(join2(cwd, "angular.json"))) {
|
|
44370
44426
|
return {
|
|
44371
44427
|
ecosystem: "angular",
|
|
44372
44428
|
framework: "angular",
|
|
@@ -44409,220 +44465,6 @@ function getPackagesToInstall(detection) {
|
|
|
44409
44465
|
return { devPackages, runtimePackages };
|
|
44410
44466
|
}
|
|
44411
44467
|
|
|
44412
|
-
// src/utils/auth-store.ts
|
|
44413
|
-
import { mkdirSync, readFileSync as readFileSync2, unlinkSync, writeFileSync } from "fs";
|
|
44414
|
-
import { homedir } from "os";
|
|
44415
|
-
import { dirname, join as join2 } from "path";
|
|
44416
|
-
function getAuthFilePath() {
|
|
44417
|
-
return join2(homedir(), ".vocoder", "auth.json");
|
|
44418
|
-
}
|
|
44419
|
-
function readAuthData() {
|
|
44420
|
-
const filePath = getAuthFilePath();
|
|
44421
|
-
try {
|
|
44422
|
-
const raw = readFileSync2(filePath, "utf8");
|
|
44423
|
-
const parsed = JSON.parse(raw);
|
|
44424
|
-
if (!parsed || typeof parsed !== "object") return null;
|
|
44425
|
-
const data = parsed;
|
|
44426
|
-
if (typeof data.token !== "string" || typeof data.userId !== "string" || typeof data.email !== "string" || typeof data.createdAt !== "string") {
|
|
44427
|
-
return null;
|
|
44428
|
-
}
|
|
44429
|
-
return {
|
|
44430
|
-
token: data.token,
|
|
44431
|
-
userId: data.userId,
|
|
44432
|
-
email: data.email,
|
|
44433
|
-
name: typeof data.name === "string" ? data.name : null,
|
|
44434
|
-
createdAt: data.createdAt
|
|
44435
|
-
};
|
|
44436
|
-
} catch {
|
|
44437
|
-
return null;
|
|
44438
|
-
}
|
|
44439
|
-
}
|
|
44440
|
-
function writeAuthData(data) {
|
|
44441
|
-
const filePath = getAuthFilePath();
|
|
44442
|
-
const dir = dirname(filePath);
|
|
44443
|
-
mkdirSync(dir, { recursive: true, mode: 448 });
|
|
44444
|
-
writeFileSync(filePath, JSON.stringify(data, null, 2), { mode: 384 });
|
|
44445
|
-
}
|
|
44446
|
-
async function verifyStoredAuth(api) {
|
|
44447
|
-
const stored = readAuthData();
|
|
44448
|
-
if (!stored) return { status: "none" };
|
|
44449
|
-
try {
|
|
44450
|
-
const userInfo = await api.getCliUserInfo(stored.token);
|
|
44451
|
-
return { status: "valid", token: stored.token, ...userInfo };
|
|
44452
|
-
} catch (err) {
|
|
44453
|
-
clearAuthData();
|
|
44454
|
-
if (err instanceof VocoderAPIError && err.status === 404) {
|
|
44455
|
-
return { status: "gone" };
|
|
44456
|
-
}
|
|
44457
|
-
return { status: "expired" };
|
|
44458
|
-
}
|
|
44459
|
-
}
|
|
44460
|
-
function clearAuthData() {
|
|
44461
|
-
const filePath = getAuthFilePath();
|
|
44462
|
-
try {
|
|
44463
|
-
unlinkSync(filePath);
|
|
44464
|
-
} catch {
|
|
44465
|
-
}
|
|
44466
|
-
}
|
|
44467
|
-
|
|
44468
|
-
// src/utils/setup-snippets.ts
|
|
44469
|
-
function getSetupSnippets(params) {
|
|
44470
|
-
const { framework, ecosystem, sourceLocale } = params;
|
|
44471
|
-
return {
|
|
44472
|
-
pluginStep: getPluginSnippet(framework, ecosystem),
|
|
44473
|
-
providerStep: getProviderSnippet(ecosystem, sourceLocale),
|
|
44474
|
-
wrapStep: getWrapSnippet(ecosystem),
|
|
44475
|
-
whatsNext: "Push to a target branch to trigger translations."
|
|
44476
|
-
};
|
|
44477
|
-
}
|
|
44478
|
-
function getPluginSnippet(framework, ecosystem) {
|
|
44479
|
-
switch (framework) {
|
|
44480
|
-
case "nextjs":
|
|
44481
|
-
return {
|
|
44482
|
-
file: "next.config.ts",
|
|
44483
|
-
code: `import { withVocoder } from '@vocoder/plugin/next';
|
|
44484
|
-
|
|
44485
|
-
export default withVocoder({
|
|
44486
|
-
// your existing Next.js config
|
|
44487
|
-
});`
|
|
44488
|
-
};
|
|
44489
|
-
case "vite":
|
|
44490
|
-
case "remix":
|
|
44491
|
-
return {
|
|
44492
|
-
file: "vite.config.ts",
|
|
44493
|
-
code: `import vocoder from '@vocoder/plugin/vite';
|
|
44494
|
-
|
|
44495
|
-
export default defineConfig({
|
|
44496
|
-
plugins: [
|
|
44497
|
-
vocoder(),
|
|
44498
|
-
// your other plugins
|
|
44499
|
-
],
|
|
44500
|
-
});`
|
|
44501
|
-
};
|
|
44502
|
-
case "nuxt":
|
|
44503
|
-
return {
|
|
44504
|
-
file: "nuxt.config.ts",
|
|
44505
|
-
code: `import vocoder from '@vocoder/plugin/vite';
|
|
44506
|
-
|
|
44507
|
-
export default defineNuxtConfig({
|
|
44508
|
-
vite: {
|
|
44509
|
-
plugins: [vocoder()],
|
|
44510
|
-
},
|
|
44511
|
-
});`
|
|
44512
|
-
};
|
|
44513
|
-
case "sveltekit":
|
|
44514
|
-
return {
|
|
44515
|
-
file: "vite.config.ts",
|
|
44516
|
-
code: `import vocoder from '@vocoder/plugin/vite';
|
|
44517
|
-
import { sveltekit } from '@sveltejs/kit/vite';
|
|
44518
|
-
|
|
44519
|
-
export default defineConfig({
|
|
44520
|
-
plugins: [
|
|
44521
|
-
sveltekit(),
|
|
44522
|
-
vocoder(),
|
|
44523
|
-
],
|
|
44524
|
-
});`
|
|
44525
|
-
};
|
|
44526
|
-
case "gatsby":
|
|
44527
|
-
return {
|
|
44528
|
-
file: "gatsby-node.js",
|
|
44529
|
-
code: `const vocoder = require('@vocoder/plugin/webpack');
|
|
44530
|
-
|
|
44531
|
-
exports.onCreateWebpackConfig = ({ actions }) => {
|
|
44532
|
-
actions.setWebpackConfig({
|
|
44533
|
-
plugins: [vocoder()],
|
|
44534
|
-
});
|
|
44535
|
-
};`
|
|
44536
|
-
};
|
|
44537
|
-
case "angular":
|
|
44538
|
-
return null;
|
|
44539
|
-
// Angular CLI doesn't expose plugin config easily
|
|
44540
|
-
default:
|
|
44541
|
-
if (ecosystem) {
|
|
44542
|
-
return {
|
|
44543
|
-
file: "your bundler config",
|
|
44544
|
-
code: `// Vite
|
|
44545
|
-
import vocoder from '@vocoder/plugin/vite';
|
|
44546
|
-
// Webpack
|
|
44547
|
-
const vocoder = require('@vocoder/plugin/webpack');
|
|
44548
|
-
|
|
44549
|
-
// Add vocoder() to your plugins array`
|
|
44550
|
-
};
|
|
44551
|
-
}
|
|
44552
|
-
return null;
|
|
44553
|
-
}
|
|
44554
|
-
}
|
|
44555
|
-
function getProviderSnippet(ecosystem, sourceLocale) {
|
|
44556
|
-
switch (ecosystem) {
|
|
44557
|
-
case "react":
|
|
44558
|
-
return {
|
|
44559
|
-
file: "your root layout or App component",
|
|
44560
|
-
code: `import { VocoderProvider } from '@vocoder/react';
|
|
44561
|
-
|
|
44562
|
-
<VocoderProvider defaultLocale="${sourceLocale}">
|
|
44563
|
-
{children}
|
|
44564
|
-
</VocoderProvider>`
|
|
44565
|
-
};
|
|
44566
|
-
case "vue":
|
|
44567
|
-
return {
|
|
44568
|
-
file: "your app entry",
|
|
44569
|
-
code: `import { createVocoder } from '@vocoder/vue';
|
|
44570
|
-
|
|
44571
|
-
const vocoder = createVocoder({
|
|
44572
|
-
defaultLocale: '${sourceLocale}',
|
|
44573
|
-
});
|
|
44574
|
-
|
|
44575
|
-
app.use(vocoder);`
|
|
44576
|
-
};
|
|
44577
|
-
case "svelte":
|
|
44578
|
-
return {
|
|
44579
|
-
file: "your root layout",
|
|
44580
|
-
code: `<script>
|
|
44581
|
-
import { VocoderProvider } from '@vocoder/svelte';
|
|
44582
|
-
</script>
|
|
44583
|
-
|
|
44584
|
-
<VocoderProvider defaultLocale="${sourceLocale}">
|
|
44585
|
-
<slot />
|
|
44586
|
-
</VocoderProvider>`
|
|
44587
|
-
};
|
|
44588
|
-
default:
|
|
44589
|
-
return null;
|
|
44590
|
-
}
|
|
44591
|
-
}
|
|
44592
|
-
function getWrapSnippet(ecosystem) {
|
|
44593
|
-
switch (ecosystem) {
|
|
44594
|
-
case "react":
|
|
44595
|
-
return {
|
|
44596
|
-
code: `import { T } from '@vocoder/react';
|
|
44597
|
-
|
|
44598
|
-
<T>Hello, world!</T>`
|
|
44599
|
-
};
|
|
44600
|
-
case "vue":
|
|
44601
|
-
return {
|
|
44602
|
-
code: `<template>
|
|
44603
|
-
<T>Hello, world!</T>
|
|
44604
|
-
</template>
|
|
44605
|
-
|
|
44606
|
-
<script setup>
|
|
44607
|
-
import { T } from '@vocoder/vue';
|
|
44608
|
-
</script>`
|
|
44609
|
-
};
|
|
44610
|
-
case "svelte":
|
|
44611
|
-
return {
|
|
44612
|
-
code: `<script>
|
|
44613
|
-
import { T } from '@vocoder/svelte';
|
|
44614
|
-
</script>
|
|
44615
|
-
|
|
44616
|
-
<T>Hello, world!</T>`
|
|
44617
|
-
};
|
|
44618
|
-
default:
|
|
44619
|
-
return {
|
|
44620
|
-
code: `// Wrap translatable strings with <T>
|
|
44621
|
-
<T>Hello, world!</T>`
|
|
44622
|
-
};
|
|
44623
|
-
}
|
|
44624
|
-
}
|
|
44625
|
-
|
|
44626
44468
|
// ../extractor/src/config.ts
|
|
44627
44469
|
var import_parser = __toESM(require_lib());
|
|
44628
44470
|
var import_traverse = __toESM(require_lib8());
|
|
@@ -44695,8 +44537,11 @@ function extractFromObject(obj) {
|
|
|
44695
44537
|
if (key === "localesPath" && prop.value.type === "StringLiteral") {
|
|
44696
44538
|
config.localesPath = prop.value.value;
|
|
44697
44539
|
}
|
|
44540
|
+
if (key === "industry" && prop.value.type === "StringLiteral") {
|
|
44541
|
+
config.industry = prop.value.value;
|
|
44542
|
+
}
|
|
44698
44543
|
if (key === "appIndustry" && prop.value.type === "StringLiteral") {
|
|
44699
|
-
config.
|
|
44544
|
+
config.industry = prop.value.value;
|
|
44700
44545
|
}
|
|
44701
44546
|
if (key === "formality" && prop.value.type === "StringLiteral") {
|
|
44702
44547
|
config.formality = prop.value.value;
|
|
@@ -51097,7 +50942,7 @@ function generateMessageHash(text, context, formality) {
|
|
|
51097
50942
|
return h.toString(36).padStart(7, "0");
|
|
51098
50943
|
}
|
|
51099
50944
|
|
|
51100
|
-
// ../
|
|
50945
|
+
// ../core/src/icu-builders.ts
|
|
51101
50946
|
var PLURAL_CLDR = /* @__PURE__ */ new Set(["zero", "one", "two", "few", "many"]);
|
|
51102
50947
|
var ALL_CLDR = /* @__PURE__ */ new Set(["zero", "one", "two", "few", "many", "other"]);
|
|
51103
50948
|
var DEFAULT_ORDINAL_ICU = "{count, selectordinal, other {#}}";
|
|
@@ -51124,9 +50969,7 @@ function buildSelectICU(props) {
|
|
|
51124
50969
|
cases.push(`other {${text}}`);
|
|
51125
50970
|
} else {
|
|
51126
50971
|
const wordCase = key.match(/^_([a-zA-Z].*)$/);
|
|
51127
|
-
if (wordCase) {
|
|
51128
|
-
cases.push(`${wordCase[1]} {${text}}`);
|
|
51129
|
-
}
|
|
50972
|
+
if (wordCase) cases.push(`${wordCase[1]} {${text}}`);
|
|
51130
50973
|
}
|
|
51131
50974
|
}
|
|
51132
50975
|
if (!hasOther) cases.push("other {other}");
|
|
@@ -51547,16 +51390,15 @@ function deduplicateStrings(strings) {
|
|
|
51547
51390
|
export {
|
|
51548
51391
|
VocoderAPIError,
|
|
51549
51392
|
VocoderAPI,
|
|
51550
|
-
detectLocalEcosystem,
|
|
51551
|
-
buildInstallCommand,
|
|
51552
|
-
getPackagesToInstall,
|
|
51553
51393
|
readAuthData,
|
|
51554
51394
|
writeAuthData,
|
|
51555
51395
|
verifyStoredAuth,
|
|
51556
51396
|
clearAuthData,
|
|
51557
|
-
|
|
51397
|
+
detectLocalEcosystem,
|
|
51398
|
+
buildInstallCommand,
|
|
51399
|
+
getPackagesToInstall,
|
|
51558
51400
|
loadVocoderConfig,
|
|
51559
51401
|
computeFingerprint,
|
|
51560
51402
|
StringExtractor
|
|
51561
51403
|
};
|
|
51562
|
-
//# sourceMappingURL=chunk-
|
|
51404
|
+
//# sourceMappingURL=chunk-2JERZ6DL.mjs.map
|