@intlayer/chokidar 4.1.3 → 4.1.5

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.
Files changed (24) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.cjs +4 -1
  3. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.cjs.map +1 -1
  4. package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs +2 -2
  5. package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs.map +1 -1
  6. package/dist/cjs/transpiler/dictionary_to_type/createType.cjs +4 -10
  7. package/dist/cjs/transpiler/dictionary_to_type/createType.cjs.map +1 -1
  8. package/dist/cjs/utils.cjs +14 -13
  9. package/dist/cjs/utils.cjs.map +1 -1
  10. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.mjs +4 -1
  11. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.mjs.map +1 -1
  12. package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs +3 -3
  13. package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs.map +1 -1
  14. package/dist/esm/transpiler/dictionary_to_type/createType.mjs +4 -10
  15. package/dist/esm/transpiler/dictionary_to_type/createType.mjs.map +1 -1
  16. package/dist/esm/utils.mjs +12 -11
  17. package/dist/esm/utils.mjs.map +1 -1
  18. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.d.ts.map +1 -1
  19. package/dist/types/transpiler/dictionary_to_type/createModuleAugmentation.d.ts +1 -1
  20. package/dist/types/transpiler/dictionary_to_type/createModuleAugmentation.d.ts.map +1 -1
  21. package/dist/types/transpiler/dictionary_to_type/createType.d.ts.map +1 -1
  22. package/dist/types/utils.d.ts +1 -1
  23. package/dist/types/utils.d.ts.map +1 -1
  24. package/package.json +12 -12
package/README.md CHANGED
@@ -20,7 +20,7 @@
20
20
 
21
21
  **Intlayer** is a suite of packages designed specifically for JavaScript developers. It is compatible with frameworks like React, React, and Express.js.
22
22
 
23
- The **`@intlayer/chokidar`** package is used to scan and build Intlayer declaration files into dictionaries using [chokidar](https://github.com/paulmillr/chokidar) and according to the [Intlayer configuration](https://intlayer.org//doc/concept/configuration).
23
+ The **`@intlayer/chokidar`** package is used to scan and build Intlayer declaration files into dictionaries using [chokidar](https://github.com/paulmillr/chokidar) and according to the [Intlayer configuration](https://intlayer.org/doc/concept/configuration).
24
24
 
25
25
  ## Usage
26
26
 
@@ -28,7 +28,10 @@ const { dictionariesDir } = (0, import_config.getConfiguration)().content;
28
28
  const writeDictionary = async (dictionaries) => {
29
29
  const resultDictionariesPaths = [];
30
30
  for await (const dictionaryContent of dictionaries) {
31
- const contentString = JSON.stringify(dictionaryContent);
31
+ const contentString = JSON.stringify({
32
+ $schema: "https://intlayer.org/schema.json",
33
+ ...dictionaryContent
34
+ });
32
35
  const id = dictionaryContent.key;
33
36
  const outputFileName = `${id}.json`;
34
37
  const resultFilePath = (0, import_path.resolve)(dictionariesDir, outputFileName);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.ts"],"sourcesContent":["import { writeFile } from 'fs/promises';\nimport { resolve } from 'path';\nimport { getConfiguration } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\n\nconst { dictionariesDir } = getConfiguration().content;\n\nexport const writeDictionary = async (dictionaries: Dictionary[]) => {\n const resultDictionariesPaths: string[] = [];\n\n for await (const dictionaryContent of dictionaries) {\n const contentString = JSON.stringify(dictionaryContent);\n\n const id = dictionaryContent.key;\n const outputFileName = `${id}.json`;\n const resultFilePath = resolve(dictionariesDir, outputFileName);\n\n // Create the json file\n await writeFile(resultFilePath, contentString, 'utf8').catch((err) => {\n console.error(`Error creating ${outputFileName}:`, err);\n });\n\n resultDictionariesPaths.push(resultFilePath);\n }\n\n return resultDictionariesPaths;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA0B;AAC1B,kBAAwB;AACxB,oBAAiC;AAGjC,MAAM,EAAE,gBAAgB,QAAI,gCAAiB,EAAE;AAExC,MAAM,kBAAkB,OAAO,iBAA+B;AACnE,QAAM,0BAAoC,CAAC;AAE3C,mBAAiB,qBAAqB,cAAc;AAClD,UAAM,gBAAgB,KAAK,UAAU,iBAAiB;AAEtD,UAAM,KAAK,kBAAkB;AAC7B,UAAM,iBAAiB,GAAG,EAAE;AAC5B,UAAM,qBAAiB,qBAAQ,iBAAiB,cAAc;AAG9D,cAAM,2BAAU,gBAAgB,eAAe,MAAM,EAAE,MAAM,CAAC,QAAQ;AACpE,cAAQ,MAAM,kBAAkB,cAAc,KAAK,GAAG;AAAA,IACxD,CAAC;AAED,4BAAwB,KAAK,cAAc;AAAA,EAC7C;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.ts"],"sourcesContent":["import { writeFile } from 'fs/promises';\nimport { resolve } from 'path';\nimport { getConfiguration } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\n\nconst { dictionariesDir } = getConfiguration().content;\n\nexport const writeDictionary = async (dictionaries: Dictionary[]) => {\n const resultDictionariesPaths: string[] = [];\n\n for await (const dictionaryContent of dictionaries) {\n const contentString = JSON.stringify({\n $schema: 'https://intlayer.org/schema.json',\n ...dictionaryContent,\n });\n\n const id = dictionaryContent.key;\n const outputFileName = `${id}.json`;\n const resultFilePath = resolve(dictionariesDir, outputFileName);\n\n // Create the json file\n await writeFile(resultFilePath, contentString, 'utf8').catch((err) => {\n console.error(`Error creating ${outputFileName}:`, err);\n });\n\n resultDictionariesPaths.push(resultFilePath);\n }\n\n return resultDictionariesPaths;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA0B;AAC1B,kBAAwB;AACxB,oBAAiC;AAGjC,MAAM,EAAE,gBAAgB,QAAI,gCAAiB,EAAE;AAExC,MAAM,kBAAkB,OAAO,iBAA+B;AACnE,QAAM,0BAAoC,CAAC;AAE3C,mBAAiB,qBAAqB,cAAc;AAClD,UAAM,gBAAgB,KAAK,UAAU;AAAA,MACnC,SAAS;AAAA,MACT,GAAG;AAAA,IACL,CAAC;AAED,UAAM,KAAK,kBAAkB;AAC7B,UAAM,iBAAiB,GAAG,EAAE;AAC5B,UAAM,qBAAiB,qBAAQ,iBAAiB,cAAc;AAG9D,cAAM,2BAAU,gBAAgB,eAAe,MAAM,EAAE,MAAM,CAAC,QAAQ;AACpE,cAAQ,MAAM,kBAAkB,cAAc,KAAK,GAAG;AAAA,IACxD,CAAC;AAED,4BAAwB,KAAK,cAAc;AAAA,EAC7C;AAEA,SAAO;AACT;","names":[]}
@@ -40,11 +40,11 @@ var import_utils = require('../../utils.cjs');
40
40
  const { content, internationalization } = (0, import_config.getConfiguration)();
41
41
  const { typesDir, moduleAugmentationDir } = content;
42
42
  const { locales, strictMode } = internationalization;
43
- const getTypeName = (id) => (0, import_utils.transformToCamelCase)(`${id}Content`);
43
+ const getTypeName = (key) => `${(0, import_utils.kebabCaseToCamelCase)(key)}Content`;
44
44
  const generateTypeIndexContent = (typeFiles) => {
45
45
  let content2 = "/* eslint-disable */\nimport { Locales } from 'intlayer';\n";
46
46
  const dictionariesRef = typeFiles.map((dictionaryPath) => ({
47
- relativePath: (0, import_path.relative)(moduleAugmentationDir, dictionaryPath),
47
+ relativePath: `./${(0, import_path.relative)(moduleAugmentationDir, dictionaryPath)}`,
48
48
  id: (0, import_path.basename)(dictionaryPath, ".d.ts"),
49
49
  // Get the base name as the dictionary id
50
50
  hash: `_${(0, import_utils.getFileHash)(dictionaryPath)}`
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/transpiler/dictionary_to_type/createModuleAugmentation.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { basename, join, relative } from 'path';\nimport { Locales, getConfiguration } from '@intlayer/config';\nimport fg from 'fast-glob';\nimport { getFileHash, transformToCamelCase } from '../../utils';\n\nconst { content, internationalization } = getConfiguration();\nconst { typesDir, moduleAugmentationDir } = content;\nconst { locales, strictMode } = internationalization;\n\nexport const getTypeName = (id: string): string =>\n transformToCamelCase(`${id}Content`);\n\n/**\n * This function generates the content of the module augmentation file\n */\nconst generateTypeIndexContent = (typeFiles: string[]): string => {\n let content = \"/* eslint-disable */\\nimport { Locales } from 'intlayer';\\n\";\n\n const dictionariesRef = typeFiles.map((dictionaryPath) => ({\n relativePath: relative(moduleAugmentationDir, dictionaryPath),\n id: basename(dictionaryPath, '.d.ts'), // Get the base name as the dictionary id\n hash: `_${getFileHash(dictionaryPath)}`, // Get the hash of the dictionary to avoid conflicts\n }));\n\n // Import all dictionaries\n dictionariesRef.forEach((dictionary) => {\n const typeName = getTypeName(dictionary.id);\n content += `import type { ${typeName} as ${dictionary.hash} } from '${dictionary.relativePath}';\\n`;\n });\n\n content += '\\n';\n\n // Format Dictionary Map\n const formattedDictionaryMap: string = dictionariesRef\n .map((dictionary) => ` \"${dictionary.id}\": ${dictionary.hash};`)\n .join('\\n');\n\n const formatLocales = locales\n .map((locale) => {\n for (const key in Locales) {\n if (Locales[key as keyof typeof Locales] === locale) {\n return `Locales.${key}`;\n }\n }\n })\n .join(' | ');\n\n const strictModeRecord =\n strictMode === 'strict'\n ? `interface IConfigLocales<Content> extends Record<ExtractedLocales, Content> {}`\n : strictMode === 'required_only'\n ? `interface IConfigLocales<Content> extends Record<ExtractedLocales, Content>, Partial<Record<ExcludedLocales, Content>> {}`\n : `interface IConfigLocales<Content> extends Partial<Record<Locales, Content>> {}`;\n\n /**\n * Write the module augmentation to extend the intlayer module with the dictionaries types\n * Will suggest the type resulting of the dictionaries\n *\n * declare module 'intlayer' {\n * interface IntlayerDictionaryTypesConnector = {\n * dictionaries: {\n * id: DictionaryType;\n * }\n * }\n *\n * type ConfigLocales = Locales.ENGLISH | Locales.FRENCH | Locales.SPANISH;\n * type ExtractedLocales = Extract<Locales, ConfigLocales>;\n * type ExcludedLocales = Exclude<Locales, ConfigLocales>;\n *\n * interface IConfigLocales<Content> extends Record<ExtractedLocales, Content>, Partial<Record<ExcludedLocales, Content>> {}\n *\n *\n * }\n * See https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation\n */\n content += `declare module 'intlayer' {\\n`;\n content += ` interface IntlayerDictionaryTypesConnector {\\n${formattedDictionaryMap}\\n }\\n\\n`;\n content += ` type ConfigLocales = ${formatLocales};\\n`;\n content += ` type ExtractedLocales = Extract<Locales, ConfigLocales>;\\n`;\n content += ` type ExcludedLocales = Exclude<Locales, ConfigLocales>;\\n\\n`;\n content += ` ${strictModeRecord}\\n`;\n content += `}`;\n\n return content;\n};\n\n/**\n * This function generates a index file merging all the types\n */\nexport const createModuleAugmentation = () => {\n // Create main directory if it doesn't exist\n if (!existsSync(moduleAugmentationDir)) {\n mkdirSync(moduleAugmentationDir, { recursive: true });\n }\n\n const dictionaries: string[] = fg.sync(`${typesDir}/**/*.d.ts`);\n // Create the dictionary list file\n\n const tsContent = generateTypeIndexContent(dictionaries);\n writeFileSync(join(moduleAugmentationDir, 'intlayer.d.ts'), tsContent);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAqD;AACrD,kBAAyC;AACzC,oBAA0C;AAC1C,uBAAe;AACf,mBAAkD;AAElD,MAAM,EAAE,SAAS,qBAAqB,QAAI,gCAAiB;AAC3D,MAAM,EAAE,UAAU,sBAAsB,IAAI;AAC5C,MAAM,EAAE,SAAS,WAAW,IAAI;AAEzB,MAAM,cAAc,CAAC,WAC1B,mCAAqB,GAAG,EAAE,SAAS;AAKrC,MAAM,2BAA2B,CAAC,cAAgC;AAChE,MAAIA,WA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AAK,uBAAuB,eAAe,GAAG,SAAS;AACvE;","names":["content","fg"]}
1
+ {"version":3,"sources":["../../../../src/transpiler/dictionary_to_type/createModuleAugmentation.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { basename, join, relative } from 'path';\nimport { Locales, getConfiguration } from '@intlayer/config';\nimport fg from 'fast-glob';\nimport { getFileHash, kebabCaseToCamelCase } from '../../utils';\n\nconst { content, internationalization } = getConfiguration();\nconst { typesDir, moduleAugmentationDir } = content;\nconst { locales, strictMode } = internationalization;\n\nexport const getTypeName = (key: string): string =>\n `${kebabCaseToCamelCase(key)}Content`;\n\n/**\n * This function generates the content of the module augmentation file\n */\nconst generateTypeIndexContent = (typeFiles: string[]): string => {\n let content = \"/* eslint-disable */\\nimport { Locales } from 'intlayer';\\n\";\n\n const dictionariesRef = typeFiles.map((dictionaryPath) => ({\n relativePath: `./${relative(moduleAugmentationDir, dictionaryPath)}`,\n id: basename(dictionaryPath, '.d.ts'), // Get the base name as the dictionary id\n hash: `_${getFileHash(dictionaryPath)}`, // Get the hash of the dictionary to avoid conflicts\n }));\n\n // Import all dictionaries\n dictionariesRef.forEach((dictionary) => {\n const typeName = getTypeName(dictionary.id);\n content += `import type { ${typeName} as ${dictionary.hash} } from '${dictionary.relativePath}';\\n`;\n });\n\n content += '\\n';\n\n // Format Dictionary Map\n const formattedDictionaryMap: string = dictionariesRef\n .map((dictionary) => ` \"${dictionary.id}\": ${dictionary.hash};`)\n .join('\\n');\n\n const formatLocales = locales\n .map((locale) => {\n for (const key in Locales) {\n if (Locales[key as keyof typeof Locales] === locale) {\n return `Locales.${key}`;\n }\n }\n })\n .join(' | ');\n\n const strictModeRecord =\n strictMode === 'strict'\n ? `interface IConfigLocales<Content> extends Record<ExtractedLocales, Content> {}`\n : strictMode === 'required_only'\n ? `interface IConfigLocales<Content> extends Record<ExtractedLocales, Content>, Partial<Record<ExcludedLocales, Content>> {}`\n : `interface IConfigLocales<Content> extends Partial<Record<Locales, Content>> {}`;\n\n /**\n * Write the module augmentation to extend the intlayer module with the dictionaries types\n * Will suggest the type resulting of the dictionaries\n *\n * declare module 'intlayer' {\n * interface IntlayerDictionaryTypesConnector = {\n * dictionaries: {\n * id: DictionaryType;\n * }\n * }\n *\n * type ConfigLocales = Locales.ENGLISH | Locales.FRENCH | Locales.SPANISH;\n * type ExtractedLocales = Extract<Locales, ConfigLocales>;\n * type ExcludedLocales = Exclude<Locales, ConfigLocales>;\n *\n * interface IConfigLocales<Content> extends Record<ExtractedLocales, Content>, Partial<Record<ExcludedLocales, Content>> {}\n *\n *\n * }\n * See https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation\n */\n content += `declare module 'intlayer' {\\n`;\n content += ` interface IntlayerDictionaryTypesConnector {\\n${formattedDictionaryMap}\\n }\\n\\n`;\n content += ` type ConfigLocales = ${formatLocales};\\n`;\n content += ` type ExtractedLocales = Extract<Locales, ConfigLocales>;\\n`;\n content += ` type ExcludedLocales = Exclude<Locales, ConfigLocales>;\\n\\n`;\n content += ` ${strictModeRecord}\\n`;\n content += `}`;\n\n return content;\n};\n\n/**\n * This function generates a index file merging all the types\n */\nexport const createModuleAugmentation = () => {\n // Create main directory if it doesn't exist\n if (!existsSync(moduleAugmentationDir)) {\n mkdirSync(moduleAugmentationDir, { recursive: true });\n }\n\n const dictionaries: string[] = fg.sync(`${typesDir}/**/*.d.ts`);\n // Create the dictionary list file\n\n const tsContent = generateTypeIndexContent(dictionaries);\n writeFileSync(join(moduleAugmentationDir, 'intlayer.d.ts'), tsContent);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAqD;AACrD,kBAAyC;AACzC,oBAA0C;AAC1C,uBAAe;AACf,mBAAkD;AAElD,MAAM,EAAE,SAAS,qBAAqB,QAAI,gCAAiB;AAC3D,MAAM,EAAE,UAAU,sBAAsB,IAAI;AAC5C,MAAM,EAAE,SAAS,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AAK,CAAC;AAAA,EACtD;AAEA,QAAM,eAAyB,iBAAAC,QAAG,KAAK,GAAG,QAAQ,YAAY;AAG9D,QAAM,YAAY,yBAAyB,YAAY;AACvD,mCAAc,kBAAK,uBAAuB,eAAe,GAAG,SAAS;AACvE;","names":["content","fg"]}
@@ -26,18 +26,13 @@ var import_fs = require("fs");
26
26
  var import_path = require("path");
27
27
  var import_config = require("@intlayer/config");
28
28
  var import_quicktype_core = require("quicktype-core");
29
+ var import_utils = require('../../utils.cjs');
29
30
  const { content } = (0, import_config.getConfiguration)();
30
31
  const { typesDir } = content;
31
32
  const requireUncached = (module2) => {
32
33
  delete import_config.ESMxCJSRequire.cache[import_config.ESMxCJSRequire.resolve(module2)];
33
34
  return (0, import_config.ESMxCJSRequire)(module2);
34
35
  };
35
- const kebabCaseToCamelCase = (name) => name.split(/[\s\-_]+/).map((word, index) => {
36
- if (index === 0) {
37
- return word;
38
- }
39
- return word.charAt(0).toUpperCase() + word.slice(1);
40
- }).join("");
41
36
  const generateTypeScriptType = async (typeName, jsonString) => {
42
37
  const { lines } = await quicktypeJSON(typeName, jsonString);
43
38
  const linesString = lines.join("\n");
@@ -71,17 +66,16 @@ const createTypes = async (dictionariesPaths) => {
71
66
  }
72
67
  for (const dictionaryPath of dictionariesPaths) {
73
68
  const dictionary = requireUncached(dictionaryPath);
74
- const dictionaryName = dictionary.key;
75
- if (!dictionaryName) {
69
+ if (!dictionary.key) {
76
70
  continue;
77
71
  }
78
- const dictionaryNameCamelCase = kebabCaseToCamelCase(dictionaryName) + "Content";
72
+ const dictionaryNameCamelCase = `${(0, import_utils.kebabCaseToCamelCase)(dictionary.key)}Content`;
79
73
  const dictionaryContentString = JSON.stringify(dictionary);
80
74
  const typeDefinition = await generateTypeScriptType(
81
75
  dictionaryNameCamelCase,
82
76
  dictionaryContentString
83
77
  );
84
- const outputPath = (0, import_path.resolve)(typesDir, `${dictionaryName}.d.ts`);
78
+ const outputPath = (0, import_path.resolve)(typesDir, `${dictionary.key}.d.ts`);
85
79
  (0, import_fs.writeFileSync)(outputPath, typeDefinition);
86
80
  resultTypesPaths.push(outputPath);
87
81
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/transpiler/dictionary_to_type/createType.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { resolve } from 'path';\nimport { getConfiguration, ESMxCJSRequire } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport {\n quicktype,\n InputData,\n jsonInputForTargetLanguage,\n} from 'quicktype-core';\n\nconst { content } = getConfiguration();\nconst { typesDir } = content;\n\nconst requireUncached = (module: string) => {\n delete ESMxCJSRequire.cache[ESMxCJSRequire.resolve(module)];\n return ESMxCJSRequire(module);\n};\n\nconst kebabCaseToCamelCase = (name: string): string =>\n name\n .split(/[\\s\\-_]+/) // Regular expression to match space, hyphen, or underscore\n .map((word, index) => {\n if (index === 0) {\n return word; // Return the first word as is\n }\n return word.charAt(0).toUpperCase() + word.slice(1); // Capitalize the first letter of subsequent words\n })\n .join(''); // Join all the segments into one string\n\nexport const generateTypeScriptType = async (\n typeName: string,\n jsonString: string\n) => {\n const { lines } = await quicktypeJSON(typeName, jsonString);\n\n const linesString: string = lines.join('\\n');\n\n return linesString;\n};\n\nconst quicktypeJSON = async (typeName: string, jsonString: string) => {\n const jsonInput = jsonInputForTargetLanguage('typescript');\n\n // We could add multiple samples for the same desired\n // type, or many sources for other types. Here we're\n // just making one type from one piece of sample JSON.\n\n await jsonInput.addSource({\n name: typeName,\n samples: [jsonString],\n });\n\n const inputData = new InputData();\n inputData.addInput(jsonInput);\n\n return await quicktype({\n inputData,\n lang: 'typescript',\n alphabetizeProperties: true,\n rendererOptions: {\n 'just-types': 'true',\n 'explicit-unions': 'true',\n 'acronym-style': 'camel',\n 'prefer-types': 'true',\n readonly: 'false',\n },\n });\n};\n\n/**\n * This function generates a TypeScript type definition from a JSON object\n */\nexport const createTypes = async (\n dictionariesPaths: string[]\n): Promise<string[]> => {\n const resultTypesPaths: string[] = [];\n\n // Create type folders if they don't exist\n if (!existsSync(typesDir)) {\n mkdirSync(typesDir, { recursive: true });\n }\n\n for (const dictionaryPath of dictionariesPaths) {\n const dictionary: Dictionary = requireUncached(dictionaryPath);\n\n const dictionaryName: string = dictionary.key;\n\n if (!dictionaryName) {\n // Skip dictionary if it doesn't have a key, if not exported as default etc\n continue;\n }\n\n const dictionaryNameCamelCase: string =\n kebabCaseToCamelCase(dictionaryName) + 'Content';\n\n const dictionaryContentString: string = JSON.stringify(dictionary);\n\n const typeDefinition: string = await generateTypeScriptType(\n dictionaryNameCamelCase,\n dictionaryContentString\n );\n\n const outputPath: string = resolve(typesDir, `${dictionaryName}.d.ts`);\n\n writeFileSync(outputPath, typeDefinition);\n\n resultTypesPaths.push(outputPath);\n }\n\n return resultTypesPaths;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAqD;AACrD,kBAAwB;AACxB,oBAAiD;AAEjD,4BAIO;AAEP,MAAM,EAAE,QAAQ,QAAI,gCAAiB;AACrC,MAAM,EAAE,SAAS,IAAI;AAErB,MAAM,kBAAkB,CAACA,YAAmB;AAC1C,SAAO,6BAAe,MAAM,6BAAe,QAAQA,OAAM,CAAC;AAC1D,aAAO,8BAAeA,OAAM;AAC9B;AAEA,MAAM,uBAAuB,CAAC,SAC5B,KACG,MAAM,UAAU,EAChB,IAAI,CAAC,MAAM,UAAU;AACpB,MAAI,UAAU,GAAG;AACf,WAAO;AAAA,EACT;AACA,SAAO,KAAK,OAAO,CAAC,EAAE,YAAY,IAAI,KAAK,MAAM,CAAC;AACpD,CAAC,EACA,KAAK,EAAE;AAEL,MAAM,yBAAyB,OACpC,UACA,eACG;AACH,QAAM,EAAE,MAAM,IAAI,MAAM,cAAc,UAAU,UAAU;AAE1D,QAAM,cAAsB,MAAM,KAAK,IAAI;AAE3C,SAAO;AACT;AAEA,MAAM,gBAAgB,OAAO,UAAkB,eAAuB;AACpE,QAAM,gBAAY,kDAA2B,YAAY;AAMzD,QAAM,UAAU,UAAU;AAAA,IACxB,MAAM;AAAA,IACN,SAAS,CAAC,UAAU;AAAA,EACtB,CAAC;AAED,QAAM,YAAY,IAAI,gCAAU;AAChC,YAAU,SAAS,SAAS;AAE5B,SAAO,UAAM,iCAAU;AAAA,IACrB;AAAA,IACA,MAAM;AAAA,IACN,uBAAuB;AAAA,IACvB,iBAAiB;AAAA,MACf,cAAc;AAAA,MACd,mBAAmB;AAAA,MACnB,iBAAiB;AAAA,MACjB,gBAAgB;AAAA,MAChB,UAAU;AAAA,IACZ;AAAA,EACF,CAAC;AACH;AAKO,MAAM,cAAc,OACzB,sBACsB;AACtB,QAAM,mBAA6B,CAAC;AAGpC,MAAI,KAAC,sBAAW,QAAQ,GAAG;AACzB,6BAAU,UAAU,EAAE,WAAW,KAAK,CAAC;AAAA,EACzC;AAEA,aAAW,kBAAkB,mBAAmB;AAC9C,UAAM,aAAyB,gBAAgB,cAAc;AAE7D,UAAM,iBAAyB,WAAW;AAE1C,QAAI,CAAC,gBAAgB;AAEnB;AAAA,IACF;AAEA,UAAM,0BACJ,qBAAqB,cAAc,IAAI;AAEzC,UAAM,0BAAkC,KAAK,UAAU,UAAU;AAEjE,UAAM,iBAAyB,MAAM;AAAA,MACnC;AAAA,MACA;AAAA,IACF;AAEA,UAAM,iBAAqB,qBAAQ,UAAU,GAAG,cAAc,OAAO;AAErE,iCAAc,YAAY,cAAc;AAExC,qBAAiB,KAAK,UAAU;AAAA,EAClC;AAEA,SAAO;AACT;","names":["module"]}
1
+ {"version":3,"sources":["../../../../src/transpiler/dictionary_to_type/createType.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { resolve } from 'path';\nimport { getConfiguration, ESMxCJSRequire } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport {\n quicktype,\n InputData,\n jsonInputForTargetLanguage,\n} from 'quicktype-core';\nimport { kebabCaseToCamelCase } from '../../utils';\n\nconst { content } = getConfiguration();\nconst { typesDir } = content;\n\nconst requireUncached = (module: string) => {\n delete ESMxCJSRequire.cache[ESMxCJSRequire.resolve(module)];\n return ESMxCJSRequire(module);\n};\n\nexport const generateTypeScriptType = async (\n typeName: string,\n jsonString: string\n) => {\n const { lines } = await quicktypeJSON(typeName, jsonString);\n\n const linesString: string = lines.join('\\n');\n\n return linesString;\n};\n\nconst quicktypeJSON = async (typeName: string, jsonString: string) => {\n const jsonInput = jsonInputForTargetLanguage('typescript');\n\n // We could add multiple samples for the same desired\n // type, or many sources for other types. Here we're\n // just making one type from one piece of sample JSON.\n\n await jsonInput.addSource({\n name: typeName,\n samples: [jsonString],\n });\n\n const inputData = new InputData();\n inputData.addInput(jsonInput);\n\n return await quicktype({\n inputData,\n lang: 'typescript',\n alphabetizeProperties: true,\n rendererOptions: {\n 'just-types': 'true',\n 'explicit-unions': 'true',\n 'acronym-style': 'camel',\n 'prefer-types': 'true',\n readonly: 'false',\n },\n });\n};\n\n/**\n * This function generates a TypeScript type definition from a JSON object\n */\nexport const createTypes = async (\n dictionariesPaths: string[]\n): Promise<string[]> => {\n const resultTypesPaths: string[] = [];\n\n // Create type folders if they don't exist\n if (!existsSync(typesDir)) {\n mkdirSync(typesDir, { recursive: true });\n }\n\n for (const dictionaryPath of dictionariesPaths) {\n const dictionary: Dictionary = requireUncached(dictionaryPath);\n\n if (!dictionary.key) {\n // Skip dictionary if it doesn't have a key, if not exported as default etc\n continue;\n }\n\n const dictionaryNameCamelCase: string = `${kebabCaseToCamelCase(dictionary.key)}Content`;\n\n const dictionaryContentString: string = JSON.stringify(dictionary);\n\n const typeDefinition: string = await generateTypeScriptType(\n dictionaryNameCamelCase,\n dictionaryContentString\n );\n\n const outputPath: string = resolve(typesDir, `${dictionary.key}.d.ts`);\n\n writeFileSync(outputPath, typeDefinition);\n\n resultTypesPaths.push(outputPath);\n }\n\n return resultTypesPaths;\n};\n"],"mappings":";;;;;;;;;;;;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C,KAAK,UAAU,UAAU;AAEjE,UAAM,iBAAyB,MAAM;AAAA,MACnC;AAAA,MACA;AAAA,IACF;AAEA,UAAM,iBAAqB,qBAAQ,UAAU,GAAG,WAAW,GAAG,OAAO;AAErE,iCAAc,YAAY,cAAc;AAExC,qBAAiB,KAAK,UAAU;AAAA,EAClC;AAEA,SAAO;AACT;","names":["module"]}
@@ -29,8 +29,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
29
29
  var utils_exports = {};
30
30
  __export(utils_exports, {
31
31
  getFileHash: () => getFileHash,
32
- sortAlphabetically: () => sortAlphabetically,
33
- transformToCamelCase: () => transformToCamelCase
32
+ kebabCaseToCamelCase: () => kebabCaseToCamelCase,
33
+ sortAlphabetically: () => sortAlphabetically
34
34
  });
35
35
  module.exports = __toCommonJS(utils_exports);
36
36
  var import_crypto_js = __toESM(require("crypto-js"));
@@ -38,21 +38,22 @@ const getFileHash = (filePath) => {
38
38
  const hash = import_crypto_js.default.SHA3(filePath);
39
39
  return hash.toString(import_crypto_js.default.enc.Base64).replace(/[^A-Z\d]/gi, "").substring(0, 20);
40
40
  };
41
- const transformToCamelCase = (string) => {
42
- const words = string.split(/[\s\-_]+/);
43
- const camelCasedWords = words.map((word, index) => {
44
- if (index === 0) {
45
- return word[0].toUpperCase() + word.slice(1);
46
- }
47
- return word.charAt(0).toUpperCase() + word.slice(1);
48
- });
49
- return camelCasedWords.join("");
41
+ const kebabCaseToCamelCase = (name) => {
42
+ return name.split(/[^a-zA-Z0-9]+/).filter(Boolean).map((word) => {
43
+ const lowerWord = word.toLowerCase();
44
+ let capitalized = lowerWord.charAt(0).toUpperCase() + lowerWord.slice(1);
45
+ capitalized = capitalized.replace(
46
+ /(\d)([a-z])/g,
47
+ (_, number, char) => number + char.toUpperCase()
48
+ );
49
+ return capitalized;
50
+ }).join("");
50
51
  };
51
52
  const sortAlphabetically = (a, b) => a.localeCompare(b);
52
53
  // Annotate the CommonJS export names for ESM import in node:
53
54
  0 && (module.exports = {
54
55
  getFileHash,
55
- sortAlphabetically,
56
- transformToCamelCase
56
+ kebabCaseToCamelCase,
57
+ sortAlphabetically
57
58
  });
58
59
  //# sourceMappingURL=utils.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils.ts"],"sourcesContent":["import crypto from 'crypto-js';\n\nexport const getFileHash = (filePath: string) => {\n const hash = crypto.SHA3(filePath);\n\n return hash\n .toString(crypto.enc.Base64)\n .replace(/[^A-Z\\d]/gi, '')\n .substring(0, 20);\n};\n\nexport const transformToCamelCase = (string: string): string => {\n // Split the string into words using a regex that finds spaces, hyphens, and underscores\n const words = string.split(/[\\s\\-_]+/);\n\n // Transform each word except the first to have its first letter uppercase\n const camelCasedWords = words.map((word, index) => {\n if (index === 0) {\n return word[0].toUpperCase() + word.slice(1);\n }\n return word.charAt(0).toUpperCase() + word.slice(1);\n });\n\n // Join the words back together\n return camelCasedWords.join('');\n};\n\nexport const sortAlphabetically = (a: string, b: string) => a.localeCompare(b);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAmB;AAEZ,MAAM,cAAc,CAAC,aAAqB;AAC/C,QAAM,OAAO,iBAAAA,QAAO,KAAK,QAAQ;AAEjC,SAAO,KACJ,SAAS,iBAAAA,QAAO,IAAI,MAAM,EAC1B,QAAQ,cAAc,EAAE,EACxB,UAAU,GAAG,EAAE;AACpB;AAEO,MAAM,uBAAuB,CAAC,WAA2B;AAE9D,QAAM,QAAQ,OAAO,MAAM,UAAU;AAGrC,QAAM,kBAAkB,MAAM,IAAI,CAAC,MAAM,UAAU;AACjD,QAAI,UAAU,GAAG;AACf,aAAO,KAAK,CAAC,EAAE,YAAY,IAAI,KAAK,MAAM,CAAC;AAAA,IAC7C;AACA,WAAO,KAAK,OAAO,CAAC,EAAE,YAAY,IAAI,KAAK,MAAM,CAAC;AAAA,EACpD,CAAC;AAGD,SAAO,gBAAgB,KAAK,EAAE;AAChC;AAEO,MAAM,qBAAqB,CAAC,GAAW,MAAc,EAAE,cAAc,CAAC;","names":["crypto"]}
1
+ {"version":3,"sources":["../../src/utils.ts"],"sourcesContent":["import crypto from 'crypto-js';\n\nexport const getFileHash = (filePath: string) => {\n const hash = crypto.SHA3(filePath);\n\n return hash\n .toString(crypto.enc.Base64)\n .replace(/[^A-Z\\d]/gi, '')\n .substring(0, 20);\n};\n\nexport const kebabCaseToCamelCase = (name: string): string => {\n return name\n .split(/[^a-zA-Z0-9]+/) // Split on any non-alphanumeric character\n .filter(Boolean) // Remove any empty strings\n .map((word) => {\n // Convert the entire word to lowercase first\n const lowerWord = word.toLowerCase();\n\n // Capitalize the first character\n let capitalized = lowerWord.charAt(0).toUpperCase() + lowerWord.slice(1);\n\n // Capitalize any letter that follows a number\n capitalized = capitalized.replace(\n /(\\d)([a-z])/g,\n (_, number, char) => number + char.toUpperCase()\n );\n\n return capitalized;\n })\n .join(''); // Concatenate all parts into a single string\n};\n\nexport const sortAlphabetically = (a: string, b: string) => a.localeCompare(b);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAmB;AAEZ,MAAM,cAAc,CAAC,aAAqB;AAC/C,QAAM,OAAO,iBAAAA,QAAO,KAAK,QAAQ;AAEjC,SAAO,KACJ,SAAS,iBAAAA,QAAO,IAAI,MAAM,EAC1B,QAAQ,cAAc,EAAE,EACxB,UAAU,GAAG,EAAE;AACpB;AAEO,MAAM,uBAAuB,CAAC,SAAyB;AAC5D,SAAO,KACJ,MAAM,eAAe,EACrB,OAAO,OAAO,EACd,IAAI,CAAC,SAAS;AAEb,UAAM,YAAY,KAAK,YAAY;AAGnC,QAAI,cAAc,UAAU,OAAO,CAAC,EAAE,YAAY,IAAI,UAAU,MAAM,CAAC;AAGvE,kBAAc,YAAY;AAAA,MACxB;AAAA,MACA,CAAC,GAAG,QAAQ,SAAS,SAAS,KAAK,YAAY;AAAA,IACjD;AAEA,WAAO;AAAA,EACT,CAAC,EACA,KAAK,EAAE;AACZ;AAEO,MAAM,qBAAqB,CAAC,GAAW,MAAc,EAAE,cAAc,CAAC;","names":["crypto"]}
@@ -5,7 +5,10 @@ const { dictionariesDir } = getConfiguration().content;
5
5
  const writeDictionary = async (dictionaries) => {
6
6
  const resultDictionariesPaths = [];
7
7
  for await (const dictionaryContent of dictionaries) {
8
- const contentString = JSON.stringify(dictionaryContent);
8
+ const contentString = JSON.stringify({
9
+ $schema: "https://intlayer.org/schema.json",
10
+ ...dictionaryContent
11
+ });
9
12
  const id = dictionaryContent.key;
10
13
  const outputFileName = `${id}.json`;
11
14
  const resultFilePath = resolve(dictionariesDir, outputFileName);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.ts"],"sourcesContent":["import { writeFile } from 'fs/promises';\nimport { resolve } from 'path';\nimport { getConfiguration } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\n\nconst { dictionariesDir } = getConfiguration().content;\n\nexport const writeDictionary = async (dictionaries: Dictionary[]) => {\n const resultDictionariesPaths: string[] = [];\n\n for await (const dictionaryContent of dictionaries) {\n const contentString = JSON.stringify(dictionaryContent);\n\n const id = dictionaryContent.key;\n const outputFileName = `${id}.json`;\n const resultFilePath = resolve(dictionariesDir, outputFileName);\n\n // Create the json file\n await writeFile(resultFilePath, contentString, 'utf8').catch((err) => {\n console.error(`Error creating ${outputFileName}:`, err);\n });\n\n resultDictionariesPaths.push(resultFilePath);\n }\n\n return resultDictionariesPaths;\n};\n"],"mappings":"AAAA,SAAS,iBAAiB;AAC1B,SAAS,eAAe;AACxB,SAAS,wBAAwB;AAGjC,MAAM,EAAE,gBAAgB,IAAI,iBAAiB,EAAE;AAExC,MAAM,kBAAkB,OAAO,iBAA+B;AACnE,QAAM,0BAAoC,CAAC;AAE3C,mBAAiB,qBAAqB,cAAc;AAClD,UAAM,gBAAgB,KAAK,UAAU,iBAAiB;AAEtD,UAAM,KAAK,kBAAkB;AAC7B,UAAM,iBAAiB,GAAG,EAAE;AAC5B,UAAM,iBAAiB,QAAQ,iBAAiB,cAAc;AAG9D,UAAM,UAAU,gBAAgB,eAAe,MAAM,EAAE,MAAM,CAAC,QAAQ;AACpE,cAAQ,MAAM,kBAAkB,cAAc,KAAK,GAAG;AAAA,IACxD,CAAC;AAED,4BAAwB,KAAK,cAAc;AAAA,EAC7C;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.ts"],"sourcesContent":["import { writeFile } from 'fs/promises';\nimport { resolve } from 'path';\nimport { getConfiguration } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\n\nconst { dictionariesDir } = getConfiguration().content;\n\nexport const writeDictionary = async (dictionaries: Dictionary[]) => {\n const resultDictionariesPaths: string[] = [];\n\n for await (const dictionaryContent of dictionaries) {\n const contentString = JSON.stringify({\n $schema: 'https://intlayer.org/schema.json',\n ...dictionaryContent,\n });\n\n const id = dictionaryContent.key;\n const outputFileName = `${id}.json`;\n const resultFilePath = resolve(dictionariesDir, outputFileName);\n\n // Create the json file\n await writeFile(resultFilePath, contentString, 'utf8').catch((err) => {\n console.error(`Error creating ${outputFileName}:`, err);\n });\n\n resultDictionariesPaths.push(resultFilePath);\n }\n\n return resultDictionariesPaths;\n};\n"],"mappings":"AAAA,SAAS,iBAAiB;AAC1B,SAAS,eAAe;AACxB,SAAS,wBAAwB;AAGjC,MAAM,EAAE,gBAAgB,IAAI,iBAAiB,EAAE;AAExC,MAAM,kBAAkB,OAAO,iBAA+B;AACnE,QAAM,0BAAoC,CAAC;AAE3C,mBAAiB,qBAAqB,cAAc;AAClD,UAAM,gBAAgB,KAAK,UAAU;AAAA,MACnC,SAAS;AAAA,MACT,GAAG;AAAA,IACL,CAAC;AAED,UAAM,KAAK,kBAAkB;AAC7B,UAAM,iBAAiB,GAAG,EAAE;AAC5B,UAAM,iBAAiB,QAAQ,iBAAiB,cAAc;AAG9D,UAAM,UAAU,gBAAgB,eAAe,MAAM,EAAE,MAAM,CAAC,QAAQ;AACpE,cAAQ,MAAM,kBAAkB,cAAc,KAAK,GAAG;AAAA,IACxD,CAAC;AAED,4BAAwB,KAAK,cAAc;AAAA,EAC7C;AAEA,SAAO;AACT;","names":[]}
@@ -2,15 +2,15 @@ import { existsSync, mkdirSync, writeFileSync } from "fs";
2
2
  import { basename, join, relative } from "path";
3
3
  import { Locales, getConfiguration } from "@intlayer/config";
4
4
  import fg from "fast-glob";
5
- import { getFileHash, transformToCamelCase } from "../../utils.mjs";
5
+ import { getFileHash, kebabCaseToCamelCase } from "../../utils.mjs";
6
6
  const { content, internationalization } = getConfiguration();
7
7
  const { typesDir, moduleAugmentationDir } = content;
8
8
  const { locales, strictMode } = internationalization;
9
- const getTypeName = (id) => transformToCamelCase(`${id}Content`);
9
+ const getTypeName = (key) => `${kebabCaseToCamelCase(key)}Content`;
10
10
  const generateTypeIndexContent = (typeFiles) => {
11
11
  let content2 = "/* eslint-disable */\nimport { Locales } from 'intlayer';\n";
12
12
  const dictionariesRef = typeFiles.map((dictionaryPath) => ({
13
- relativePath: relative(moduleAugmentationDir, dictionaryPath),
13
+ relativePath: `./${relative(moduleAugmentationDir, dictionaryPath)}`,
14
14
  id: basename(dictionaryPath, ".d.ts"),
15
15
  // Get the base name as the dictionary id
16
16
  hash: `_${getFileHash(dictionaryPath)}`
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/transpiler/dictionary_to_type/createModuleAugmentation.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { basename, join, relative } from 'path';\nimport { Locales, getConfiguration } from '@intlayer/config';\nimport fg from 'fast-glob';\nimport { getFileHash, transformToCamelCase } from '../../utils';\n\nconst { content, internationalization } = getConfiguration();\nconst { typesDir, moduleAugmentationDir } = content;\nconst { locales, strictMode } = internationalization;\n\nexport const getTypeName = (id: string): string =>\n transformToCamelCase(`${id}Content`);\n\n/**\n * This function generates the content of the module augmentation file\n */\nconst generateTypeIndexContent = (typeFiles: string[]): string => {\n let content = \"/* eslint-disable */\\nimport { Locales } from 'intlayer';\\n\";\n\n const dictionariesRef = typeFiles.map((dictionaryPath) => ({\n relativePath: relative(moduleAugmentationDir, dictionaryPath),\n id: basename(dictionaryPath, '.d.ts'), // Get the base name as the dictionary id\n hash: `_${getFileHash(dictionaryPath)}`, // Get the hash of the dictionary to avoid conflicts\n }));\n\n // Import all dictionaries\n dictionariesRef.forEach((dictionary) => {\n const typeName = getTypeName(dictionary.id);\n content += `import type { ${typeName} as ${dictionary.hash} } from '${dictionary.relativePath}';\\n`;\n });\n\n content += '\\n';\n\n // Format Dictionary Map\n const formattedDictionaryMap: string = dictionariesRef\n .map((dictionary) => ` \"${dictionary.id}\": ${dictionary.hash};`)\n .join('\\n');\n\n const formatLocales = locales\n .map((locale) => {\n for (const key in Locales) {\n if (Locales[key as keyof typeof Locales] === locale) {\n return `Locales.${key}`;\n }\n }\n })\n .join(' | ');\n\n const strictModeRecord =\n strictMode === 'strict'\n ? `interface IConfigLocales<Content> extends Record<ExtractedLocales, Content> {}`\n : strictMode === 'required_only'\n ? `interface IConfigLocales<Content> extends Record<ExtractedLocales, Content>, Partial<Record<ExcludedLocales, Content>> {}`\n : `interface IConfigLocales<Content> extends Partial<Record<Locales, Content>> {}`;\n\n /**\n * Write the module augmentation to extend the intlayer module with the dictionaries types\n * Will suggest the type resulting of the dictionaries\n *\n * declare module 'intlayer' {\n * interface IntlayerDictionaryTypesConnector = {\n * dictionaries: {\n * id: DictionaryType;\n * }\n * }\n *\n * type ConfigLocales = Locales.ENGLISH | Locales.FRENCH | Locales.SPANISH;\n * type ExtractedLocales = Extract<Locales, ConfigLocales>;\n * type ExcludedLocales = Exclude<Locales, ConfigLocales>;\n *\n * interface IConfigLocales<Content> extends Record<ExtractedLocales, Content>, Partial<Record<ExcludedLocales, Content>> {}\n *\n *\n * }\n * See https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation\n */\n content += `declare module 'intlayer' {\\n`;\n content += ` interface IntlayerDictionaryTypesConnector {\\n${formattedDictionaryMap}\\n }\\n\\n`;\n content += ` type ConfigLocales = ${formatLocales};\\n`;\n content += ` type ExtractedLocales = Extract<Locales, ConfigLocales>;\\n`;\n content += ` type ExcludedLocales = Exclude<Locales, ConfigLocales>;\\n\\n`;\n content += ` ${strictModeRecord}\\n`;\n content += `}`;\n\n return content;\n};\n\n/**\n * This function generates a index file merging all the types\n */\nexport const createModuleAugmentation = () => {\n // Create main directory if it doesn't exist\n if (!existsSync(moduleAugmentationDir)) {\n mkdirSync(moduleAugmentationDir, { recursive: true });\n }\n\n const dictionaries: string[] = fg.sync(`${typesDir}/**/*.d.ts`);\n // Create the dictionary list file\n\n const tsContent = generateTypeIndexContent(dictionaries);\n writeFileSync(join(moduleAugmentationDir, 'intlayer.d.ts'), tsContent);\n};\n"],"mappings":"AAAA,SAAS,YAAY,WAAW,qBAAqB;AACrD,SAAS,UAAU,MAAM,gBAAgB;AACzC,SAAS,SAAS,wBAAwB;AAC1C,OAAO,QAAQ;AACf,SAAS,aAAa,4BAA4B;AAElD,MAAM,EAAE,SAAS,qBAAqB,IAAI,iBAAiB;AAC3D,MAAM,EAAE,UAAU,sBAAsB,IAAI;AAC5C,MAAM,EAAE,SAAS,WAAW,IAAI;AAEzB,MAAM,cAAc,CAAC,OAC1B,qBAAqB,GAAG,EAAE,SAAS;AAKrC,MAAM,2BAA2B,CAAC,cAAgC;AAChE,MAAIA,WAAU;AAEd,QAAM,kBAAkB,UAAU,IAAI,CAAC,oBAAoB;AAAA,IACzD,cAAc,SAAS,uBAAuB,cAAc;AAAA,IAC5D,IAAI,SAAS,gBAAgB,OAAO;AAAA;AAAA,IACpC,MAAM,IAAI,YAAY,cAAc,CAAC;AAAA;AAAA,EACvC,EAAE;AAGF,kBAAgB,QAAQ,CAAC,eAAe;AACtC,UAAM,WAAW,YAAY,WAAW,EAAE;AAC1C,IAAAA,YAAW,iBAAiB,QAAQ,OAAO,WAAW,IAAI,YAAY,WAAW,YAAY;AAAA;AAAA,EAC/F,CAAC;AAED,EAAAA,YAAW;AAGX,QAAM,yBAAiC,gBACpC,IAAI,CAAC,eAAe,QAAQ,WAAW,EAAE,MAAM,WAAW,IAAI,GAAG,EACjE,KAAK,IAAI;AAEZ,QAAM,gBAAgB,QACnB,IAAI,CAAC,WAAW;AACf,eAAW,OAAO,SAAS;AACzB,UAAI,QAAQ,GAA2B,MAAM,QAAQ;AACnD,eAAO,WAAW,GAAG;AAAA,MACvB;AAAA,IACF;AAAA,EACF,CAAC,EACA,KAAK,KAAK;AAEb,QAAM,mBACJ,eAAe,WACX,mFACA,eAAe,kBACb,8HACA;AAuBR,EAAAA,YAAW;AAAA;AACX,EAAAA,YAAW;AAAA,EAAmD,sBAAsB;AAAA;AAAA;AAAA;AACpF,EAAAA,YAAW,0BAA0B,aAAa;AAAA;AAClD,EAAAA,YAAW;AAAA;AACX,EAAAA,YAAW;AAAA;AAAA;AACX,EAAAA,YAAW,KAAK,gBAAgB;AAAA;AAChC,EAAAA,YAAW;AAEX,SAAOA;AACT;AAKO,MAAM,2BAA2B,MAAM;AAE5C,MAAI,CAAC,WAAW,qBAAqB,GAAG;AACtC,cAAU,uBAAuB,EAAE,WAAW,KAAK,CAAC;AAAA,EACtD;AAEA,QAAM,eAAyB,GAAG,KAAK,GAAG,QAAQ,YAAY;AAG9D,QAAM,YAAY,yBAAyB,YAAY;AACvD,gBAAc,KAAK,uBAAuB,eAAe,GAAG,SAAS;AACvE;","names":["content"]}
1
+ {"version":3,"sources":["../../../../src/transpiler/dictionary_to_type/createModuleAugmentation.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { basename, join, relative } from 'path';\nimport { Locales, getConfiguration } from '@intlayer/config';\nimport fg from 'fast-glob';\nimport { getFileHash, kebabCaseToCamelCase } from '../../utils';\n\nconst { content, internationalization } = getConfiguration();\nconst { typesDir, moduleAugmentationDir } = content;\nconst { locales, strictMode } = internationalization;\n\nexport const getTypeName = (key: string): string =>\n `${kebabCaseToCamelCase(key)}Content`;\n\n/**\n * This function generates the content of the module augmentation file\n */\nconst generateTypeIndexContent = (typeFiles: string[]): string => {\n let content = \"/* eslint-disable */\\nimport { Locales } from 'intlayer';\\n\";\n\n const dictionariesRef = typeFiles.map((dictionaryPath) => ({\n relativePath: `./${relative(moduleAugmentationDir, dictionaryPath)}`,\n id: basename(dictionaryPath, '.d.ts'), // Get the base name as the dictionary id\n hash: `_${getFileHash(dictionaryPath)}`, // Get the hash of the dictionary to avoid conflicts\n }));\n\n // Import all dictionaries\n dictionariesRef.forEach((dictionary) => {\n const typeName = getTypeName(dictionary.id);\n content += `import type { ${typeName} as ${dictionary.hash} } from '${dictionary.relativePath}';\\n`;\n });\n\n content += '\\n';\n\n // Format Dictionary Map\n const formattedDictionaryMap: string = dictionariesRef\n .map((dictionary) => ` \"${dictionary.id}\": ${dictionary.hash};`)\n .join('\\n');\n\n const formatLocales = locales\n .map((locale) => {\n for (const key in Locales) {\n if (Locales[key as keyof typeof Locales] === locale) {\n return `Locales.${key}`;\n }\n }\n })\n .join(' | ');\n\n const strictModeRecord =\n strictMode === 'strict'\n ? `interface IConfigLocales<Content> extends Record<ExtractedLocales, Content> {}`\n : strictMode === 'required_only'\n ? `interface IConfigLocales<Content> extends Record<ExtractedLocales, Content>, Partial<Record<ExcludedLocales, Content>> {}`\n : `interface IConfigLocales<Content> extends Partial<Record<Locales, Content>> {}`;\n\n /**\n * Write the module augmentation to extend the intlayer module with the dictionaries types\n * Will suggest the type resulting of the dictionaries\n *\n * declare module 'intlayer' {\n * interface IntlayerDictionaryTypesConnector = {\n * dictionaries: {\n * id: DictionaryType;\n * }\n * }\n *\n * type ConfigLocales = Locales.ENGLISH | Locales.FRENCH | Locales.SPANISH;\n * type ExtractedLocales = Extract<Locales, ConfigLocales>;\n * type ExcludedLocales = Exclude<Locales, ConfigLocales>;\n *\n * interface IConfigLocales<Content> extends Record<ExtractedLocales, Content>, Partial<Record<ExcludedLocales, Content>> {}\n *\n *\n * }\n * See https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation\n */\n content += `declare module 'intlayer' {\\n`;\n content += ` interface IntlayerDictionaryTypesConnector {\\n${formattedDictionaryMap}\\n }\\n\\n`;\n content += ` type ConfigLocales = ${formatLocales};\\n`;\n content += ` type ExtractedLocales = Extract<Locales, ConfigLocales>;\\n`;\n content += ` type ExcludedLocales = Exclude<Locales, ConfigLocales>;\\n\\n`;\n content += ` ${strictModeRecord}\\n`;\n content += `}`;\n\n return content;\n};\n\n/**\n * This function generates a index file merging all the types\n */\nexport const createModuleAugmentation = () => {\n // Create main directory if it doesn't exist\n if (!existsSync(moduleAugmentationDir)) {\n mkdirSync(moduleAugmentationDir, { recursive: true });\n }\n\n const dictionaries: string[] = fg.sync(`${typesDir}/**/*.d.ts`);\n // Create the dictionary list file\n\n const tsContent = generateTypeIndexContent(dictionaries);\n writeFileSync(join(moduleAugmentationDir, 'intlayer.d.ts'), tsContent);\n};\n"],"mappings":"AAAA,SAAS,YAAY,WAAW,qBAAqB;AACrD,SAAS,UAAU,MAAM,gBAAgB;AACzC,SAAS,SAAS,wBAAwB;AAC1C,OAAO,QAAQ;AACf,SAAS,aAAa,4BAA4B;AAElD,MAAM,EAAE,SAAS,qBAAqB,IAAI,iBAAiB;AAC3D,MAAM,EAAE,UAAU,sBAAsB,IAAI;AAC5C,MAAM,EAAE,SAAS,WAAW,IAAI;AAEzB,MAAM,cAAc,CAAC,QAC1B,GAAG,qBAAqB,GAAG,CAAC;AAK9B,MAAM,2BAA2B,CAAC,cAAgC;AAChE,MAAIA,WAAU;AAEd,QAAM,kBAAkB,UAAU,IAAI,CAAC,oBAAoB;AAAA,IACzD,cAAc,KAAK,SAAS,uBAAuB,cAAc,CAAC;AAAA,IAClE,IAAI,SAA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{ kebabCaseToCamelCase } from "../../utils.mjs";
9
10
  const { content } = getConfiguration();
10
11
  const { typesDir } = content;
11
12
  const requireUncached = (module) => {
12
13
  delete ESMxCJSRequire.cache[ESMxCJSRequire.resolve(module)];
13
14
  return ESMxCJSRequire(module);
14
15
  };
15
- const kebabCaseToCamelCase = (name) => name.split(/[\s\-_]+/).map((word, index) => {
16
- if (index === 0) {
17
- return word;
18
- }
19
- return word.charAt(0).toUpperCase() + word.slice(1);
20
- }).join("");
21
16
  const generateTypeScriptType = async (typeName, jsonString) => {
22
17
  const { lines } = await quicktypeJSON(typeName, jsonString);
23
18
  const linesString = lines.join("\n");
@@ -51,17 +46,16 @@ const createTypes = async (dictionariesPaths) => {
51
46
  }
52
47
  for (const dictionaryPath of dictionariesPaths) {
53
48
  const dictionary = requireUncached(dictionaryPath);
54
- const dictionaryName = dictionary.key;
55
- if (!dictionaryName) {
49
+ if (!dictionary.key) {
56
50
  continue;
57
51
  }
58
- const dictionaryNameCamelCase = kebabCaseToCamelCase(dictionaryName) + "Content";
52
+ const dictionaryNameCamelCase = `${kebabCaseToCamelCase(dictionary.key)}Content`;
59
53
  const dictionaryContentString = JSON.stringify(dictionary);
60
54
  const typeDefinition = await generateTypeScriptType(
61
55
  dictionaryNameCamelCase,
62
56
  dictionaryContentString
63
57
  );
64
- const outputPath = resolve(typesDir, `${dictionaryName}.d.ts`);
58
+ const outputPath = resolve(typesDir, `${dictionary.key}.d.ts`);
65
59
  writeFileSync(outputPath, typeDefinition);
66
60
  resultTypesPaths.push(outputPath);
67
61
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/transpiler/dictionary_to_type/createType.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { resolve } from 'path';\nimport { getConfiguration, ESMxCJSRequire } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport {\n quicktype,\n InputData,\n jsonInputForTargetLanguage,\n} from 'quicktype-core';\n\nconst { content } = getConfiguration();\nconst { typesDir } = content;\n\nconst requireUncached = (module: string) => {\n delete ESMxCJSRequire.cache[ESMxCJSRequire.resolve(module)];\n return ESMxCJSRequire(module);\n};\n\nconst kebabCaseToCamelCase = (name: string): string =>\n name\n .split(/[\\s\\-_]+/) // Regular expression to match space, hyphen, or underscore\n .map((word, index) => {\n if (index === 0) {\n return word; // Return the first word as is\n }\n return word.charAt(0).toUpperCase() + word.slice(1); // Capitalize the first letter of subsequent words\n })\n .join(''); // Join all the segments into one string\n\nexport const generateTypeScriptType = async (\n typeName: string,\n jsonString: string\n) => {\n const { lines } = await quicktypeJSON(typeName, jsonString);\n\n const linesString: string = lines.join('\\n');\n\n return linesString;\n};\n\nconst quicktypeJSON = async (typeName: string, jsonString: string) => {\n const jsonInput = jsonInputForTargetLanguage('typescript');\n\n // We could add multiple samples for the same desired\n // type, or many sources for other types. Here we're\n // just making one type from one piece of sample JSON.\n\n await jsonInput.addSource({\n name: typeName,\n samples: [jsonString],\n });\n\n const inputData = new InputData();\n inputData.addInput(jsonInput);\n\n return await quicktype({\n inputData,\n lang: 'typescript',\n alphabetizeProperties: true,\n rendererOptions: {\n 'just-types': 'true',\n 'explicit-unions': 'true',\n 'acronym-style': 'camel',\n 'prefer-types': 'true',\n readonly: 'false',\n },\n });\n};\n\n/**\n * This function generates a TypeScript type definition from a JSON object\n */\nexport const createTypes = async (\n dictionariesPaths: string[]\n): Promise<string[]> => {\n const resultTypesPaths: string[] = [];\n\n // Create type folders if they don't exist\n if (!existsSync(typesDir)) {\n mkdirSync(typesDir, { recursive: true });\n }\n\n for (const dictionaryPath of dictionariesPaths) {\n const dictionary: Dictionary = requireUncached(dictionaryPath);\n\n const dictionaryName: string = dictionary.key;\n\n if (!dictionaryName) {\n // Skip dictionary if it doesn't have a key, if not exported as default etc\n continue;\n }\n\n const dictionaryNameCamelCase: string =\n kebabCaseToCamelCase(dictionaryName) + 'Content';\n\n const dictionaryContentString: string = JSON.stringify(dictionary);\n\n const typeDefinition: string = await generateTypeScriptType(\n dictionaryNameCamelCase,\n dictionaryContentString\n );\n\n const outputPath: string = resolve(typesDir, `${dictionaryName}.d.ts`);\n\n writeFileSync(outputPath, typeDefinition);\n\n resultTypesPaths.push(outputPath);\n }\n\n return resultTypesPaths;\n};\n"],"mappings":"AAAA,SAAS,YAAY,WAAW,qBAAqB;AACrD,SAAS,eAAe;AACxB,SAAS,kBAAkB,sBAAsB;AAEjD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,MAAM,EAAE,QAAQ,IAAI,iBAAiB;AACrC,MAAM,EAAE,SAAS,IAAI;AAErB,MAAM,kBAAkB,CAAC,WAAmB;AAC1C,SAAO,eAAe,MAAM,eAAe,QAAQ,MAAM,CAAC;AAC1D,SAAO,eAAe,MAAM;AAC9B;AAEA,MAAM,uBAAuB,CAAC,SAC5B,KACG,MAAM,UAAU,EAChB,IAAI,CAAC,MAAM,UAAU;AACpB,MAAI,UAAU,GAAG;AACf,WAAO;AAAA,EACT;AACA,SAAO,KAAK,OAAO,CAAC,EAAE,YAAY,IAAI,KAAK,MAAM,CAAC;AACpD,CAAC,EACA,KAAK,EAAE;AAEL,MAAM,yBAAyB,OACpC,UACA,eACG;AACH,QAAM,EAAE,MAAM,IAAI,MAAM,cAAc,UAAU,UAAU;AAE1D,QAAM,cAAsB,MAAM,KAAK,IAAI;AAE3C,SAAO;AACT;AAEA,MAAM,gBAAgB,OAAO,UAAkB,eAAuB;AACpE,QAAM,YAAY,2BAA2B,YAAY;AAMzD,QAAM,UAAU,UAAU;AAAA,IACxB,MAAM;AAAA,IACN,SAAS,CAAC,UAAU;AAAA,EACtB,CAAC;AAED,QAAM,YAAY,IAAI,UAAU;AAChC,YAAU,SAAS,SAAS;AAE5B,SAAO,MAAM,UAAU;AAAA,IACrB;AAAA,IACA,MAAM;AAAA,IACN,uBAAuB;AAAA,IACvB,iBAAiB;AAAA,MACf,cAAc;AAAA,MACd,mBAAmB;AAAA,MACnB,iBAAiB;AAAA,MACjB,gBAAgB;AAAA,MAChB,UAAU;AAAA,IACZ;AAAA,EACF,CAAC;AACH;AAKO,MAAM,cAAc,OACzB,sBACsB;AACtB,QAAM,mBAA6B,CAAC;AAGpC,MAAI,CAAC,WAAW,QAAQ,GAAG;AACzB,cAAU,UAAU,EAAE,WAAW,KAAK,CAAC;AAAA,EACzC;AAEA,aAAW,kBAAkB,mBAAmB;AAC9C,UAAM,aAAyB,gBAAgB,cAAc;AAE7D,UAAM,iBAAyB,WAAW;AAE1C,QAAI,CAAC,gBAAgB;AAEnB;AAAA,IACF;AAEA,UAAM,0BACJ,qBAAqB,cAAc,IAAI;AAEzC,UAAM,0BAAkC,KAAK,UAAU,UAAU;AAEjE,UAAM,iBAAyB,MAAM;AAAA,MACnC;AAAA,MACA;AAAA,IACF;AAEA,UAAM,aAAqB,QAAQ,UAAU,GAAG,cAAc,OAAO;AAErE,kBAAc,YAAY,cAAc;AAExC,qBAAiB,KAAK,UAAU;AAAA,EAClC;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../../src/transpiler/dictionary_to_type/createType.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { resolve } from 'path';\nimport { getConfiguration, ESMxCJSRequire } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport {\n quicktype,\n InputData,\n jsonInputForTargetLanguage,\n} from 'quicktype-core';\nimport { kebabCaseToCamelCase } from '../../utils';\n\nconst { content } = getConfiguration();\nconst { typesDir } = content;\n\nconst requireUncached = (module: string) => {\n delete ESMxCJSRequire.cache[ESMxCJSRequire.resolve(module)];\n return ESMxCJSRequire(module);\n};\n\nexport const generateTypeScriptType = async (\n typeName: string,\n jsonString: string\n) => {\n const { lines } = await quicktypeJSON(typeName, jsonString);\n\n const linesString: string = lines.join('\\n');\n\n return linesString;\n};\n\nconst quicktypeJSON = async (typeName: string, jsonString: string) => {\n const jsonInput = jsonInputForTargetLanguage('typescript');\n\n // We could add multiple samples for the same desired\n // type, or many sources for other types. Here we're\n // just making one type from one piece of sample JSON.\n\n await jsonInput.addSource({\n name: typeName,\n samples: [jsonString],\n });\n\n const inputData = new InputData();\n inputData.addInput(jsonInput);\n\n return await quicktype({\n inputData,\n lang: 'typescript',\n alphabetizeProperties: true,\n rendererOptions: {\n 'just-types': 'true',\n 'explicit-unions': 'true',\n 'acronym-style': 'camel',\n 'prefer-types': 'true',\n readonly: 'false',\n },\n });\n};\n\n/**\n * This function generates a TypeScript type definition from a JSON object\n */\nexport const createTypes = async (\n dictionariesPaths: string[]\n): Promise<string[]> => {\n const resultTypesPaths: string[] = [];\n\n // Create type folders if they don't exist\n if (!existsSync(typesDir)) {\n mkdirSync(typesDir, { recursive: true });\n }\n\n for (const dictionaryPath of dictionariesPaths) {\n const dictionary: Dictionary = requireUncached(dictionaryPath);\n\n if (!dictionary.key) {\n // Skip dictionary if it doesn't have a key, if not exported as default etc\n continue;\n }\n\n const dictionaryNameCamelCase: string = `${kebabCaseToCamelCase(dictionary.key)}Content`;\n\n const dictionaryContentString: string = JSON.stringify(dictionary);\n\n const typeDefinition: string = await generateTypeScriptType(\n dictionaryNameCamelCase,\n dictionaryContentString\n );\n\n const outputPath: string = resolve(typesDir, `${dictionary.key}.d.ts`);\n\n writeFileSync(outputPath, typeDefinition);\n\n resultTypesPaths.push(outputPath);\n }\n\n return resultTypesPaths;\n};\n"],"mappings":"AAAA,SAAS,YAAY,WAAW,qBAAqB;AACrD,SAAS,eAAe;AACxB,SAAS,kBAAkB,sBAAsB;AAEjD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,4BAA4B;AAErC,MAAM,EAAE,QAAQ,IAAI,iBAAiB;AACrC,MAAM,EAAE,SAAS,IAAI;AAErB,MAAM,kBAAkB,CAAC,WAAmB;AAC1C,SAAO,eAAe,MAAM,eAAe,QAAQ,MAAM,CAAC;AAC1D,SAAO,eAAe,MAAM;AAC9B;AAEO,MAAM,yBAAyB,OACpC,UACA,eACG;AACH,QAAM,EAAE,MAAM,IAAI,MAAM,cAAc,UAAU,UAAU;AAE1D,QAAM,cAAsB,MAAM,KAAK,IAAI;AAE3C,SAAO;AACT;AAEA,MAAM,gBAAgB,OAAO,UAAkB,eAAuB;AACpE,QAAM,YAAY,2BAA2B,YAAY;AAMzD,QAAM,UAAU,UAAU;AAAA,IACxB,MAAM;AAAA,IACN,SAAS,CAAC,UAAU;AAAA,EACtB,CAAC;AAED,QAAM,YAAY,IAAI,UAAU;AAChC,YAAU,SAAS,SAAS;AAE5B,SAAO,MAAM,UAAU;AAAA,IACrB;AAAA,IACA,MAAM;AAAA,IACN,uBAAuB;AAAA,IACvB,iBAAiB;AAAA,MACf,cAAc;AAAA,MACd,mBAAmB;AAAA,MACnB,iBAAiB;AAAA,MACjB,gBAAgB;AAAA,MAChB,UAAU;AAAA,IACZ;AAAA,EACF,CAAC;AACH;AAKO,MAAM,cAAc,OACzB,sBACsB;AACtB,QAAM,mBAA6B,CAAC;AAGpC,MAAI,CAAC,WAAW,QAAQ,GAAG;AACzB,cAAU,UAAU,EAAE,WAAW,KAAK,CAAC;AAAA,EACzC;AAEA,aAAW,kBAAkB,mBAAmB;AAC9C,UAAM,aAAyB,gBAAgB,cAAc;AAE7D,QAAI,CAAC,WAAW,KAAK;AAEnB;AAAA,IACF;AAEA,UAAM,0BAAkC,GAAG,qBAAqB,WAAW,GAAG,CAAC;AAE/E,UAAM,0BAAkC,KAAK,UAAU,UAAU;AAEjE,UAAM,iBAAyB,MAAM;AAAA,MACnC;AAAA,MACA;AAAA,IACF;AAEA,UAAM,aAAqB,QAAQ,UAAU,GAAG,WAAW,GAAG,OAAO;AAErE,kBAAc,YAAY,cAAc;AAExC,qBAAiB,KAAK,UAAU;AAAA,EAClC;AAEA,SAAO;AACT;","names":[]}
@@ -3,20 +3,21 @@ const getFileHash = (filePath) => {
3
3
  const hash = crypto.SHA3(filePath);
4
4
  return hash.toString(crypto.enc.Base64).replace(/[^A-Z\d]/gi, "").substring(0, 20);
5
5
  };
6
- const transformToCamelCase = (string) => {
7
- const words = string.split(/[\s\-_]+/);
8
- const camelCasedWords = words.map((word, index) => {
9
- if (index === 0) {
10
- return word[0].toUpperCase() + word.slice(1);
11
- }
12
- return word.charAt(0).toUpperCase() + word.slice(1);
13
- });
14
- return camelCasedWords.join("");
6
+ const kebabCaseToCamelCase = (name) => {
7
+ return name.split(/[^a-zA-Z0-9]+/).filter(Boolean).map((word) => {
8
+ const lowerWord = word.toLowerCase();
9
+ let capitalized = lowerWord.charAt(0).toUpperCase() + lowerWord.slice(1);
10
+ capitalized = capitalized.replace(
11
+ /(\d)([a-z])/g,
12
+ (_, number, char) => number + char.toUpperCase()
13
+ );
14
+ return capitalized;
15
+ }).join("");
15
16
  };
16
17
  const sortAlphabetically = (a, b) => a.localeCompare(b);
17
18
  export {
18
19
  getFileHash,
19
- sortAlphabetically,
20
- transformToCamelCase
20
+ kebabCaseToCamelCase,
21
+ sortAlphabetically
21
22
  };
22
23
  //# sourceMappingURL=utils.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils.ts"],"sourcesContent":["import crypto from 'crypto-js';\n\nexport const getFileHash = (filePath: string) => {\n const hash = crypto.SHA3(filePath);\n\n return hash\n .toString(crypto.enc.Base64)\n .replace(/[^A-Z\\d]/gi, '')\n .substring(0, 20);\n};\n\nexport const transformToCamelCase = (string: string): string => {\n // Split the string into words using a regex that finds spaces, hyphens, and underscores\n const words = string.split(/[\\s\\-_]+/);\n\n // Transform each word except the first to have its first letter uppercase\n const camelCasedWords = words.map((word, index) => {\n if (index === 0) {\n return word[0].toUpperCase() + word.slice(1);\n }\n return word.charAt(0).toUpperCase() + word.slice(1);\n });\n\n // Join the words back together\n return camelCasedWords.join('');\n};\n\nexport const sortAlphabetically = (a: string, b: string) => a.localeCompare(b);\n"],"mappings":"AAAA,OAAO,YAAY;AAEZ,MAAM,cAAc,CAAC,aAAqB;AAC/C,QAAM,OAAO,OAAO,KAAK,QAAQ;AAEjC,SAAO,KACJ,SAAS,OAAO,IAAI,MAAM,EAC1B,QAAQ,cAAc,EAAE,EACxB,UAAU,GAAG,EAAE;AACpB;AAEO,MAAM,uBAAuB,CAAC,WAA2B;AAE9D,QAAM,QAAQ,OAAO,MAAM,UAAU;AAGrC,QAAM,kBAAkB,MAAM,IAAI,CAAC,MAAM,UAAU;AACjD,QAAI,UAAU,GAAG;AACf,aAAO,KAAK,CAAC,EAAE,YAAY,IAAI,KAAK,MAAM,CAAC;AAAA,IAC7C;AACA,WAAO,KAAK,OAAO,CAAC,EAAE,YAAY,IAAI,KAAK,MAAM,CAAC;AAAA,EACpD,CAAC;AAGD,SAAO,gBAAgB,KAAK,EAAE;AAChC;AAEO,MAAM,qBAAqB,CAAC,GAAW,MAAc,EAAE,cAAc,CAAC;","names":[]}
1
+ {"version":3,"sources":["../../src/utils.ts"],"sourcesContent":["import crypto from 'crypto-js';\n\nexport const getFileHash = (filePath: string) => {\n const hash = crypto.SHA3(filePath);\n\n return hash\n .toString(crypto.enc.Base64)\n .replace(/[^A-Z\\d]/gi, '')\n .substring(0, 20);\n};\n\nexport const kebabCaseToCamelCase = (name: string): string => {\n return name\n .split(/[^a-zA-Z0-9]+/) // Split on any non-alphanumeric character\n .filter(Boolean) // Remove any empty strings\n .map((word) => {\n // Convert the entire word to lowercase first\n const lowerWord = word.toLowerCase();\n\n // Capitalize the first character\n let capitalized = lowerWord.charAt(0).toUpperCase() + lowerWord.slice(1);\n\n // Capitalize any letter that follows a number\n capitalized = capitalized.replace(\n /(\\d)([a-z])/g,\n (_, number, char) => number + char.toUpperCase()\n );\n\n return capitalized;\n })\n .join(''); // Concatenate all parts into a single string\n};\n\nexport const sortAlphabetically = (a: string, b: string) => a.localeCompare(b);\n"],"mappings":"AAAA,OAAO,YAAY;AAEZ,MAAM,cAAc,CAAC,aAAqB;AAC/C,QAAM,OAAO,OAAO,KAAK,QAAQ;AAEjC,SAAO,KACJ,SAAS,OAAO,IAAI,MAAM,EAC1B,QAAQ,cAAc,EAAE,EACxB,UAAU,GAAG,EAAE;AACpB;AAEO,MAAM,uBAAuB,CAAC,SAAyB;AAC5D,SAAO,KACJ,MAAM,eAAe,EACrB,OAAO,OAAO,EACd,IAAI,CAAC,SAAS;AAEb,UAAM,YAAY,KAAK,YAAY;AAGnC,QAAI,cAAc,UAAU,OAAO,CAAC,EAAE,YAAY,IAAI,UAAU,MAAM,CAAC;AAGvE,kBAAc,YAAY;AAAA,MACxB;AAAA,MACA,CAAC,GAAG,QAAQ,SAAS,SAAS,KAAK,YAAY;AAAA,IACjD;AAEA,WAAO;AAAA,EACT,CAAC,EACA,KAAK,EAAE;AACZ;AAEO,MAAM,qBAAqB,CAAC,GAAW,MAAc,EAAE,cAAc,CAAC;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"writeDictionary.d.ts","sourceRoot":"","sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAIjD,eAAO,MAAM,eAAe,iBAAwB,UAAU,EAAE,sBAmB/D,CAAC"}
1
+ {"version":3,"file":"writeDictionary.d.ts","sourceRoot":"","sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAIjD,eAAO,MAAM,eAAe,iBAAwB,UAAU,EAAE,sBAsB/D,CAAC"}
@@ -1,4 +1,4 @@
1
- export declare const getTypeName: (id: string) => string;
1
+ export declare const getTypeName: (key: string) => string;
2
2
  /**
3
3
  * This function generates a index file merging all the types
4
4
  */
@@ -1 +1 @@
1
- {"version":3,"file":"createModuleAugmentation.d.ts","sourceRoot":"","sources":["../../../../src/transpiler/dictionary_to_type/createModuleAugmentation.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,WAAW,OAAQ,MAAM,KAAG,MACH,CAAC;AA4EvC;;GAEG;AACH,eAAO,MAAM,wBAAwB,YAWpC,CAAC"}
1
+ {"version":3,"file":"createModuleAugmentation.d.ts","sourceRoot":"","sources":["../../../../src/transpiler/dictionary_to_type/createModuleAugmentation.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,WAAW,QAAS,MAAM,KAAG,MACH,CAAC;AA4ExC;;GAEG;AACH,eAAO,MAAM,wBAAwB,YAWpC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"createType.d.ts","sourceRoot":"","sources":["../../../../src/transpiler/dictionary_to_type/createType.ts"],"names":[],"mappings":"AA6BA,eAAO,MAAM,sBAAsB,aACvB,MAAM,cACJ,MAAM,oBAOnB,CAAC;AA+BF;;GAEG;AACH,eAAO,MAAM,WAAW,sBACH,MAAM,EAAE,KAC1B,OAAO,CAAC,MAAM,EAAE,CAoClB,CAAC"}
1
+ {"version":3,"file":"createType.d.ts","sourceRoot":"","sources":["../../../../src/transpiler/dictionary_to_type/createType.ts"],"names":[],"mappings":"AAmBA,eAAO,MAAM,sBAAsB,aACvB,MAAM,cACJ,MAAM,oBAOnB,CAAC;AA+BF;;GAEG;AACH,eAAO,MAAM,WAAW,sBACH,MAAM,EAAE,KAC1B,OAAO,CAAC,MAAM,EAAE,CAiClB,CAAC"}
@@ -1,4 +1,4 @@
1
1
  export declare const getFileHash: (filePath: string) => string;
2
- export declare const transformToCamelCase: (string: string) => string;
2
+ export declare const kebabCaseToCamelCase: (name: string) => string;
3
3
  export declare const sortAlphabetically: (a: string, b: string) => number;
4
4
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,WAAW,aAAc,MAAM,WAO3C,CAAC;AAEF,eAAO,MAAM,oBAAoB,WAAY,MAAM,KAAG,MAcrD,CAAC;AAEF,eAAO,MAAM,kBAAkB,MAAO,MAAM,KAAK,MAAM,WAAuB,CAAC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,WAAW,aAAc,MAAM,WAO3C,CAAC;AAEF,eAAO,MAAM,oBAAoB,SAAU,MAAM,KAAG,MAoBnD,CAAC;AAEF,eAAO,MAAM,kBAAkB,MAAO,MAAM,KAAK,MAAM,WAAuB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intlayer/chokidar",
3
- "version": "4.1.3",
3
+ "version": "4.1.5",
4
4
  "private": false,
5
5
  "description": "Uses chokidar to scan and build Intlayer declaration files into dictionaries based on Intlayer configuration.",
6
6
  "keywords": [
@@ -63,10 +63,10 @@
63
63
  "fast-glob": "^3.3.3",
64
64
  "p-limit": "^3.1.0",
65
65
  "quicktype-core": "^23.0.170",
66
- "@intlayer/api": "4.1.3",
67
- "@intlayer/core": "4.1.3",
68
- "intlayer": "4.1.3",
69
- "@intlayer/config": "4.1.3"
66
+ "@intlayer/api": "4.1.5",
67
+ "@intlayer/config": "4.1.5",
68
+ "@intlayer/core": "4.1.5",
69
+ "intlayer": "4.1.5"
70
70
  },
71
71
  "devDependencies": {
72
72
  "@changesets/cli": "2.27.11",
@@ -80,19 +80,19 @@
80
80
  "tsc-alias": "^1.8.10",
81
81
  "tsup": "^8.3.5",
82
82
  "typescript": "^5.7.3",
83
- "@intlayer/backend": "4.1.3",
83
+ "@intlayer/backend": "4.1.5",
84
84
  "@utils/eslint-config": "1.0.4",
85
85
  "@utils/ts-config": "1.0.4",
86
- "@utils/ts-config-types": "1.0.4",
87
- "@utils/tsup-config": "1.0.4"
86
+ "@utils/tsup-config": "1.0.4",
87
+ "@utils/ts-config-types": "1.0.4"
88
88
  },
89
89
  "peerDependencies": {
90
90
  "fast-glob": "^3.3.3",
91
91
  "react": ">=16.0.0",
92
- "@intlayer/core": "4.1.3",
93
- "intlayer": "^4.1.3",
94
- "@intlayer/config": "4.1.3",
95
- "@intlayer/api": "4.1.3"
92
+ "@intlayer/api": "4.1.5",
93
+ "@intlayer/config": "4.1.5",
94
+ "@intlayer/core": "4.1.5",
95
+ "intlayer": "^4.1.5"
96
96
  },
97
97
  "engines": {
98
98
  "node": ">=14.18"