poly-lexis 0.4.2 → 0.4.3

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.
@@ -795,19 +795,19 @@ __export(generate_types_exports, {
795
795
  generateTranslationTypes: () => generateTranslationTypes
796
796
  });
797
797
  import { execSync } from "child_process";
798
- import * as fs4 from "fs";
799
- import * as path8 from "path";
798
+ import * as fs3 from "fs";
799
+ import * as path4 from "path";
800
800
  function generateTranslationTypes(projectRoot = process.cwd()) {
801
801
  console.log("=====");
802
802
  console.time("i18n types generated");
803
803
  console.log("Generating i18n types");
804
804
  console.log("=====");
805
805
  const config = loadConfig(projectRoot);
806
- const translationsPath = path8.join(projectRoot, config.translationsPath);
806
+ const translationsPath = path4.join(projectRoot, config.translationsPath);
807
807
  const sourceLanguage = config.sourceLanguage;
808
- const outputFilePath = path8.join(projectRoot, config.typesOutputPath);
809
- const dirPath = path8.join(translationsPath, sourceLanguage);
810
- if (!fs4.existsSync(dirPath)) {
808
+ const outputFilePath = path4.join(projectRoot, config.typesOutputPath);
809
+ const dirPath = path4.join(translationsPath, sourceLanguage);
810
+ if (!fs3.existsSync(dirPath)) {
811
811
  throw new Error(`Source language directory not found: ${dirPath}`);
812
812
  }
813
813
  const namespaces = getNamespaces(translationsPath, sourceLanguage);
@@ -820,12 +820,12 @@ function generateTranslationTypes(projectRoot = process.cwd()) {
820
820
  const keys = Object.keys(translations[namespace] || {});
821
821
  allKeys = allKeys.concat(keys);
822
822
  }
823
- const outputDir = path8.dirname(outputFilePath);
824
- if (!fs4.existsSync(outputDir)) {
825
- fs4.mkdirSync(outputDir, { recursive: true });
823
+ const outputDir = path4.dirname(outputFilePath);
824
+ if (!fs3.existsSync(outputDir)) {
825
+ fs3.mkdirSync(outputDir, { recursive: true });
826
826
  }
827
827
  const typeString = typeTemplate(allKeys, namespaces);
828
- fs4.writeFileSync(outputFilePath, typeString, "utf8");
828
+ fs3.writeFileSync(outputFilePath, typeString, "utf8");
829
829
  console.log(`Generated types with ${allKeys.length} keys and ${namespaces.length} namespaces`);
830
830
  console.log(`Output: ${outputFilePath}`);
831
831
  try {
@@ -866,7 +866,7 @@ import { confirm as confirm2, input as input2, select as select2 } from "@inquir
866
866
 
867
867
  // src/translations/cli/add-key.ts
868
868
  init_esm_shims();
869
- import * as path4 from "path";
869
+ import * as path5 from "path";
870
870
 
871
871
  // src/translations/utils/deepl-translate-provider.ts
872
872
  init_esm_shims();
@@ -1067,10 +1067,11 @@ async function translateText(text, targetLang, sourceLang = "en", apiKey, useFal
1067
1067
 
1068
1068
  // src/translations/cli/add-key.ts
1069
1069
  init_utils();
1070
+ init_generate_types();
1070
1071
  init_init();
1071
1072
  async function addTranslationKey(projectRoot, options) {
1072
1073
  const config = loadConfig(projectRoot);
1073
- const translationsPath = path4.join(projectRoot, config.translationsPath);
1074
+ const translationsPath = path5.join(projectRoot, config.translationsPath);
1074
1075
  const { namespace, key, value, autoTranslate = false, apiKey } = options;
1075
1076
  const currentProvider = getTranslationProvider();
1076
1077
  const isDefaultGoogleProvider = currentProvider.constructor.name === "GoogleTranslateProvider";
@@ -1147,6 +1148,12 @@ async function addTranslationKey(projectRoot, options) {
1147
1148
  console.log("=====");
1148
1149
  console.log("Translation key added successfully!");
1149
1150
  console.log("=====");
1151
+ console.log("\nRegenerating TypeScript types...");
1152
+ try {
1153
+ generateTranslationTypes(projectRoot);
1154
+ } catch (error) {
1155
+ console.error("Failed to generate types:", error instanceof Error ? error.message : "Unknown error");
1156
+ }
1150
1157
  }
1151
1158
 
1152
1159
  // src/cli/translations.ts
@@ -1157,13 +1164,13 @@ init_esm_shims();
1157
1164
  init_schema();
1158
1165
  init_types();
1159
1166
  init_init();
1160
- import * as fs3 from "fs";
1161
- import * as path5 from "path";
1167
+ import * as fs4 from "fs";
1168
+ import * as path6 from "path";
1162
1169
  import { checkbox, confirm, input, select } from "@inquirer/prompts";
1163
1170
  async function initTranslationsInteractive(projectRoot = process.cwd()) {
1164
1171
  console.log("\n\u{1F30D} Translation System Setup\n");
1165
- const configPath = path5.join(projectRoot, ".translationsrc.json");
1166
- const alreadyExists = fs3.existsSync(configPath);
1172
+ const configPath = path6.join(projectRoot, ".translationsrc.json");
1173
+ const alreadyExists = fs4.existsSync(configPath);
1167
1174
  if (alreadyExists) {
1168
1175
  console.log("\u26A0\uFE0F Configuration file already exists at .translationsrc.json\n");
1169
1176
  const shouldOverwrite = await confirm({
@@ -1337,7 +1344,7 @@ import * as path9 from "path";
1337
1344
 
1338
1345
  // src/translations/cli/auto-fill.ts
1339
1346
  init_esm_shims();
1340
- import * as path7 from "path";
1347
+ import * as path8 from "path";
1341
1348
  init_utils();
1342
1349
  init_init();
1343
1350
 
@@ -1345,10 +1352,10 @@ init_init();
1345
1352
  init_esm_shims();
1346
1353
  init_utils();
1347
1354
  init_init();
1348
- import * as path6 from "path";
1355
+ import * as path7 from "path";
1349
1356
  function validateTranslations(projectRoot = process.cwd()) {
1350
1357
  const config = loadConfig(projectRoot);
1351
- const translationsPath = path6.join(projectRoot, config.translationsPath);
1358
+ const translationsPath = path7.join(projectRoot, config.translationsPath);
1352
1359
  const sourceLanguage = config.sourceLanguage;
1353
1360
  const missing = [];
1354
1361
  const empty = [];
@@ -1431,7 +1438,7 @@ function getMissingForLanguage(projectRoot, language) {
1431
1438
  // src/translations/cli/auto-fill.ts
1432
1439
  async function autoFillTranslations(projectRoot = process.cwd(), options = {}) {
1433
1440
  const config = loadConfig(projectRoot);
1434
- const translationsPath = path7.join(projectRoot, config.translationsPath);
1441
+ const translationsPath = path8.join(projectRoot, config.translationsPath);
1435
1442
  const { apiKey, limit = 1e3, delayMs = 100, dryRun = false } = options;
1436
1443
  const currentProvider = getTranslationProvider();
1437
1444
  const isDefaultGoogleProvider = currentProvider.constructor.name === "GoogleTranslateProvider";