@intlayer/chokidar 1.2.0

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 (100) hide show
  1. package/LICENSE +21 -0
  2. package/dist/cjs/chokidar/index.cjs +23 -0
  3. package/dist/cjs/chokidar/index.cjs.map +1 -0
  4. package/dist/cjs/chokidar/index.d.ts +2 -0
  5. package/dist/cjs/chokidar/watcher.cjs +89 -0
  6. package/dist/cjs/chokidar/watcher.cjs.map +1 -0
  7. package/dist/cjs/chokidar/watcher.d.ts +5 -0
  8. package/dist/cjs/index.cjs +35 -0
  9. package/dist/cjs/index.cjs.map +1 -0
  10. package/dist/cjs/index.d.ts +4 -0
  11. package/dist/cjs/transpiler/dictionary_to_main/createDictionaryList.cjs +76 -0
  12. package/dist/cjs/transpiler/dictionary_to_main/createDictionaryList.cjs.map +1 -0
  13. package/dist/cjs/transpiler/dictionary_to_main/createDictionaryList.d.ts +6 -0
  14. package/dist/cjs/transpiler/dictionary_to_main/index.cjs +23 -0
  15. package/dist/cjs/transpiler/dictionary_to_main/index.cjs.map +1 -0
  16. package/dist/cjs/transpiler/dictionary_to_main/index.d.ts +1 -0
  17. package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs +87 -0
  18. package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs.map +1 -0
  19. package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.d.ts +7 -0
  20. package/dist/cjs/transpiler/dictionary_to_type/createType.cjs +114 -0
  21. package/dist/cjs/transpiler/dictionary_to_type/createType.cjs.map +1 -0
  22. package/dist/cjs/transpiler/dictionary_to_type/createType.d.ts +42 -0
  23. package/dist/cjs/transpiler/dictionary_to_type/index.cjs +25 -0
  24. package/dist/cjs/transpiler/dictionary_to_type/index.cjs.map +1 -0
  25. package/dist/cjs/transpiler/dictionary_to_type/index.d.ts +3 -0
  26. package/dist/cjs/transpiler/intlater_module_to_dictionary/extractNestedJSON.cjs +45 -0
  27. package/dist/cjs/transpiler/intlater_module_to_dictionary/extractNestedJSON.cjs.map +1 -0
  28. package/dist/cjs/transpiler/intlater_module_to_dictionary/extractNestedJSON.d.ts +44 -0
  29. package/dist/cjs/transpiler/intlater_module_to_dictionary/index.cjs +27 -0
  30. package/dist/cjs/transpiler/intlater_module_to_dictionary/index.cjs.map +1 -0
  31. package/dist/cjs/transpiler/intlater_module_to_dictionary/index.d.ts +4 -0
  32. package/dist/cjs/transpiler/intlater_module_to_dictionary/loadContentDeclaration.cjs +98 -0
  33. package/dist/cjs/transpiler/intlater_module_to_dictionary/loadContentDeclaration.cjs.map +1 -0
  34. package/dist/cjs/transpiler/intlater_module_to_dictionary/loadContentDeclaration.d.ts +10 -0
  35. package/dist/cjs/transpiler/intlater_module_to_dictionary/processModule.cjs +69 -0
  36. package/dist/cjs/transpiler/intlater_module_to_dictionary/processModule.cjs.map +1 -0
  37. package/dist/cjs/transpiler/intlater_module_to_dictionary/processModule.d.ts +8 -0
  38. package/dist/cjs/transpiler/intlater_module_to_dictionary/transpileContentDeclaration.cjs +66 -0
  39. package/dist/cjs/transpiler/intlater_module_to_dictionary/transpileContentDeclaration.cjs.map +1 -0
  40. package/dist/cjs/transpiler/intlater_module_to_dictionary/transpileContentDeclaration.d.ts +6 -0
  41. package/dist/cjs/utils.cjs +55 -0
  42. package/dist/cjs/utils.cjs.map +1 -0
  43. package/dist/cjs/utils.d.ts +4 -0
  44. package/dist/esm/chokidar/index.d.mts +2 -0
  45. package/dist/esm/chokidar/index.mjs +2 -0
  46. package/dist/esm/chokidar/index.mjs.map +1 -0
  47. package/dist/esm/chokidar/watcher.d.mts +5 -0
  48. package/dist/esm/chokidar/watcher.mjs +58 -0
  49. package/dist/esm/chokidar/watcher.mjs.map +1 -0
  50. package/dist/esm/index.d.mts +4 -0
  51. package/dist/esm/index.mjs +9 -0
  52. package/dist/esm/index.mjs.map +1 -0
  53. package/dist/esm/transpiler/dictionary_to_main/createDictionaryList.d.mts +6 -0
  54. package/dist/esm/transpiler/dictionary_to_main/createDictionaryList.mjs +52 -0
  55. package/dist/esm/transpiler/dictionary_to_main/createDictionaryList.mjs.map +1 -0
  56. package/dist/esm/transpiler/dictionary_to_main/index.d.mts +1 -0
  57. package/dist/esm/transpiler/dictionary_to_main/index.mjs +2 -0
  58. package/dist/esm/transpiler/dictionary_to_main/index.mjs.map +1 -0
  59. package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.d.mts +7 -0
  60. package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs +62 -0
  61. package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs.map +1 -0
  62. package/dist/esm/transpiler/dictionary_to_type/createType.d.mts +42 -0
  63. package/dist/esm/transpiler/dictionary_to_type/createType.mjs +89 -0
  64. package/dist/esm/transpiler/dictionary_to_type/createType.mjs.map +1 -0
  65. package/dist/esm/transpiler/dictionary_to_type/index.d.mts +3 -0
  66. package/dist/esm/transpiler/dictionary_to_type/index.mjs +3 -0
  67. package/dist/esm/transpiler/dictionary_to_type/index.mjs.map +1 -0
  68. package/dist/esm/transpiler/intlater_module_to_dictionary/extractNestedJSON.d.mts +44 -0
  69. package/dist/esm/transpiler/intlater_module_to_dictionary/extractNestedJSON.mjs +21 -0
  70. package/dist/esm/transpiler/intlater_module_to_dictionary/extractNestedJSON.mjs.map +1 -0
  71. package/dist/esm/transpiler/intlater_module_to_dictionary/index.d.mts +4 -0
  72. package/dist/esm/transpiler/intlater_module_to_dictionary/index.mjs +4 -0
  73. package/dist/esm/transpiler/intlater_module_to_dictionary/index.mjs.map +1 -0
  74. package/dist/esm/transpiler/intlater_module_to_dictionary/loadContentDeclaration.d.mts +10 -0
  75. package/dist/esm/transpiler/intlater_module_to_dictionary/loadContentDeclaration.mjs +73 -0
  76. package/dist/esm/transpiler/intlater_module_to_dictionary/loadContentDeclaration.mjs.map +1 -0
  77. package/dist/esm/transpiler/intlater_module_to_dictionary/processModule.d.mts +8 -0
  78. package/dist/esm/transpiler/intlater_module_to_dictionary/processModule.mjs +45 -0
  79. package/dist/esm/transpiler/intlater_module_to_dictionary/processModule.mjs.map +1 -0
  80. package/dist/esm/transpiler/intlater_module_to_dictionary/transpileContentDeclaration.d.mts +6 -0
  81. package/dist/esm/transpiler/intlater_module_to_dictionary/transpileContentDeclaration.mjs +42 -0
  82. package/dist/esm/transpiler/intlater_module_to_dictionary/transpileContentDeclaration.mjs.map +1 -0
  83. package/dist/esm/utils.d.mts +4 -0
  84. package/dist/esm/utils.mjs +20 -0
  85. package/dist/esm/utils.mjs.map +1 -0
  86. package/package.json +85 -0
  87. package/src/chokidar/index.ts +1 -0
  88. package/src/chokidar/watcher.ts +84 -0
  89. package/src/index.ts +3 -0
  90. package/src/transpiler/dictionary_to_main/createDictionaryList.ts +65 -0
  91. package/src/transpiler/dictionary_to_main/index.ts +1 -0
  92. package/src/transpiler/dictionary_to_type/createModuleAugmentation.ts +95 -0
  93. package/src/transpiler/dictionary_to_type/createType.ts +145 -0
  94. package/src/transpiler/dictionary_to_type/index.ts +2 -0
  95. package/src/transpiler/intlater_module_to_dictionary/extractNestedJSON.ts +60 -0
  96. package/src/transpiler/intlater_module_to_dictionary/index.ts +3 -0
  97. package/src/transpiler/intlater_module_to_dictionary/loadContentDeclaration.ts +114 -0
  98. package/src/transpiler/intlater_module_to_dictionary/processModule.ts +66 -0
  99. package/src/transpiler/intlater_module_to_dictionary/transpileContentDeclaration.ts +62 -0
  100. package/src/utils.ts +26 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020-2021 Sébastien Vanvelthem
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+ var chokidar_exports = {};
17
+ module.exports = __toCommonJS(chokidar_exports);
18
+ __reExport(chokidar_exports, require('./watcher.cjs'), module.exports);
19
+ // Annotate the CommonJS export names for ESM import in node:
20
+ 0 && (module.exports = {
21
+ ...require('./watcher.cjs')
22
+ });
23
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/chokidar/index.ts"],"sourcesContent":["export * from './watcher';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,6BAAc,sBAAd;","names":[]}
@@ -0,0 +1,2 @@
1
+ export { watch } from './watcher.js';
2
+ import 'chokidar';
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var watcher_exports = {};
30
+ __export(watcher_exports, {
31
+ watch: () => watch
32
+ });
33
+ module.exports = __toCommonJS(watcher_exports);
34
+ var import_path = require("path");
35
+ var import_config = require("@intlayer/config");
36
+ var import_chokidar = __toESM(require("chokidar"));
37
+ var import_glob = require("glob");
38
+ var import_createDictionaryList = require('../transpiler/dictionary_to_main/createDictionaryList.cjs');
39
+ var import_dictionary_to_type = require('../transpiler/dictionary_to_type/index.cjs');
40
+ var import_transpileContentDeclaration = require('../transpiler/intlater_module_to_dictionary/transpileContentDeclaration.cjs');
41
+ const watch = (options) => {
42
+ const { content } = (0, import_config.getConfiguration)({
43
+ verbose: true
44
+ });
45
+ const { watchedFilesPatternWithPath, baseDir } = content;
46
+ const files = (0, import_glob.sync)(watchedFilesPatternWithPath);
47
+ return import_chokidar.default.watch(watchedFilesPatternWithPath, {
48
+ persistent: true,
49
+ // Make the watcher persistent
50
+ ignoreInitial: true,
51
+ // Process existing files
52
+ ...options
53
+ }).on("ready", async () => {
54
+ const dictionariesPaths = await (0, import_transpileContentDeclaration.transpileContentDeclaration)(files);
55
+ console.info("Building Intlayer types...");
56
+ (0, import_dictionary_to_type.createTypes)(dictionariesPaths);
57
+ console.info("Building Intlayer module augmentation...");
58
+ (0, import_dictionary_to_type.createModuleAugmentation)();
59
+ console.info("Building Intlayer dictionary list...");
60
+ (0, import_createDictionaryList.createDictionaryList)();
61
+ const relativeDictionariesPath = dictionariesPaths.map(
62
+ (dictionary) => (0, import_path.relative)(baseDir, dictionary)
63
+ );
64
+ console.info("Dictionaries:", relativeDictionariesPath);
65
+ }).on("unlink", (filePath) => {
66
+ console.info("Removed file detected: ", (0, import_path.relative)(baseDir, filePath));
67
+ }).on("add", async (filePath) => {
68
+ console.info("Additional file detected: ", (0, import_path.relative)(baseDir, filePath));
69
+ const dictionaries = await (0, import_transpileContentDeclaration.transpileContentDeclaration)(filePath);
70
+ console.info("Building TypeScript types...");
71
+ (0, import_dictionary_to_type.createTypes)(dictionaries);
72
+ console.info("Building type index...");
73
+ (0, import_dictionary_to_type.createModuleAugmentation)();
74
+ console.info("Building main...");
75
+ (0, import_createDictionaryList.createDictionaryList)();
76
+ }).on("change", async (filePath) => {
77
+ console.info("Change detected: ", (0, import_path.relative)(baseDir, filePath));
78
+ const dictionaries = await (0, import_transpileContentDeclaration.transpileContentDeclaration)(filePath);
79
+ console.info("Building TypeScript types...");
80
+ (0, import_dictionary_to_type.createTypes)(dictionaries);
81
+ }).on("error", (error) => {
82
+ console.error("Watcher error:", error);
83
+ });
84
+ };
85
+ // Annotate the CommonJS export names for ESM import in node:
86
+ 0 && (module.exports = {
87
+ watch
88
+ });
89
+ //# sourceMappingURL=watcher.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/chokidar/watcher.ts"],"sourcesContent":["import { relative } from 'path';\nimport { getConfiguration } from '@intlayer/config';\nimport chokidar, { type WatchOptions } from 'chokidar';\nimport { sync } from 'glob';\nimport { createDictionaryList } from '../transpiler/dictionary_to_main/createDictionaryList';\nimport {\n createTypes,\n createModuleAugmentation,\n} from '../transpiler/dictionary_to_type/index';\nimport { transpileContentDeclaration } from '../transpiler/intlater_module_to_dictionary/transpileContentDeclaration';\n\n// Initialize chokidar watcher (non-persistent)\nexport const watch = (options?: WatchOptions) => {\n const { content } = getConfiguration({\n verbose: true,\n });\n const { watchedFilesPatternWithPath, baseDir } = content;\n\n const files: string[] = sync(watchedFilesPatternWithPath);\n\n return chokidar\n .watch(watchedFilesPatternWithPath, {\n persistent: true, // Make the watcher persistent\n ignoreInitial: true, // Process existing files\n ...options,\n })\n .on('ready', async () => {\n const dictionariesPaths = await transpileContentDeclaration(files);\n\n console.info('Building Intlayer types...');\n createTypes(dictionariesPaths);\n\n console.info('Building Intlayer module augmentation...');\n createModuleAugmentation();\n\n console.info('Building Intlayer dictionary list...');\n createDictionaryList();\n\n const relativeDictionariesPath = dictionariesPaths.map((dictionary) =>\n relative(baseDir, dictionary)\n );\n\n console.info('Dictionaries:', relativeDictionariesPath);\n })\n .on('unlink', (filePath) => {\n // Process the file with the functionToRun\n console.info('Removed file detected: ', relative(baseDir, filePath));\n // await transpileContentDeclaration(filePath);\n\n // console.info('Building TypeScript types...');\n // createTypes([filePath]);\n\n // console.info('Building type index...');\n // createModuleAugmentation();\n\n // console.info('Building main...');\n // createDictionaryList();\n })\n .on('add', async (filePath) => {\n // Process the file with the functionToRun\n console.info('Additional file detected: ', relative(baseDir, filePath));\n const dictionaries = await transpileContentDeclaration(filePath);\n\n console.info('Building TypeScript types...');\n createTypes(dictionaries);\n\n console.info('Building type index...');\n createModuleAugmentation();\n\n console.info('Building main...');\n createDictionaryList();\n })\n .on('change', async (filePath) => {\n // Process the file with the functionToRun\n console.info('Change detected: ', relative(baseDir, filePath));\n const dictionaries = await transpileContentDeclaration(filePath);\n\n console.info('Building TypeScript types...');\n createTypes(dictionaries);\n })\n .on('error', (error) => {\n console.error('Watcher error:', error);\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAyB;AACzB,oBAAiC;AACjC,sBAA4C;AAC5C,kBAAqB;AACrB,kCAAqC;AACrC,gCAGO;AACP,yCAA4C;AAGrC,MAAM,QAAQ,CAAC,YAA2B;AAC/C,QAAM,EAAE,QAAQ,QAAI,gCAAiB;AAAA,IACnC,SAAS;AAAA,EACX,CAAC;AACD,QAAM,EAAE,6BAA6B,QAAQ,IAAI;AAEjD,QAAM,YAAkB,kBAAK,2BAA2B;AAExD,SAAO,gBAAAA,QACJ,MAAM,6BAA6B;AAAA,IAClC,YAAY;AAAA;AAAA,IACZ,eAAe;AAAA;AAAA,IACf,GAAG;AAAA,EACL,CAAC,EACA,GAAG,SAAS,YAAY;AACvB,UAAM,oBAAoB,UAAM,gEAA4B,KAAK;AAEjE,YAAQ,KAAK,4BAA4B;AACzC,+CAAY,iBAAiB;AAE7B,YAAQ,KAAK,0CAA0C;AACvD,4DAAyB;AAEzB,YAAQ,KAAK,sCAAsC;AACnD,0DAAqB;AAErB,UAAM,2BAA2B,kBAAkB;AAAA,MAAI,CAAC,mBACtD,sBAAS,SAAS,UAAU;AAAA,IAC9B;AAEA,YAAQ,KAAK,iBAAiB,wBAAwB;AAAA,EACxD,CAAC,EACA,GAAG,UAAU,CAAC,aAAa;AAE1B,YAAQ,KAAK,+BAA2B,sBAAS,SAAS,QAAQ,CAAC;AAAA,EAWrE,CAAC,EACA,GAAG,OAAO,OAAO,aAAa;AAE7B,YAAQ,KAAK,kCAA8B,sBAAS,SAAS,QAAQ,CAAC;AACtE,UAAM,eAAe,UAAM,gEAA4B,QAAQ;AAE/D,YAAQ,KAAK,8BAA8B;AAC3C,+CAAY,YAAY;AAExB,YAAQ,KAAK,wBAAwB;AACrC,4DAAyB;AAEzB,YAAQ,KAAK,kBAAkB;AAC/B,0DAAqB;AAAA,EACvB,CAAC,EACA,GAAG,UAAU,OAAO,aAAa;AAEhC,YAAQ,KAAK,yBAAqB,sBAAS,SAAS,QAAQ,CAAC;AAC7D,UAAM,eAAe,UAAM,gEAA4B,QAAQ;AAE/D,YAAQ,KAAK,8BAA8B;AAC3C,+CAAY,YAAY;AAAA,EAC1B,CAAC,EACA,GAAG,SAAS,CAAC,UAAU;AACtB,YAAQ,MAAM,kBAAkB,KAAK;AAAA,EACvC,CAAC;AACL;","names":["chokidar"]}
@@ -0,0 +1,5 @@
1
+ import chokidar, { WatchOptions } from 'chokidar';
2
+
3
+ declare const watch: (options?: WatchOptions) => chokidar.FSWatcher;
4
+
5
+ export { watch };
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var src_exports = {};
20
+ __export(src_exports, {
21
+ createDictionaryList: () => import_createDictionaryList.createDictionaryList,
22
+ createModuleAugmentation: () => import_createModuleAugmentation.createModuleAugmentation,
23
+ watch: () => import_watcher.watch
24
+ });
25
+ module.exports = __toCommonJS(src_exports);
26
+ var import_watcher = require('./chokidar/watcher.cjs');
27
+ var import_createDictionaryList = require('./transpiler/dictionary_to_main/createDictionaryList.cjs');
28
+ var import_createModuleAugmentation = require('./transpiler/dictionary_to_type/createModuleAugmentation.cjs');
29
+ // Annotate the CommonJS export names for ESM import in node:
30
+ 0 && (module.exports = {
31
+ createDictionaryList,
32
+ createModuleAugmentation,
33
+ watch
34
+ });
35
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export { watch } from './chokidar/watcher';\nexport { createDictionaryList } from './transpiler/dictionary_to_main/createDictionaryList';\nexport { createModuleAugmentation } from './transpiler/dictionary_to_type/createModuleAugmentation';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAsB;AACtB,kCAAqC;AACrC,sCAAyC;","names":[]}
@@ -0,0 +1,4 @@
1
+ export { watch } from './chokidar/watcher.js';
2
+ export { createDictionaryList } from './transpiler/dictionary_to_main/createDictionaryList.js';
3
+ export { createModuleAugmentation } from './transpiler/dictionary_to_type/createModuleAugmentation.js';
4
+ import 'chokidar';
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var createDictionaryList_exports = {};
20
+ __export(createDictionaryList_exports, {
21
+ createDictionaryList: () => createDictionaryList
22
+ });
23
+ module.exports = __toCommonJS(createDictionaryList_exports);
24
+ var import_fs = require("fs");
25
+ var import_path = require("path");
26
+ var import_config = require("@intlayer/config");
27
+ var import_glob = require("glob");
28
+ var import_utils = require('../../utils.cjs');
29
+ const { content } = (0, import_config.getConfiguration)();
30
+ const { dictionariesDir, mainDir } = content;
31
+ const generateDictionaryListContent = (dictionaries, format = "esm") => {
32
+ let content2 = "";
33
+ const dictionariesRef = dictionaries.map((dictionaryPath) => ({
34
+ relativePath: (0, import_path.relative)(mainDir, dictionaryPath),
35
+ id: (0, import_path.basename)(dictionaryPath, (0, import_path.extname)(dictionaryPath)),
36
+ // Get the base name as the dictionary id
37
+ hash: `_${(0, import_utils.getFileHash)(dictionaryPath)}`
38
+ // Get the hash of the dictionary to avoid conflicts
39
+ }));
40
+ dictionariesRef.forEach((dictionary) => {
41
+ if (format === "esm")
42
+ content2 += `import ${dictionary.hash} from '${dictionary.relativePath}';
43
+ `;
44
+ if (format === "cjs")
45
+ content2 += `const ${dictionary.hash} = require('${dictionary.relativePath}');
46
+ `;
47
+ });
48
+ content2 += "\n";
49
+ const formattedDictionaryMap = dictionariesRef.map((dictionary) => `"${dictionary.id}": ${dictionary.hash}`).join(",\n");
50
+ if (format === "esm")
51
+ content2 += `export default {
52
+ ${formattedDictionaryMap}
53
+ };
54
+ `;
55
+ if (format === "cjs")
56
+ content2 += `module.exports = {
57
+ ${formattedDictionaryMap}
58
+ };
59
+ `;
60
+ return content2;
61
+ };
62
+ const createDictionaryList = () => {
63
+ if (!(0, import_fs.existsSync)(mainDir)) {
64
+ (0, import_fs.mkdirSync)(mainDir, { recursive: true });
65
+ }
66
+ const dictionaries = (0, import_glob.sync)(`${dictionariesDir}/**/*.json`);
67
+ const cjsContent = generateDictionaryListContent(dictionaries, "cjs");
68
+ (0, import_fs.writeFileSync)((0, import_path.resolve)(mainDir, "dictionaries.cjs"), cjsContent);
69
+ const esmContent = generateDictionaryListContent(dictionaries, "esm");
70
+ (0, import_fs.writeFileSync)((0, import_path.resolve)(mainDir, "dictionaries.mjs"), esmContent);
71
+ };
72
+ // Annotate the CommonJS export names for ESM import in node:
73
+ 0 && (module.exports = {
74
+ createDictionaryList
75
+ });
76
+ //# sourceMappingURL=createDictionaryList.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/transpiler/dictionary_to_main/createDictionaryList.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { basename, extname, relative, resolve } from 'path';\nimport { getConfiguration } from '@intlayer/config';\nimport { sync } from 'glob';\nimport { getFileHash } from '../../utils';\n\nconst { content } = getConfiguration();\nconst { dictionariesDir, mainDir } = content;\n\n/**\n * This function generates the content of the dictionary list file\n */\nconst generateDictionaryListContent = (\n dictionaries: string[],\n format: 'cjs' | 'esm' = 'esm'\n): string => {\n let content = '';\n\n const dictionariesRef = dictionaries.map((dictionaryPath) => ({\n relativePath: relative(mainDir, dictionaryPath),\n id: basename(dictionaryPath, extname(dictionaryPath)), // 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 if (format === 'esm')\n content += `import ${dictionary.hash} from '${dictionary.relativePath}';\\n`;\n if (format === 'cjs')\n content += `const ${dictionary.hash} = require('${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 if (format === 'esm')\n content += `export default {\\n${formattedDictionaryMap}\\n};\\n`;\n if (format === 'cjs')\n content += `module.exports = {\\n${formattedDictionaryMap}\\n};\\n`;\n\n return content;\n};\n\n/**\n * This function generates a list of dictionaries in the main directory\n */\nexport const createDictionaryList = () => {\n // Create main directory if it doesn't exist\n if (!existsSync(mainDir)) {\n mkdirSync(mainDir, { recursive: true });\n }\n\n const dictionaries: string[] = sync(`${dictionariesDir}/**/*.json`);\n\n // Create the dictionary list file\n const cjsContent = generateDictionaryListContent(dictionaries, 'cjs');\n writeFileSync(resolve(mainDir, 'dictionaries.cjs'), cjsContent);\n\n const esmContent = generateDictionaryListContent(dictionaries, 'esm');\n writeFileSync(resolve(mainDir, 'dictionaries.mjs'), esmContent);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAqD;AACrD,kBAAqD;AACrD,oBAAiC;AACjC,kBAAqB;AACrB,mBAA4B;AAE5B,MAAM,EAAE,QAAQ,QAAI,gCAAiB;AACrC,MAAM,EAAE,iBAAiB,QAAQ,IAAI;AAKrC,MAAM,gCAAgC,CACpC,cACA,SAAwB,UACb;AACX,MAAIA,WAAU;AAEd,QAAM,kBAAkB,aAAa,IAAI,CAAC,oBAAoB;AAAA,IAC5D,kBAAc,sBAAS,SAAS,cAAc;AAAA,IAC9C,QAAI,sBAAS,oBAAgB,qBAAQ,cAAc,CAAC;AAAA;AAAA,IACpD,MAAM,QAAI,0BAAY,cAAc,CAAC;AAAA;AAAA,EACvC,EAAE;AAGF,kBAAgB,QAAQ,CAAC,eAAe;AACtC,QAAI,WAAW;AACb,MAAAA,YAAW,UAAU,WAAW,IAAI,UAAU,WAAW,YAAY;AAAA;AACvE,QAAI,WAAW;AACb,MAAAA,YAAW,SAAS,WAAW,IAAI,eAAe,WAAW,YAAY;AAAA;AAAA,EAC7E,CAAC;AAED,EAAAA,YAAW;AAGX,QAAM,yBAAiC,gBACpC,IAAI,CAAC,eAAe,IAAI,WAAW,EAAE,MAAM,WAAW,IAAI,EAAE,EAC5D,KAAK,KAAK;AAEb,MAAI,WAAW;AACb,IAAAA,YAAW;AAAA,EAAqB,sBAAsB;AAAA;AAAA;AACxD,MAAI,WAAW;AACb,IAAAA,YAAW;AAAA,EAAuB,sBAAsB;AAAA;AAAA;AAE1D,SAAOA;AACT;AAKO,MAAM,uBAAuB,MAAM;AAExC,MAAI,KAAC,sBAAW,OAAO,GAAG;AACxB,6BAAU,SAAS,EAAE,WAAW,KAAK,CAAC;AAAA,EACxC;AAEA,QAAM,mBAAyB,kBAAK,GAAG,eAAe,YAAY;AAGlE,QAAM,aAAa,8BAA8B,cAAc,KAAK;AACpE,mCAAc,qBAAQ,SAAS,kBAAkB,GAAG,UAAU;AAE9D,QAAM,aAAa,8BAA8B,cAAc,KAAK;AACpE,mCAAc,qBAAQ,SAAS,kBAAkB,GAAG,UAAU;AAChE;","names":["content"]}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * This function generates a list of dictionaries in the main directory
3
+ */
4
+ declare const createDictionaryList: () => void;
5
+
6
+ export { createDictionaryList };
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+ var dictionary_to_main_exports = {};
17
+ module.exports = __toCommonJS(dictionary_to_main_exports);
18
+ __reExport(dictionary_to_main_exports, require('./createDictionaryList.cjs'), module.exports);
19
+ // Annotate the CommonJS export names for ESM import in node:
20
+ 0 && (module.exports = {
21
+ ...require('./createDictionaryList.cjs')
22
+ });
23
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/transpiler/dictionary_to_main/index.ts"],"sourcesContent":["export * from './createDictionaryList';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,uCAAc,mCAAd;","names":[]}
@@ -0,0 +1 @@
1
+ export { createDictionaryList } from './createDictionaryList.js';
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var createModuleAugmentation_exports = {};
20
+ __export(createModuleAugmentation_exports, {
21
+ createModuleAugmentation: () => createModuleAugmentation,
22
+ getTypeName: () => getTypeName
23
+ });
24
+ module.exports = __toCommonJS(createModuleAugmentation_exports);
25
+ var import_fs = require("fs");
26
+ var import_path = require("path");
27
+ var import_config = require("@intlayer/config");
28
+ var import_glob = require("glob");
29
+ var import_utils = require('../../utils.cjs');
30
+ const { content, internationalization } = (0, import_config.getConfiguration)();
31
+ const { typesDir, moduleAugmentationDir } = content;
32
+ const { locales } = internationalization;
33
+ const getTypeName = (id) => (0, import_utils.transformToCamelCase)(`${id}Content`);
34
+ const generateTypeIndexContent = (typeFiles) => {
35
+ let content2 = "/* eslint-disable */\nimport 'intlayer';\nimport { Locales } from '@intlayer/config'\n";
36
+ const dictionariesRef = typeFiles.map((dictionaryPath) => ({
37
+ relativePath: (0, import_path.relative)(moduleAugmentationDir, dictionaryPath),
38
+ id: (0, import_path.basename)(dictionaryPath, ".d.ts"),
39
+ // Get the base name as the dictionary id
40
+ hash: `_${(0, import_utils.getFileHash)(dictionaryPath)}`
41
+ // Get the hash of the dictionary to avoid conflicts
42
+ }));
43
+ dictionariesRef.forEach((dictionary) => {
44
+ const typeName = getTypeName(dictionary.id);
45
+ content2 += `import type { ${typeName} as ${dictionary.hash} } from '${dictionary.relativePath}';
46
+ `;
47
+ });
48
+ content2 += "\n";
49
+ const formattedDictionaryMap = dictionariesRef.map((dictionary) => ` "${dictionary.id}": ${dictionary.hash};`).join("\n");
50
+ const formatLocales = locales.map((locale) => {
51
+ for (const key in import_config.Locales) {
52
+ if (import_config.Locales[key] === locale) {
53
+ return ` ${key} = '${locale}'`;
54
+ }
55
+ }
56
+ }).join(",\n");
57
+ content2 += `declare module 'intlayer' {
58
+ `;
59
+ content2 += ` interface IntlayerDictionaryTypesConnector {
60
+ ${formattedDictionaryMap}
61
+ }
62
+
63
+ `;
64
+ content2 += ` enum ConfigLocales {
65
+ ${formatLocales}
66
+ };
67
+
68
+ `;
69
+ content2 += ` interface IConfigLocales<Content> extends Record<ConfigLocales, Content> {}
70
+ `;
71
+ content2 += `};`;
72
+ return content2;
73
+ };
74
+ const createModuleAugmentation = () => {
75
+ if (!(0, import_fs.existsSync)(moduleAugmentationDir)) {
76
+ (0, import_fs.mkdirSync)(moduleAugmentationDir, { recursive: true });
77
+ }
78
+ const dictionaries = (0, import_glob.sync)(`${typesDir}/**/*.d.ts`);
79
+ const tsContent = generateTypeIndexContent(dictionaries);
80
+ (0, import_fs.writeFileSync)((0, import_path.join)(moduleAugmentationDir, "intlayer.d.ts"), tsContent);
81
+ };
82
+ // Annotate the CommonJS export names for ESM import in node:
83
+ 0 && (module.exports = {
84
+ createModuleAugmentation,
85
+ getTypeName
86
+ });
87
+ //# sourceMappingURL=createModuleAugmentation.cjs.map
@@ -0,0 +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 { sync } from 'glob';\nimport { getFileHash, transformToCamelCase } from '../../utils';\n\nconst { content, internationalization } = getConfiguration();\nconst { typesDir, moduleAugmentationDir } = content;\nconst { locales } = 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 =\n \"/* eslint-disable */\\nimport 'intlayer';\\nimport { Locales } from '@intlayer/config'\\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 ` ${key} = '${locale}'`;\n }\n }\n })\n .join(',\\n');\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 * enum ConfigLocales {\n * ENGLISH = 'en',\n * FRENCH = 'fr',\n * SPANISH = 'es',\n * }\n *\n * interface IConfigLocales<Content> extends Record<ConfigLocales, Content> {}\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 += ` enum ConfigLocales {\\n${formatLocales}\\n };\\n\\n`;\n content += ` interface IConfigLocales<Content> extends Record<ConfigLocales, Content> {}\\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[] = 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,kBAAqB;AACrB,mBAAkD;AAElD,MAAM,EAAE,SAAS,qBAAqB,QAAI,gCAAiB;AAC3D,MAAM,EAAE,UAAU,sBAAsB,IAAI;AAC5C,MAAM,EAAE,QAAQ,IAAI;AAEb,MAAM,cAAc,CAAC,WAC1B,mCAAqB,GAAG,EAAE,SAAS;AAKrC,MAAM,2BAA2B,CAAC,cAAgC;AAChE,MAAIA,WACF;AAEF,QAAM,kBAAkB,UAAU,IAAI,CAAC,oBAAoB;AAAA,IACzD,kBAAc,sBAAS,uBAAuB,cAAc;AAAA,IAC5D,QAAI,sBAAS,gBAAgB,OAAO;AAAA;AAAA,IACpC,MAAM,QAAI,0BAAY,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,uBAAS;AACzB,UAAI,sBAAQ,GAA2B,MAAM,QAAQ;AACnD,eAAO,OAAO,GAAG,OAAO,MAAM;AAAA,MAChC;AAAA,IACF;AAAA,EACF,CAAC,EACA,KAAK,KAAK;AAwBb,EAAAA,YAAW;AAAA;AACX,EAAAA,YAAW;AAAA,EAAmD,sBAAsB;AAAA;AAAA;AAAA;AACpF,EAAAA,YAAW;AAAA,EAA2B,aAAa;AAAA;AAAA;AAAA;AACnD,EAAAA,YAAW;AAAA;AACX,EAAAA,YAAW;AAEX,SAAOA;AACT;AAKO,MAAM,2BAA2B,MAAM;AAE5C,MAAI,KAAC,sBAAW,qBAAqB,GAAG;AACtC,6BAAU,uBAAuB,EAAE,WAAW,KAAK,CAAC;AAAA,EACtD;AAEA,QAAM,mBAAyB,kBAAK,GAAG,QAAQ,YAAY;AAG3D,QAAM,YAAY,yBAAyB,YAAY;AACvD,mCAAc,kBAAK,uBAAuB,eAAe,GAAG,SAAS;AACvE;","names":["content"]}
@@ -0,0 +1,7 @@
1
+ declare const getTypeName: (id: string) => string;
2
+ /**
3
+ * This function generates a index file merging all the types
4
+ */
5
+ declare const createModuleAugmentation: () => void;
6
+
7
+ export { createModuleAugmentation, getTypeName };
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var createType_exports = {};
20
+ __export(createType_exports, {
21
+ createTypes: () => createTypes,
22
+ generateTypeScriptType: () => generateTypeScriptType,
23
+ generateTypeScriptTypeContent: () => generateTypeScriptTypeContent
24
+ });
25
+ module.exports = __toCommonJS(createType_exports);
26
+ var import_fs = require("fs");
27
+ var import_module = require("module");
28
+ var import_path = require("path");
29
+ var import_config = require("@intlayer/config");
30
+ var import_core = require("@intlayer/core");
31
+ var import_createModuleAugmentation = require('./createModuleAugmentation.cjs');
32
+ const import_meta = {};
33
+ const { content, internationalization } = (0, import_config.getConfiguration)();
34
+ const { typesDir } = content;
35
+ const isESModule = typeof import_meta.url === "string";
36
+ const requireFunction = isESModule ? (0, import_module.createRequire)(import_meta.url) : require;
37
+ const generateTypeScriptType = (obj) => {
38
+ let typeDefinition = ``;
39
+ const typeName = (0, import_createModuleAugmentation.getTypeName)(obj.id);
40
+ typeDefinition += `export type ${typeName} = {
41
+ `;
42
+ typeDefinition += generateTypeScriptTypeContent(obj);
43
+ typeDefinition += "};\n\n";
44
+ return typeDefinition;
45
+ };
46
+ const generateTypeScriptTypeContent = (obj) => {
47
+ let typeDefinition = ``;
48
+ for (const [key, value] of Object.entries(obj)) {
49
+ const nodeType = value.nodeType;
50
+ if (
51
+ // Check if the value is a typed node
52
+ typeof value === "object" && nodeType === import_core.NodeType.Translation
53
+ ) {
54
+ const tsType = typeof value?.[internationalization.defaultLocale];
55
+ typeDefinition += ` ${key}: ${tsType},
56
+ `;
57
+ } else if (
58
+ // Check if the value is a typed node
59
+ typeof value === "object" && nodeType === import_core.NodeType.Enumeration
60
+ ) {
61
+ const tsType = typeof value?.[internationalization.defaultLocale];
62
+ typeDefinition += ` ${key}: (quantity: number) => ${tsType},
63
+ `;
64
+ } else if (
65
+ // Check if the value is a nested object
66
+ typeof value === "object" && !Array.isArray(value)
67
+ ) {
68
+ const nestedType = generateTypeScriptTypeContent(value);
69
+ typeDefinition += ` ${key}: {${nestedType}},
70
+ `;
71
+ } else if (
72
+ // Check if the value is an array
73
+ Array.isArray(value)
74
+ ) {
75
+ const arrayType = typeof value[0];
76
+ typeDefinition += ` ${key}: ${arrayType}[],
77
+ `;
78
+ } else if (
79
+ // Check if the value is an 'id'
80
+ typeof value === "string" && key === "id"
81
+ ) {
82
+ const tsType = `"${value}"`;
83
+ typeDefinition += ` ${key}: ${tsType},
84
+ `;
85
+ } else {
86
+ const tsType = typeof value;
87
+ typeDefinition += ` ${key}: ${tsType},
88
+ `;
89
+ }
90
+ }
91
+ return typeDefinition;
92
+ };
93
+ const createTypes = (dictionariesPaths) => {
94
+ const resultTypesPaths = [];
95
+ if (!(0, import_fs.existsSync)(typesDir)) {
96
+ (0, import_fs.mkdirSync)(typesDir, { recursive: true });
97
+ }
98
+ for (const dictionaryPath of dictionariesPaths) {
99
+ const contentModule = requireFunction(dictionaryPath);
100
+ const dictionaryName = contentModule.id;
101
+ const typeDefinition = generateTypeScriptType(contentModule);
102
+ const outputPath = (0, import_path.resolve)(typesDir, `${dictionaryName}.d.ts`);
103
+ (0, import_fs.writeFileSync)(outputPath, typeDefinition);
104
+ resultTypesPaths.push(outputPath);
105
+ }
106
+ return resultTypesPaths;
107
+ };
108
+ // Annotate the CommonJS export names for ESM import in node:
109
+ 0 && (module.exports = {
110
+ createTypes,
111
+ generateTypeScriptType,
112
+ generateTypeScriptTypeContent
113
+ });
114
+ //# sourceMappingURL=createType.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/transpiler/dictionary_to_type/createType.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { createRequire } from 'module';\nimport { resolve } from 'path';\nimport { getConfiguration } from '@intlayer/config';\nimport {\n NodeType,\n type Content,\n type ContentModule,\n type TypedNode,\n} from '@intlayer/core';\nimport { getTypeName } from './createModuleAugmentation';\n\nconst { content, internationalization } = getConfiguration();\nconst { typesDir } = content;\n\nconst isESModule = typeof import.meta.url === 'string';\nconst requireFunction = isESModule ? createRequire(import.meta.url) : require;\n\n/**\n *\n * This function generates a TypeScript type definition from a JSON object\n *\n * Example:\n *\n * const input = {\n * id: '1',\n * name: 'John Doe',\n * address: {\n * id: '2',\n * street: '123 Main St',\n * city: 'Springfield',\n * }\n * };\n *\n * const result = generateTypeScriptType(input, 'RootObject');\n * console.log(result);\n *\n * Output:\n *\n * type RootObject = {\n * id: '1',\n * name: string,\n * address: {\n * id: '2',\n * street: string,\n * city: string,\n * },\n * };\n *\n */\nexport const generateTypeScriptType = (obj: ContentModule): string => {\n let typeDefinition = ``;\n\n const typeName = getTypeName(obj.id);\n\n typeDefinition += `export type ${typeName} = {\\n`;\n typeDefinition += generateTypeScriptTypeContent(obj);\n typeDefinition += '};\\n\\n';\n\n return typeDefinition;\n};\n\nexport const generateTypeScriptTypeContent = (obj: Content): string => {\n let typeDefinition = ``;\n\n for (const [key, value] of Object.entries(obj)) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const nodeType: NodeType | undefined = (value as TypedNode).nodeType;\n type ValueKey = keyof typeof value;\n\n if (\n // Check if the value is a typed node\n typeof value === 'object' &&\n nodeType === NodeType.Translation\n ) {\n const tsType =\n typeof value?.[internationalization.defaultLocale as ValueKey];\n typeDefinition += ` ${key}: ${tsType},\\n`;\n } else if (\n // Check if the value is a typed node\n typeof value === 'object' &&\n nodeType === NodeType.Enumeration\n ) {\n const tsType =\n typeof value?.[internationalization.defaultLocale as ValueKey];\n\n typeDefinition += ` ${key}: (quantity: number) => ${tsType},\\n`;\n } else if (\n // Check if the value is a nested object\n typeof value === 'object' &&\n !Array.isArray(value)\n ) {\n // Nested object, recurse\n const nestedType = generateTypeScriptTypeContent(value as Content);\n typeDefinition += ` ${key}: {${nestedType}},\\n`;\n } else if (\n // Check if the value is an array\n Array.isArray(value)\n ) {\n // Array handling (simplified, assumes non-empty arrays with uniform type)\n const arrayType = typeof value[0];\n typeDefinition += ` ${key}: ${arrayType}[],\\n`;\n } else if (\n // Check if the value is an 'id'\n typeof value === 'string' &&\n key === 'id'\n ) {\n // Special handling for 'id' field\n const tsType = `\"${value}\"`;\n typeDefinition += ` ${key}: ${tsType},\\n`;\n } else {\n // Primitive type\n const tsType = typeof value;\n typeDefinition += ` ${key}: ${tsType},\\n`;\n }\n }\n\n return typeDefinition;\n};\n\n/**\n * This function generates a TypeScript type definition from a JSON object\n */\nexport const createTypes = (dictionariesPaths: string[]): 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 contentModule: ContentModule = requireFunction(dictionaryPath);\n const dictionaryName: string = contentModule.id;\n const typeDefinition: string = generateTypeScriptType(contentModule);\n\n const outputPath = 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;AAAA,gBAAqD;AACrD,oBAA8B;AAC9B,kBAAwB;AACxB,oBAAiC;AACjC,kBAKO;AACP,sCAA4B;AAV5B;AAYA,MAAM,EAAE,SAAS,qBAAqB,QAAI,gCAAiB;AAC3D,MAAM,EAAE,SAAS,IAAI;AAErB,MAAM,aAAa,OAAO,YAAY,QAAQ;AAC9C,MAAM,kBAAkB,iBAAa,6BAAc,YAAY,GAAG,IAAI;AAkC/D,MAAM,yBAAyB,CAAC,QAA+B;AACpE,MAAI,iBAAiB;AAErB,QAAM,eAAW,6CAAY,IAAI,EAAE;AAEnC,oBAAkB,eAAe,QAAQ;AAAA;AACzC,oBAAkB,8BAA8B,GAAG;AACnD,oBAAkB;AAElB,SAAO;AACT;AAEO,MAAM,gCAAgC,CAAC,QAAyB;AACrE,MAAI,iBAAiB;AAErB,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,GAAG,GAAG;AAE9C,UAAM,WAAkC,MAAoB;AAG5D;AAAA;AAAA,MAEE,OAAO,UAAU,YACjB,aAAa,qBAAS;AAAA,MACtB;AACA,YAAM,SACJ,OAAO,QAAQ,qBAAqB,aAAyB;AAC/D,wBAAkB,KAAK,GAAG,KAAK,MAAM;AAAA;AAAA,IACvC;AAAA;AAAA,MAEE,OAAO,UAAU,YACjB,aAAa,qBAAS;AAAA,MACtB;AACA,YAAM,SACJ,OAAO,QAAQ,qBAAqB,aAAyB;AAE/D,wBAAkB,KAAK,GAAG,2BAA2B,MAAM;AAAA;AAAA,IAC7D;AAAA;AAAA,MAEE,OAAO,UAAU,YACjB,CAAC,MAAM,QAAQ,KAAK;AAAA,MACpB;AAEA,YAAM,aAAa,8BAA8B,KAAgB;AACjE,wBAAkB,KAAK,GAAG,MAAM,UAAU;AAAA;AAAA,IAC5C;AAAA;AAAA,MAEE,MAAM,QAAQ,KAAK;AAAA,MACnB;AAEA,YAAM,YAAY,OAAO,MAAM,CAAC;AAChC,wBAAkB,KAAK,GAAG,KAAK,SAAS;AAAA;AAAA,IAC1C;AAAA;AAAA,MAEE,OAAO,UAAU,YACjB,QAAQ;AAAA,MACR;AAEA,YAAM,SAAS,IAAI,KAAK;AACxB,wBAAkB,KAAK,GAAG,KAAK,MAAM;AAAA;AAAA,IACvC,OAAO;AAEL,YAAM,SAAS,OAAO;AACtB,wBAAkB,KAAK,GAAG,KAAK,MAAM;AAAA;AAAA,IACvC;AAAA,EACF;AAEA,SAAO;AACT;AAKO,MAAM,cAAc,CAAC,sBAA0C;AACpE,QAAM,mBAA6B,CAAC;AAGpC,MAAI,KAAC,sBAAW,QAAQ,GAAG;AACzB,6BAAU,UAAU,EAAE,WAAW,KAAK,CAAC;AAAA,EACzC;AAEA,aAAW,kBAAkB,mBAAmB;AAC9C,UAAM,gBAA+B,gBAAgB,cAAc;AACnE,UAAM,iBAAyB,cAAc;AAC7C,UAAM,iBAAyB,uBAAuB,aAAa;AAEnE,UAAM,iBAAa,qBAAQ,UAAU,GAAG,cAAc,OAAO;AAE7D,iCAAc,YAAY,cAAc;AAExC,qBAAiB,KAAK,UAAU;AAAA,EAClC;AAEA,SAAO;AACT;","names":[]}
@@ -0,0 +1,42 @@
1
+ import { ContentModule, Content } from '@intlayer/core';
2
+
3
+ /**
4
+ *
5
+ * This function generates a TypeScript type definition from a JSON object
6
+ *
7
+ * Example:
8
+ *
9
+ * const input = {
10
+ * id: '1',
11
+ * name: 'John Doe',
12
+ * address: {
13
+ * id: '2',
14
+ * street: '123 Main St',
15
+ * city: 'Springfield',
16
+ * }
17
+ * };
18
+ *
19
+ * const result = generateTypeScriptType(input, 'RootObject');
20
+ * console.log(result);
21
+ *
22
+ * Output:
23
+ *
24
+ * type RootObject = {
25
+ * id: '1',
26
+ * name: string,
27
+ * address: {
28
+ * id: '2',
29
+ * street: string,
30
+ * city: string,
31
+ * },
32
+ * };
33
+ *
34
+ */
35
+ declare const generateTypeScriptType: (obj: ContentModule) => string;
36
+ declare const generateTypeScriptTypeContent: (obj: Content) => string;
37
+ /**
38
+ * This function generates a TypeScript type definition from a JSON object
39
+ */
40
+ declare const createTypes: (dictionariesPaths: string[]) => string[];
41
+
42
+ export { createTypes, generateTypeScriptType, generateTypeScriptTypeContent };
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+ var dictionary_to_type_exports = {};
17
+ module.exports = __toCommonJS(dictionary_to_type_exports);
18
+ __reExport(dictionary_to_type_exports, require('./createModuleAugmentation.cjs'), module.exports);
19
+ __reExport(dictionary_to_type_exports, require('./createType.cjs'), module.exports);
20
+ // Annotate the CommonJS export names for ESM import in node:
21
+ 0 && (module.exports = {
22
+ ...require('./createModuleAugmentation.cjs'),
23
+ ...require('./createType.cjs')
24
+ });
25
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/transpiler/dictionary_to_type/index.ts"],"sourcesContent":["export * from './createModuleAugmentation';\nexport * from './createType';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,uCAAc,uCAAd;AACA,uCAAc,yBADd;","names":[]}