@intlayer/chokidar 2.0.13 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/chokidar/watcher.cjs +18 -26
- package/dist/cjs/chokidar/watcher.cjs.map +1 -1
- package/dist/cjs/fetchDistantDictionaries.cjs +101 -0
- package/dist/cjs/fetchDistantDictionaries.cjs.map +1 -0
- package/dist/cjs/fetchDistantDictionaryKeys.cjs +50 -0
- package/dist/cjs/fetchDistantDictionaryKeys.cjs.map +1 -0
- package/dist/cjs/index.cjs +10 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/loadDictionaries/index.cjs +29 -0
- package/dist/cjs/loadDictionaries/index.cjs.map +1 -0
- package/dist/cjs/{transpiler/declaration_file_to_dictionary/intlayer_dictionary → loadDictionaries}/loadContentDeclaration.cjs +23 -7
- package/dist/cjs/loadDictionaries/loadContentDeclaration.cjs.map +1 -0
- package/dist/cjs/loadDictionaries/loadDictionaries.cjs +86 -0
- package/dist/cjs/loadDictionaries/loadDictionaries.cjs.map +1 -0
- package/dist/cjs/{transpiler/declaration_file_to_dictionary/intlayer_dictionary/extractNestedJSON.cjs → loadDictionaries/loadDistantDictionaries.cjs} +15 -22
- package/dist/cjs/loadDictionaries/loadDistantDictionaries.cjs.map +1 -0
- package/dist/cjs/loadDictionaries/loadLocalDictionaries.cjs +51 -0
- package/dist/cjs/loadDictionaries/loadLocalDictionaries.cjs.map +1 -0
- package/dist/cjs/log.cjs +255 -0
- package/dist/cjs/log.cjs.map +1 -0
- package/dist/cjs/mergeDictionaries.cjs +62 -0
- package/dist/cjs/mergeDictionaries.cjs.map +1 -0
- package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/buildI18nDictionary.cjs +13 -49
- package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/buildI18nDictionary.cjs.map +1 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertContentDeclarationInto18nDictionaries.cjs.map +1 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/writeDictionary.cjs +52 -0
- package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/writeDictionary.cjs.map +1 -0
- package/dist/cjs/transpiler/declaration_file_to_dictionary/index.cjs +1 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/index.cjs.map +1 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.cjs +4 -37
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.cjs.map +1 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/index.cjs +0 -2
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/index.cjs.map +1 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.cjs +8 -10
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.cjs.map +1 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.cjs +46 -0
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.cjs.map +1 -0
- package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs +1 -1
- package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs.map +1 -1
- package/dist/cjs/transpiler/dictionary_to_type/createType.cjs +8 -9
- package/dist/cjs/transpiler/dictionary_to_type/createType.cjs.map +1 -1
- package/dist/esm/chokidar/watcher.mjs +18 -16
- package/dist/esm/chokidar/watcher.mjs.map +1 -1
- package/dist/esm/fetchDistantDictionaries.mjs +67 -0
- package/dist/esm/fetchDistantDictionaries.mjs.map +1 -0
- package/dist/esm/fetchDistantDictionaryKeys.mjs +26 -0
- package/dist/esm/fetchDistantDictionaryKeys.mjs.map +1 -0
- package/dist/esm/index.mjs +10 -0
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/loadDictionaries/index.mjs +5 -0
- package/dist/esm/loadDictionaries/index.mjs.map +1 -0
- package/dist/esm/{transpiler/declaration_file_to_dictionary/intlayer_dictionary → loadDictionaries}/loadContentDeclaration.mjs +22 -5
- package/dist/esm/loadDictionaries/loadContentDeclaration.mjs.map +1 -0
- package/dist/esm/loadDictionaries/loadDictionaries.mjs +52 -0
- package/dist/esm/loadDictionaries/loadDictionaries.mjs.map +1 -0
- package/dist/esm/loadDictionaries/loadDistantDictionaries.mjs +14 -0
- package/dist/esm/loadDictionaries/loadDistantDictionaries.mjs.map +1 -0
- package/dist/esm/loadDictionaries/loadLocalDictionaries.mjs +27 -0
- package/dist/esm/loadDictionaries/loadLocalDictionaries.mjs.map +1 -0
- package/dist/esm/log.mjs +221 -0
- package/dist/esm/log.mjs.map +1 -0
- package/dist/esm/mergeDictionaries.mjs +28 -0
- package/dist/esm/mergeDictionaries.mjs.map +1 -0
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/buildI18nDictionary.mjs +15 -54
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/buildI18nDictionary.mjs.map +1 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertContentDeclarationInto18nDictionaries.mjs.map +1 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/writeDictionary.mjs +28 -0
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/writeDictionary.mjs.map +1 -0
- package/dist/esm/transpiler/declaration_file_to_dictionary/index.mjs +1 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/index.mjs.map +1 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.mjs +5 -38
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.mjs.map +1 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/index.mjs +0 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/index.mjs.map +1 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.mjs +8 -10
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.mjs.map +1 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.mjs +22 -0
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.mjs.map +1 -0
- package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs +1 -1
- package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs.map +1 -1
- package/dist/esm/transpiler/dictionary_to_type/createType.mjs +9 -9
- package/dist/esm/transpiler/dictionary_to_type/createType.mjs.map +1 -1
- package/dist/types/chokidar/index.d.ts +2 -0
- package/dist/types/chokidar/index.d.ts.map +1 -0
- package/dist/types/chokidar/watcher.d.ts +4 -0
- package/dist/types/chokidar/watcher.d.ts.map +1 -0
- package/dist/types/fetchDistantDictionaries.d.ts +12 -0
- package/dist/types/fetchDistantDictionaries.d.ts.map +1 -0
- package/dist/types/fetchDistantDictionaryKeys.d.ts +2 -0
- package/dist/types/fetchDistantDictionaryKeys.d.ts.map +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/loadDictionaries/index.d.ts +5 -0
- package/dist/types/loadDictionaries/index.d.ts.map +1 -0
- package/dist/types/loadDictionaries/loadContentDeclaration.d.ts +3 -0
- package/dist/types/loadDictionaries/loadContentDeclaration.d.ts.map +1 -0
- package/dist/types/loadDictionaries/loadDictionaries.d.ts +3 -0
- package/dist/types/loadDictionaries/loadDictionaries.d.ts.map +1 -0
- package/dist/types/loadDictionaries/loadDistantDictionaries.d.ts +8 -0
- package/dist/types/loadDictionaries/loadDistantDictionaries.d.ts.map +1 -0
- package/dist/types/loadDictionaries/loadLocalDictionaries.d.ts +3 -0
- package/dist/types/loadDictionaries/loadLocalDictionaries.d.ts.map +1 -0
- package/dist/types/log.d.ts +40 -0
- package/dist/types/log.d.ts.map +1 -0
- package/dist/types/mergeDictionaries.d.ts +5 -0
- package/dist/types/mergeDictionaries.d.ts.map +1 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/i18n_dictionary/buildI18nDictionary.d.ts +6 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/i18n_dictionary/buildI18nDictionary.d.ts.map +1 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertContentDeclarationInto18nDictionaries.d.ts +7 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertContentDeclarationInto18nDictionaries.d.ts.map +1 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertPluralsValues.d.ts +2 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertPluralsValues.d.ts.map +1 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/i18n_dictionary/index.d.ts +2 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/i18n_dictionary/index.d.ts.map +1 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/i18n_dictionary/writeDictionary.d.ts +7 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/i18n_dictionary/writeDictionary.d.ts.map +1 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/index.d.ts +3 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/index.d.ts.map +1 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.d.ts +6 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.d.ts.map +1 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/index.d.ts +3 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/index.d.ts.map +1 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.d.ts +6 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.d.ts.map +1 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.d.ts +3 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.d.ts.map +1 -0
- package/dist/types/transpiler/dictionary_to_main/createDictionaryList.d.ts +5 -0
- package/dist/types/transpiler/dictionary_to_main/createDictionaryList.d.ts.map +1 -0
- package/dist/types/transpiler/dictionary_to_main/index.d.ts +2 -0
- package/dist/types/transpiler/dictionary_to_main/index.d.ts.map +1 -0
- package/dist/types/transpiler/dictionary_to_type/createModuleAugmentation.d.ts +6 -0
- package/dist/types/transpiler/dictionary_to_type/createModuleAugmentation.d.ts.map +1 -0
- package/dist/types/transpiler/dictionary_to_type/createType.d.ts +6 -0
- package/dist/types/transpiler/dictionary_to_type/createType.d.ts.map +1 -0
- package/dist/types/transpiler/dictionary_to_type/index.d.ts +3 -0
- package/dist/types/transpiler/dictionary_to_type/index.d.ts.map +1 -0
- package/dist/types/utils.d.ts +3 -0
- package/dist/types/utils.d.ts.map +1 -0
- package/package.json +32 -16
- package/dist/cjs/chokidar/index.d.ts +0 -2
- package/dist/cjs/chokidar/watcher.d.ts +0 -5
- package/dist/cjs/index.d.ts +0 -4
- package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/buildI18nDictionary.d.ts +0 -6
- package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertContentDeclarationInto18nDictionaries.d.ts +0 -8
- package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertPluralsValues.d.ts +0 -3
- package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/index.d.ts +0 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/index.d.ts +0 -3
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.d.ts +0 -6
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/extractNestedJSON.cjs.map +0 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/extractNestedJSON.d.ts +0 -44
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/index.d.ts +0 -4
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/loadContentDeclaration.cjs.map +0 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/loadContentDeclaration.d.ts +0 -10
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.d.ts +0 -8
- package/dist/cjs/transpiler/dictionary_to_main/createDictionaryList.d.ts +0 -6
- package/dist/cjs/transpiler/dictionary_to_main/index.d.ts +0 -1
- package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.d.ts +0 -7
- package/dist/cjs/transpiler/dictionary_to_type/createType.d.ts +0 -7
- package/dist/cjs/transpiler/dictionary_to_type/index.d.ts +0 -2
- package/dist/cjs/utils.d.ts +0 -4
- package/dist/esm/chokidar/index.d.mts +0 -2
- package/dist/esm/chokidar/watcher.d.mts +0 -5
- package/dist/esm/index.d.mts +0 -4
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/buildI18nDictionary.d.mts +0 -6
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertContentDeclarationInto18nDictionaries.d.mts +0 -8
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertPluralsValues.d.mts +0 -3
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/index.d.mts +0 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/index.d.mts +0 -3
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.d.mts +0 -6
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/extractNestedJSON.d.mts +0 -44
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/extractNestedJSON.mjs +0 -21
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/extractNestedJSON.mjs.map +0 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/index.d.mts +0 -4
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/loadContentDeclaration.d.mts +0 -10
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/loadContentDeclaration.mjs.map +0 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.d.mts +0 -8
- package/dist/esm/transpiler/dictionary_to_main/createDictionaryList.d.mts +0 -6
- package/dist/esm/transpiler/dictionary_to_main/index.d.mts +0 -1
- package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.d.mts +0 -7
- package/dist/esm/transpiler/dictionary_to_type/createType.d.mts +0 -7
- package/dist/esm/transpiler/dictionary_to_type/index.d.mts +0 -2
- package/dist/esm/utils.d.mts +0 -4
|
@@ -24,46 +24,13 @@ module.exports = __toCommonJS(buildIntlayerDictionary_exports);
|
|
|
24
24
|
var import_promises = require("fs/promises");
|
|
25
25
|
var import_path = require("path");
|
|
26
26
|
var import_config = require("@intlayer/config");
|
|
27
|
-
var
|
|
28
|
-
var import_processContentDeclaration = require('./processContentDeclaration.cjs');
|
|
27
|
+
var import_writeDictionary = require('./writeDictionary.cjs');
|
|
29
28
|
const { content } = (0, import_config.getConfiguration)();
|
|
30
29
|
const { dictionariesDir } = content;
|
|
31
|
-
const
|
|
32
|
-
const resultDictionariesPaths = [];
|
|
33
|
-
for await (const dictionaryContent of dictionaries) {
|
|
34
|
-
const contentString = JSON.stringify(dictionaryContent);
|
|
35
|
-
const id = dictionaryContent.id;
|
|
36
|
-
const outputFileName = `${id}.json`;
|
|
37
|
-
const resultFilePath = (0, import_path.resolve)(dictionariesDir, outputFileName);
|
|
38
|
-
await (0, import_promises.writeFile)(resultFilePath, contentString, "utf8").catch((err) => {
|
|
39
|
-
console.error(`Error creating ${outputFileName}:`, err);
|
|
40
|
-
});
|
|
41
|
-
resultDictionariesPaths.push(resultFilePath);
|
|
42
|
-
}
|
|
43
|
-
return resultDictionariesPaths;
|
|
44
|
-
};
|
|
45
|
-
const buildIntlayerDictionary = async (contentDeclarationsPaths) => {
|
|
46
|
-
const resultDictionariesPaths = [];
|
|
47
|
-
if (typeof contentDeclarationsPaths === "string") {
|
|
48
|
-
contentDeclarationsPaths = [contentDeclarationsPaths];
|
|
49
|
-
}
|
|
30
|
+
const buildIntlayerDictionary = async (contentDeclarations) => {
|
|
50
31
|
await (0, import_promises.mkdir)((0, import_path.resolve)(dictionariesDir), { recursive: true });
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if (!result) {
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
56
|
-
const nestedContent = (0, import_extractNestedJSON.extractObjectsWithId)(result);
|
|
57
|
-
const contentWithFilePath = nestedContent.map(
|
|
58
|
-
(content2) => ({
|
|
59
|
-
...content2,
|
|
60
|
-
filePath: contentDeclarationPath
|
|
61
|
-
})
|
|
62
|
-
);
|
|
63
|
-
const dictionariesPaths = await writeDictionary(contentWithFilePath);
|
|
64
|
-
resultDictionariesPaths.push(...dictionariesPaths);
|
|
65
|
-
}
|
|
66
|
-
return resultDictionariesPaths;
|
|
32
|
+
const dictionariesPaths = await (0, import_writeDictionary.writeDictionary)(contentDeclarations);
|
|
33
|
+
return dictionariesPaths;
|
|
67
34
|
};
|
|
68
35
|
// Annotate the CommonJS export names for ESM import in node:
|
|
69
36
|
0 && (module.exports = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.ts"],"sourcesContent":["import { mkdir
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.ts"],"sourcesContent":["import { mkdir } from 'fs/promises';\nimport { resolve } from 'path';\nimport { getConfiguration } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { writeDictionary } from './writeDictionary';\n\nconst { content } = getConfiguration();\nconst { dictionariesDir } = content;\n\n/**\n * This function transpile the bundled code to to make dictionaries as JSON files\n */\nexport const buildIntlayerDictionary = async (\n contentDeclarations: Dictionary[]\n) => {\n // Create the dictionaries folder if it doesn't exist\n await mkdir(resolve(dictionariesDir), { recursive: true });\n\n const dictionariesPaths: string[] =\n await writeDictionary(contentDeclarations);\n\n return dictionariesPaths;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAsB;AACtB,kBAAwB;AACxB,oBAAiC;AAEjC,6BAAgC;AAEhC,MAAM,EAAE,QAAQ,QAAI,gCAAiB;AACrC,MAAM,EAAE,gBAAgB,IAAI;AAKrB,MAAM,0BAA0B,OACrC,wBACG;AAEH,YAAM,2BAAM,qBAAQ,eAAe,GAAG,EAAE,WAAW,KAAK,CAAC;AAEzD,QAAM,oBACJ,UAAM,wCAAgB,mBAAmB;AAE3C,SAAO;AACT;","names":[]}
|
|
@@ -15,12 +15,10 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
|
|
|
15
15
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
16
|
var intlayer_dictionary_exports = {};
|
|
17
17
|
module.exports = __toCommonJS(intlayer_dictionary_exports);
|
|
18
|
-
__reExport(intlayer_dictionary_exports, require('./extractNestedJSON.cjs'), module.exports);
|
|
19
18
|
__reExport(intlayer_dictionary_exports, require('./processContentDeclaration.cjs'), module.exports);
|
|
20
19
|
__reExport(intlayer_dictionary_exports, require('./buildIntlayerDictionary.cjs'), module.exports);
|
|
21
20
|
// Annotate the CommonJS export names for ESM import in node:
|
|
22
21
|
0 && (module.exports = {
|
|
23
|
-
...require('./extractNestedJSON.cjs'),
|
|
24
22
|
...require('./processContentDeclaration.cjs'),
|
|
25
23
|
...require('./buildIntlayerDictionary.cjs')
|
|
26
24
|
});
|
package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/index.ts"],"sourcesContent":["export * from './
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/index.ts"],"sourcesContent":["export * from './processContentDeclaration';\nexport * from './buildIntlayerDictionary';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,wCAAc,wCAAd;AACA,wCAAc,sCADd;","names":[]}
|
|
@@ -21,8 +21,6 @@ __export(processContentDeclaration_exports, {
|
|
|
21
21
|
processContentDeclaration: () => processContentDeclaration
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(processContentDeclaration_exports);
|
|
24
|
-
var import_path = require("path");
|
|
25
|
-
var import_loadContentDeclaration = require('./loadContentDeclaration.cjs');
|
|
26
24
|
const processFunctionResults = async (entry) => {
|
|
27
25
|
if (entry && typeof entry === "object") {
|
|
28
26
|
const promises = [];
|
|
@@ -55,15 +53,15 @@ const processFunctionResults = async (entry) => {
|
|
|
55
53
|
}
|
|
56
54
|
return entry;
|
|
57
55
|
};
|
|
58
|
-
const processContentDeclaration = async (
|
|
56
|
+
const processContentDeclaration = async (contentDeclaration) => {
|
|
59
57
|
try {
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
58
|
+
const content = await processFunctionResults(
|
|
59
|
+
contentDeclaration.content
|
|
60
|
+
);
|
|
61
|
+
return {
|
|
62
|
+
...contentDeclaration,
|
|
63
|
+
content
|
|
64
|
+
};
|
|
67
65
|
} catch (error) {
|
|
68
66
|
console.error("Error processing module:", error);
|
|
69
67
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.ts"],"sourcesContent":["import type {\n Content,\n DeclarationContent,\n Dictionary,\n FlatContent,\n FlatContentValue,\n} from '@intlayer/core';\n\n/**\n * Function to replace function and async function fields with their results in the object\n */\nconst processFunctionResults = async (entry: Content): Promise<FlatContent> => {\n if (entry && typeof entry === 'object') {\n const promises: Promise<void>[] = [];\n const result: FlatContent = {};\n\n for (const key of Object.keys(entry)) {\n const field = entry?.[key];\n const isArray = Array.isArray(field);\n\n if (typeof field === 'object' && isArray) {\n result[key] = (await Promise.all(\n field.map(async (el) => {\n return await processFunctionResults(el as Content);\n })\n )) as unknown as FlatContentValue;\n } else if (typeof field === 'object') {\n result[key] = (await processFunctionResults(\n field as Content\n )) as FlatContentValue;\n } else if (typeof field === 'function') {\n // Wait for the function to resolve if it's an async function\n const promise = (async () => {\n // Execute the function and await the result if it's a Promise\n const value = await field();\n\n result[key] = value as FlatContentValue;\n })();\n promises.push(promise);\n } else {\n result[key] = field as FlatContentValue;\n }\n }\n\n // Wait for all async operations to complete\n await Promise.all(promises);\n\n return result;\n }\n\n return entry as FlatContent;\n};\n\n/**\n * Function to load, process the module and return the Intlayer DeclarationContent from the module file\n */\nexport const processContentDeclaration = async (\n contentDeclaration: DeclarationContent\n): Promise<Dictionary | undefined> => {\n try {\n const content = (await processFunctionResults(\n contentDeclaration.content\n )) as DeclarationContent['content'];\n\n return {\n ...contentDeclaration,\n content,\n } as Dictionary;\n } catch (error) {\n console.error('Error processing module:', error);\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA,MAAM,yBAAyB,OAAO,UAAyC;AAC7E,MAAI,SAAS,OAAO,UAAU,UAAU;AACtC,UAAM,WAA4B,CAAC;AACnC,UAAM,SAAsB,CAAC;AAE7B,eAAW,OAAO,OAAO,KAAK,KAAK,GAAG;AACpC,YAAM,QAAQ,QAAQ,GAAG;AACzB,YAAM,UAAU,MAAM,QAAQ,KAAK;AAEnC,UAAI,OAAO,UAAU,YAAY,SAAS;AACxC,eAAO,GAAG,IAAK,MAAM,QAAQ;AAAA,UAC3B,MAAM,IAAI,OAAO,OAAO;AACtB,mBAAO,MAAM,uBAAuB,EAAa;AAAA,UACnD,CAAC;AAAA,QACH;AAAA,MACF,WAAW,OAAO,UAAU,UAAU;AACpC,eAAO,GAAG,IAAK,MAAM;AAAA,UACnB;AAAA,QACF;AAAA,MACF,WAAW,OAAO,UAAU,YAAY;AAEtC,cAAM,WAAW,YAAY;AAE3B,gBAAM,QAAQ,MAAM,MAAM;AAE1B,iBAAO,GAAG,IAAI;AAAA,QAChB,GAAG;AACH,iBAAS,KAAK,OAAO;AAAA,MACvB,OAAO;AACL,eAAO,GAAG,IAAI;AAAA,MAChB;AAAA,IACF;AAGA,UAAM,QAAQ,IAAI,QAAQ;AAE1B,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAKO,MAAM,4BAA4B,OACvC,uBACoC;AACpC,MAAI;AACF,UAAM,UAAW,MAAM;AAAA,MACrB,mBAAmB;AAAA,IACrB;AAEA,WAAO;AAAA,MACL,GAAG;AAAA,MACH;AAAA,IACF;AAAA,EACF,SAAS,OAAO;AACd,YAAQ,MAAM,4BAA4B,KAAK;AAAA,EACjD;AACF;","names":[]}
|
package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.cjs
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
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 writeDictionary_exports = {};
|
|
20
|
+
__export(writeDictionary_exports, {
|
|
21
|
+
writeDictionary: () => writeDictionary
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(writeDictionary_exports);
|
|
24
|
+
var import_promises = require("fs/promises");
|
|
25
|
+
var import_path = require("path");
|
|
26
|
+
var import_config = require("@intlayer/config");
|
|
27
|
+
const { dictionariesDir } = (0, import_config.getConfiguration)().content;
|
|
28
|
+
const writeDictionary = async (dictionaries) => {
|
|
29
|
+
const resultDictionariesPaths = [];
|
|
30
|
+
for await (const dictionaryContent of dictionaries) {
|
|
31
|
+
const contentString = JSON.stringify(dictionaryContent);
|
|
32
|
+
const id = dictionaryContent.key;
|
|
33
|
+
const outputFileName = `${id}.json`;
|
|
34
|
+
const resultFilePath = (0, import_path.resolve)(dictionariesDir, outputFileName);
|
|
35
|
+
await (0, import_promises.writeFile)(resultFilePath, contentString, "utf8").catch((err) => {
|
|
36
|
+
console.error(`Error creating ${outputFileName}:`, err);
|
|
37
|
+
});
|
|
38
|
+
resultDictionariesPaths.push(resultFilePath);
|
|
39
|
+
}
|
|
40
|
+
return resultDictionariesPaths;
|
|
41
|
+
};
|
|
42
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
43
|
+
0 && (module.exports = {
|
|
44
|
+
writeDictionary
|
|
45
|
+
});
|
|
46
|
+
//# sourceMappingURL=writeDictionary.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.ts"],"sourcesContent":["import { writeFile } from 'fs/promises';\nimport { resolve } from 'path';\nimport { getConfiguration } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\n\nconst { dictionariesDir } = getConfiguration().content;\n\nexport const writeDictionary = async (dictionaries: Dictionary[]) => {\n const resultDictionariesPaths: string[] = [];\n\n for await (const dictionaryContent of dictionaries) {\n const contentString = JSON.stringify(dictionaryContent);\n\n const id = dictionaryContent.key;\n const outputFileName = `${id}.json`;\n const resultFilePath = resolve(dictionariesDir, outputFileName);\n\n // Create the json file\n await writeFile(resultFilePath, contentString, 'utf8').catch((err) => {\n console.error(`Error creating ${outputFileName}:`, err);\n });\n\n resultDictionariesPaths.push(resultFilePath);\n }\n\n return resultDictionariesPaths;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA0B;AAC1B,kBAAwB;AACxB,oBAAiC;AAGjC,MAAM,EAAE,gBAAgB,QAAI,gCAAiB,EAAE;AAExC,MAAM,kBAAkB,OAAO,iBAA+B;AACnE,QAAM,0BAAoC,CAAC;AAE3C,mBAAiB,qBAAqB,cAAc;AAClD,UAAM,gBAAgB,KAAK,UAAU,iBAAiB;AAEtD,UAAM,KAAK,kBAAkB;AAC7B,UAAM,iBAAiB,GAAG,EAAE;AAC5B,UAAM,qBAAiB,qBAAQ,iBAAiB,cAAc;AAG9D,cAAM,2BAAU,gBAAgB,eAAe,MAAM,EAAE,MAAM,CAAC,QAAQ;AACpE,cAAQ,MAAM,kBAAkB,cAAc,KAAK,GAAG;AAAA,IACxD,CAAC;AAED,4BAAwB,KAAK,cAAc;AAAA,EAC7C;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -32,7 +32,7 @@ const { typesDir, moduleAugmentationDir } = content;
|
|
|
32
32
|
const { locales, strictMode } = internationalization;
|
|
33
33
|
const getTypeName = (id) => (0, import_utils.transformToCamelCase)(`${id}Content`);
|
|
34
34
|
const generateTypeIndexContent = (typeFiles) => {
|
|
35
|
-
let content2 = "/* eslint-disable */\nimport { Locales } from 'intlayer'
|
|
35
|
+
let content2 = "/* eslint-disable */\nimport { Locales } from 'intlayer';\n";
|
|
36
36
|
const dictionariesRef = typeFiles.map((dictionaryPath) => ({
|
|
37
37
|
relativePath: (0, import_path.relative)(moduleAugmentationDir, dictionaryPath),
|
|
38
38
|
id: (0, import_path.basename)(dictionaryPath, ".d.ts"),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/transpiler/dictionary_to_type/createModuleAugmentation.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { basename, join, relative } from 'path';\nimport { Locales, getConfiguration } from '@intlayer/config';\nimport { sync } from 'glob';\nimport { getFileHash, transformToCamelCase } from '../../utils';\n\nconst { content, internationalization } = getConfiguration();\nconst { typesDir, moduleAugmentationDir } = content;\nconst { locales, strictMode } = internationalization;\n\nexport const getTypeName = (id: string): string =>\n transformToCamelCase(`${id}Content`);\n\n/**\n * This function generates the content of the module augmentation file\n */\nconst generateTypeIndexContent = (typeFiles: string[]): string => {\n let content = \"/* eslint-disable */\\nimport { Locales } from 'intlayer'
|
|
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, strictMode } = internationalization;\n\nexport const getTypeName = (id: string): string =>\n transformToCamelCase(`${id}Content`);\n\n/**\n * This function generates the content of the module augmentation file\n */\nconst generateTypeIndexContent = (typeFiles: string[]): string => {\n let content = \"/* eslint-disable */\\nimport { Locales } from 'intlayer';\\n\";\n\n const dictionariesRef = typeFiles.map((dictionaryPath) => ({\n relativePath: relative(moduleAugmentationDir, dictionaryPath),\n id: basename(dictionaryPath, '.d.ts'), // Get the base name as the dictionary id\n hash: `_${getFileHash(dictionaryPath)}`, // Get the hash of the dictionary to avoid conflicts\n }));\n\n // Import all dictionaries\n dictionariesRef.forEach((dictionary) => {\n const typeName = getTypeName(dictionary.id);\n content += `import type { ${typeName} as ${dictionary.hash} } from '${dictionary.relativePath}';\\n`;\n });\n\n content += '\\n';\n\n // Format Dictionary Map\n const formattedDictionaryMap: string = dictionariesRef\n .map((dictionary) => ` \"${dictionary.id}\": ${dictionary.hash};`)\n .join('\\n');\n\n const formatLocales = locales\n .map((locale) => {\n for (const key in Locales) {\n if (Locales[key as keyof typeof Locales] === locale) {\n return `Locales.${key}`;\n }\n }\n })\n .join(' | ');\n\n const strictModeRecord =\n strictMode === 'strict'\n ? `interface IConfigLocales<Content> extends Record<ExtractedLocales, Content> {}`\n : strictMode === 'required_only'\n ? `interface IConfigLocales<Content> extends Record<ExtractedLocales, Content>, Partial<Record<ExcludedLocales, Content>> {}`\n : `interface IConfigLocales<Content> extends Partial<Record<Locales, Content>> {}`;\n\n /**\n * Write the module augmentation to extend the intlayer module with the dictionaries types\n * Will suggest the type resulting of the dictionaries\n *\n * declare module 'intlayer' {\n * interface IntlayerDictionaryTypesConnector = {\n * dictionaries: {\n * id: DictionaryType;\n * }\n * }\n *\n * type ConfigLocales = Locales.ENGLISH | Locales.FRENCH | Locales.SPANISH;\n * type ExtractedLocales = Extract<Locales, ConfigLocales>;\n * type ExcludedLocales = Exclude<Locales, ConfigLocales>;\n *\n * interface IConfigLocales<Content> extends Record<ExtractedLocales, Content>, Partial<Record<ExcludedLocales, Content>> {}\n *\n *\n * }\n * See https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation\n */\n content += `declare module 'intlayer' {\\n`;\n content += ` interface IntlayerDictionaryTypesConnector {\\n${formattedDictionaryMap}\\n }\\n\\n`;\n content += ` type ConfigLocales = ${formatLocales};\\n`;\n content += ` type ExtractedLocales = Extract<Locales, ConfigLocales>;\\n`;\n content += ` type ExcludedLocales = Exclude<Locales, ConfigLocales>;\\n\\n`;\n content += ` ${strictModeRecord}\\n`;\n content += `}`;\n\n return content;\n};\n\n/**\n * This function generates a index file merging all the types\n */\nexport const createModuleAugmentation = () => {\n // Create main directory if it doesn't exist\n if (!existsSync(moduleAugmentationDir)) {\n mkdirSync(moduleAugmentationDir, { recursive: true });\n }\n\n const dictionaries: string[] = 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,SAAS,WAAW,IAAI;AAEzB,MAAM,cAAc,CAAC,WAC1B,mCAAqB,GAAG,EAAE,SAAS;AAKrC,MAAM,2BAA2B,CAAC,cAAgC;AAChE,MAAIA,WAAU;AAEd,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,WAAW,GAAG;AAAA,MACvB;AAAA,IACF;AAAA,EACF,CAAC,EACA,KAAK,KAAK;AAEb,QAAM,mBACJ,eAAe,WACX,mFACA,eAAe,kBACb,8HACA;AAuBR,EAAAA,YAAW;AAAA;AACX,EAAAA,YAAW;AAAA,EAAmD,sBAAsB;AAAA;AAAA;AAAA;AACpF,EAAAA,YAAW,0BAA0B,aAAa;AAAA;AAClD,EAAAA,YAAW;AAAA;AACX,EAAAA,YAAW;AAAA;AAAA;AACX,EAAAA,YAAW,KAAK,gBAAgB;AAAA;AAChC,EAAAA,YAAW;AAEX,SAAOA;AACT;AAKO,MAAM,2BAA2B,MAAM;AAE5C,MAAI,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"]}
|
|
@@ -23,20 +23,16 @@ __export(createType_exports, {
|
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(createType_exports);
|
|
25
25
|
var import_fs = require("fs");
|
|
26
|
-
var import_module = require("module");
|
|
27
26
|
var import_path = require("path");
|
|
28
27
|
var import_config = require("@intlayer/config");
|
|
29
28
|
var import_quicktype_core = require("quicktype-core");
|
|
30
|
-
const import_meta = {};
|
|
31
29
|
const { content } = (0, import_config.getConfiguration)();
|
|
32
30
|
const { typesDir } = content;
|
|
33
|
-
const isESModule = typeof import_meta.url === "string";
|
|
34
|
-
const requireFunction = isESModule ? (0, import_module.createRequire)(import_meta.url) : require;
|
|
35
31
|
const requireUncached = (module2) => {
|
|
36
|
-
delete
|
|
37
|
-
return
|
|
32
|
+
delete import_config.ESMxCJSRequire.cache[import_config.ESMxCJSRequire.resolve(module2)];
|
|
33
|
+
return (0, import_config.ESMxCJSRequire)(module2);
|
|
38
34
|
};
|
|
39
|
-
const
|
|
35
|
+
const kebabCaseToCamelCase = (name) => name.split(/[\s\-_]+/).map((word, index) => {
|
|
40
36
|
if (index === 0) {
|
|
41
37
|
return word;
|
|
42
38
|
}
|
|
@@ -75,8 +71,11 @@ const createTypes = async (dictionariesPaths) => {
|
|
|
75
71
|
}
|
|
76
72
|
for (const dictionaryPath of dictionariesPaths) {
|
|
77
73
|
const dictionary = requireUncached(dictionaryPath);
|
|
78
|
-
const dictionaryName = dictionary.
|
|
79
|
-
|
|
74
|
+
const dictionaryName = dictionary.key;
|
|
75
|
+
if (!dictionaryName) {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
const dictionaryNameCamelCase = kebabCaseToCamelCase(dictionaryName) + "Content";
|
|
80
79
|
const dictionaryContentString = JSON.stringify(dictionary);
|
|
81
80
|
const typeDefinition = await generateTypeScriptType(
|
|
82
81
|
dictionaryNameCamelCase,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/transpiler/dictionary_to_type/createType.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/dictionary_to_type/createType.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { resolve } from 'path';\nimport { getConfiguration, ESMxCJSRequire } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport {\n quicktype,\n InputData,\n jsonInputForTargetLanguage,\n} from 'quicktype-core';\n\nconst { content } = getConfiguration();\nconst { typesDir } = content;\n\nconst requireUncached = (module: string) => {\n delete ESMxCJSRequire.cache[ESMxCJSRequire.resolve(module)];\n return ESMxCJSRequire(module);\n};\n\nconst kebabCaseToCamelCase = (name: string): string =>\n name\n .split(/[\\s\\-_]+/) // Regular expression to match space, hyphen, or underscore\n .map((word, index) => {\n if (index === 0) {\n return word; // Return the first word as is\n }\n return word.charAt(0).toUpperCase() + word.slice(1); // Capitalize the first letter of subsequent words\n })\n .join(''); // Join all the segments into one string\n\nexport const generateTypeScriptType = async (\n typeName: string,\n jsonString: string\n) => {\n const { lines } = await quicktypeJSON(typeName, jsonString);\n\n const linesString: string = lines.join('\\n');\n\n return linesString;\n};\n\nconst quicktypeJSON = async (typeName: string, jsonString: string) => {\n const jsonInput = jsonInputForTargetLanguage('typescript');\n\n // We could add multiple samples for the same desired\n // type, or many sources for other types. Here we're\n // just making one type from one piece of sample JSON.\n\n await jsonInput.addSource({\n name: typeName,\n samples: [jsonString],\n });\n\n const inputData = new InputData();\n inputData.addInput(jsonInput);\n\n return await quicktype({\n inputData,\n lang: 'typescript',\n alphabetizeProperties: true,\n rendererOptions: {\n 'just-types': 'true',\n 'explicit-unions': 'true',\n 'acronym-style': 'camel',\n 'prefer-types': 'true',\n readonly: 'false',\n },\n });\n};\n\n/**\n * This function generates a TypeScript type definition from a JSON object\n */\nexport const createTypes = async (\n dictionariesPaths: string[]\n): Promise<string[]> => {\n const resultTypesPaths: string[] = [];\n\n // Create type folders if they don't exist\n if (!existsSync(typesDir)) {\n mkdirSync(typesDir, { recursive: true });\n }\n\n for (const dictionaryPath of dictionariesPaths) {\n const dictionary: Dictionary = requireUncached(dictionaryPath);\n\n const dictionaryName: string = dictionary.key;\n\n if (!dictionaryName) {\n // Skip dictionary if it doesn't have a key, if not exported as default etc\n continue;\n }\n\n const dictionaryNameCamelCase: string =\n kebabCaseToCamelCase(dictionaryName) + 'Content';\n\n const dictionaryContentString: string = JSON.stringify(dictionary);\n\n const typeDefinition: string = await generateTypeScriptType(\n dictionaryNameCamelCase,\n dictionaryContentString\n );\n\n const outputPath: string = resolve(typesDir, `${dictionaryName}.d.ts`);\n\n writeFileSync(outputPath, typeDefinition);\n\n resultTypesPaths.push(outputPath);\n }\n\n return resultTypesPaths;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAqD;AACrD,kBAAwB;AACxB,oBAAiD;AAEjD,4BAIO;AAEP,MAAM,EAAE,QAAQ,QAAI,gCAAiB;AACrC,MAAM,EAAE,SAAS,IAAI;AAErB,MAAM,kBAAkB,CAACA,YAAmB;AAC1C,SAAO,6BAAe,MAAM,6BAAe,QAAQA,OAAM,CAAC;AAC1D,aAAO,8BAAeA,OAAM;AAC9B;AAEA,MAAM,uBAAuB,CAAC,SAC5B,KACG,MAAM,UAAU,EAChB,IAAI,CAAC,MAAM,UAAU;AACpB,MAAI,UAAU,GAAG;AACf,WAAO;AAAA,EACT;AACA,SAAO,KAAK,OAAO,CAAC,EAAE,YAAY,IAAI,KAAK,MAAM,CAAC;AACpD,CAAC,EACA,KAAK,EAAE;AAEL,MAAM,yBAAyB,OACpC,UACA,eACG;AACH,QAAM,EAAE,MAAM,IAAI,MAAM,cAAc,UAAU,UAAU;AAE1D,QAAM,cAAsB,MAAM,KAAK,IAAI;AAE3C,SAAO;AACT;AAEA,MAAM,gBAAgB,OAAO,UAAkB,eAAuB;AACpE,QAAM,gBAAY,kDAA2B,YAAY;AAMzD,QAAM,UAAU,UAAU;AAAA,IACxB,MAAM;AAAA,IACN,SAAS,CAAC,UAAU;AAAA,EACtB,CAAC;AAED,QAAM,YAAY,IAAI,gCAAU;AAChC,YAAU,SAAS,SAAS;AAE5B,SAAO,UAAM,iCAAU;AAAA,IACrB;AAAA,IACA,MAAM;AAAA,IACN,uBAAuB;AAAA,IACvB,iBAAiB;AAAA,MACf,cAAc;AAAA,MACd,mBAAmB;AAAA,MACnB,iBAAiB;AAAA,MACjB,gBAAgB;AAAA,MAChB,UAAU;AAAA,IACZ;AAAA,EACF,CAAC;AACH;AAKO,MAAM,cAAc,OACzB,sBACsB;AACtB,QAAM,mBAA6B,CAAC;AAGpC,MAAI,KAAC,sBAAW,QAAQ,GAAG;AACzB,6BAAU,UAAU,EAAE,WAAW,KAAK,CAAC;AAAA,EACzC;AAEA,aAAW,kBAAkB,mBAAmB;AAC9C,UAAM,aAAyB,gBAAgB,cAAc;AAE7D,UAAM,iBAAyB,WAAW;AAE1C,QAAI,CAAC,gBAAgB;AAEnB;AAAA,IACF;AAEA,UAAM,0BACJ,qBAAqB,cAAc,IAAI;AAEzC,UAAM,0BAAkC,KAAK,UAAU,UAAU;AAEjE,UAAM,iBAAyB,MAAM;AAAA,MACnC;AAAA,MACA;AAAA,IACF;AAEA,UAAM,iBAAqB,qBAAQ,UAAU,GAAG,cAAc,OAAO;AAErE,iCAAc,YAAY,cAAc;AAExC,qBAAiB,KAAK,UAAU;AAAA,EAClC;AAEA,SAAO;AACT;","names":["module"]}
|
|
@@ -1,55 +1,57 @@
|
|
|
1
1
|
import { relative } from "path";
|
|
2
2
|
import { getConfiguration } from "@intlayer/config";
|
|
3
|
-
import
|
|
3
|
+
import { watch as chokidarWatch } from "chokidar";
|
|
4
4
|
import { sync } from "glob";
|
|
5
|
+
import { loadDictionaries } from '../loadDictionaries/loadDictionaries.mjs';
|
|
6
|
+
import { loadLocalDictionaries } from '../loadDictionaries/loadLocalDictionaries.mjs';
|
|
5
7
|
import { buildDictionary } from '../transpiler/declaration_file_to_dictionary/index.mjs';
|
|
6
8
|
import { createDictionaryList } from '../transpiler/dictionary_to_main/createDictionaryList.mjs';
|
|
7
9
|
import {
|
|
8
10
|
createTypes,
|
|
9
11
|
createModuleAugmentation
|
|
10
12
|
} from '../transpiler/dictionary_to_type/index.mjs';
|
|
13
|
+
const LOG_PREFIX = "[intlayer] ";
|
|
11
14
|
const watch = (options) => {
|
|
12
15
|
const { content } = getConfiguration({
|
|
13
16
|
verbose: true
|
|
14
17
|
});
|
|
15
18
|
const { watchedFilesPatternWithPath, baseDir } = content;
|
|
16
19
|
const files = sync(watchedFilesPatternWithPath);
|
|
17
|
-
return
|
|
20
|
+
return chokidarWatch(watchedFilesPatternWithPath, {
|
|
18
21
|
persistent: true,
|
|
19
22
|
// Make the watcher persistent
|
|
20
23
|
ignoreInitial: true,
|
|
21
24
|
// Process existing files
|
|
22
25
|
...options
|
|
23
26
|
}).on("ready", async () => {
|
|
24
|
-
const
|
|
27
|
+
const dictionaries = await loadDictionaries(files);
|
|
28
|
+
const dictionariesPaths = await buildDictionary(dictionaries);
|
|
25
29
|
await createTypes(dictionariesPaths);
|
|
26
|
-
console.info(
|
|
30
|
+
console.info(`${LOG_PREFIX}TypeScript types built`);
|
|
27
31
|
createModuleAugmentation();
|
|
28
|
-
console.info(
|
|
32
|
+
console.info(`${LOG_PREFIX}Intlayer module augmentation built`);
|
|
29
33
|
createDictionaryList();
|
|
30
|
-
console.info(
|
|
31
|
-
const relativeDictionariesPath = dictionariesPaths.map(
|
|
32
|
-
(dictionary) => relative(baseDir, dictionary)
|
|
33
|
-
);
|
|
34
|
-
console.info("[intlayer] Dictionaries:", relativeDictionariesPath);
|
|
34
|
+
console.info(`${LOG_PREFIX}Intlayer dictionary list built`);
|
|
35
35
|
}).on("unlink", (filePath) => {
|
|
36
36
|
console.info("Removed file detected: ", relative(baseDir, filePath));
|
|
37
37
|
}).on("add", async (filePath) => {
|
|
38
38
|
console.info(
|
|
39
|
-
|
|
39
|
+
`${LOG_PREFIX}Additional file detected: `,
|
|
40
40
|
relative(baseDir, filePath)
|
|
41
41
|
);
|
|
42
|
-
const
|
|
42
|
+
const localeDictionaries = await loadLocalDictionaries(filePath);
|
|
43
|
+
const dictionaries = await buildDictionary(localeDictionaries);
|
|
43
44
|
await createTypes(dictionaries);
|
|
44
|
-
console.info(
|
|
45
|
+
console.info(`${LOG_PREFIX}TypeScript types built`);
|
|
45
46
|
createModuleAugmentation();
|
|
46
|
-
console.info(
|
|
47
|
+
console.info(`${LOG_PREFIX}Intlayer module augmentation built`);
|
|
47
48
|
createDictionaryList();
|
|
48
49
|
}).on("change", async (filePath) => {
|
|
49
50
|
console.info("Change detected: ", relative(baseDir, filePath));
|
|
50
|
-
const
|
|
51
|
+
const localeDictionaries = await loadLocalDictionaries(filePath);
|
|
52
|
+
const dictionaries = await buildDictionary(localeDictionaries);
|
|
51
53
|
await createTypes(dictionaries);
|
|
52
|
-
console.info(
|
|
54
|
+
console.info(`${LOG_PREFIX}TypeScript types built`);
|
|
53
55
|
}).on("error", (error) => {
|
|
54
56
|
console.error("Watcher error:", error);
|
|
55
57
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/chokidar/watcher.ts"],"sourcesContent":["import { relative } from 'path';\nimport { getConfiguration } from '@intlayer/config';\
|
|
1
|
+
{"version":3,"sources":["../../../src/chokidar/watcher.ts"],"sourcesContent":["import { relative } from 'path';\nimport { 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 { sync } from 'glob';\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\nconst LOG_PREFIX = '[intlayer] ';\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 } = content;\n\n const files: string[] = sync(watchedFilesPatternWithPath);\n\n /** @ts-ignore remove error Expected 0-1 arguments, but got 2. */\n return chokidarWatch(watchedFilesPatternWithPath, {\n persistent: true, // Make the watcher persistent\n ignoreInitial: true, // Process existing files\n ...options,\n })\n .on('ready', async () => {\n const dictionaries = await loadDictionaries(files);\n\n // Build locale dictionaries\n const dictionariesPaths = await buildDictionary(dictionaries);\n\n await createTypes(dictionariesPaths);\n console.info(`${LOG_PREFIX}TypeScript types built`);\n\n createModuleAugmentation();\n console.info(`${LOG_PREFIX}Intlayer module augmentation built`);\n\n createDictionaryList();\n console.info(`${LOG_PREFIX}Intlayer dictionary list built`);\n })\n .on('unlink', (filePath) => {\n // Process the file with the functionToRun\n console.info('Removed file detected: ', relative(baseDir, filePath));\n })\n .on('add', async (filePath) => {\n // Process the file with the functionToRun\n console.info(\n `${LOG_PREFIX}Additional file detected: `,\n relative(baseDir, filePath)\n );\n\n const localeDictionaries = await loadLocalDictionaries(filePath);\n const dictionaries = await buildDictionary(localeDictionaries);\n\n await createTypes(dictionaries);\n console.info(`${LOG_PREFIX}TypeScript types built`);\n\n createModuleAugmentation();\n console.info(`${LOG_PREFIX}Intlayer module augmentation built`);\n\n createDictionaryList();\n })\n .on('change', async (filePath) => {\n // Process the file with the functionToRun\n console.info('Change detected: ', relative(baseDir, filePath));\n\n const localeDictionaries = await loadLocalDictionaries(filePath);\n const dictionaries = await buildDictionary(localeDictionaries);\n\n await createTypes(dictionaries);\n console.info(`${LOG_PREFIX}TypeScript types built`);\n })\n .on('error', (error) => {\n console.error('Watcher error:', error);\n });\n};\n"],"mappings":"AAAA,SAAS,gBAAgB;AACzB,SAAS,wBAAwB;AAEjC,SAA+B,SAAS,qBAAqB;AAC7D,SAAS,YAAY;AACrB,SAAS,wBAAwB;AACjC,SAAS,6BAA6B;AACtC,SAAS,uBAAuB;AAChC,SAAS,4BAA4B;AACrC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAEP,MAAM,aAAa;AAGZ,MAAM,QAAQ,CAAC,YAA8B;AAClD,QAAM,EAAE,QAAQ,IAAI,iBAAiB;AAAA,IACnC,SAAS;AAAA,EACX,CAAC;AAED,QAAM,EAAE,6BAA6B,QAAQ,IAAI;AAEjD,QAAM,QAAkB,KAAK,2BAA2B;AAGxD,SAAO,cAAc,6BAA6B;AAAA,IAChD,YAAY;AAAA;AAAA,IACZ,eAAe;AAAA;AAAA,IACf,GAAG;AAAA,EACL,CAAC,EACE,GAAG,SAAS,YAAY;AACvB,UAAM,eAAe,MAAM,iBAAiB,KAAK;AAGjD,UAAM,oBAAoB,MAAM,gBAAgB,YAAY;AAE5D,UAAM,YAAY,iBAAiB;AACnC,YAAQ,KAAK,GAAG,UAAU,wBAAwB;AAElD,6BAAyB;AACzB,YAAQ,KAAK,GAAG,UAAU,oCAAoC;AAE9D,yBAAqB;AACrB,YAAQ,KAAK,GAAG,UAAU,gCAAgC;AAAA,EAC5D,CAAC,EACA,GAAG,UAAU,CAAC,aAAa;AAE1B,YAAQ,KAAK,2BAA2B,SAAS,SAAS,QAAQ,CAAC;AAAA,EACrE,CAAC,EACA,GAAG,OAAO,OAAO,aAAa;AAE7B,YAAQ;AAAA,MACN,GAAG,UAAU;AAAA,MACb,SAAS,SAAS,QAAQ;AAAA,IAC5B;AAEA,UAAM,qBAAqB,MAAM,sBAAsB,QAAQ;AAC/D,UAAM,eAAe,MAAM,gBAAgB,kBAAkB;AAE7D,UAAM,YAAY,YAAY;AAC9B,YAAQ,KAAK,GAAG,UAAU,wBAAwB;AAElD,6BAAyB;AACzB,YAAQ,KAAK,GAAG,UAAU,oCAAoC;AAE9D,yBAAqB;AAAA,EACvB,CAAC,EACA,GAAG,UAAU,OAAO,aAAa;AAEhC,YAAQ,KAAK,qBAAqB,SAAS,SAAS,QAAQ,CAAC;AAE7D,UAAM,qBAAqB,MAAM,sBAAsB,QAAQ;AAC/D,UAAM,eAAe,MAAM,gBAAgB,kBAAkB;AAE7D,UAAM,YAAY,YAAY;AAC9B,YAAQ,KAAK,GAAG,UAAU,wBAAwB;AAAA,EACpD,CAAC,EACA,GAAG,SAAS,CAAC,UAAU;AACtB,YAAQ,MAAM,kBAAkB,KAAK;AAAA,EACvC,CAAC;AACL;","names":[]}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { getConfiguration } from "@intlayer/config";
|
|
2
|
+
import { intlayerAPI } from "@intlayer/design-system/libs";
|
|
3
|
+
import pLimit from "p-limit";
|
|
4
|
+
import { logger } from './log.mjs';
|
|
5
|
+
const fetchDistantDictionaries = async (options) => {
|
|
6
|
+
try {
|
|
7
|
+
const {
|
|
8
|
+
editor: { clientId, clientSecret }
|
|
9
|
+
} = getConfiguration();
|
|
10
|
+
if (!clientId || !clientSecret) {
|
|
11
|
+
throw new Error(
|
|
12
|
+
"Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project."
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
const oAuth2TokenResult = await intlayerAPI.auth.getOAuth2AccessToken();
|
|
16
|
+
const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;
|
|
17
|
+
const distantDictionariesKeys = options.dictionaryKeys;
|
|
18
|
+
const limit = pLimit(5);
|
|
19
|
+
const processDictionary = async (dictionaryKey) => {
|
|
20
|
+
logger.updateStatus(dictionaryKey, "distant", { status: "fetching" });
|
|
21
|
+
try {
|
|
22
|
+
const getDictionaryResult = await intlayerAPI.dictionary.getDictionary(
|
|
23
|
+
dictionaryKey,
|
|
24
|
+
void 0,
|
|
25
|
+
{
|
|
26
|
+
headers: { Authorization: `Bearer ${oAuth2AccessToken}` }
|
|
27
|
+
}
|
|
28
|
+
);
|
|
29
|
+
const distantDictionary = getDictionaryResult.data;
|
|
30
|
+
if (!distantDictionary) {
|
|
31
|
+
throw new Error(`Dictionary ${dictionaryKey} not found on remote`);
|
|
32
|
+
}
|
|
33
|
+
logger.updateStatus(dictionaryKey, "distant", { status: "imported" });
|
|
34
|
+
return distantDictionary;
|
|
35
|
+
} catch (error) {
|
|
36
|
+
logger.updateStatus(dictionaryKey, "distant", {
|
|
37
|
+
status: "error",
|
|
38
|
+
error,
|
|
39
|
+
errorMessage: `${options?.logPrefix ?? ""}Error fetching dictionary ${dictionaryKey}: ${error}`
|
|
40
|
+
});
|
|
41
|
+
return void 0;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const fetchPromises = distantDictionariesKeys.map(
|
|
45
|
+
(dictionaryKey) => limit(() => processDictionary(dictionaryKey))
|
|
46
|
+
);
|
|
47
|
+
const result = await Promise.all(fetchPromises);
|
|
48
|
+
const statuses = logger.getStatuses();
|
|
49
|
+
for (const statusObj of statuses) {
|
|
50
|
+
const currentState = statusObj.state.find((s) => s.type === "distant");
|
|
51
|
+
if (currentState && currentState.errorMessage) {
|
|
52
|
+
console.error(currentState.errorMessage);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const filteredResult = result.filter(
|
|
56
|
+
(dict) => dict !== void 0
|
|
57
|
+
);
|
|
58
|
+
return filteredResult;
|
|
59
|
+
} catch (error) {
|
|
60
|
+
console.error(error);
|
|
61
|
+
return [];
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
export {
|
|
65
|
+
fetchDistantDictionaries
|
|
66
|
+
};
|
|
67
|
+
//# sourceMappingURL=fetchDistantDictionaries.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/fetchDistantDictionaries.ts"],"sourcesContent":["// @ts-ignore @intlayer/backend not build yet\nimport { type DictionaryAPI } from '@intlayer/backend';\nimport { getConfiguration } from '@intlayer/config';\n// @ts-ignore @intlayer/design-system not build yet\nimport { intlayerAPI } from '@intlayer/design-system/libs';\nimport pLimit from 'p-limit';\nimport { logger } from './log';\n\ntype FetchDistantDictionariesOptions = {\n dictionaryKeys: string[];\n newDictionariesPath?: string;\n logPrefix?: string;\n};\n\n/**\n * Fetch distant dictionaries and update the logger with their statuses.\n */\nexport const fetchDistantDictionaries = async (\n options: FetchDistantDictionariesOptions\n): Promise<DictionaryAPI[]> => {\n try {\n const {\n editor: { clientId, clientSecret },\n } = getConfiguration();\n\n if (!clientId || !clientSecret) {\n throw new Error(\n 'Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project.'\n );\n }\n\n const oAuth2TokenResult = await intlayerAPI.auth.getOAuth2AccessToken();\n\n const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;\n\n const distantDictionariesKeys = options.dictionaryKeys;\n\n // Process dictionaries in parallel with a concurrency limit\n const limit = pLimit(5); // Adjust the limit as needed\n\n const processDictionary = async (\n dictionaryKey: string\n ): Promise<DictionaryAPI | undefined> => {\n logger.updateStatus(dictionaryKey, 'distant', { status: 'fetching' });\n\n try {\n // Fetch the dictionary\n const getDictionaryResult = await intlayerAPI.dictionary.getDictionary(\n dictionaryKey,\n undefined,\n {\n headers: { Authorization: `Bearer ${oAuth2AccessToken}` },\n }\n );\n\n const distantDictionary = getDictionaryResult.data;\n\n if (!distantDictionary) {\n throw new Error(`Dictionary ${dictionaryKey} not found on remote`);\n }\n\n logger.updateStatus(dictionaryKey, 'distant', { status: 'imported' });\n\n return distantDictionary;\n } catch (error) {\n logger.updateStatus(dictionaryKey, 'distant', {\n status: 'error',\n error: error as Error,\n errorMessage: `${options?.logPrefix ?? ''}Error fetching dictionary ${dictionaryKey}: ${error}`,\n });\n return undefined;\n }\n };\n\n const fetchPromises = distantDictionariesKeys.map((dictionaryKey) =>\n limit(() => processDictionary(dictionaryKey))\n );\n\n const result = await Promise.all(fetchPromises);\n\n // Output any error messages\n const statuses = logger.getStatuses();\n for (const statusObj of statuses) {\n const currentState = statusObj.state.find((s) => s.type === 'distant');\n if (currentState && currentState.errorMessage) {\n console.error(currentState.errorMessage);\n }\n }\n\n // Remove undefined values\n const filteredResult = result.filter(\n (dict): dict is DictionaryAPI => dict !== undefined\n );\n\n return filteredResult;\n } catch (error) {\n console.error(error);\n return [];\n }\n};\n"],"mappings":"AAEA,SAAS,wBAAwB;AAEjC,SAAS,mBAAmB;AAC5B,OAAO,YAAY;AACnB,SAAS,cAAc;AAWhB,MAAM,2BAA2B,OACtC,YAC6B;AAC7B,MAAI;AACF,UAAM;AAAA,MACJ,QAAQ,EAAE,UAAU,aAAa;AAAA,IACnC,IAAI,iBAAiB;AAErB,QAAI,CAAC,YAAY,CAAC,cAAc;AAC9B,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,UAAM,oBAAoB,MAAM,YAAY,KAAK,qBAAqB;AAEtE,UAAM,oBAAoB,kBAAkB,MAAM;AAElD,UAAM,0BAA0B,QAAQ;AAGxC,UAAM,QAAQ,OAAO,CAAC;AAEtB,UAAM,oBAAoB,OACxB,kBACuC;AACvC,aAAO,aAAa,eAAe,WAAW,EAAE,QAAQ,WAAW,CAAC;AAEpE,UAAI;AAEF,cAAM,sBAAsB,MAAM,YAAY,WAAW;AAAA,UACvD;AAAA,UACA;AAAA,UACA;AAAA,YACE,SAAS,EAAE,eAAe,UAAU,iBAAiB,GAAG;AAAA,UAC1D;AAAA,QACF;AAEA,cAAM,oBAAoB,oBAAoB;AAE9C,YAAI,CAAC,mBAAmB;AACtB,gBAAM,IAAI,MAAM,cAAc,aAAa,sBAAsB;AAAA,QACnE;AAEA,eAAO,aAAa,eAAe,WAAW,EAAE,QAAQ,WAAW,CAAC;AAEpE,eAAO;AAAA,MACT,SAAS,OAAO;AACd,eAAO,aAAa,eAAe,WAAW;AAAA,UAC5C,QAAQ;AAAA,UACR;AAAA,UACA,cAAc,GAAG,SAAS,aAAa,EAAE,6BAA6B,aAAa,KAAK,KAAK;AAAA,QAC/F,CAAC;AACD,eAAO;AAAA,MACT;AAAA,IACF;AAEA,UAAM,gBAAgB,wBAAwB;AAAA,MAAI,CAAC,kBACjD,MAAM,MAAM,kBAAkB,aAAa,CAAC;AAAA,IAC9C;AAEA,UAAM,SAAS,MAAM,QAAQ,IAAI,aAAa;AAG9C,UAAM,WAAW,OAAO,YAAY;AACpC,eAAW,aAAa,UAAU;AAChC,YAAM,eAAe,UAAU,MAAM,KAAK,CAAC,MAAM,EAAE,SAAS,SAAS;AACrE,UAAI,gBAAgB,aAAa,cAAc;AAC7C,gBAAQ,MAAM,aAAa,YAAY;AAAA,MACzC;AAAA,IACF;AAGA,UAAM,iBAAiB,OAAO;AAAA,MAC5B,CAAC,SAAgC,SAAS;AAAA,IAC5C;AAEA,WAAO;AAAA,EACT,SAAS,OAAO;AACd,YAAQ,MAAM,KAAK;AACnB,WAAO,CAAC;AAAA,EACV;AACF;","names":[]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { getConfiguration } from "@intlayer/config";
|
|
2
|
+
import { intlayerAPI } from "@intlayer/design-system/libs";
|
|
3
|
+
const fetchDistantDictionaryKeys = async () => {
|
|
4
|
+
const {
|
|
5
|
+
editor: { clientId, clientSecret }
|
|
6
|
+
} = getConfiguration();
|
|
7
|
+
if (!clientId || !clientSecret) {
|
|
8
|
+
throw new Error(
|
|
9
|
+
"Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project."
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
const oAuth2TokenResult = await intlayerAPI.auth.getOAuth2AccessToken();
|
|
13
|
+
const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;
|
|
14
|
+
const getDictionariesKeysResult = await intlayerAPI.dictionary.getDictionariesKeys({
|
|
15
|
+
headers: { Authorization: `Bearer ${oAuth2AccessToken}` }
|
|
16
|
+
});
|
|
17
|
+
if (!getDictionariesKeysResult.data) {
|
|
18
|
+
throw new Error("No distant dictionaries found");
|
|
19
|
+
}
|
|
20
|
+
const distantDictionariesKeys = getDictionariesKeysResult.data;
|
|
21
|
+
return distantDictionariesKeys;
|
|
22
|
+
};
|
|
23
|
+
export {
|
|
24
|
+
fetchDistantDictionaryKeys
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=fetchDistantDictionaryKeys.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/fetchDistantDictionaryKeys.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config';\n// @ts-ignore @intlayer/design-system not build yet\nimport { intlayerAPI } from '@intlayer/design-system/libs';\n\nexport const fetchDistantDictionaryKeys = async (): Promise<string[]> => {\n const {\n editor: { clientId, clientSecret },\n } = getConfiguration();\n\n if (!clientId || !clientSecret) {\n throw new Error(\n 'Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project.'\n );\n }\n\n const oAuth2TokenResult = await intlayerAPI.auth.getOAuth2AccessToken();\n\n const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;\n\n // Get the list of dictionary keys\n const getDictionariesKeysResult =\n await intlayerAPI.dictionary.getDictionariesKeys({\n headers: { Authorization: `Bearer ${oAuth2AccessToken}` },\n });\n\n if (!getDictionariesKeysResult.data) {\n throw new Error('No distant dictionaries found');\n }\n\n const distantDictionariesKeys: string[] = getDictionariesKeysResult.data;\n\n // Apply any filtering if needed\n return distantDictionariesKeys;\n};\n"],"mappings":"AAAA,SAAS,wBAAwB;AAEjC,SAAS,mBAAmB;AAErB,MAAM,6BAA6B,YAA+B;AACvE,QAAM;AAAA,IACJ,QAAQ,EAAE,UAAU,aAAa;AAAA,EACnC,IAAI,iBAAiB;AAErB,MAAI,CAAC,YAAY,CAAC,cAAc;AAC9B,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,QAAM,oBAAoB,MAAM,YAAY,KAAK,qBAAqB;AAEtE,QAAM,oBAAoB,kBAAkB,MAAM;AAGlD,QAAM,4BACJ,MAAM,YAAY,WAAW,oBAAoB;AAAA,IAC/C,SAAS,EAAE,eAAe,UAAU,iBAAiB,GAAG;AAAA,EAC1D,CAAC;AAEH,MAAI,CAAC,0BAA0B,MAAM;AACnC,UAAM,IAAI,MAAM,+BAA+B;AAAA,EACjD;AAEA,QAAM,0BAAoC,0BAA0B;AAGpE,SAAO;AACT;","names":[]}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
import { watch } from './chokidar/watcher.mjs';
|
|
2
2
|
import { createDictionaryList } from './transpiler/dictionary_to_main/createDictionaryList.mjs';
|
|
3
3
|
import { createModuleAugmentation } from './transpiler/dictionary_to_type/createModuleAugmentation.mjs';
|
|
4
|
+
import { fetchDistantDictionaries } from './fetchDistantDictionaries.mjs';
|
|
5
|
+
import {
|
|
6
|
+
loadDistantDictionaries,
|
|
7
|
+
loadDictionaries,
|
|
8
|
+
loadLocalDictionaries
|
|
9
|
+
} from './loadDictionaries/index.mjs';
|
|
4
10
|
export {
|
|
5
11
|
createDictionaryList,
|
|
6
12
|
createModuleAugmentation,
|
|
13
|
+
fetchDistantDictionaries,
|
|
14
|
+
loadDictionaries,
|
|
15
|
+
loadDistantDictionaries,
|
|
16
|
+
loadLocalDictionaries,
|
|
7
17
|
watch
|
|
8
18
|
};
|
|
9
19
|
//# sourceMappingURL=index.mjs.map
|
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +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,SAAS,aAAa;AACtB,SAAS,4BAA4B;AACrC,SAAS,gCAAgC;","names":[]}
|
|
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';\nexport { fetchDistantDictionaries } from './fetchDistantDictionaries';\nexport {\n loadDistantDictionaries,\n loadDictionaries,\n loadLocalDictionaries,\n} from './loadDictionaries/index';\n"],"mappings":"AAAA,SAAS,aAAa;AACtB,SAAS,4BAA4B;AACrC,SAAS,gCAAgC;AACzC,SAAS,gCAAgC;AACzC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/loadDictionaries/index.ts"],"sourcesContent":["export * from './loadDictionaries';\nexport * from './loadDistantDictionaries';\nexport * from './loadLocalDictionaries';\nexport * from './loadContentDeclaration';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { createRequire } from "module";
|
|
2
1
|
import { runInNewContext } from "vm";
|
|
2
|
+
import { ESMxCJSRequire } from "@intlayer/config";
|
|
3
3
|
import { buildSync } from "esbuild";
|
|
4
|
-
|
|
4
|
+
import { processContentDeclaration } from '../transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.mjs';
|
|
5
5
|
const sandboxContext = {
|
|
6
6
|
exports: {
|
|
7
7
|
default: {}
|
|
@@ -10,7 +10,7 @@ const sandboxContext = {
|
|
|
10
10
|
exports: {}
|
|
11
11
|
},
|
|
12
12
|
console,
|
|
13
|
-
require:
|
|
13
|
+
require: ESMxCJSRequire
|
|
14
14
|
};
|
|
15
15
|
const transformationOption = {
|
|
16
16
|
loader: {
|
|
@@ -37,7 +37,7 @@ const loadContentDeclaration = (contentDeclarationFilePath) => {
|
|
|
37
37
|
const fileExtension = contentDeclarationFilePath.split(".").pop() ?? "";
|
|
38
38
|
try {
|
|
39
39
|
if (fileExtension === "json") {
|
|
40
|
-
return
|
|
40
|
+
return ESMxCJSRequire(contentDeclarationFilePath);
|
|
41
41
|
}
|
|
42
42
|
const moduleResult = buildSync({
|
|
43
43
|
entryPoints: [contentDeclarationFilePath],
|
|
@@ -67,7 +67,24 @@ const loadContentDeclaration = (contentDeclarationFilePath) => {
|
|
|
67
67
|
console.error("Error:", error);
|
|
68
68
|
}
|
|
69
69
|
};
|
|
70
|
+
const loadContentDeclarations = async (contentDeclarationFilePath) => {
|
|
71
|
+
const contentDeclarations = contentDeclarationFilePath.map(
|
|
72
|
+
loadContentDeclaration
|
|
73
|
+
);
|
|
74
|
+
const resultDictionariesPaths = [];
|
|
75
|
+
for await (const contentDeclaration of contentDeclarations) {
|
|
76
|
+
if (!contentDeclaration) {
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const processedContentDeclaration = await processContentDeclaration(contentDeclaration);
|
|
80
|
+
if (!processedContentDeclaration) {
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
resultDictionariesPaths.push(processedContentDeclaration);
|
|
84
|
+
}
|
|
85
|
+
return resultDictionariesPaths;
|
|
86
|
+
};
|
|
70
87
|
export {
|
|
71
|
-
|
|
88
|
+
loadContentDeclarations
|
|
72
89
|
};
|
|
73
90
|
//# sourceMappingURL=loadContentDeclaration.mjs.map
|