@intlayer/chokidar 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/cjs/chokidar/index.cjs +23 -0
- package/dist/cjs/chokidar/index.cjs.map +1 -0
- package/dist/cjs/chokidar/index.d.ts +2 -0
- package/dist/cjs/chokidar/watcher.cjs +89 -0
- package/dist/cjs/chokidar/watcher.cjs.map +1 -0
- package/dist/cjs/chokidar/watcher.d.ts +5 -0
- package/dist/cjs/index.cjs +35 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.ts +4 -0
- package/dist/cjs/transpiler/dictionary_to_main/createDictionaryList.cjs +76 -0
- package/dist/cjs/transpiler/dictionary_to_main/createDictionaryList.cjs.map +1 -0
- package/dist/cjs/transpiler/dictionary_to_main/createDictionaryList.d.ts +6 -0
- package/dist/cjs/transpiler/dictionary_to_main/index.cjs +23 -0
- package/dist/cjs/transpiler/dictionary_to_main/index.cjs.map +1 -0
- package/dist/cjs/transpiler/dictionary_to_main/index.d.ts +1 -0
- package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs +87 -0
- package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs.map +1 -0
- package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.d.ts +7 -0
- package/dist/cjs/transpiler/dictionary_to_type/createType.cjs +114 -0
- package/dist/cjs/transpiler/dictionary_to_type/createType.cjs.map +1 -0
- package/dist/cjs/transpiler/dictionary_to_type/createType.d.ts +42 -0
- package/dist/cjs/transpiler/dictionary_to_type/index.cjs +25 -0
- package/dist/cjs/transpiler/dictionary_to_type/index.cjs.map +1 -0
- package/dist/cjs/transpiler/dictionary_to_type/index.d.ts +3 -0
- package/dist/cjs/transpiler/intlater_module_to_dictionary/extractNestedJSON.cjs +45 -0
- package/dist/cjs/transpiler/intlater_module_to_dictionary/extractNestedJSON.cjs.map +1 -0
- package/dist/cjs/transpiler/intlater_module_to_dictionary/extractNestedJSON.d.ts +44 -0
- package/dist/cjs/transpiler/intlater_module_to_dictionary/index.cjs +27 -0
- package/dist/cjs/transpiler/intlater_module_to_dictionary/index.cjs.map +1 -0
- package/dist/cjs/transpiler/intlater_module_to_dictionary/index.d.ts +4 -0
- package/dist/cjs/transpiler/intlater_module_to_dictionary/loadContentDeclaration.cjs +98 -0
- package/dist/cjs/transpiler/intlater_module_to_dictionary/loadContentDeclaration.cjs.map +1 -0
- package/dist/cjs/transpiler/intlater_module_to_dictionary/loadContentDeclaration.d.ts +10 -0
- package/dist/cjs/transpiler/intlater_module_to_dictionary/processModule.cjs +69 -0
- package/dist/cjs/transpiler/intlater_module_to_dictionary/processModule.cjs.map +1 -0
- package/dist/cjs/transpiler/intlater_module_to_dictionary/processModule.d.ts +8 -0
- package/dist/cjs/transpiler/intlater_module_to_dictionary/transpileContentDeclaration.cjs +66 -0
- package/dist/cjs/transpiler/intlater_module_to_dictionary/transpileContentDeclaration.cjs.map +1 -0
- package/dist/cjs/transpiler/intlater_module_to_dictionary/transpileContentDeclaration.d.ts +6 -0
- package/dist/cjs/utils.cjs +55 -0
- package/dist/cjs/utils.cjs.map +1 -0
- package/dist/cjs/utils.d.ts +4 -0
- package/dist/esm/chokidar/index.d.mts +2 -0
- package/dist/esm/chokidar/index.mjs +2 -0
- package/dist/esm/chokidar/index.mjs.map +1 -0
- package/dist/esm/chokidar/watcher.d.mts +5 -0
- package/dist/esm/chokidar/watcher.mjs +58 -0
- package/dist/esm/chokidar/watcher.mjs.map +1 -0
- package/dist/esm/index.d.mts +4 -0
- package/dist/esm/index.mjs +9 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/transpiler/dictionary_to_main/createDictionaryList.d.mts +6 -0
- package/dist/esm/transpiler/dictionary_to_main/createDictionaryList.mjs +52 -0
- package/dist/esm/transpiler/dictionary_to_main/createDictionaryList.mjs.map +1 -0
- package/dist/esm/transpiler/dictionary_to_main/index.d.mts +1 -0
- package/dist/esm/transpiler/dictionary_to_main/index.mjs +2 -0
- package/dist/esm/transpiler/dictionary_to_main/index.mjs.map +1 -0
- package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.d.mts +7 -0
- package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs +62 -0
- package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs.map +1 -0
- package/dist/esm/transpiler/dictionary_to_type/createType.d.mts +42 -0
- package/dist/esm/transpiler/dictionary_to_type/createType.mjs +89 -0
- package/dist/esm/transpiler/dictionary_to_type/createType.mjs.map +1 -0
- package/dist/esm/transpiler/dictionary_to_type/index.d.mts +3 -0
- package/dist/esm/transpiler/dictionary_to_type/index.mjs +3 -0
- package/dist/esm/transpiler/dictionary_to_type/index.mjs.map +1 -0
- package/dist/esm/transpiler/intlater_module_to_dictionary/extractNestedJSON.d.mts +44 -0
- package/dist/esm/transpiler/intlater_module_to_dictionary/extractNestedJSON.mjs +21 -0
- package/dist/esm/transpiler/intlater_module_to_dictionary/extractNestedJSON.mjs.map +1 -0
- package/dist/esm/transpiler/intlater_module_to_dictionary/index.d.mts +4 -0
- package/dist/esm/transpiler/intlater_module_to_dictionary/index.mjs +4 -0
- package/dist/esm/transpiler/intlater_module_to_dictionary/index.mjs.map +1 -0
- package/dist/esm/transpiler/intlater_module_to_dictionary/loadContentDeclaration.d.mts +10 -0
- package/dist/esm/transpiler/intlater_module_to_dictionary/loadContentDeclaration.mjs +73 -0
- package/dist/esm/transpiler/intlater_module_to_dictionary/loadContentDeclaration.mjs.map +1 -0
- package/dist/esm/transpiler/intlater_module_to_dictionary/processModule.d.mts +8 -0
- package/dist/esm/transpiler/intlater_module_to_dictionary/processModule.mjs +45 -0
- package/dist/esm/transpiler/intlater_module_to_dictionary/processModule.mjs.map +1 -0
- package/dist/esm/transpiler/intlater_module_to_dictionary/transpileContentDeclaration.d.mts +6 -0
- package/dist/esm/transpiler/intlater_module_to_dictionary/transpileContentDeclaration.mjs +42 -0
- package/dist/esm/transpiler/intlater_module_to_dictionary/transpileContentDeclaration.mjs.map +1 -0
- package/dist/esm/utils.d.mts +4 -0
- package/dist/esm/utils.mjs +20 -0
- package/dist/esm/utils.mjs.map +1 -0
- package/package.json +85 -0
- package/src/chokidar/index.ts +1 -0
- package/src/chokidar/watcher.ts +84 -0
- package/src/index.ts +3 -0
- package/src/transpiler/dictionary_to_main/createDictionaryList.ts +65 -0
- package/src/transpiler/dictionary_to_main/index.ts +1 -0
- package/src/transpiler/dictionary_to_type/createModuleAugmentation.ts +95 -0
- package/src/transpiler/dictionary_to_type/createType.ts +145 -0
- package/src/transpiler/dictionary_to_type/index.ts +2 -0
- package/src/transpiler/intlater_module_to_dictionary/extractNestedJSON.ts +60 -0
- package/src/transpiler/intlater_module_to_dictionary/index.ts +3 -0
- package/src/transpiler/intlater_module_to_dictionary/loadContentDeclaration.ts +114 -0
- package/src/transpiler/intlater_module_to_dictionary/processModule.ts +66 -0
- package/src/transpiler/intlater_module_to_dictionary/transpileContentDeclaration.ts +62 -0
- package/src/utils.ts +26 -0
|
@@ -0,0 +1,45 @@
|
|
|
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 extractNestedJSON_exports = {};
|
|
20
|
+
__export(extractNestedJSON_exports, {
|
|
21
|
+
extractObjectsWithId: () => extractObjectsWithId
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(extractNestedJSON_exports);
|
|
24
|
+
const extractObjectsWithId = (input) => {
|
|
25
|
+
const search = (obj, results2) => {
|
|
26
|
+
if (obj && typeof obj === "object") {
|
|
27
|
+
if (Object.prototype.hasOwnProperty.call(obj, "id")) {
|
|
28
|
+
results2.push(obj);
|
|
29
|
+
}
|
|
30
|
+
for (const key of Object.keys(obj)) {
|
|
31
|
+
if (typeof obj[key] === "object") {
|
|
32
|
+
search(obj[key], results2);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
const results = [];
|
|
38
|
+
search(input, results);
|
|
39
|
+
return results;
|
|
40
|
+
};
|
|
41
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
42
|
+
0 && (module.exports = {
|
|
43
|
+
extractObjectsWithId
|
|
44
|
+
});
|
|
45
|
+
//# sourceMappingURL=extractNestedJSON.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/intlater_module_to_dictionary/extractNestedJSON.ts"],"sourcesContent":["import type { Content, ContentModule } from '@intlayer/core';\n\n/**\n *\n * This function extracts all nested objects with an 'id' field from the input object and returns them as an array\n *\n * Example:\n *\n * const input = {\n * id: '1',\n * name: 'John Doe',\n * address: {\n * id: '2',\n * street: '123 Main St',\n * city: 'Springfield',\n * state: 'IL'\n * },\n * };\n * const result = extractObjectsWithId(input);\n * console.log(result);\n *\n * Output:\n *\n * [{\n * id: '1',\n * name: 'John Doe',\n * address: {\n * id: '2',\n * street: '123 Main St',\n * city: 'Springfield',\n * state: 'IL'\n * }\n * },\n * {\n * id: '2',\n * street: '123 Main St',\n * city: 'Springfield',\n * state: 'IL'\n * }]\n *\n */\nexport const extractObjectsWithId = (input: ContentModule): ContentModule[] => {\n // Function to recursively search and extract nested objects with an 'id'\n const search = (obj: Content, results: ContentModule[]): void => {\n if (obj && typeof obj === 'object') {\n if (Object.prototype.hasOwnProperty.call(obj, 'id')) {\n results.push(obj as ContentModule);\n }\n for (const key of Object.keys(obj)) {\n if (typeof obj[key] === 'object') {\n search(obj[key] as Content, results);\n }\n }\n }\n };\n\n const results: ContentModule[] = [];\n search(input, results);\n return results;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAyCO,MAAM,uBAAuB,CAAC,UAA0C;AAE7E,QAAM,SAAS,CAAC,KAAcA,aAAmC;AAC/D,QAAI,OAAO,OAAO,QAAQ,UAAU;AAClC,UAAI,OAAO,UAAU,eAAe,KAAK,KAAK,IAAI,GAAG;AACnD,QAAAA,SAAQ,KAAK,GAAoB;AAAA,MACnC;AACA,iBAAW,OAAO,OAAO,KAAK,GAAG,GAAG;AAClC,YAAI,OAAO,IAAI,GAAG,MAAM,UAAU;AAChC,iBAAO,IAAI,GAAG,GAAcA,QAAO;AAAA,QACrC;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,QAAM,UAA2B,CAAC;AAClC,SAAO,OAAO,OAAO;AACrB,SAAO;AACT;","names":["results"]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ContentModule } from '@intlayer/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* This function extracts all nested objects with an 'id' field from the input object and returns them as an array
|
|
6
|
+
*
|
|
7
|
+
* Example:
|
|
8
|
+
*
|
|
9
|
+
* const input = {
|
|
10
|
+
* id: '1',
|
|
11
|
+
* name: 'John Doe',
|
|
12
|
+
* address: {
|
|
13
|
+
* id: '2',
|
|
14
|
+
* street: '123 Main St',
|
|
15
|
+
* city: 'Springfield',
|
|
16
|
+
* state: 'IL'
|
|
17
|
+
* },
|
|
18
|
+
* };
|
|
19
|
+
* const result = extractObjectsWithId(input);
|
|
20
|
+
* console.log(result);
|
|
21
|
+
*
|
|
22
|
+
* Output:
|
|
23
|
+
*
|
|
24
|
+
* [{
|
|
25
|
+
* id: '1',
|
|
26
|
+
* name: 'John Doe',
|
|
27
|
+
* address: {
|
|
28
|
+
* id: '2',
|
|
29
|
+
* street: '123 Main St',
|
|
30
|
+
* city: 'Springfield',
|
|
31
|
+
* state: 'IL'
|
|
32
|
+
* }
|
|
33
|
+
* },
|
|
34
|
+
* {
|
|
35
|
+
* id: '2',
|
|
36
|
+
* street: '123 Main St',
|
|
37
|
+
* city: 'Springfield',
|
|
38
|
+
* state: 'IL'
|
|
39
|
+
* }]
|
|
40
|
+
*
|
|
41
|
+
*/
|
|
42
|
+
declare const extractObjectsWithId: (input: ContentModule) => ContentModule[];
|
|
43
|
+
|
|
44
|
+
export { extractObjectsWithId };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var intlater_module_to_dictionary_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(intlater_module_to_dictionary_exports);
|
|
18
|
+
__reExport(intlater_module_to_dictionary_exports, require('./extractNestedJSON.cjs'), module.exports);
|
|
19
|
+
__reExport(intlater_module_to_dictionary_exports, require('./processModule.cjs'), module.exports);
|
|
20
|
+
__reExport(intlater_module_to_dictionary_exports, require('./transpileContentDeclaration.cjs'), module.exports);
|
|
21
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
22
|
+
0 && (module.exports = {
|
|
23
|
+
...require('./extractNestedJSON.cjs'),
|
|
24
|
+
...require('./processModule.cjs'),
|
|
25
|
+
...require('./transpileContentDeclaration.cjs')
|
|
26
|
+
});
|
|
27
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/intlater_module_to_dictionary/index.ts"],"sourcesContent":["export * from './extractNestedJSON';\nexport * from './processModule';\nexport * from './transpileContentDeclaration';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,kDAAc,gCAAd;AACA,kDAAc,4BADd;AAEA,kDAAc,0CAFd;","names":[]}
|
|
@@ -0,0 +1,98 @@
|
|
|
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 loadContentDeclaration_exports = {};
|
|
20
|
+
__export(loadContentDeclaration_exports, {
|
|
21
|
+
loadContentDeclaration: () => loadContentDeclaration
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(loadContentDeclaration_exports);
|
|
24
|
+
var import_module = require("module");
|
|
25
|
+
var import_vm = require("vm");
|
|
26
|
+
var import_esbuild = require("esbuild");
|
|
27
|
+
const import_meta = {};
|
|
28
|
+
const isESModule = typeof import_meta.url === "string";
|
|
29
|
+
const sandboxContext = {
|
|
30
|
+
exports: {
|
|
31
|
+
default: {}
|
|
32
|
+
},
|
|
33
|
+
module: {
|
|
34
|
+
exports: {}
|
|
35
|
+
},
|
|
36
|
+
console,
|
|
37
|
+
require: isESModule ? (0, import_module.createRequire)(import_meta.url) : require
|
|
38
|
+
};
|
|
39
|
+
const transformationOption = {
|
|
40
|
+
loader: {
|
|
41
|
+
".js": "js",
|
|
42
|
+
".jsx": "jsx",
|
|
43
|
+
".mjs": "js",
|
|
44
|
+
".ts": "ts",
|
|
45
|
+
".tsx": "tsx",
|
|
46
|
+
".cjs": "js",
|
|
47
|
+
".json": "json"
|
|
48
|
+
},
|
|
49
|
+
format: "cjs",
|
|
50
|
+
// Output format as commonjs
|
|
51
|
+
target: "es2017",
|
|
52
|
+
packages: "external",
|
|
53
|
+
write: false,
|
|
54
|
+
bundle: true
|
|
55
|
+
};
|
|
56
|
+
const filterValidContentDeclaration = (contentDeclaration) => {
|
|
57
|
+
return contentDeclaration;
|
|
58
|
+
};
|
|
59
|
+
const loadContentDeclaration = (contentDeclarationFilePath) => {
|
|
60
|
+
let contentDeclaration = void 0;
|
|
61
|
+
const fileExtension = contentDeclarationFilePath.split(".").pop() ?? "";
|
|
62
|
+
try {
|
|
63
|
+
if (fileExtension === "json") {
|
|
64
|
+
return require(contentDeclarationFilePath);
|
|
65
|
+
}
|
|
66
|
+
const moduleResult = (0, import_esbuild.buildSync)({
|
|
67
|
+
entryPoints: [contentDeclarationFilePath],
|
|
68
|
+
...transformationOption
|
|
69
|
+
});
|
|
70
|
+
const moduleResultString = moduleResult.outputFiles?.[0].text;
|
|
71
|
+
if (!moduleResultString) {
|
|
72
|
+
console.error("Configuration file could not be loaded.");
|
|
73
|
+
return void 0;
|
|
74
|
+
}
|
|
75
|
+
(0, import_vm.runInNewContext)(moduleResultString, sandboxContext);
|
|
76
|
+
if (sandboxContext.exports.default && Object.keys(sandboxContext.exports.default).length > 0) {
|
|
77
|
+
contentDeclaration = sandboxContext.exports.default;
|
|
78
|
+
} else if (sandboxContext.module.exports.defaults && Object.keys(sandboxContext.module.exports.defaults).length > 0) {
|
|
79
|
+
contentDeclaration = sandboxContext.module.exports.default;
|
|
80
|
+
} else if (sandboxContext.module.exports.default && Object.keys(sandboxContext.module.exports.default).length > 0) {
|
|
81
|
+
contentDeclaration = sandboxContext.module.exports.default;
|
|
82
|
+
} else if (sandboxContext.module.exports && Object.keys(sandboxContext.module.exports).length > 0) {
|
|
83
|
+
contentDeclaration = sandboxContext.module.exports;
|
|
84
|
+
}
|
|
85
|
+
if (typeof contentDeclaration === "undefined") {
|
|
86
|
+
console.error("Configuration file could not be loaded.");
|
|
87
|
+
return void 0;
|
|
88
|
+
}
|
|
89
|
+
return filterValidContentDeclaration(contentDeclaration);
|
|
90
|
+
} catch (error) {
|
|
91
|
+
console.error("Error:", error);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
95
|
+
0 && (module.exports = {
|
|
96
|
+
loadContentDeclaration
|
|
97
|
+
});
|
|
98
|
+
//# sourceMappingURL=loadContentDeclaration.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/intlater_module_to_dictionary/loadContentDeclaration.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-var-requires */\nimport { createRequire } from 'module';\nimport { type Context, runInNewContext } from 'vm';\nimport type { ContentModule } from '@intlayer/core';\nimport { type BuildOptions, buildSync, type BuildResult } from 'esbuild';\n\nconst isESModule = typeof import.meta.url === 'string';\n\nconst sandboxContext: Context = {\n exports: {\n default: {},\n },\n module: {\n exports: {},\n },\n console,\n require: isESModule ? createRequire(import.meta.url) : require,\n};\n\nconst transformationOption: BuildOptions = {\n loader: {\n '.js': 'js',\n '.jsx': 'jsx',\n '.mjs': 'js',\n '.ts': 'ts',\n '.tsx': 'tsx',\n '.cjs': 'js',\n '.json': 'json',\n },\n format: 'cjs', // Output format as commonjs\n target: 'es2017',\n packages: 'external',\n write: false,\n bundle: true,\n};\n\nconst filterValidContentDeclaration = (\n contentDeclaration: ContentModule\n): ContentModule => {\n // @TODO Implement filtering of valid content declaration\n return contentDeclaration;\n};\n\n/**\n * Load the content declaration from the given path\n *\n * Accepts JSON, JS, MJS and TS files as configuration\n */\nexport const loadContentDeclaration = (\n contentDeclarationFilePath: string\n): ContentModule | undefined => {\n let contentDeclaration: ContentModule | undefined = undefined;\n\n const fileExtension = contentDeclarationFilePath.split('.').pop() ?? '';\n\n try {\n if (fileExtension === 'json') {\n // Assume JSON\n return require(contentDeclarationFilePath);\n }\n\n // Rest is JS, MJS or TS\n\n const moduleResult: BuildResult = buildSync({\n entryPoints: [contentDeclarationFilePath],\n\n ...transformationOption,\n });\n\n const moduleResultString = moduleResult.outputFiles?.[0].text;\n\n if (!moduleResultString) {\n console.error('Configuration file could not be loaded.');\n return undefined;\n }\n\n runInNewContext(moduleResultString, sandboxContext);\n\n if (\n sandboxContext.exports.default &&\n Object.keys(sandboxContext.exports.default).length > 0\n ) {\n // ES Module\n contentDeclaration = sandboxContext.exports.default;\n } else if (\n sandboxContext.module.exports.defaults &&\n Object.keys(sandboxContext.module.exports.defaults).length > 0\n ) {\n // CommonJS\n contentDeclaration = sandboxContext.module.exports.default;\n } else if (\n sandboxContext.module.exports.default &&\n Object.keys(sandboxContext.module.exports.default).length > 0\n ) {\n // ES Module\n contentDeclaration = sandboxContext.module.exports.default;\n } else if (\n sandboxContext.module.exports &&\n Object.keys(sandboxContext.module.exports).length > 0\n ) {\n // Other\n contentDeclaration = sandboxContext.module.exports;\n }\n\n if (typeof contentDeclaration === 'undefined') {\n console.error('Configuration file could not be loaded.');\n return undefined;\n }\n\n return filterValidContentDeclaration(contentDeclaration);\n } catch (error) {\n console.error('Error:', error);\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAA8B;AAC9B,gBAA8C;AAE9C,qBAA+D;AAJ/D;AAMA,MAAM,aAAa,OAAO,YAAY,QAAQ;AAE9C,MAAM,iBAA0B;AAAA,EAC9B,SAAS;AAAA,IACP,SAAS,CAAC;AAAA,EACZ;AAAA,EACA,QAAQ;AAAA,IACN,SAAS,CAAC;AAAA,EACZ;AAAA,EACA;AAAA,EACA,SAAS,iBAAa,6BAAc,YAAY,GAAG,IAAI;AACzD;AAEA,MAAM,uBAAqC;AAAA,EACzC,QAAQ;AAAA,IACN,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,SAAS;AAAA,EACX;AAAA,EACA,QAAQ;AAAA;AAAA,EACR,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,OAAO;AAAA,EACP,QAAQ;AACV;AAEA,MAAM,gCAAgC,CACpC,uBACkB;AAElB,SAAO;AACT;AAOO,MAAM,yBAAyB,CACpC,+BAC8B;AAC9B,MAAI,qBAAgD;AAEpD,QAAM,gBAAgB,2BAA2B,MAAM,GAAG,EAAE,IAAI,KAAK;AAErE,MAAI;AACF,QAAI,kBAAkB,QAAQ;AAE5B,aAAO,QAAQ,0BAA0B;AAAA,IAC3C;AAIA,UAAM,mBAA4B,0BAAU;AAAA,MAC1C,aAAa,CAAC,0BAA0B;AAAA,MAExC,GAAG;AAAA,IACL,CAAC;AAED,UAAM,qBAAqB,aAAa,cAAc,CAAC,EAAE;AAEzD,QAAI,CAAC,oBAAoB;AACvB,cAAQ,MAAM,yCAAyC;AACvD,aAAO;AAAA,IACT;AAEA,mCAAgB,oBAAoB,cAAc;AAElD,QACE,eAAe,QAAQ,WACvB,OAAO,KAAK,eAAe,QAAQ,OAAO,EAAE,SAAS,GACrD;AAEA,2BAAqB,eAAe,QAAQ;AAAA,IAC9C,WACE,eAAe,OAAO,QAAQ,YAC9B,OAAO,KAAK,eAAe,OAAO,QAAQ,QAAQ,EAAE,SAAS,GAC7D;AAEA,2BAAqB,eAAe,OAAO,QAAQ;AAAA,IACrD,WACE,eAAe,OAAO,QAAQ,WAC9B,OAAO,KAAK,eAAe,OAAO,QAAQ,OAAO,EAAE,SAAS,GAC5D;AAEA,2BAAqB,eAAe,OAAO,QAAQ;AAAA,IACrD,WACE,eAAe,OAAO,WACtB,OAAO,KAAK,eAAe,OAAO,OAAO,EAAE,SAAS,GACpD;AAEA,2BAAqB,eAAe,OAAO;AAAA,IAC7C;AAEA,QAAI,OAAO,uBAAuB,aAAa;AAC7C,cAAQ,MAAM,yCAAyC;AACvD,aAAO;AAAA,IACT;AAEA,WAAO,8BAA8B,kBAAkB;AAAA,EACzD,SAAS,OAAO;AACd,YAAQ,MAAM,UAAU,KAAK;AAAA,EAC/B;AACF;","names":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ContentModule } from '@intlayer/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Load the content declaration from the given path
|
|
5
|
+
*
|
|
6
|
+
* Accepts JSON, JS, MJS and TS files as configuration
|
|
7
|
+
*/
|
|
8
|
+
declare const loadContentDeclaration: (contentDeclarationFilePath: string) => ContentModule | undefined;
|
|
9
|
+
|
|
10
|
+
export { loadContentDeclaration };
|
|
@@ -0,0 +1,69 @@
|
|
|
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 processModule_exports = {};
|
|
20
|
+
__export(processModule_exports, {
|
|
21
|
+
processContentDeclaration: () => processContentDeclaration
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(processModule_exports);
|
|
24
|
+
var import_path = require("path");
|
|
25
|
+
var import_loadContentDeclaration = require('./loadContentDeclaration.cjs');
|
|
26
|
+
const processFunctionResults = async (entry) => {
|
|
27
|
+
if (entry && typeof entry === "object") {
|
|
28
|
+
const promises = [];
|
|
29
|
+
const result = {};
|
|
30
|
+
for (const key of Object.keys(entry)) {
|
|
31
|
+
const field = entry?.[key];
|
|
32
|
+
if (typeof field === "object") {
|
|
33
|
+
result[key] = await processFunctionResults(
|
|
34
|
+
field
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
if (typeof field === "function") {
|
|
38
|
+
const promise = (async () => {
|
|
39
|
+
const value = await field();
|
|
40
|
+
result[key] = value;
|
|
41
|
+
})();
|
|
42
|
+
promises.push(promise);
|
|
43
|
+
} else {
|
|
44
|
+
result[key] = field;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
await Promise.all(promises);
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
return entry;
|
|
51
|
+
};
|
|
52
|
+
const processContentDeclaration = async (file) => {
|
|
53
|
+
try {
|
|
54
|
+
const functionPath = (0, import_path.resolve)(file);
|
|
55
|
+
const entry = (0, import_loadContentDeclaration.loadContentDeclaration)(functionPath);
|
|
56
|
+
if (!entry) {
|
|
57
|
+
console.error("No entry found in module:", functionPath);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
return await processFunctionResults(entry);
|
|
61
|
+
} catch (error) {
|
|
62
|
+
console.error("Error processing module:", error);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
66
|
+
0 && (module.exports = {
|
|
67
|
+
processContentDeclaration
|
|
68
|
+
});
|
|
69
|
+
//# sourceMappingURL=processModule.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/intlater_module_to_dictionary/processModule.ts"],"sourcesContent":["import { resolve } from 'path';\nimport type {\n Content,\n ContentModule,\n FlatContent,\n FlatContentValue,\n} from '@intlayer/core';\nimport { loadContentDeclaration } from './loadContentDeclaration';\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\n if (typeof field === 'object') {\n result[key] = (await processFunctionResults(\n field as Content\n )) as FlatContentValue;\n }\n\n 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 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;\n};\n\n/**\n * Function to load, process the module and return the Intlayer ContentModule from the module file\n */\nexport const processContentDeclaration = async (file: string) => {\n try {\n const functionPath = resolve(file);\n const entry = loadContentDeclaration(functionPath);\n\n if (!entry) {\n console.error('No entry found in module:', functionPath);\n return;\n }\n\n return (await processFunctionResults(entry)) as ContentModule;\n } catch (error) {\n console.error('Error processing module:', error);\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAwB;AAOxB,oCAAuC;AAKvC,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;AAEzB,UAAI,OAAO,UAAU,UAAU;AAC7B,eAAO,GAAG,IAAK,MAAM;AAAA,UACnB;AAAA,QACF;AAAA,MACF;AAEA,UAAI,OAAO,UAAU,YAAY;AAE/B,cAAM,WAAW,YAAY;AAE3B,gBAAM,QAAQ,MAAM,MAAM;AAC1B,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,OAAO,SAAiB;AAC/D,MAAI;AACF,UAAM,mBAAe,qBAAQ,IAAI;AACjC,UAAM,YAAQ,sDAAuB,YAAY;AAEjD,QAAI,CAAC,OAAO;AACV,cAAQ,MAAM,6BAA6B,YAAY;AACvD;AAAA,IACF;AAEA,WAAQ,MAAM,uBAAuB,KAAK;AAAA,EAC5C,SAAS,OAAO;AACd,YAAQ,MAAM,4BAA4B,KAAK;AAAA,EACjD;AACF;","names":[]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ContentModule } from '@intlayer/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Function to load, process the module and return the Intlayer ContentModule from the module file
|
|
5
|
+
*/
|
|
6
|
+
declare const processContentDeclaration: (file: string) => Promise<ContentModule | undefined>;
|
|
7
|
+
|
|
8
|
+
export { processContentDeclaration };
|
|
@@ -0,0 +1,66 @@
|
|
|
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 transpileContentDeclaration_exports = {};
|
|
20
|
+
__export(transpileContentDeclaration_exports, {
|
|
21
|
+
transpileContentDeclaration: () => transpileContentDeclaration
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(transpileContentDeclaration_exports);
|
|
24
|
+
var import_promises = require("fs/promises");
|
|
25
|
+
var import_path = require("path");
|
|
26
|
+
var import_config = require("@intlayer/config");
|
|
27
|
+
var import_extractNestedJSON = require('./extractNestedJSON.cjs');
|
|
28
|
+
var import_processModule = require('./processModule.cjs');
|
|
29
|
+
const { content } = (0, import_config.getConfiguration)();
|
|
30
|
+
const { dictionariesDir } = content;
|
|
31
|
+
const buildDictionary = async (dictionaries) => {
|
|
32
|
+
const resultDictionariesPaths = [];
|
|
33
|
+
for await (const content2 of dictionaries) {
|
|
34
|
+
const contentString = JSON.stringify(content2);
|
|
35
|
+
const id = content2.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 transpileContentDeclaration = async (contentDeclarationsPaths) => {
|
|
46
|
+
const resultDictionariesPaths = [];
|
|
47
|
+
if (typeof contentDeclarationsPaths === "string") {
|
|
48
|
+
contentDeclarationsPaths = [contentDeclarationsPaths];
|
|
49
|
+
}
|
|
50
|
+
await (0, import_promises.mkdir)((0, import_path.resolve)(dictionariesDir), { recursive: true });
|
|
51
|
+
for await (const contentDeclarationPath of contentDeclarationsPaths) {
|
|
52
|
+
const result = await (0, import_processModule.processContentDeclaration)(contentDeclarationPath);
|
|
53
|
+
if (!result) {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
const nestedContent = (0, import_extractNestedJSON.extractObjectsWithId)(result);
|
|
57
|
+
const dictionariesPaths = await buildDictionary(nestedContent);
|
|
58
|
+
resultDictionariesPaths.push(...dictionariesPaths);
|
|
59
|
+
}
|
|
60
|
+
return resultDictionariesPaths;
|
|
61
|
+
};
|
|
62
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
63
|
+
0 && (module.exports = {
|
|
64
|
+
transpileContentDeclaration
|
|
65
|
+
});
|
|
66
|
+
//# sourceMappingURL=transpileContentDeclaration.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/intlater_module_to_dictionary/transpileContentDeclaration.ts"],"sourcesContent":["import { mkdir, writeFile } from 'fs/promises';\nimport { resolve } from 'path';\nimport { getConfiguration } from '@intlayer/config';\nimport type { ContentModule } from '@intlayer/core';\nimport { extractObjectsWithId } from './extractNestedJSON';\nimport { processContentDeclaration } from './processModule';\n\nconst { content } = getConfiguration();\nconst { dictionariesDir } = content;\n\nconst buildDictionary = async (dictionaries: ContentModule[]) => {\n const resultDictionariesPaths: string[] = [];\n\n for await (const content of dictionaries) {\n const contentString = JSON.stringify(content);\n\n const id = content.id;\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\n/**\n * This function transpile the bundled code to to make dictionaries as JSON files\n */\nexport const transpileContentDeclaration = async (\n contentDeclarationsPaths: string[] | string\n) => {\n const resultDictionariesPaths: string[] = [];\n\n if (typeof contentDeclarationsPaths === 'string') {\n contentDeclarationsPaths = [contentDeclarationsPaths];\n }\n\n // Create the dictionaries folder if it doesn't exist\n await mkdir(resolve(dictionariesDir), { recursive: true });\n\n for await (const contentDeclarationPath of contentDeclarationsPaths) {\n const result = await processContentDeclaration(contentDeclarationPath);\n\n if (!result) {\n continue;\n }\n\n const nestedContent: ContentModule[] = extractObjectsWithId(result);\n\n const dictionariesPaths: string[] = await buildDictionary(nestedContent);\n\n resultDictionariesPaths.push(...dictionariesPaths);\n }\n\n return resultDictionariesPaths;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAiC;AACjC,kBAAwB;AACxB,oBAAiC;AAEjC,+BAAqC;AACrC,2BAA0C;AAE1C,MAAM,EAAE,QAAQ,QAAI,gCAAiB;AACrC,MAAM,EAAE,gBAAgB,IAAI;AAE5B,MAAM,kBAAkB,OAAO,iBAAkC;AAC/D,QAAM,0BAAoC,CAAC;AAE3C,mBAAiBA,YAAW,cAAc;AACxC,UAAM,gBAAgB,KAAK,UAAUA,QAAO;AAE5C,UAAM,KAAKA,SAAQ;AACnB,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;AAKO,MAAM,8BAA8B,OACzC,6BACG;AACH,QAAM,0BAAoC,CAAC;AAE3C,MAAI,OAAO,6BAA6B,UAAU;AAChD,+BAA2B,CAAC,wBAAwB;AAAA,EACtD;AAGA,YAAM,2BAAM,qBAAQ,eAAe,GAAG,EAAE,WAAW,KAAK,CAAC;AAEzD,mBAAiB,0BAA0B,0BAA0B;AACnE,UAAM,SAAS,UAAM,gDAA0B,sBAAsB;AAErE,QAAI,CAAC,QAAQ;AACX;AAAA,IACF;AAEA,UAAM,oBAAiC,+CAAqB,MAAM;AAElE,UAAM,oBAA8B,MAAM,gBAAgB,aAAa;AAEvE,4BAAwB,KAAK,GAAG,iBAAiB;AAAA,EACnD;AAEA,SAAO;AACT;","names":["content"]}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var utils_exports = {};
|
|
30
|
+
__export(utils_exports, {
|
|
31
|
+
getFileHash: () => getFileHash,
|
|
32
|
+
transformToCamelCase: () => transformToCamelCase
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(utils_exports);
|
|
35
|
+
var import_crypto_js = __toESM(require("crypto-js"));
|
|
36
|
+
const getFileHash = (filePath) => {
|
|
37
|
+
const hash = import_crypto_js.default.SHA3(filePath);
|
|
38
|
+
return hash.toString(import_crypto_js.default.enc.Base64).replace(/[^A-Z\d]/gi, "").substring(0, 20);
|
|
39
|
+
};
|
|
40
|
+
const transformToCamelCase = (string) => {
|
|
41
|
+
const words = string.split(/[\s\-_]+/);
|
|
42
|
+
const camelCasedWords = words.map((word, index) => {
|
|
43
|
+
if (index === 0) {
|
|
44
|
+
return word[0].toUpperCase() + word.slice(1);
|
|
45
|
+
}
|
|
46
|
+
return word.charAt(0).toUpperCase() + word.slice(1);
|
|
47
|
+
});
|
|
48
|
+
return camelCasedWords.join("");
|
|
49
|
+
};
|
|
50
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
51
|
+
0 && (module.exports = {
|
|
52
|
+
getFileHash,
|
|
53
|
+
transformToCamelCase
|
|
54
|
+
});
|
|
55
|
+
//# sourceMappingURL=utils.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils.ts"],"sourcesContent":["import crypto from 'crypto-js';\n\nexport const getFileHash = (filePath: string) => {\n const hash = crypto.SHA3(filePath);\n\n return hash\n .toString(crypto.enc.Base64)\n .replace(/[^A-Z\\d]/gi, '')\n .substring(0, 20);\n};\n\nexport const transformToCamelCase = (string: string): string => {\n // Split the string into words using a regex that finds spaces, hyphens, and underscores\n const words = string.split(/[\\s\\-_]+/);\n\n // Transform each word except the first to have its first letter uppercase\n const camelCasedWords = words.map((word, index) => {\n if (index === 0) {\n return word[0].toUpperCase() + word.slice(1);\n }\n return word.charAt(0).toUpperCase() + word.slice(1);\n });\n\n // Join the words back together\n return camelCasedWords.join('');\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAmB;AAEZ,MAAM,cAAc,CAAC,aAAqB;AAC/C,QAAM,OAAO,iBAAAA,QAAO,KAAK,QAAQ;AAEjC,SAAO,KACJ,SAAS,iBAAAA,QAAO,IAAI,MAAM,EAC1B,QAAQ,cAAc,EAAE,EACxB,UAAU,GAAG,EAAE;AACpB;AAEO,MAAM,uBAAuB,CAAC,WAA2B;AAE9D,QAAM,QAAQ,OAAO,MAAM,UAAU;AAGrC,QAAM,kBAAkB,MAAM,IAAI,CAAC,MAAM,UAAU;AACjD,QAAI,UAAU,GAAG;AACf,aAAO,KAAK,CAAC,EAAE,YAAY,IAAI,KAAK,MAAM,CAAC;AAAA,IAC7C;AACA,WAAO,KAAK,OAAO,CAAC,EAAE,YAAY,IAAI,KAAK,MAAM,CAAC;AAAA,EACpD,CAAC;AAGD,SAAO,gBAAgB,KAAK,EAAE;AAChC;","names":["crypto"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/chokidar/index.ts"],"sourcesContent":["export * from './watcher';\n"],"mappings":"AAAA,cAAc;","names":[]}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { relative } from "path";
|
|
2
|
+
import { getConfiguration } from "@intlayer/config";
|
|
3
|
+
import chokidar from "chokidar";
|
|
4
|
+
import { sync } from "glob";
|
|
5
|
+
import { createDictionaryList } from '../transpiler/dictionary_to_main/createDictionaryList.mjs';
|
|
6
|
+
import {
|
|
7
|
+
createTypes,
|
|
8
|
+
createModuleAugmentation
|
|
9
|
+
} from '../transpiler/dictionary_to_type/index.mjs';
|
|
10
|
+
import { transpileContentDeclaration } from '../transpiler/intlater_module_to_dictionary/transpileContentDeclaration.mjs';
|
|
11
|
+
const watch = (options) => {
|
|
12
|
+
const { content } = getConfiguration({
|
|
13
|
+
verbose: true
|
|
14
|
+
});
|
|
15
|
+
const { watchedFilesPatternWithPath, baseDir } = content;
|
|
16
|
+
const files = sync(watchedFilesPatternWithPath);
|
|
17
|
+
return chokidar.watch(watchedFilesPatternWithPath, {
|
|
18
|
+
persistent: true,
|
|
19
|
+
// Make the watcher persistent
|
|
20
|
+
ignoreInitial: true,
|
|
21
|
+
// Process existing files
|
|
22
|
+
...options
|
|
23
|
+
}).on("ready", async () => {
|
|
24
|
+
const dictionariesPaths = await transpileContentDeclaration(files);
|
|
25
|
+
console.info("Building Intlayer types...");
|
|
26
|
+
createTypes(dictionariesPaths);
|
|
27
|
+
console.info("Building Intlayer module augmentation...");
|
|
28
|
+
createModuleAugmentation();
|
|
29
|
+
console.info("Building Intlayer dictionary list...");
|
|
30
|
+
createDictionaryList();
|
|
31
|
+
const relativeDictionariesPath = dictionariesPaths.map(
|
|
32
|
+
(dictionary) => relative(baseDir, dictionary)
|
|
33
|
+
);
|
|
34
|
+
console.info("Dictionaries:", relativeDictionariesPath);
|
|
35
|
+
}).on("unlink", (filePath) => {
|
|
36
|
+
console.info("Removed file detected: ", relative(baseDir, filePath));
|
|
37
|
+
}).on("add", async (filePath) => {
|
|
38
|
+
console.info("Additional file detected: ", relative(baseDir, filePath));
|
|
39
|
+
const dictionaries = await transpileContentDeclaration(filePath);
|
|
40
|
+
console.info("Building TypeScript types...");
|
|
41
|
+
createTypes(dictionaries);
|
|
42
|
+
console.info("Building type index...");
|
|
43
|
+
createModuleAugmentation();
|
|
44
|
+
console.info("Building main...");
|
|
45
|
+
createDictionaryList();
|
|
46
|
+
}).on("change", async (filePath) => {
|
|
47
|
+
console.info("Change detected: ", relative(baseDir, filePath));
|
|
48
|
+
const dictionaries = await transpileContentDeclaration(filePath);
|
|
49
|
+
console.info("Building TypeScript types...");
|
|
50
|
+
createTypes(dictionaries);
|
|
51
|
+
}).on("error", (error) => {
|
|
52
|
+
console.error("Watcher error:", error);
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
export {
|
|
56
|
+
watch
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=watcher.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/chokidar/watcher.ts"],"sourcesContent":["import { relative } from 'path';\nimport { getConfiguration } from '@intlayer/config';\nimport chokidar, { type WatchOptions } from 'chokidar';\nimport { sync } from 'glob';\nimport { createDictionaryList } from '../transpiler/dictionary_to_main/createDictionaryList';\nimport {\n createTypes,\n createModuleAugmentation,\n} from '../transpiler/dictionary_to_type/index';\nimport { transpileContentDeclaration } from '../transpiler/intlater_module_to_dictionary/transpileContentDeclaration';\n\n// Initialize chokidar watcher (non-persistent)\nexport const watch = (options?: WatchOptions) => {\n const { content } = getConfiguration({\n verbose: true,\n });\n const { watchedFilesPatternWithPath, baseDir } = content;\n\n const files: string[] = sync(watchedFilesPatternWithPath);\n\n return chokidar\n .watch(watchedFilesPatternWithPath, {\n persistent: true, // Make the watcher persistent\n ignoreInitial: true, // Process existing files\n ...options,\n })\n .on('ready', async () => {\n const dictionariesPaths = await transpileContentDeclaration(files);\n\n console.info('Building Intlayer types...');\n createTypes(dictionariesPaths);\n\n console.info('Building Intlayer module augmentation...');\n createModuleAugmentation();\n\n console.info('Building Intlayer dictionary list...');\n createDictionaryList();\n\n const relativeDictionariesPath = dictionariesPaths.map((dictionary) =>\n relative(baseDir, dictionary)\n );\n\n console.info('Dictionaries:', relativeDictionariesPath);\n })\n .on('unlink', (filePath) => {\n // Process the file with the functionToRun\n console.info('Removed file detected: ', relative(baseDir, filePath));\n // await transpileContentDeclaration(filePath);\n\n // console.info('Building TypeScript types...');\n // createTypes([filePath]);\n\n // console.info('Building type index...');\n // createModuleAugmentation();\n\n // console.info('Building main...');\n // createDictionaryList();\n })\n .on('add', async (filePath) => {\n // Process the file with the functionToRun\n console.info('Additional file detected: ', relative(baseDir, filePath));\n const dictionaries = await transpileContentDeclaration(filePath);\n\n console.info('Building TypeScript types...');\n createTypes(dictionaries);\n\n console.info('Building type index...');\n createModuleAugmentation();\n\n console.info('Building main...');\n createDictionaryList();\n })\n .on('change', async (filePath) => {\n // Process the file with the functionToRun\n console.info('Change detected: ', relative(baseDir, filePath));\n const dictionaries = await transpileContentDeclaration(filePath);\n\n console.info('Building TypeScript types...');\n createTypes(dictionaries);\n })\n .on('error', (error) => {\n console.error('Watcher error:', error);\n });\n};\n"],"mappings":"AAAA,SAAS,gBAAgB;AACzB,SAAS,wBAAwB;AACjC,OAAO,cAAqC;AAC5C,SAAS,YAAY;AACrB,SAAS,4BAA4B;AACrC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,mCAAmC;AAGrC,MAAM,QAAQ,CAAC,YAA2B;AAC/C,QAAM,EAAE,QAAQ,IAAI,iBAAiB;AAAA,IACnC,SAAS;AAAA,EACX,CAAC;AACD,QAAM,EAAE,6BAA6B,QAAQ,IAAI;AAEjD,QAAM,QAAkB,KAAK,2BAA2B;AAExD,SAAO,SACJ,MAAM,6BAA6B;AAAA,IAClC,YAAY;AAAA;AAAA,IACZ,eAAe;AAAA;AAAA,IACf,GAAG;AAAA,EACL,CAAC,EACA,GAAG,SAAS,YAAY;AACvB,UAAM,oBAAoB,MAAM,4BAA4B,KAAK;AAEjE,YAAQ,KAAK,4BAA4B;AACzC,gBAAY,iBAAiB;AAE7B,YAAQ,KAAK,0CAA0C;AACvD,6BAAyB;AAEzB,YAAQ,KAAK,sCAAsC;AACnD,yBAAqB;AAErB,UAAM,2BAA2B,kBAAkB;AAAA,MAAI,CAAC,eACtD,SAAS,SAAS,UAAU;AAAA,IAC9B;AAEA,YAAQ,KAAK,iBAAiB,wBAAwB;AAAA,EACxD,CAAC,EACA,GAAG,UAAU,CAAC,aAAa;AAE1B,YAAQ,KAAK,2BAA2B,SAAS,SAAS,QAAQ,CAAC;AAAA,EAWrE,CAAC,EACA,GAAG,OAAO,OAAO,aAAa;AAE7B,YAAQ,KAAK,8BAA8B,SAAS,SAAS,QAAQ,CAAC;AACtE,UAAM,eAAe,MAAM,4BAA4B,QAAQ;AAE/D,YAAQ,KAAK,8BAA8B;AAC3C,gBAAY,YAAY;AAExB,YAAQ,KAAK,wBAAwB;AACrC,6BAAyB;AAEzB,YAAQ,KAAK,kBAAkB;AAC/B,yBAAqB;AAAA,EACvB,CAAC,EACA,GAAG,UAAU,OAAO,aAAa;AAEhC,YAAQ,KAAK,qBAAqB,SAAS,SAAS,QAAQ,CAAC;AAC7D,UAAM,eAAe,MAAM,4BAA4B,QAAQ;AAE/D,YAAQ,KAAK,8BAA8B;AAC3C,gBAAY,YAAY;AAAA,EAC1B,CAAC,EACA,GAAG,SAAS,CAAC,UAAU;AACtB,YAAQ,MAAM,kBAAkB,KAAK;AAAA,EACvC,CAAC;AACL;","names":[]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { watch } from './chokidar/watcher.mjs';
|
|
2
|
+
export { createDictionaryList } from './transpiler/dictionary_to_main/createDictionaryList.mjs';
|
|
3
|
+
export { createModuleAugmentation } from './transpiler/dictionary_to_type/createModuleAugmentation.mjs';
|
|
4
|
+
import 'chokidar';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { watch } from './chokidar/watcher.mjs';
|
|
2
|
+
import { createDictionaryList } from './transpiler/dictionary_to_main/createDictionaryList.mjs';
|
|
3
|
+
import { createModuleAugmentation } from './transpiler/dictionary_to_type/createModuleAugmentation.mjs';
|
|
4
|
+
export {
|
|
5
|
+
createDictionaryList,
|
|
6
|
+
createModuleAugmentation,
|
|
7
|
+
watch
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export { watch } from './chokidar/watcher';\nexport { createDictionaryList } from './transpiler/dictionary_to_main/createDictionaryList';\nexport { createModuleAugmentation } from './transpiler/dictionary_to_type/createModuleAugmentation';\n"],"mappings":"AAAA,SAAS,aAAa;AACtB,SAAS,4BAA4B;AACrC,SAAS,gCAAgC;","names":[]}
|