@intlayer/chokidar 4.1.0 → 4.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  <div align="center">
2
- <a href="https://www.npmjs.com/package/intlayer">
2
+ <a href="https://intlayer.org">
3
3
  <img src="https://raw.githubusercontent.com/aymericzip/intlayer/572ae9c9acafb74307b81530c1931a8e98990aef/docs/assets/logo.png" width="500" alt="intlayer" />
4
4
  </a>
5
5
  </div>
@@ -14,25 +14,22 @@
14
14
  <a href="https://npmjs.org/package/intlayer">
15
15
  <img alt="types included" src="https://badgen.net/npm/types/intlayer?labelColor=49516F&color=8994BC"
16
16
  />
17
- </a>
18
17
  </div>
19
18
 
20
19
  # @intlayer/chokidar: Scan and build Intlayer declaration files into dictionaries
21
20
 
22
21
  **Intlayer** is a suite of packages designed specifically for JavaScript developers. It is compatible with frameworks like React, React, and Express.js.
23
22
 
24
- 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://github.com/aymericzip/intlayer/blob/main/docs/en/configuration.md).
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).
25
24
 
26
25
  ## Usage
27
26
 
28
27
  ```ts
29
- import { watch } from "@intlayer/chokidar";
30
-
31
- watch(); // Build Intlayer dictionaries
28
+ import { watch, prepareIntlayer } from "@intlayer/chokidar";
32
29
 
33
- // Or
30
+ await prepareIntlayer(); // Build Intlayer dictionaries
34
31
 
35
- watch({ persistent: true }); // Watch mode
32
+ watch({ persistent: true }); // Watch changes in the configuration files
36
33
  ```
37
34
 
38
35
  ## Installation
@@ -28,6 +28,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
  var watcher_exports = {};
30
30
  __export(watcher_exports, {
31
+ buildAndWatchIntlayer: () => buildAndWatchIntlayer,
32
+ handleAdditionalContentDeclarationFile: () => handleAdditionalContentDeclarationFile,
33
+ handleContentDeclarationFileChange: () => handleContentDeclarationFileChange,
34
+ prepareIntlayer: () => prepareIntlayer,
31
35
  watch: () => watch
32
36
  });
33
37
  module.exports = __toCommonJS(watcher_exports);
@@ -42,79 +46,112 @@ var import_loadLocalDictionaries = require('../loadDictionaries/loadLocalDiction
42
46
  var import_declaration_file_to_dictionary = require('../transpiler/declaration_file_to_dictionary/index.cjs');
43
47
  var import_createDictionaryList = require('../transpiler/dictionary_to_main/createDictionaryList.cjs');
44
48
  var import_dictionary_to_type = require('../transpiler/dictionary_to_type/index.cjs');
45
- const watch = (options) => {
46
- const { content } = (0, import_config.getConfiguration)({
49
+ const prepareIntlayer = async (configuration) => {
50
+ const { content } = configuration ?? (0, import_config.getConfiguration)({
47
51
  verbose: true
48
52
  });
49
- const { watchedFilesPatternWithPath, baseDir, watch: isWatchMode } = content;
53
+ const { watchedFilesPatternWithPath } = content;
54
+ (0, import_cleanOutputDir.cleanOutputDir)();
55
+ (0, import_config.appLogger)("Output directory cleaned", {
56
+ isVerbose: true
57
+ });
50
58
  const files = import_fast_glob.default.sync(watchedFilesPatternWithPath);
51
- return (0, import_chokidar.watch)(watchedFilesPatternWithPath, {
52
- persistent: isWatchMode,
53
- // Make the watcher persistent
54
- ignoreInitial: true,
55
- // Process existing files
56
- ...options
57
- }).on("ready", async () => {
58
- (0, import_cleanOutputDir.cleanOutputDir)();
59
- (0, import_config.appLogger)("Output directory cleaned", {
60
- isVerbose: true
61
- });
62
- const dictionaries = await (0, import_loadDictionaries.loadDictionaries)(files);
63
- const dictionariesPaths = await (0, import_declaration_file_to_dictionary.buildDictionary)(dictionaries);
64
- await (0, import_dictionary_to_type.createTypes)(dictionariesPaths);
65
- (0, import_createDictionaryList.createDictionaryList)();
66
- (0, import_config.appLogger)("Dictionaries built");
67
- (0, import_dictionary_to_type.createModuleAugmentation)();
68
- (0, import_config.appLogger)("Module augmentation built", {
69
- isVerbose: true
70
- });
71
- }).on("add", async (filePath) => {
72
- (0, import_config.appLogger)(`Additional file detected: ${(0, import_path.relative)(baseDir, filePath)}`, {
59
+ const dictionaries = await (0, import_loadDictionaries.loadDictionaries)(files);
60
+ const dictionariesPaths = await (0, import_declaration_file_to_dictionary.buildDictionary)(dictionaries);
61
+ await (0, import_dictionary_to_type.createTypes)(dictionariesPaths);
62
+ (0, import_createDictionaryList.createDictionaryList)();
63
+ (0, import_config.appLogger)("Dictionaries built");
64
+ (0, import_dictionary_to_type.createModuleAugmentation)();
65
+ (0, import_config.appLogger)("Module augmentation built", {
66
+ isVerbose: true
67
+ });
68
+ };
69
+ const handleAdditionalContentDeclarationFile = async (filePath, configuration) => {
70
+ const { content } = configuration ?? (0, import_config.getConfiguration)({
71
+ verbose: true
72
+ });
73
+ (0, import_config.appLogger)(
74
+ `Additional file detected: ${(0, import_path.relative)(content.baseDir, filePath)}`,
75
+ {
73
76
  isVerbose: true
74
- });
75
- const localeDictionaries = await (0, import_loadLocalDictionaries.loadLocalDictionaries)(filePath);
76
- const dictionariesPaths = await (0, import_declaration_file_to_dictionary.buildDictionary)(localeDictionaries);
77
- await (0, import_dictionary_to_type.createTypes)(dictionariesPaths);
77
+ }
78
+ );
79
+ const localeDictionaries = await (0, import_loadLocalDictionaries.loadLocalDictionaries)(filePath);
80
+ const dictionariesPaths = await (0, import_declaration_file_to_dictionary.buildDictionary)(localeDictionaries);
81
+ await (0, import_dictionary_to_type.createTypes)(dictionariesPaths);
82
+ (0, import_createDictionaryList.createDictionaryList)();
83
+ (0, import_config.appLogger)("Dictionaries built", {
84
+ isVerbose: true
85
+ });
86
+ (0, import_dictionary_to_type.createModuleAugmentation)();
87
+ (0, import_config.appLogger)("Module augmentation built", {
88
+ isVerbose: true
89
+ });
90
+ };
91
+ const handleContentDeclarationFileChange = async (filePath, configuration) => {
92
+ const { content } = configuration ?? (0, import_config.getConfiguration)({
93
+ verbose: true
94
+ });
95
+ (0, import_config.appLogger)(`Change detected: ${(0, import_path.relative)(content.baseDir, filePath)}`, {
96
+ isVerbose: true
97
+ });
98
+ const localeDictionaries = await (0, import_loadLocalDictionaries.loadLocalDictionaries)(filePath);
99
+ const updatedDictionariesPaths = await (0, import_declaration_file_to_dictionary.buildDictionary)(localeDictionaries);
100
+ const allDictionariesPaths = (0, import_getDictionariesPath.getDictionariesPath)();
101
+ await (0, import_dictionary_to_type.createTypes)(updatedDictionariesPaths);
102
+ (0, import_config.appLogger)("TypeScript types built", {
103
+ isVerbose: true
104
+ });
105
+ if (updatedDictionariesPaths.some(
106
+ (updatedDictionaryPath) => allDictionariesPaths.includes(updatedDictionaryPath)
107
+ )) {
78
108
  (0, import_createDictionaryList.createDictionaryList)();
79
- (0, import_config.appLogger)("Dictionaries built", {
109
+ (0, import_config.appLogger)("Dictionary list built", {
80
110
  isVerbose: true
81
111
  });
82
112
  (0, import_dictionary_to_type.createModuleAugmentation)();
83
113
  (0, import_config.appLogger)("Module augmentation built", {
84
114
  isVerbose: true
85
115
  });
86
- }).on("change", async (filePath) => {
87
- (0, import_config.appLogger)(`Change detected: ${(0, import_path.relative)(baseDir, filePath)}`, {
88
- isVerbose: true
89
- });
90
- const localeDictionaries = await (0, import_loadLocalDictionaries.loadLocalDictionaries)(filePath);
91
- const updatedDictionariesPaths = await (0, import_declaration_file_to_dictionary.buildDictionary)(localeDictionaries);
92
- const allDictionariesPaths = (0, import_getDictionariesPath.getDictionariesPath)();
93
- await (0, import_dictionary_to_type.createTypes)(updatedDictionariesPaths);
94
- (0, import_config.appLogger)("TypeScript types built", {
95
- isVerbose: true
96
- });
97
- if (updatedDictionariesPaths.some(
98
- (updatedDictionaryPath) => allDictionariesPaths.includes(updatedDictionaryPath)
99
- )) {
100
- (0, import_createDictionaryList.createDictionaryList)();
101
- (0, import_config.appLogger)("Dictionary list built", {
102
- isVerbose: true
103
- });
104
- (0, import_dictionary_to_type.createModuleAugmentation)();
105
- (0, import_config.appLogger)("Module augmentation built", {
106
- isVerbose: true
107
- });
108
- }
116
+ }
117
+ };
118
+ const watch = (options) => {
119
+ const configuration = options?.configuration ?? (0, import_config.getConfiguration)({
120
+ verbose: true
121
+ });
122
+ const { watch: isWatchMode, watchedFilesPatternWithPath } = configuration.content;
123
+ return (0, import_chokidar.watch)(watchedFilesPatternWithPath, {
124
+ persistent: isWatchMode,
125
+ // Make the watcher persistent
126
+ ignoreInitial: true,
127
+ // Process existing files
128
+ ...options
109
129
  }).on(
130
+ "add",
131
+ async (filePath) => await handleAdditionalContentDeclarationFile(filePath, configuration)
132
+ ).on(
133
+ "change",
134
+ async (filePath) => await handleContentDeclarationFileChange(filePath, configuration)
135
+ ).on(
110
136
  "error",
111
137
  (error) => (0, import_config.appLogger)("Watcher error: " + error, {
112
138
  level: "error"
113
139
  })
114
140
  );
115
141
  };
142
+ const buildAndWatchIntlayer = async (options) => {
143
+ const configuration = options?.configuration ?? (0, import_config.getConfiguration)();
144
+ await prepareIntlayer(configuration);
145
+ if (configuration.content.watch) {
146
+ watch({ ...options, configuration });
147
+ }
148
+ };
116
149
  // Annotate the CommonJS export names for ESM import in node:
117
150
  0 && (module.exports = {
151
+ buildAndWatchIntlayer,
152
+ handleAdditionalContentDeclarationFile,
153
+ handleContentDeclarationFileChange,
154
+ prepareIntlayer,
118
155
  watch
119
156
  });
120
157
  //# sourceMappingURL=watcher.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/chokidar/watcher.ts"],"sourcesContent":["import { relative } from 'path';\nimport { appLogger, getConfiguration } from '@intlayer/config';\n/** @ts-ignore remove error Module '\"chokidar\"' has no exported member 'ChokidarOptions' */\nimport { type ChokidarOptions, watch as chokidarWatch } from 'chokidar';\nimport fg from 'fast-glob';\nimport { cleanOutputDir } from '../cleanOutputDir';\nimport { getDictionariesPath } from '../getDictionariesPath';\nimport { loadDictionaries } from '../loadDictionaries/loadDictionaries';\nimport { loadLocalDictionaries } from '../loadDictionaries/loadLocalDictionaries';\nimport { buildDictionary } from '../transpiler/declaration_file_to_dictionary/index';\nimport { createDictionaryList } from '../transpiler/dictionary_to_main/createDictionaryList';\nimport {\n createTypes,\n createModuleAugmentation,\n} from '../transpiler/dictionary_to_type/index';\n\n// Initialize chokidar watcher (non-persistent)\nexport const watch = (options?: ChokidarOptions) => {\n const { content } = getConfiguration({\n verbose: true,\n });\n\n const { watchedFilesPatternWithPath, baseDir, watch: isWatchMode } = content;\n\n const files: string[] = fg.sync(watchedFilesPatternWithPath);\n\n /** @ts-ignore remove error Expected 0-1 arguments, but got 2. */\n return chokidarWatch(watchedFilesPatternWithPath, {\n persistent: isWatchMode, // Make the watcher persistent\n ignoreInitial: true, // Process existing files\n ...options,\n })\n .on('ready', async () => {\n cleanOutputDir();\n\n appLogger('Output directory cleaned', {\n isVerbose: true,\n });\n\n const dictionaries = await loadDictionaries(files);\n\n // Build locale dictionaries\n const dictionariesPaths = await buildDictionary(dictionaries);\n\n await createTypes(dictionariesPaths);\n\n createDictionaryList();\n\n appLogger('Dictionaries built');\n\n createModuleAugmentation();\n\n appLogger('Module augmentation built', {\n isVerbose: true,\n });\n })\n .on('add', async (filePath) => {\n // Process the file with the functionToRun\n appLogger(`Additional file detected: ${relative(baseDir, filePath)}`, {\n isVerbose: true,\n });\n\n const localeDictionaries = await loadLocalDictionaries(filePath);\n\n const dictionariesPaths = await buildDictionary(localeDictionaries);\n\n await createTypes(dictionariesPaths);\n\n createDictionaryList();\n\n appLogger('Dictionaries built', {\n isVerbose: true,\n });\n\n createModuleAugmentation();\n\n appLogger('Module augmentation built', {\n isVerbose: true,\n });\n })\n .on('change', async (filePath) => {\n // Process the file with the functionToRun\n appLogger(`Change detected: ${relative(baseDir, filePath)}`, {\n isVerbose: true,\n });\n\n const localeDictionaries = await loadLocalDictionaries(filePath);\n const updatedDictionariesPaths =\n await buildDictionary(localeDictionaries);\n const allDictionariesPaths: string[] = getDictionariesPath();\n\n await createTypes(updatedDictionariesPaths);\n appLogger('TypeScript types built', {\n isVerbose: true,\n });\n\n if (\n updatedDictionariesPaths.some((updatedDictionaryPath) =>\n allDictionariesPaths.includes(updatedDictionaryPath)\n )\n ) {\n createDictionaryList();\n\n appLogger('Dictionary list built', {\n isVerbose: true,\n });\n\n createModuleAugmentation();\n\n appLogger('Module augmentation built', {\n isVerbose: true,\n });\n }\n })\n .on('error', (error) =>\n appLogger('Watcher error: ' + error, {\n level: 'error',\n })\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAyB;AACzB,oBAA4C;AAE5C,sBAA6D;AAC7D,uBAAe;AACf,4BAA+B;AAC/B,iCAAoC;AACpC,8BAAiC;AACjC,mCAAsC;AACtC,4CAAgC;AAChC,kCAAqC;AACrC,gCAGO;AAGA,MAAM,QAAQ,CAAC,YAA8B;AAClD,QAAM,EAAE,QAAQ,QAAI,gCAAiB;AAAA,IACnC,SAAS;AAAA,EACX,CAAC;AAED,QAAM,EAAE,6BAA6B,SAAS,OAAO,YAAY,IAAI;AAErE,QAAM,QAAkB,iBAAAA,QAAG,KAAK,2BAA2B;AAG3D,aAAO,gBAAAC,OAAc,6BAA6B;AAAA,IAChD,YAAY;AAAA;AAAA,IACZ,eAAe;AAAA;AAAA,IACf,GAAG;AAAA,EACL,CAAC,EACE,GAAG,SAAS,YAAY;AACvB,8CAAe;AAEf,iCAAU,4BAA4B;AAAA,MACpC,WAAW;AAAA,IACb,CAAC;AAED,UAAM,eAAe,UAAM,0CAAiB,KAAK;AAGjD,UAAM,oBAAoB,UAAM,uDAAgB,YAAY;AAE5D,cAAM,uCAAY,iBAAiB;AAEnC,0DAAqB;AAErB,iCAAU,oBAAoB;AAE9B,4DAAyB;AAEzB,iCAAU,6BAA6B;AAAA,MACrC,WAAW;AAAA,IACb,CAAC;AAAA,EACH,CAAC,EACA,GAAG,OAAO,OAAO,aAAa;AAE7B,iCAAU,iCAA6B,sBAAS,SAAS,QAAQ,CAAC,IAAI;AAAA,MACpE,WAAW;AAAA,IACb,CAAC;AAED,UAAM,qBAAqB,UAAM,oDAAsB,QAAQ;AAE/D,UAAM,oBAAoB,UAAM,uDAAgB,kBAAkB;AAElE,cAAM,uCAAY,iBAAiB;AAEnC,0DAAqB;AAErB,iCAAU,sBAAsB;AAAA,MAC9B,WAAW;AAAA,IACb,CAAC;AAED,4DAAyB;AAEzB,iCAAU,6BAA6B;AAAA,MACrC,WAAW;AAAA,IACb,CAAC;AAAA,EACH,CAAC,EACA,GAAG,UAAU,OAAO,aAAa;AAEhC,iCAAU,wBAAoB,sBAAS,SAAS,QAAQ,CAAC,IAAI;AAAA,MAC3D,WAAW;AAAA,IACb,CAAC;AAED,UAAM,qBAAqB,UAAM,oDAAsB,QAAQ;AAC/D,UAAM,2BACJ,UAAM,uDAAgB,kBAAkB;AAC1C,UAAM,2BAAiC,gDAAoB;AAE3D,cAAM,uCAAY,wBAAwB;AAC1C,iCAAU,0BAA0B;AAAA,MAClC,WAAW;AAAA,IACb,CAAC;AAED,QACE,yBAAyB;AAAA,MAAK,CAAC,0BAC7B,qBAAqB,SAAS,qBAAqB;AAAA,IACrD,GACA;AACA,4DAAqB;AAErB,mCAAU,yBAAyB;AAAA,QACjC,WAAW;AAAA,MACb,CAAC;AAED,8DAAyB;AAEzB,mCAAU,6BAA6B;AAAA,QACrC,WAAW;AAAA,MACb,CAAC;AAAA,IACH;AAAA,EACF,CAAC,EACA;AAAA,IAAG;AAAA,IAAS,CAAC,cACZ,yBAAU,oBAAoB,OAAO;AAAA,MACnC,OAAO;AAAA,IACT,CAAC;AAAA,EACH;AACJ;","names":["fg","chokidarWatch"]}
1
+ {"version":3,"sources":["../../../src/chokidar/watcher.ts"],"sourcesContent":["import { relative } from 'path';\nimport { appLogger, getConfiguration, IntlayerConfig } from '@intlayer/config';\n/** @ts-ignore remove error Module '\"chokidar\"' has no exported member 'ChokidarOptions' */\nimport { type ChokidarOptions, watch as chokidarWatch } from 'chokidar';\nimport fg from 'fast-glob';\nimport { cleanOutputDir } from '../cleanOutputDir';\nimport { getDictionariesPath } from '../getDictionariesPath';\nimport { loadDictionaries } from '../loadDictionaries/loadDictionaries';\nimport { loadLocalDictionaries } from '../loadDictionaries/loadLocalDictionaries';\nimport { buildDictionary } from '../transpiler/declaration_file_to_dictionary/index';\nimport { createDictionaryList } from '../transpiler/dictionary_to_main/createDictionaryList';\nimport {\n createTypes,\n createModuleAugmentation,\n} from '../transpiler/dictionary_to_type/index';\n\nexport const prepareIntlayer = async (configuration?: IntlayerConfig) => {\n const { content } =\n configuration ??\n getConfiguration({\n verbose: true,\n });\n\n const { watchedFilesPatternWithPath } = content;\n\n cleanOutputDir();\n\n appLogger('Output directory cleaned', {\n isVerbose: true,\n });\n\n const files: string[] = fg.sync(watchedFilesPatternWithPath);\n\n const dictionaries = await loadDictionaries(files);\n\n // Build locale dictionaries\n const dictionariesPaths = await buildDictionary(dictionaries);\n\n await createTypes(dictionariesPaths);\n\n createDictionaryList();\n\n appLogger('Dictionaries built');\n\n createModuleAugmentation();\n\n appLogger('Module augmentation built', {\n isVerbose: true,\n });\n};\n\nexport const handleAdditionalContentDeclarationFile = async (\n filePath: string,\n configuration?: IntlayerConfig\n) => {\n const { content } =\n configuration ??\n getConfiguration({\n verbose: true,\n });\n\n // Process the file with the functionToRun\n appLogger(\n `Additional file detected: ${relative(content.baseDir, filePath)}`,\n {\n isVerbose: true,\n }\n );\n\n const localeDictionaries = await loadLocalDictionaries(filePath);\n\n const dictionariesPaths = await buildDictionary(localeDictionaries);\n\n await createTypes(dictionariesPaths);\n\n createDictionaryList();\n\n appLogger('Dictionaries built', {\n isVerbose: true,\n });\n\n createModuleAugmentation();\n\n appLogger('Module augmentation built', {\n isVerbose: true,\n });\n};\n\nexport const handleContentDeclarationFileChange = async (\n filePath: string,\n configuration?: IntlayerConfig\n) => {\n const { content } =\n configuration ??\n getConfiguration({\n verbose: true,\n });\n\n // Process the file with the functionToRun\n appLogger(`Change detected: ${relative(content.baseDir, filePath)}`, {\n isVerbose: true,\n });\n\n const localeDictionaries = await loadLocalDictionaries(filePath);\n const updatedDictionariesPaths = await buildDictionary(localeDictionaries);\n const allDictionariesPaths: string[] = getDictionariesPath();\n\n await createTypes(updatedDictionariesPaths);\n appLogger('TypeScript types built', {\n isVerbose: true,\n });\n\n if (\n updatedDictionariesPaths.some((updatedDictionaryPath) =>\n allDictionariesPaths.includes(updatedDictionaryPath)\n )\n ) {\n createDictionaryList();\n\n appLogger('Dictionary list built', {\n isVerbose: true,\n });\n\n createModuleAugmentation();\n\n appLogger('Module augmentation built', {\n isVerbose: true,\n });\n }\n};\n\ntype WatchOptions = ChokidarOptions & {\n configuration?: IntlayerConfig;\n};\n\n// Initialize chokidar watcher (non-persistent)\nexport const watch = (options?: WatchOptions) => {\n const configuration =\n options?.configuration ??\n getConfiguration({\n verbose: true,\n });\n\n const { watch: isWatchMode, watchedFilesPatternWithPath } =\n configuration.content;\n\n /** @ts-ignore remove error Expected 0-1 arguments, but got 2. */\n return chokidarWatch(watchedFilesPatternWithPath, {\n persistent: isWatchMode, // Make the watcher persistent\n ignoreInitial: true, // Process existing files\n ...options,\n })\n .on(\n 'add',\n async (filePath) =>\n await handleAdditionalContentDeclarationFile(filePath, configuration)\n )\n .on(\n 'change',\n async (filePath) =>\n await handleContentDeclarationFileChange(filePath, configuration)\n )\n .on('error', (error) =>\n appLogger('Watcher error: ' + error, {\n level: 'error',\n })\n );\n};\n\nexport const buildAndWatchIntlayer = async (options?: WatchOptions) => {\n const configuration = options?.configuration ?? getConfiguration();\n\n await prepareIntlayer(configuration);\n\n if (configuration.content.watch) {\n // Start watching (assuming watch is also async)\n watch({ ...options, configuration });\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;A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AAE/B,UAAM,EAAE,GAAG,SAAS,cAAc,CAAC;AAAA,EACrC;AACF;","names":["fg","chokidarWatch"]}
@@ -18,13 +18,17 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var index_exports = {};
20
20
  __export(index_exports, {
21
+ buildAndWatchIntlayer: () => import_watcher.buildAndWatchIntlayer,
21
22
  buildDictionary: () => import_declaration_file_to_dictionary.buildDictionary,
22
23
  createDictionaryList: () => import_createDictionaryList.createDictionaryList,
23
24
  createModuleAugmentation: () => import_createModuleAugmentation.createModuleAugmentation,
24
25
  fetchDistantDictionaries: () => import_fetchDistantDictionaries.fetchDistantDictionaries,
26
+ handleAdditionalContentDeclarationFile: () => import_watcher.handleAdditionalContentDeclarationFile,
27
+ handleContentDeclarationFileChange: () => import_watcher.handleContentDeclarationFileChange,
25
28
  loadDictionaries: () => import_loadDictionaries.loadDictionaries,
26
29
  loadDistantDictionaries: () => import_loadDictionaries.loadDistantDictionaries,
27
30
  loadLocalDictionaries: () => import_loadDictionaries.loadLocalDictionaries,
31
+ prepareIntlayer: () => import_watcher.prepareIntlayer,
28
32
  watch: () => import_watcher.watch
29
33
  });
30
34
  module.exports = __toCommonJS(index_exports);
@@ -36,13 +40,17 @@ var import_fetchDistantDictionaries = require('./fetchDistantDictionaries.cjs');
36
40
  var import_loadDictionaries = require('./loadDictionaries/index.cjs');
37
41
  // Annotate the CommonJS export names for ESM import in node:
38
42
  0 && (module.exports = {
43
+ buildAndWatchIntlayer,
39
44
  buildDictionary,
40
45
  createDictionaryList,
41
46
  createModuleAugmentation,
42
47
  fetchDistantDictionaries,
48
+ handleAdditionalContentDeclarationFile,
49
+ handleContentDeclarationFileChange,
43
50
  loadDictionaries,
44
51
  loadDistantDictionaries,
45
52
  loadLocalDictionaries,
53
+ prepareIntlayer,
46
54
  watch
47
55
  });
48
56
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export { watch } from './chokidar/watcher';\nexport { buildDictionary } from './transpiler/declaration_file_to_dictionary/index';\nexport { createDictionaryList } from './transpiler/dictionary_to_main/createDictionaryList';\nexport { createModuleAugmentation } from './transpiler/dictionary_to_type/createModuleAugmentation';\nexport { fetchDistantDictionaries } from './fetchDistantDictionaries';\nexport {\n loadDistantDictionaries,\n loadDictionaries,\n loadLocalDictionaries,\n} from './loadDictionaries/index';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAsB;AACtB,4CAAgC;AAChC,kCAAqC;AACrC,sCAAyC;AACzC,sCAAyC;AACzC,8BAIO;","names":[]}
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export {\n watch,\n prepareIntlayer,\n handleAdditionalContentDeclarationFile,\n handleContentDeclarationFileChange,\n buildAndWatchIntlayer,\n} from './chokidar/watcher';\nexport { buildDictionary } from './transpiler/declaration_file_to_dictionary/index';\nexport { createDictionaryList } from './transpiler/dictionary_to_main/createDictionaryList';\nexport { createModuleAugmentation } from './transpiler/dictionary_to_type/createModuleAugmentation';\nexport { fetchDistantDictionaries } from './fetchDistantDictionaries';\nexport {\n loadDistantDictionaries,\n loadDictionaries,\n loadLocalDictionaries,\n} from './loadDictionaries/index';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAMO;AACP,4CAAgC;AAChC,kCAAqC;AACrC,sCAAyC;AACzC,sCAAyC;AACzC,8BAIO;","names":[]}
@@ -39,14 +39,14 @@ const generateDictionaryListContent = (dictionaries, format = "esm") => {
39
39
  }));
40
40
  dictionariesRef.forEach((dictionary) => {
41
41
  if (format === "esm")
42
- content2 += `import ${dictionary.hash} from '${dictionary.relativePath}';
42
+ content2 += `import ${dictionary.hash} from '${dictionary.relativePath}' with { type: 'json' };
43
43
  `;
44
44
  if (format === "cjs")
45
45
  content2 += `const ${dictionary.hash} = require('${dictionary.relativePath}');
46
46
  `;
47
47
  });
48
48
  content2 += "\n";
49
- const formattedDictionaryMap = dictionariesRef.map((dictionary) => `"${dictionary.id}": ${dictionary.hash}`).join(",\n");
49
+ const formattedDictionaryMap = dictionariesRef.map((dictionary) => ` "${dictionary.id}": ${dictionary.hash}`).join(",\n");
50
50
  if (format === "esm")
51
51
  content2 += `export default {
52
52
  ${formattedDictionaryMap}
@@ -1 +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 { getDictionariesPath } from '../../getDictionariesPath';\nimport { getFileHash } from '../../utils';\n\nconst { content } = getConfiguration();\nconst { 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 dictionariesPath: string[] = getDictionariesPath();\n\n // Create the dictionary list file\n const cjsContent = generateDictionaryListContent(dictionariesPath, 'cjs');\n writeFileSync(resolve(mainDir, 'dictionaries.cjs'), cjsContent);\n\n const esmContent = generateDictionaryListContent(dictionariesPath, 'esm');\n writeFileSync(resolve(mainDir, 'dictionaries.mjs'), esmContent);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAqD;AACrD,kBAAqD;AACrD,oBAAiC;AACjC,iCAAoC;AACpC,mBAA4B;AAE5B,MAAM,EAAE,QAAQ,QAAI,gCAAiB;AACrC,MAAM,EAAE,QAAQ,IAAI;AAKpB,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,uBAA6B,gDAAoB;AAGvD,QAAM,aAAa,8BAA8B,kBAAkB,KAAK;AACxE,mCAAc,qBAAQ,SAAS,kBAAkB,GAAG,UAAU;AAE9D,QAAM,aAAa,8BAA8B,kBAAkB,KAAK;AACxE,mCAAc,qBAAQ,SAAS,kBAAkB,GAAG,UAAU;AAChE;","names":["content"]}
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 { getDictionariesPath } from '../../getDictionariesPath';\nimport { getFileHash } from '../../utils';\n\nconst { content } = getConfiguration();\nconst { 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}' with { type: 'json' };\\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 dictionariesPath: string[] = getDictionariesPath();\n\n // Create the dictionary list file\n const cjsContent = generateDictionaryListContent(dictionariesPath, 'cjs');\n writeFileSync(resolve(mainDir, 'dictionaries.cjs'), cjsContent);\n\n const esmContent = generateDictionaryListContent(dictionariesPath, 'esm');\n writeFileSync(resolve(mainDir, 'dictionaries.mjs'), esmContent);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAqD;AACrD,kBAAqD;AACrD,oBAAiC;AACjC,iCAAoC;AACpC,mBAA4B;AAE5B,MAAM,EAAE,QAAQ,QAAI,gCAAiB;AACrC,MAAM,EAAE,QAAQ,IAAI;AAKpB,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,MAAM,WAAW,EAAE,MAAM,WAAW,IAAI,EAAE,EAC9D,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,uBAA6B,gDAAoB;AAGvD,QAAM,aAAa,8BAA8B,kBAAkB,KAAK;AACxE,mCAAc,qBAAQ,SAAS,kBAAkB,GAAG,UAAU;AAE9D,QAAM,aAAa,8BAA8B,kBAAkB,KAAK;AACxE,mCAAc,qBAAQ,SAAS,kBAAkB,GAAG,UAAU;AAChE;","names":["content"]}
@@ -12,78 +12,111 @@ import {
12
12
  createTypes,
13
13
  createModuleAugmentation
14
14
  } from "../transpiler/dictionary_to_type/index.mjs";
15
- const watch = (options) => {
16
- const { content } = getConfiguration({
15
+ const prepareIntlayer = async (configuration) => {
16
+ const { content } = configuration ?? getConfiguration({
17
17
  verbose: true
18
18
  });
19
- const { watchedFilesPatternWithPath, baseDir, watch: isWatchMode } = content;
19
+ const { watchedFilesPatternWithPath } = content;
20
+ cleanOutputDir();
21
+ appLogger("Output directory cleaned", {
22
+ isVerbose: true
23
+ });
20
24
  const files = fg.sync(watchedFilesPatternWithPath);
21
- return chokidarWatch(watchedFilesPatternWithPath, {
22
- persistent: isWatchMode,
23
- // Make the watcher persistent
24
- ignoreInitial: true,
25
- // Process existing files
26
- ...options
27
- }).on("ready", async () => {
28
- cleanOutputDir();
29
- appLogger("Output directory cleaned", {
30
- isVerbose: true
31
- });
32
- const dictionaries = await loadDictionaries(files);
33
- const dictionariesPaths = await buildDictionary(dictionaries);
34
- await createTypes(dictionariesPaths);
35
- createDictionaryList();
36
- appLogger("Dictionaries built");
37
- createModuleAugmentation();
38
- appLogger("Module augmentation built", {
39
- isVerbose: true
40
- });
41
- }).on("add", async (filePath) => {
42
- appLogger(`Additional file detected: ${relative(baseDir, filePath)}`, {
25
+ const dictionaries = await loadDictionaries(files);
26
+ const dictionariesPaths = await buildDictionary(dictionaries);
27
+ await createTypes(dictionariesPaths);
28
+ createDictionaryList();
29
+ appLogger("Dictionaries built");
30
+ createModuleAugmentation();
31
+ appLogger("Module augmentation built", {
32
+ isVerbose: true
33
+ });
34
+ };
35
+ const handleAdditionalContentDeclarationFile = async (filePath, configuration) => {
36
+ const { content } = configuration ?? getConfiguration({
37
+ verbose: true
38
+ });
39
+ appLogger(
40
+ `Additional file detected: ${relative(content.baseDir, filePath)}`,
41
+ {
43
42
  isVerbose: true
44
- });
45
- const localeDictionaries = await loadLocalDictionaries(filePath);
46
- const dictionariesPaths = await buildDictionary(localeDictionaries);
47
- await createTypes(dictionariesPaths);
43
+ }
44
+ );
45
+ const localeDictionaries = await loadLocalDictionaries(filePath);
46
+ const dictionariesPaths = await buildDictionary(localeDictionaries);
47
+ await createTypes(dictionariesPaths);
48
+ createDictionaryList();
49
+ appLogger("Dictionaries built", {
50
+ isVerbose: true
51
+ });
52
+ createModuleAugmentation();
53
+ appLogger("Module augmentation built", {
54
+ isVerbose: true
55
+ });
56
+ };
57
+ const handleContentDeclarationFileChange = async (filePath, configuration) => {
58
+ const { content } = configuration ?? getConfiguration({
59
+ verbose: true
60
+ });
61
+ appLogger(`Change detected: ${relative(content.baseDir, filePath)}`, {
62
+ isVerbose: true
63
+ });
64
+ const localeDictionaries = await loadLocalDictionaries(filePath);
65
+ const updatedDictionariesPaths = await buildDictionary(localeDictionaries);
66
+ const allDictionariesPaths = getDictionariesPath();
67
+ await createTypes(updatedDictionariesPaths);
68
+ appLogger("TypeScript types built", {
69
+ isVerbose: true
70
+ });
71
+ if (updatedDictionariesPaths.some(
72
+ (updatedDictionaryPath) => allDictionariesPaths.includes(updatedDictionaryPath)
73
+ )) {
48
74
  createDictionaryList();
49
- appLogger("Dictionaries built", {
75
+ appLogger("Dictionary list built", {
50
76
  isVerbose: true
51
77
  });
52
78
  createModuleAugmentation();
53
79
  appLogger("Module augmentation built", {
54
80
  isVerbose: true
55
81
  });
56
- }).on("change", async (filePath) => {
57
- appLogger(`Change detected: ${relative(baseDir, filePath)}`, {
58
- isVerbose: true
59
- });
60
- const localeDictionaries = await loadLocalDictionaries(filePath);
61
- const updatedDictionariesPaths = await buildDictionary(localeDictionaries);
62
- const allDictionariesPaths = getDictionariesPath();
63
- await createTypes(updatedDictionariesPaths);
64
- appLogger("TypeScript types built", {
65
- isVerbose: true
66
- });
67
- if (updatedDictionariesPaths.some(
68
- (updatedDictionaryPath) => allDictionariesPaths.includes(updatedDictionaryPath)
69
- )) {
70
- createDictionaryList();
71
- appLogger("Dictionary list built", {
72
- isVerbose: true
73
- });
74
- createModuleAugmentation();
75
- appLogger("Module augmentation built", {
76
- isVerbose: true
77
- });
78
- }
82
+ }
83
+ };
84
+ const watch = (options) => {
85
+ const configuration = options?.configuration ?? getConfiguration({
86
+ verbose: true
87
+ });
88
+ const { watch: isWatchMode, watchedFilesPatternWithPath } = configuration.content;
89
+ return chokidarWatch(watchedFilesPatternWithPath, {
90
+ persistent: isWatchMode,
91
+ // Make the watcher persistent
92
+ ignoreInitial: true,
93
+ // Process existing files
94
+ ...options
79
95
  }).on(
96
+ "add",
97
+ async (filePath) => await handleAdditionalContentDeclarationFile(filePath, configuration)
98
+ ).on(
99
+ "change",
100
+ async (filePath) => await handleContentDeclarationFileChange(filePath, configuration)
101
+ ).on(
80
102
  "error",
81
103
  (error) => appLogger("Watcher error: " + error, {
82
104
  level: "error"
83
105
  })
84
106
  );
85
107
  };
108
+ const buildAndWatchIntlayer = async (options) => {
109
+ const configuration = options?.configuration ?? getConfiguration();
110
+ await prepareIntlayer(configuration);
111
+ if (configuration.content.watch) {
112
+ watch({ ...options, configuration });
113
+ }
114
+ };
86
115
  export {
116
+ buildAndWatchIntlayer,
117
+ handleAdditionalContentDeclarationFile,
118
+ handleContentDeclarationFileChange,
119
+ prepareIntlayer,
87
120
  watch
88
121
  };
89
122
  //# sourceMappingURL=watcher.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/chokidar/watcher.ts"],"sourcesContent":["import { relative } from 'path';\nimport { appLogger, getConfiguration } from '@intlayer/config';\n/** @ts-ignore remove error Module '\"chokidar\"' has no exported member 'ChokidarOptions' */\nimport { type ChokidarOptions, watch as chokidarWatch } from 'chokidar';\nimport fg from 'fast-glob';\nimport { cleanOutputDir } from '../cleanOutputDir';\nimport { getDictionariesPath } from '../getDictionariesPath';\nimport { loadDictionaries } from '../loadDictionaries/loadDictionaries';\nimport { loadLocalDictionaries } from '../loadDictionaries/loadLocalDictionaries';\nimport { buildDictionary } from '../transpiler/declaration_file_to_dictionary/index';\nimport { createDictionaryList } from '../transpiler/dictionary_to_main/createDictionaryList';\nimport {\n createTypes,\n createModuleAugmentation,\n} from '../transpiler/dictionary_to_type/index';\n\n// Initialize chokidar watcher (non-persistent)\nexport const watch = (options?: ChokidarOptions) => {\n const { content } = getConfiguration({\n verbose: true,\n });\n\n const { watchedFilesPatternWithPath, baseDir, watch: isWatchMode } = content;\n\n const files: string[] = fg.sync(watchedFilesPatternWithPath);\n\n /** @ts-ignore remove error Expected 0-1 arguments, but got 2. */\n return chokidarWatch(watchedFilesPatternWithPath, {\n persistent: isWatchMode, // Make the watcher persistent\n ignoreInitial: true, // Process existing files\n ...options,\n })\n .on('ready', async () => {\n cleanOutputDir();\n\n appLogger('Output directory cleaned', {\n isVerbose: true,\n });\n\n const dictionaries = await loadDictionaries(files);\n\n // Build locale dictionaries\n const dictionariesPaths = await buildDictionary(dictionaries);\n\n await createTypes(dictionariesPaths);\n\n createDictionaryList();\n\n appLogger('Dictionaries built');\n\n createModuleAugmentation();\n\n appLogger('Module augmentation built', {\n isVerbose: true,\n });\n })\n .on('add', async (filePath) => {\n // Process the file with the functionToRun\n appLogger(`Additional file detected: ${relative(baseDir, filePath)}`, {\n isVerbose: true,\n });\n\n const localeDictionaries = await loadLocalDictionaries(filePath);\n\n const dictionariesPaths = await buildDictionary(localeDictionaries);\n\n await createTypes(dictionariesPaths);\n\n createDictionaryList();\n\n appLogger('Dictionaries built', {\n isVerbose: true,\n });\n\n createModuleAugmentation();\n\n appLogger('Module augmentation built', {\n isVerbose: true,\n });\n })\n .on('change', async (filePath) => {\n // Process the file with the functionToRun\n appLogger(`Change detected: ${relative(baseDir, filePath)}`, {\n isVerbose: true,\n });\n\n const localeDictionaries = await loadLocalDictionaries(filePath);\n const updatedDictionariesPaths =\n await buildDictionary(localeDictionaries);\n const allDictionariesPaths: string[] = getDictionariesPath();\n\n await createTypes(updatedDictionariesPaths);\n appLogger('TypeScript types built', {\n isVerbose: true,\n });\n\n if (\n updatedDictionariesPaths.some((updatedDictionaryPath) =>\n allDictionariesPaths.includes(updatedDictionaryPath)\n )\n ) {\n createDictionaryList();\n\n appLogger('Dictionary list built', {\n isVerbose: true,\n });\n\n createModuleAugmentation();\n\n appLogger('Module augmentation built', {\n isVerbose: true,\n });\n }\n })\n .on('error', (error) =>\n appLogger('Watcher error: ' + error, {\n level: 'error',\n })\n );\n};\n"],"mappings":"AAAA,SAAS,gBAAgB;AACzB,SAAS,WAAW,wBAAwB;AAE5C,SAA+B,SAAS,qBAAqB;AAC7D,OAAO,QAAQ;AACf,SAAS,sBAAsB;AAC/B,SAAS,2BAA2B;AACpC,SAAS,wBAAwB;AACjC,SAAS,6BAA6B;AACtC,SAAS,uBAAuB;AAChC,SAAS,4BAA4B;AACrC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAGA,MAAM,QAAQ,CAAC,YAA8B;AAClD,QAAM,EAAE,QAAQ,IAAI,iBAAiB;AAAA,IACnC,SAAS;AAAA,EACX,CAAC;AAED,QAAM,EA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AAA,MAAK,CAAC,0BAC7B,qBAAqB,SAAS,qBAAqB;AAAA,IACrD,GACA;AACA,2BAAqB;AAErB,gBAAU,yBAAyB;AAAA,QACjC,WAAW;AAAA,MACb,CAAC;AAED,+BAAyB;AAEzB,gBAAU,6BAA6B;AAAA,QACrC,WAAW;AAAA,MACb,CAAC;AAAA,IACH;AAAA,EACF,CAAC,EACA;AAAA,IAAG;AAAA,IAAS,CAAC,UACZ,UAAU,oBAAoB,OAAO;AAAA,MACnC,OAAO;AAAA,IACT,CAAC;AAAA,EACH;AACJ;","names":[]}
1
+ {"version":3,"sources":["../../../src/chokidar/watcher.ts"],"sourcesContent":["import { relative } from 'path';\nimport { appLogger, getConfiguration, IntlayerConfig } from '@intlayer/config';\n/** @ts-ignore remove error Module '\"chokidar\"' has no exported member 'ChokidarOptions' */\nimport { type ChokidarOptions, watch as chokidarWatch } from 'chokidar';\nimport fg from 'fast-glob';\nimport { cleanOutputDir } from '../cleanOutputDir';\nimport { getDictionariesPath } from '../getDictionariesPath';\nimport { loadDictionaries } from '../loadDictionaries/loadDictionaries';\nimport { loadLocalDictionaries } from '../loadDictionaries/loadLocalDictionaries';\nimport { buildDictionary } from '../transpiler/declaration_file_to_dictionary/index';\nimport { createDictionaryList } from '../transpiler/dictionary_to_main/createDictionaryList';\nimport {\n createTypes,\n createModuleAugmentation,\n} from '../transpiler/dictionary_to_type/index';\n\nexport const prepareIntlayer = async (configuration?: IntlayerConfig) => {\n const { content } =\n configuration ??\n getConfiguration({\n verbose: true,\n });\n\n const { watchedFilesPatternWithPath } = content;\n\n cleanOutputDir();\n\n appLogger('Output directory cleaned', {\n isVerbose: true,\n });\n\n const files: string[] = fg.sync(watchedFilesPatternWithPath);\n\n const dictionaries = await loadDictionaries(files);\n\n // Build locale dictionaries\n const dictionariesPaths = await buildDictionary(dictionaries);\n\n await createTypes(dictionariesPaths);\n\n createDictionaryList();\n\n appLogger('Dictionaries built');\n\n createModuleAugmentation();\n\n appLogger('Module augmentation built', {\n isVerbose: true,\n });\n};\n\nexport const handleAdditionalContentDeclarationFile = async (\n filePath: string,\n configuration?: IntlayerConfig\n) => {\n const { content } =\n configuration ??\n getConfiguration({\n verbose: true,\n });\n\n // Process the file with the functionToRun\n appLogger(\n `Additional file detected: ${relative(content.baseDir, filePath)}`,\n {\n isVerbose: true,\n }\n );\n\n const localeDictionaries = await loadLocalDictionaries(filePath);\n\n const dictionariesPaths = await buildDictionary(localeDictionaries);\n\n await createTypes(dictionariesPaths);\n\n createDictionaryList();\n\n appLogger('Dictionaries built', {\n isVerbose: true,\n });\n\n createModuleAugmentation();\n\n appLogger('Module augmentation built', {\n isVerbose: true,\n });\n};\n\nexport const handleContentDeclarationFileChange = async (\n filePath: string,\n configuration?: IntlayerConfig\n) => {\n const { content } =\n configuration ??\n getConfiguration({\n verbose: true,\n });\n\n // Process the file with the functionToRun\n appLogger(`Change detected: ${relative(content.baseDir, filePath)}`, {\n isVerbose: true,\n });\n\n const localeDictionaries = await loadLocalDictionaries(filePath);\n const updatedDictionariesPaths = await buildDictionary(localeDictionaries);\n const allDictionariesPaths: string[] = getDictionariesPath();\n\n await createTypes(updatedDictionariesPaths);\n appLogger('TypeScript types built', {\n isVerbose: true,\n });\n\n if (\n updatedDictionariesPaths.some((updatedDictionaryPath) =>\n allDictionariesPaths.includes(updatedDictionaryPath)\n )\n ) {\n createDictionaryList();\n\n appLogger('Dictionary list built', {\n isVerbose: true,\n });\n\n createModuleAugmentation();\n\n appLogger('Module augmentation built', {\n isVerbose: true,\n });\n }\n};\n\ntype WatchOptions = ChokidarOptions & {\n configuration?: IntlayerConfig;\n};\n\n// Initialize chokidar watcher (non-persistent)\nexport const watch = (options?: WatchOptions) => {\n const configuration =\n options?.configuration ??\n getConfiguration({\n verbose: true,\n });\n\n const { watch: isWatchMode, watchedFilesPatternWithPath } =\n configuration.content;\n\n /** @ts-ignore remove error Expected 0-1 arguments, but got 2. */\n return chokidarWatch(watchedFilesPatternWithPath, {\n persistent: isWatchMode, // Make the watcher persistent\n ignoreInitial: true, // Process existing files\n ...options,\n })\n .on(\n 'add',\n async (filePath) =>\n await handleAdditionalContentDeclarationFile(filePath, configuration)\n )\n .on(\n 'change',\n async (filePath) =>\n await handleContentDeclarationFileChange(filePath, configuration)\n )\n .on('error', (error) =>\n appLogger('Watcher error: ' + error, {\n level: 'error',\n })\n );\n};\n\nexport const buildAndWatchIntlayer = async (options?: WatchOptions) => {\n const configuration = options?.configuration ?? getConfiguration();\n\n await prepareIntlayer(configuration);\n\n if (configuration.content.watch) {\n // Start watching (assuming watch is also async)\n watch({ ...options, configuration });\n }\n};\n"],"mappings":"AAAA,SAAS,gBAAgB;AACzB,SAAS,WAAW,wBAAwC;AAE5D,SAA+B,SAAS,qBAAqB;AAC7D,OAAO,QAAQ;AACf,SAAS,sBAAsB;AAC/B,SAAS,2BAA2B;AACpC,SAAS,wBAAwB;AACjC,SAAS,6BAA6B;AACtC,SAAS,uBAAuB;AAChC,SAAS,4BAA4B;AACrC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAEA,MAAM,kBAAkB,OAAO,kBAAmC;AACvE,QAAM,EAAE,QAAQ,IACd,iBACA,iBAAiB;AAAA,IACf,SAAS;AAAA,EACX,CAAC;AAEH,QAAM,EAAE,4BAA4B,IAAI;AAExC,iBAAe;AAEf,YAAU,4BAA4B;AAAA,IACpC,WAAW;AAAA,EACb,CAAC;AAED,QAAM,QAAkB,GAAG,KAAK,2BAA2B;AAE3D,QAAM,eAAe,MAAM,iBAAiB,KAAK;AAGjD,QAAM,oBAAoB,MAAM,gBAAgB,YAAY;AAE5D,QAAM,YAAY,iBAAiB;AAEnC,uBAAqB;AAErB,YAAU,oBAAoB;AAE9B,2BAAyB;AAEzB,YAAU,6BAA6B;AAAA,IACrC,WAAW;AAAA,EACb,CAAC;AACH;AAEO,MAAM,yCAAyC,OACpD,UACA,kBACG;AACH,QAAM,EAAE,QAAQ,IACd,iBACA,iBAAiB;AAAA,IACf,SAAS;AAAA,EACX,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A,IACZ,eAAe;AAAA;AAAA,IACf,GAAG;AAAA,EACL,CAAC,EACE;AAAA,IACC;AAAA,IACA,OAAO,aACL,MAAM,uCAAuC,UAAU,aAAa;AAAA,EACxE,EACC;AAAA,IACC;AAAA,IACA,OAAO,aACL,MAAM,mCAAmC,UAAU,aAAa;AAAA,EACpE,EACC;AAAA,IAAG;AAAA,IAAS,CAAC,UACZ,UAAU,oBAAoB,OAAO;AAAA,MACnC,OAAO;AAAA,IACT,CAAC;AAAA,EACH;AACJ;AAEO,MAAM,wBAAwB,OAAO,YAA2B;AACrE,QAAM,gBAAgB,SAAS,iBAAiB,iBAAiB;AAEjE,QAAM,gBAAgB,aAAa;AAEnC,MAAI,cAAc,QAAQ,OAAO;AAE/B,UAAM,EAAE,GAAG,SAAS,cAAc,CAAC;AAAA,EACrC;AACF;","names":[]}
@@ -1,4 +1,10 @@
1
- import { watch } from "./chokidar/watcher.mjs";
1
+ import {
2
+ watch,
3
+ prepareIntlayer,
4
+ handleAdditionalContentDeclarationFile,
5
+ handleContentDeclarationFileChange,
6
+ buildAndWatchIntlayer
7
+ } from "./chokidar/watcher.mjs";
2
8
  import { buildDictionary } from "./transpiler/declaration_file_to_dictionary/index.mjs";
3
9
  import { createDictionaryList } from "./transpiler/dictionary_to_main/createDictionaryList.mjs";
4
10
  import { createModuleAugmentation } from "./transpiler/dictionary_to_type/createModuleAugmentation.mjs";
@@ -9,13 +15,17 @@ import {
9
15
  loadLocalDictionaries
10
16
  } from "./loadDictionaries/index.mjs";
11
17
  export {
18
+ buildAndWatchIntlayer,
12
19
  buildDictionary,
13
20
  createDictionaryList,
14
21
  createModuleAugmentation,
15
22
  fetchDistantDictionaries,
23
+ handleAdditionalContentDeclarationFile,
24
+ handleContentDeclarationFileChange,
16
25
  loadDictionaries,
17
26
  loadDistantDictionaries,
18
27
  loadLocalDictionaries,
28
+ prepareIntlayer,
19
29
  watch
20
30
  };
21
31
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export { watch } from './chokidar/watcher';\nexport { buildDictionary } from './transpiler/declaration_file_to_dictionary/index';\nexport { createDictionaryList } from './transpiler/dictionary_to_main/createDictionaryList';\nexport { createModuleAugmentation } from './transpiler/dictionary_to_type/createModuleAugmentation';\nexport { fetchDistantDictionaries } from './fetchDistantDictionaries';\nexport {\n loadDistantDictionaries,\n loadDictionaries,\n loadLocalDictionaries,\n} from './loadDictionaries/index';\n"],"mappings":"AAAA,SAAS,aAAa;AACtB,SAAS,uBAAuB;AAChC,SAAS,4BAA4B;AACrC,SAAS,gCAAgC;AACzC,SAAS,gCAAgC;AACzC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;","names":[]}
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export {\n watch,\n prepareIntlayer,\n handleAdditionalContentDeclarationFile,\n handleContentDeclarationFileChange,\n buildAndWatchIntlayer,\n} from './chokidar/watcher';\nexport { buildDictionary } from './transpiler/declaration_file_to_dictionary/index';\nexport { createDictionaryList } from './transpiler/dictionary_to_main/createDictionaryList';\nexport { createModuleAugmentation } from './transpiler/dictionary_to_type/createModuleAugmentation';\nexport { fetchDistantDictionaries } from './fetchDistantDictionaries';\nexport {\n loadDistantDictionaries,\n loadDictionaries,\n loadLocalDictionaries,\n} from './loadDictionaries/index';\n"],"mappings":"AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,uBAAuB;AAChC,SAAS,4BAA4B;AACrC,SAAS,gCAAgC;AACzC,SAAS,gCAAgC;AACzC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;","names":[]}
@@ -16,14 +16,14 @@ const generateDictionaryListContent = (dictionaries, format = "esm") => {
16
16
  }));
17
17
  dictionariesRef.forEach((dictionary) => {
18
18
  if (format === "esm")
19
- content2 += `import ${dictionary.hash} from '${dictionary.relativePath}';
19
+ content2 += `import ${dictionary.hash} from '${dictionary.relativePath}' with { type: 'json' };
20
20
  `;
21
21
  if (format === "cjs")
22
22
  content2 += `const ${dictionary.hash} = require('${dictionary.relativePath}');
23
23
  `;
24
24
  });
25
25
  content2 += "\n";
26
- const formattedDictionaryMap = dictionariesRef.map((dictionary) => `"${dictionary.id}": ${dictionary.hash}`).join(",\n");
26
+ const formattedDictionaryMap = dictionariesRef.map((dictionary) => ` "${dictionary.id}": ${dictionary.hash}`).join(",\n");
27
27
  if (format === "esm")
28
28
  content2 += `export default {
29
29
  ${formattedDictionaryMap}
@@ -1 +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 { getDictionariesPath } from '../../getDictionariesPath';\nimport { getFileHash } from '../../utils';\n\nconst { content } = getConfiguration();\nconst { 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 dictionariesPath: string[] = getDictionariesPath();\n\n // Create the dictionary list file\n const cjsContent = generateDictionaryListContent(dictionariesPath, 'cjs');\n writeFileSync(resolve(mainDir, 'dictionaries.cjs'), cjsContent);\n\n const esmContent = generateDictionaryListContent(dictionariesPath, 'esm');\n writeFileSync(resolve(mainDir, 'dictionaries.mjs'), esmContent);\n};\n"],"mappings":"AAAA,SAAS,YAAY,WAAW,qBAAqB;AACrD,SAAS,UAAU,SAAS,UAAU,eAAe;AACrD,SAAS,wBAAwB;AACjC,SAAS,2BAA2B;AACpC,SAAS,mBAAmB;AAE5B,MAAM,EAAE,QAAQ,IAAI,iBAAiB;AACrC,MAAM,EAAE,QAAQ,IAAI;AAKpB,MAAM,gCAAgC,CACpC,cACA,SAAwB,UACb;AACX,MAAIA,WAAU;AAEd,QAAM,kBAAkB,aAAa,IAAI,CAAC,oBAAoB;AAAA,IAC5D,cAAc,SAAS,SAAS,cAAc;AAAA,IAC9C,IAAI,SAAS,gBAAgB,QAAQ,cAAc,CAAC;AAAA;AAAA,IACpD,MAAM,IAAI,YAAY,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,CAAC,WAAW,OAAO,GAAG;AACxB,cAAU,SAAS,EAAE,WAAW,KAAK,CAAC;AAAA,EACxC;AAEA,QAAM,mBAA6B,oBAAoB;AAGvD,QAAM,aAAa,8BAA8B,kBAAkB,KAAK;AACxE,gBAAc,QAAQ,SAAS,kBAAkB,GAAG,UAAU;AAE9D,QAAM,aAAa,8BAA8B,kBAAkB,KAAK;AACxE,gBAAc,QAAQ,SAAS,kBAAkB,GAAG,UAAU;AAChE;","names":["content"]}
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 { getDictionariesPath } from '../../getDictionariesPath';\nimport { getFileHash } from '../../utils';\n\nconst { content } = getConfiguration();\nconst { 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}' with { type: 'json' };\\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 dictionariesPath: string[] = getDictionariesPath();\n\n // Create the dictionary list file\n const cjsContent = generateDictionaryListContent(dictionariesPath, 'cjs');\n writeFileSync(resolve(mainDir, 'dictionaries.cjs'), cjsContent);\n\n const esmContent = generateDictionaryListContent(dictionariesPath, 'esm');\n writeFileSync(resolve(mainDir, 'dictionaries.mjs'), esmContent);\n};\n"],"mappings":"AAAA,SAAS,YAAY,WAAW,qBAAqB;AACrD,SAAS,UAAU,SAAS,UAAU,eAAe;AACrD,SAAS,wBAAwB;AACjC,SAAS,2BAA2B;AACpC,SAAS,mBAAmB;AAE5B,MAAM,EAAE,QAAQ,IAAI,iBAAiB;AACrC,MAAM,EAAE,QAAQ,IAAI;AAKpB,MAAM,gCAAgC,CACpC,cACA,SAAwB,UACb;AACX,MAAIA,WAAU;AAEd,QAAM,kBAAkB,aAAa,IAAI,CAAC,oBAAoB;AAAA,IAC5D,cAAc,SAAS,SAAS,cAAc;AAAA,IAC9C,IAAI,SAAS,gBAAgB,QAAQ,cAAc,CAAC;AAAA;AAAA,IACpD,MAAM,IAAI,YAAY,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,MAAM,WAAW,EAAE,MAAM,WAAW,IAAI,EAAE,EAC9D,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,CAAC,WAAW,OAAO,GAAG;AACxB,cAAU,SAAS,EAAE,WAAW,KAAK,CAAC;AAAA,EACxC;AAEA,QAAM,mBAA6B,oBAAoB;AAGvD,QAAM,aAAa,8BAA8B,kBAAkB,KAAK;AACxE,gBAAc,QAAQ,SAAS,kBAAkB,GAAG,UAAU;AAE9D,QAAM,aAAa,8BAA8B,kBAAkB,KAAK;AACxE,gBAAc,QAAQ,SAAS,kBAAkB,GAAG,UAAU;AAChE;","names":["content"]}
@@ -1,4 +1,13 @@
1
+ import { IntlayerConfig } from '@intlayer/config';
1
2
  /** @ts-ignore remove error Module '"chokidar"' has no exported member 'ChokidarOptions' */
2
3
  import { type ChokidarOptions } from '../chokidar';
3
- export declare const watch: (options?: ChokidarOptions) => any;
4
+ export declare const prepareIntlayer: (configuration?: IntlayerConfig) => Promise<void>;
5
+ export declare const handleAdditionalContentDeclarationFile: (filePath: string, configuration?: IntlayerConfig) => Promise<void>;
6
+ export declare const handleContentDeclarationFileChange: (filePath: string, configuration?: IntlayerConfig) => Promise<void>;
7
+ type WatchOptions = ChokidarOptions & {
8
+ configuration?: IntlayerConfig;
9
+ };
10
+ export declare const watch: (options?: WatchOptions) => any;
11
+ export declare const buildAndWatchIntlayer: (options?: WatchOptions) => Promise<void>;
12
+ export {};
4
13
  //# sourceMappingURL=watcher.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"watcher.d.ts","sourceRoot":"","sources":["../../../src/chokidar/watcher.ts"],"names":[],"mappings":"AAEA,2FAA2F;AAC3F,OAAO,EAAE,KAAK,eAAe,EAA0B,MAAM,UAAU,CAAC;AAcxE,eAAO,MAAM,KAAK,aAAc,eAAe,QAsG9C,CAAC"}
1
+ {"version":3,"file":"watcher.d.ts","sourceRoot":"","sources":["../../../src/chokidar/watcher.ts"],"names":[],"mappings":"AACA,OAAO,EAA+B,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC/E,2FAA2F;AAC3F,OAAO,EAAE,KAAK,eAAe,EAA0B,MAAM,UAAU,CAAC;AAaxE,eAAO,MAAM,eAAe,mBAA0B,cAAc,kBAiCnE,CAAC;AAEF,eAAO,MAAM,sCAAsC,aACvC,MAAM,kBACA,cAAc,kBAiC/B,CAAC;AAEF,eAAO,MAAM,kCAAkC,aACnC,MAAM,kBACA,cAAc,kBAuC/B,CAAC;AAEF,KAAK,YAAY,GAAG,eAAe,GAAG;IACpC,aAAa,CAAC,EAAE,cAAc,CAAC;CAChC,CAAC;AAGF,eAAO,MAAM,KAAK,aAAc,YAAY,QA+B3C,CAAC;AAEF,eAAO,MAAM,qBAAqB,aAAoB,YAAY,kBASjE,CAAC"}
@@ -1,4 +1,4 @@
1
- export { watch } from './chokidar/watcher';
1
+ export { watch, prepareIntlayer, handleAdditionalContentDeclarationFile, handleContentDeclarationFileChange, buildAndWatchIntlayer, } from './chokidar/watcher';
2
2
  export { buildDictionary } from './transpiler/declaration_file_to_dictionary/index';
3
3
  export { createDictionaryList } from './transpiler/dictionary_to_main/createDictionaryList';
4
4
  export { createModuleAugmentation } from './transpiler/dictionary_to_type/createModuleAugmentation';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,mDAAmD,CAAC;AACpF,OAAO,EAAE,oBAAoB,EAAE,MAAM,sDAAsD,CAAC;AAC5F,OAAO,EAAE,wBAAwB,EAAE,MAAM,0DAA0D,CAAC;AACpG,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,0BAA0B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,eAAe,EACf,sCAAsC,EACtC,kCAAkC,EAClC,qBAAqB,GACtB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,eAAe,EAAE,MAAM,mDAAmD,CAAC;AACpF,OAAO,EAAE,oBAAoB,EAAE,MAAM,sDAAsD,CAAC;AAC5F,OAAO,EAAE,wBAAwB,EAAE,MAAM,0DAA0D,CAAC;AACpG,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,0BAA0B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intlayer/chokidar",
3
- "version": "4.1.0",
3
+ "version": "4.1.2",
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": [
@@ -64,10 +64,10 @@
64
64
  "p-limit": "^3.1.0",
65
65
  "quicktype-core": "^23.0.170",
66
66
  "react": "^18.3.1",
67
- "@intlayer/api": "4.1.0",
68
- "@intlayer/core": "4.1.0",
69
- "@intlayer/config": "4.1.0",
70
- "intlayer": "4.1.0"
67
+ "@intlayer/config": "4.1.2",
68
+ "intlayer": "4.1.2",
69
+ "@intlayer/api": "4.1.2",
70
+ "@intlayer/core": "4.1.2"
71
71
  },
72
72
  "devDependencies": {
73
73
  "@changesets/cli": "2.27.11",
@@ -81,18 +81,18 @@
81
81
  "tsc-alias": "^1.8.10",
82
82
  "tsup": "^8.3.5",
83
83
  "typescript": "^5.7.3",
84
+ "@intlayer/backend": "4.1.2",
84
85
  "@utils/eslint-config": "1.0.4",
85
86
  "@utils/ts-config": "1.0.4",
86
87
  "@utils/ts-config-types": "1.0.4",
87
- "@intlayer/backend": "4.1.0",
88
88
  "@utils/tsup-config": "1.0.4"
89
89
  },
90
90
  "peerDependencies": {
91
91
  "fast-glob": "^3.3.3",
92
- "@intlayer/api": "4.1.0",
93
- "@intlayer/config": "4.1.0",
94
- "@intlayer/core": "4.1.0",
95
- "intlayer": "^4.1.0"
92
+ "@intlayer/api": "4.1.2",
93
+ "@intlayer/config": "4.1.2",
94
+ "@intlayer/core": "4.1.2",
95
+ "intlayer": "^4.1.2"
96
96
  },
97
97
  "engines": {
98
98
  "node": ">=14.18"