@vocoder/cli 0.1.21 → 0.1.23
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 +54 -10
- package/dist/bin.mjs.map +1 -1
- package/package.json +1 -1
package/dist/bin.mjs
CHANGED
|
@@ -595,6 +595,25 @@ var VocoderAPI = class {
|
|
|
595
595
|
});
|
|
596
596
|
}
|
|
597
597
|
const result = payload;
|
|
598
|
+
return result;
|
|
599
|
+
}
|
|
600
|
+
async listCompatibleLocales(userToken, sourceLocale) {
|
|
601
|
+
const url = `${this.apiUrl}/api/cli/locales/compatible?source=${encodeURIComponent(sourceLocale)}`;
|
|
602
|
+
const response = await fetch(url, {
|
|
603
|
+
headers: { Authorization: `Bearer ${userToken}` }
|
|
604
|
+
});
|
|
605
|
+
const payload = await readPayload(response);
|
|
606
|
+
if (!response.ok) {
|
|
607
|
+
throw new VocoderAPIError({
|
|
608
|
+
message: extractErrorMessage(
|
|
609
|
+
payload,
|
|
610
|
+
`Failed to list compatible locales (${response.status})`
|
|
611
|
+
),
|
|
612
|
+
status: response.status,
|
|
613
|
+
payload
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
const result = payload;
|
|
598
617
|
return result.locales;
|
|
599
618
|
}
|
|
600
619
|
// ── Project creation ──────────────────────────────────────────────────────────
|
|
@@ -1621,17 +1640,16 @@ async function runProjectCreate(params) {
|
|
|
1621
1640
|
const { api, userToken, organizationId, repoCanonical } = params;
|
|
1622
1641
|
const projectName = (params.defaultName ?? "my-project").trim();
|
|
1623
1642
|
p3.log.success(`Project: ${chalk4.bold(projectName)}`);
|
|
1624
|
-
let
|
|
1643
|
+
let sourceLocales;
|
|
1625
1644
|
try {
|
|
1626
|
-
|
|
1645
|
+
({ sourceLocales } = await api.listLocales(userToken));
|
|
1627
1646
|
} catch {
|
|
1628
1647
|
p3.log.error(
|
|
1629
1648
|
"Failed to fetch supported locales. Check your connection and try again."
|
|
1630
1649
|
);
|
|
1631
1650
|
return null;
|
|
1632
1651
|
}
|
|
1633
|
-
const languageOptions = buildLanguageOptions(
|
|
1634
|
-
const localeOptions = buildLocaleOptions(rawLocales);
|
|
1652
|
+
const languageOptions = buildLanguageOptions(sourceLocales);
|
|
1635
1653
|
let appDir;
|
|
1636
1654
|
if (params.defaultAppDir) {
|
|
1637
1655
|
appDir = params.defaultAppDir;
|
|
@@ -1658,6 +1676,16 @@ async function runProjectCreate(params) {
|
|
|
1658
1676
|
params.defaultSourceLocale ?? "en"
|
|
1659
1677
|
);
|
|
1660
1678
|
if (sourceLocale === null) return null;
|
|
1679
|
+
let compatibleTargets;
|
|
1680
|
+
try {
|
|
1681
|
+
compatibleTargets = await api.listCompatibleLocales(userToken, sourceLocale);
|
|
1682
|
+
} catch {
|
|
1683
|
+
p3.log.error(
|
|
1684
|
+
"Failed to fetch compatible target locales. Check your connection and try again."
|
|
1685
|
+
);
|
|
1686
|
+
return null;
|
|
1687
|
+
}
|
|
1688
|
+
const localeOptions = buildLocaleOptions(compatibleTargets);
|
|
1661
1689
|
const targetOptions = localeOptions.filter(
|
|
1662
1690
|
(opt) => opt.bcp47 !== sourceLocale
|
|
1663
1691
|
);
|
|
@@ -1716,17 +1744,16 @@ async function runProjectCreate(params) {
|
|
|
1716
1744
|
async function runProjectAppCreate(params) {
|
|
1717
1745
|
const { api, userToken, projectId, projectName, repoCanonical } = params;
|
|
1718
1746
|
const existingScopes = new Set(params.existingApps.map((a) => a.appDir));
|
|
1719
|
-
let
|
|
1747
|
+
let sourceLocales;
|
|
1720
1748
|
try {
|
|
1721
|
-
|
|
1749
|
+
({ sourceLocales } = await api.listLocales(userToken));
|
|
1722
1750
|
} catch {
|
|
1723
1751
|
p3.log.error(
|
|
1724
1752
|
"Failed to fetch supported locales. Check your connection and try again."
|
|
1725
1753
|
);
|
|
1726
1754
|
return null;
|
|
1727
1755
|
}
|
|
1728
|
-
const languageOptions = buildLanguageOptions(
|
|
1729
|
-
const localeOptions = buildLocaleOptions(rawLocales);
|
|
1756
|
+
const languageOptions = buildLanguageOptions(sourceLocales);
|
|
1730
1757
|
let appDir;
|
|
1731
1758
|
if (params.defaultAppDir && !existingScopes.has(params.defaultAppDir)) {
|
|
1732
1759
|
appDir = params.defaultAppDir;
|
|
@@ -1763,7 +1790,16 @@ async function runProjectAppCreate(params) {
|
|
|
1763
1790
|
"en"
|
|
1764
1791
|
);
|
|
1765
1792
|
if (sourceLocale === null) return null;
|
|
1766
|
-
|
|
1793
|
+
let compatibleTargets;
|
|
1794
|
+
try {
|
|
1795
|
+
compatibleTargets = await api.listCompatibleLocales(userToken, sourceLocale);
|
|
1796
|
+
} catch {
|
|
1797
|
+
p3.log.error(
|
|
1798
|
+
"Failed to fetch compatible target locales. Check your connection and try again."
|
|
1799
|
+
);
|
|
1800
|
+
return null;
|
|
1801
|
+
}
|
|
1802
|
+
const targetOptions = buildLocaleOptions(compatibleTargets).filter(
|
|
1767
1803
|
(opt) => opt.bcp47 !== sourceLocale
|
|
1768
1804
|
);
|
|
1769
1805
|
const targetLocales = await searchMultiSelectLocales(
|
|
@@ -3564,7 +3600,15 @@ async function sync(options = {}) {
|
|
|
3564
3600
|
}
|
|
3565
3601
|
if (error instanceof Error) {
|
|
3566
3602
|
p8.log.error(error.message);
|
|
3567
|
-
|
|
3603
|
+
const isInvalidKey = error.message.toLowerCase().includes("invalid api key") || error instanceof VocoderAPIError && error.status === 401;
|
|
3604
|
+
if (isInvalidKey) {
|
|
3605
|
+
p8.log.warn(
|
|
3606
|
+
"API key rejected \u2014 the project may have been deleted or the key revoked."
|
|
3607
|
+
);
|
|
3608
|
+
p8.log.info(
|
|
3609
|
+
" Run `npx @vocoder/cli init` to create a new project and key."
|
|
3610
|
+
);
|
|
3611
|
+
} else if (error.message.includes("VOCODER_API_KEY")) {
|
|
3568
3612
|
p8.log.warn(
|
|
3569
3613
|
"VOCODER_API_KEY is only needed for `vocoder sync` (CLI push)."
|
|
3570
3614
|
);
|