@intlayer/chokidar 3.2.2 → 3.3.3
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 -10
- package/dist/cjs/chokidar/watcher.cjs.map +1 -1
- package/dist/cjs/cleanOutputDir.cjs +38 -0
- package/dist/cjs/cleanOutputDir.cjs.map +1 -0
- package/dist/cjs/loadDictionaries/loadDictionaries.cjs +19 -16
- package/dist/cjs/loadDictionaries/loadDictionaries.cjs.map +1 -1
- package/dist/cjs/log.cjs +20 -30
- package/dist/cjs/log.cjs.map +1 -1
- package/dist/cjs/transpiler/dictionary_to_main/createDictionaryList.cjs +12 -2
- package/dist/cjs/transpiler/dictionary_to_main/createDictionaryList.cjs.map +1 -1
- package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs +12 -2
- package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs.map +1 -1
- package/dist/cjs/utils.cjs +3 -0
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/esm/chokidar/watcher.mjs +8 -10
- package/dist/esm/chokidar/watcher.mjs.map +1 -1
- package/dist/esm/cleanOutputDir.mjs +14 -0
- package/dist/esm/cleanOutputDir.mjs.map +1 -0
- package/dist/esm/loadDictionaries/loadDictionaries.mjs +19 -16
- package/dist/esm/loadDictionaries/loadDictionaries.mjs.map +1 -1
- package/dist/esm/log.mjs +20 -30
- package/dist/esm/log.mjs.map +1 -1
- package/dist/esm/transpiler/dictionary_to_main/createDictionaryList.mjs +2 -2
- package/dist/esm/transpiler/dictionary_to_main/createDictionaryList.mjs.map +1 -1
- package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs +2 -2
- package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs.map +1 -1
- package/dist/esm/utils.mjs +2 -0
- package/dist/esm/utils.mjs.map +1 -1
- package/dist/types/chokidar/watcher.d.ts.map +1 -1
- package/dist/types/cleanOutputDir.d.ts +2 -0
- package/dist/types/cleanOutputDir.d.ts.map +1 -0
- package/dist/types/loadDictionaries/loadDictionaries.d.ts.map +1 -1
- package/dist/types/log.d.ts.map +1 -1
- package/dist/types/utils.d.ts +1 -0
- package/dist/types/utils.d.ts.map +1 -1
- package/package.json +20 -19
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
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
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
var watcher_exports = {};
|
|
20
30
|
__export(watcher_exports, {
|
|
@@ -24,7 +34,8 @@ module.exports = __toCommonJS(watcher_exports);
|
|
|
24
34
|
var import_path = require("path");
|
|
25
35
|
var import_config = require("@intlayer/config");
|
|
26
36
|
var import_chokidar = require("chokidar");
|
|
27
|
-
var
|
|
37
|
+
var import_fast_glob = __toESM(require("fast-glob"));
|
|
38
|
+
var import_cleanOutputDir = require('../cleanOutputDir.cjs');
|
|
28
39
|
var import_loadDictionaries = require('../loadDictionaries/loadDictionaries.cjs');
|
|
29
40
|
var import_loadLocalDictionaries = require('../loadDictionaries/loadLocalDictionaries.cjs');
|
|
30
41
|
var import_declaration_file_to_dictionary = require('../transpiler/declaration_file_to_dictionary/index.cjs');
|
|
@@ -36,24 +47,23 @@ const watch = (options) => {
|
|
|
36
47
|
verbose: true
|
|
37
48
|
});
|
|
38
49
|
const { watchedFilesPatternWithPath, baseDir } = content;
|
|
39
|
-
const files =
|
|
50
|
+
const files = import_fast_glob.default.sync(watchedFilesPatternWithPath);
|
|
40
51
|
return (0, import_chokidar.watch)(watchedFilesPatternWithPath, {
|
|
41
|
-
persistent:
|
|
52
|
+
persistent: false,
|
|
42
53
|
// Make the watcher persistent
|
|
43
54
|
ignoreInitial: true,
|
|
44
55
|
// Process existing files
|
|
45
56
|
...options
|
|
46
57
|
}).on("ready", async () => {
|
|
58
|
+
(0, import_cleanOutputDir.cleanOutputDir)();
|
|
47
59
|
const dictionaries = await (0, import_loadDictionaries.loadDictionaries)(files);
|
|
48
60
|
const dictionariesPaths = await (0, import_declaration_file_to_dictionary.buildDictionary)(dictionaries);
|
|
49
61
|
await (0, import_dictionary_to_type.createTypes)(dictionariesPaths);
|
|
50
|
-
console.info(
|
|
62
|
+
console.info(
|
|
63
|
+
`${LOG_PREFIX}${dictionariesPaths.length} dictionaries built`
|
|
64
|
+
);
|
|
51
65
|
(0, import_dictionary_to_type.createModuleAugmentation)();
|
|
52
|
-
console.info(`${LOG_PREFIX}Intlayer module augmentation built`);
|
|
53
66
|
(0, import_createDictionaryList.createDictionaryList)();
|
|
54
|
-
console.info(`${LOG_PREFIX}Intlayer dictionary list built`);
|
|
55
|
-
}).on("unlink", (filePath) => {
|
|
56
|
-
console.info("Removed file detected: ", (0, import_path.relative)(baseDir, filePath));
|
|
57
67
|
}).on("add", async (filePath) => {
|
|
58
68
|
console.info(
|
|
59
69
|
`${LOG_PREFIX}Additional file detected: `,
|
|
@@ -62,9 +72,7 @@ const watch = (options) => {
|
|
|
62
72
|
const localeDictionaries = await (0, import_loadLocalDictionaries.loadLocalDictionaries)(filePath);
|
|
63
73
|
const dictionaries = await (0, import_declaration_file_to_dictionary.buildDictionary)(localeDictionaries);
|
|
64
74
|
await (0, import_dictionary_to_type.createTypes)(dictionaries);
|
|
65
|
-
console.info(`${LOG_PREFIX}TypeScript types built`);
|
|
66
75
|
(0, import_dictionary_to_type.createModuleAugmentation)();
|
|
67
|
-
console.info(`${LOG_PREFIX}Intlayer module augmentation built`);
|
|
68
76
|
(0, import_createDictionaryList.createDictionaryList)();
|
|
69
77
|
}).on("change", async (filePath) => {
|
|
70
78
|
console.info("Change detected: ", (0, import_path.relative)(baseDir, filePath));
|
|
@@ -1 +1 @@
|
|
|
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 {
|
|
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 fg from 'fast-glob';\nimport { cleanOutputDir } from '../cleanOutputDir';\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[] = fg.sync(watchedFilesPatternWithPath);\n\n /** @ts-ignore remove error Expected 0-1 arguments, but got 2. */\n return chokidarWatch(watchedFilesPatternWithPath, {\n persistent: false, // Make the watcher persistent\n ignoreInitial: true, // Process existing files\n ...options,\n })\n .on('ready', async () => {\n cleanOutputDir();\n\n const dictionaries = await loadDictionaries(files);\n\n // Build locale dictionaries\n const dictionariesPaths = await buildDictionary(dictionaries);\n\n await createTypes(dictionariesPaths);\n\n console.info(\n `${LOG_PREFIX}${dictionariesPaths.length} dictionaries built`\n );\n\n createModuleAugmentation();\n\n createDictionaryList();\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\n const dictionaries = await buildDictionary(localeDictionaries);\n\n await createTypes(dictionaries);\n\n createModuleAugmentation();\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;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAyB;AACzB,oBAAiC;AAEjC,sBAA6D;AAC7D,uBAAe;AACf,4BAA+B;AAC/B,8BAAiC;AACjC,mCAAsC;AACtC,4CAAgC;AAChC,kCAAqC;AACrC,gCAGO;AAEP,MAAM,aAAa;AAGZ,MAAM,QAAQ,CAAC,YAA8B;AAClD,QAAM,EAAE,QAA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
|
|
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 cleanOutputDir_exports = {};
|
|
20
|
+
__export(cleanOutputDir_exports, {
|
|
21
|
+
cleanOutputDir: () => cleanOutputDir
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(cleanOutputDir_exports);
|
|
24
|
+
var import_fs = require("fs");
|
|
25
|
+
var import_config = require("@intlayer/config");
|
|
26
|
+
const cleanOutputDir = () => {
|
|
27
|
+
const { content } = (0, import_config.getConfiguration)();
|
|
28
|
+
const { resultDir } = content;
|
|
29
|
+
if ((0, import_fs.existsSync)(resultDir)) {
|
|
30
|
+
(0, import_fs.rmSync)(resultDir, { recursive: true });
|
|
31
|
+
}
|
|
32
|
+
(0, import_fs.mkdirSync)(resultDir);
|
|
33
|
+
};
|
|
34
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
35
|
+
0 && (module.exports = {
|
|
36
|
+
cleanOutputDir
|
|
37
|
+
});
|
|
38
|
+
//# sourceMappingURL=cleanOutputDir.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/cleanOutputDir.ts"],"sourcesContent":["import { existsSync, rmSync, mkdirSync } from 'fs';\nimport { getConfiguration } from '@intlayer/config';\n\nexport const cleanOutputDir = () => {\n const { content } = getConfiguration();\n\n const { resultDir } = content;\n\n // Delete the dictionary directory dictionariesDir\n if (existsSync(resultDir)) {\n rmSync(resultDir, { recursive: true });\n }\n\n // Create the dictionary directory dictionariesDir\n mkdirSync(resultDir);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAA8C;AAC9C,oBAAiC;AAE1B,MAAM,iBAAiB,MAAM;AAClC,QAAM,EAAE,QAAQ,QAAI,gCAAiB;AAErC,QAAM,EAAE,UAAU,IAAI;AAGtB,UAAI,sBAAW,SAAS,GAAG;AACzB,0BAAO,WAAW,EAAE,WAAW,KAAK,CAAC;AAAA,EACvC;AAGA,2BAAU,SAAS;AACrB;","names":[]}
|
|
@@ -36,14 +36,13 @@ var import_deepmerge = __toESM(require("deepmerge"));
|
|
|
36
36
|
var import_fetchDistantDictionaryKeys = require('../fetchDistantDictionaryKeys.cjs');
|
|
37
37
|
var import_log = require('../log.cjs');
|
|
38
38
|
var import_mergeDictionaries = require('../mergeDictionaries.cjs');
|
|
39
|
+
var import_utils = require('../utils.cjs');
|
|
39
40
|
var import_loadContentDeclaration = require('./loadContentDeclaration.cjs');
|
|
40
41
|
var import_loadDistantDictionaries = require('./loadDistantDictionaries.cjs');
|
|
41
42
|
const LOG_PREFIX = "[intlayer] ";
|
|
42
43
|
const loadDictionaries = async (contentDeclarationsPaths) => {
|
|
43
44
|
try {
|
|
44
|
-
const { editor } = (0, import_config.getConfiguration)(
|
|
45
|
-
verbose: true
|
|
46
|
-
});
|
|
45
|
+
const { editor } = (0, import_config.getConfiguration)();
|
|
47
46
|
console.info(`${LOG_PREFIX}Dictionaries:`);
|
|
48
47
|
const files = Array.isArray(contentDeclarationsPaths) ? contentDeclarationsPaths : [contentDeclarationsPaths];
|
|
49
48
|
const localDictionaries = await (0, import_loadContentDeclaration.loadContentDeclarations)(files);
|
|
@@ -56,25 +55,29 @@ const loadDictionaries = async (contentDeclarationsPaths) => {
|
|
|
56
55
|
let distantDictionaryKeys = [];
|
|
57
56
|
let mergedDictionaries = localDictionaries;
|
|
58
57
|
if (editor.clientId && editor.clientSecret) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
mergedDictionaries = (0, import_deepmerge.default)(localDictionaries, distantDictionaries, {
|
|
66
|
-
arrayMerge: (0, import_mergeDictionaries.mergeByKey)("key")
|
|
67
|
-
});
|
|
68
|
-
} else {
|
|
69
|
-
mergedDictionaries = (0, import_deepmerge.default)(distantDictionaries, localDictionaries, {
|
|
70
|
-
arrayMerge: (0, import_mergeDictionaries.mergeByKey)("key")
|
|
58
|
+
try {
|
|
59
|
+
distantDictionaryKeys = await (0, import_fetchDistantDictionaryKeys.fetchDistantDictionaryKeys)();
|
|
60
|
+
const orderedDistantDictionaryKeys = distantDictionaryKeys.sort(import_utils.sortAlphabetically);
|
|
61
|
+
import_log.logger.addDictionaryKeys("distant", orderedDistantDictionaryKeys);
|
|
62
|
+
distantDictionaries = await (0, import_loadDistantDictionaries.loadDistantDictionaries)({
|
|
63
|
+
dictionaryKeys: orderedDistantDictionaryKeys
|
|
71
64
|
});
|
|
65
|
+
if (editor.dictionaryPriorityStrategy === "distant_first") {
|
|
66
|
+
mergedDictionaries = (0, import_deepmerge.default)(localDictionaries, distantDictionaries, {
|
|
67
|
+
arrayMerge: (0, import_mergeDictionaries.mergeByKey)("key")
|
|
68
|
+
});
|
|
69
|
+
} else {
|
|
70
|
+
mergedDictionaries = (0, import_deepmerge.default)(distantDictionaries, localDictionaries, {
|
|
71
|
+
arrayMerge: (0, import_mergeDictionaries.mergeByKey)("key")
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
} catch (error) {
|
|
75
|
+
console.error("Error during fetching distant dictionaries");
|
|
72
76
|
}
|
|
73
77
|
}
|
|
74
78
|
import_log.logger.stop();
|
|
75
79
|
return mergedDictionaries;
|
|
76
80
|
} catch (error) {
|
|
77
|
-
console.error(error);
|
|
78
81
|
import_log.logger.stop();
|
|
79
82
|
throw error;
|
|
80
83
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/loadDictionaries/loadDictionaries.ts"],"sourcesContent":["// @ts-ignore @intlayer/backend not build yet\nimport { type DictionaryAPI } from '@intlayer/backend';\nimport { getConfiguration } from '@intlayer/config';\nimport { Dictionary } from '@intlayer/core';\nimport merge from 'deepmerge';\nimport { fetchDistantDictionaryKeys } from '../fetchDistantDictionaryKeys';\nimport { logger } from '../log';\nimport { mergeByKey } from '../mergeDictionaries';\nimport { loadContentDeclarations } from './loadContentDeclaration';\nimport { loadDistantDictionaries } from './loadDistantDictionaries';\n\nconst LOG_PREFIX = '[intlayer] ';\n\nexport const loadDictionaries = async (\n contentDeclarationsPaths: string[] | string\n): Promise<Dictionary[]> => {\n try {\n const { editor } = getConfiguration(
|
|
1
|
+
{"version":3,"sources":["../../../src/loadDictionaries/loadDictionaries.ts"],"sourcesContent":["// @ts-ignore @intlayer/backend not build yet\nimport { type DictionaryAPI } from '@intlayer/backend';\nimport { getConfiguration } from '@intlayer/config';\nimport { Dictionary } from '@intlayer/core';\nimport merge from 'deepmerge';\nimport { fetchDistantDictionaryKeys } from '../fetchDistantDictionaryKeys';\nimport { logger } from '../log';\nimport { mergeByKey } from '../mergeDictionaries';\nimport { sortAlphabetically } from '../utils';\nimport { loadContentDeclarations } from './loadContentDeclaration';\nimport { loadDistantDictionaries } from './loadDistantDictionaries';\n\nconst LOG_PREFIX = '[intlayer] ';\n\nexport const loadDictionaries = async (\n contentDeclarationsPaths: string[] | string\n): Promise<Dictionary[]> => {\n try {\n const { editor } = getConfiguration();\n\n console.info(`${LOG_PREFIX}Dictionaries:`);\n\n const files = Array.isArray(contentDeclarationsPaths)\n ? contentDeclarationsPaths\n : [contentDeclarationsPaths];\n\n const localDictionaries: Dictionary[] =\n await loadContentDeclarations(files);\n const localDictionaryKeys = localDictionaries.map((dict) => dict.key);\n\n // Initialize the logger with both local and distant dictionaries\n logger.init(localDictionaryKeys, []);\n\n // Update logger statuses for local dictionaries\n for (const dict of localDictionaries) {\n logger.updateStatus(dict.key, 'local', { status: 'built' });\n }\n\n let distantDictionaries: DictionaryAPI[] = [];\n let distantDictionaryKeys: string[] = [];\n let mergedDictionaries = localDictionaries;\n\n if (editor.clientId && editor.clientSecret) {\n try {\n // Fetch distant dictionary keys\n distantDictionaryKeys = await fetchDistantDictionaryKeys();\n\n const orderedDistantDictionaryKeys =\n distantDictionaryKeys.sort(sortAlphabetically);\n // Add distant dictionaries to the logger\n logger.addDictionaryKeys('distant', orderedDistantDictionaryKeys);\n\n // Fetch distant dictionaries\n distantDictionaries = await loadDistantDictionaries({\n dictionaryKeys: orderedDistantDictionaryKeys,\n });\n if (editor.dictionaryPriorityStrategy === 'distant_first') {\n // Merge the dictionaries\n mergedDictionaries = merge(localDictionaries, distantDictionaries, {\n arrayMerge: mergeByKey('key'),\n });\n } else {\n // Merge the dictionaries\n mergedDictionaries = merge(distantDictionaries, localDictionaries, {\n arrayMerge: mergeByKey('key'),\n });\n }\n } catch (error) {\n console.error('Error during fetching distant dictionaries');\n }\n }\n\n // Ensure the logger is stopped\n logger.stop();\n\n return mergedDictionaries;\n } catch (error) {\n // Ensure the logger is stopped\n logger.stop();\n\n throw error; // Re-throw the error after logging\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oBAAiC;AAEjC,uBAAkB;AAClB,wCAA2C;AAC3C,iBAAuB;AACvB,+BAA2B;AAC3B,mBAAmC;AACnC,oCAAwC;AACxC,qCAAwC;AAExC,MAAM,aAAa;AAEZ,MAAM,mBAAmB,OAC9B,6BAC0B;AAC1B,MAAI;AACF,UAAM,EAAE,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33
|
module.exports = __toCommonJS(log_exports);
|
|
34
|
-
var
|
|
34
|
+
var import_log_update = __toESM(require("log-update"));
|
|
35
|
+
var import_utils = require('./utils.cjs');
|
|
35
36
|
class Logger {
|
|
36
37
|
dictionariesStatuses = [];
|
|
37
38
|
spinnerFrames = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
@@ -56,7 +57,11 @@ class Logger {
|
|
|
56
57
|
}
|
|
57
58
|
init(localDictionariesKeys, distantDictionariesKeys) {
|
|
58
59
|
const allKeys = Array.from(
|
|
59
|
-
|
|
60
|
+
new Set(
|
|
61
|
+
[...localDictionariesKeys, ...distantDictionariesKeys].sort(
|
|
62
|
+
import_utils.sortAlphabetically
|
|
63
|
+
)
|
|
64
|
+
)
|
|
60
65
|
);
|
|
61
66
|
this.maxDictionaryKeyLength = allKeys.reduce(
|
|
62
67
|
(max, key) => key.length > max ? key.length : max,
|
|
@@ -83,10 +88,8 @@ class Logger {
|
|
|
83
88
|
state: states
|
|
84
89
|
};
|
|
85
90
|
});
|
|
86
|
-
for (const statusObj of this.dictionariesStatuses) {
|
|
87
|
-
process.stdout.write(this.getStatusLine(statusObj) + "\n");
|
|
88
|
-
}
|
|
89
91
|
this.startSpinner();
|
|
92
|
+
this.updateAllStatusLines();
|
|
90
93
|
}
|
|
91
94
|
// New method to add dictionary keys after initialization
|
|
92
95
|
addDictionaryKeys(type, dictionaryKeys) {
|
|
@@ -109,7 +112,6 @@ class Logger {
|
|
|
109
112
|
spinnerFrameIndex: 0
|
|
110
113
|
};
|
|
111
114
|
statusObj.state.push(newState);
|
|
112
|
-
process.stdout.write(this.getStatusLine(statusObj) + "\n");
|
|
113
115
|
} else {
|
|
114
116
|
const existingState = statusObj.state.find((s) => s.type === type);
|
|
115
117
|
if (!existingState) {
|
|
@@ -119,22 +121,10 @@ class Logger {
|
|
|
119
121
|
spinnerFrameIndex: 0
|
|
120
122
|
};
|
|
121
123
|
statusObj.state.push(newState);
|
|
122
|
-
const lineIndex = this.dictionariesStatuses.indexOf(statusObj);
|
|
123
|
-
readline.moveCursor(
|
|
124
|
-
process.stdout,
|
|
125
|
-
0,
|
|
126
|
-
-(this.dictionariesStatuses.length - lineIndex)
|
|
127
|
-
);
|
|
128
|
-
readline.clearLine(process.stdout, 0);
|
|
129
|
-
process.stdout.write(this.getStatusLine(statusObj) + "\n");
|
|
130
|
-
readline.moveCursor(
|
|
131
|
-
process.stdout,
|
|
132
|
-
0,
|
|
133
|
-
this.dictionariesStatuses.length - lineIndex - 1
|
|
134
|
-
);
|
|
135
124
|
}
|
|
136
125
|
}
|
|
137
126
|
}
|
|
127
|
+
this.updateAllStatusLines();
|
|
138
128
|
}
|
|
139
129
|
startSpinner() {
|
|
140
130
|
if (!this.spinnerTimer) {
|
|
@@ -151,7 +141,11 @@ class Logger {
|
|
|
151
141
|
}
|
|
152
142
|
stop() {
|
|
153
143
|
this.stopSpinner();
|
|
154
|
-
|
|
144
|
+
import_log_update.default.clear();
|
|
145
|
+
const lines = this.dictionariesStatuses.map(
|
|
146
|
+
(statusObj) => this.getStatusLine(statusObj)
|
|
147
|
+
);
|
|
148
|
+
console.log(lines.join("\n"));
|
|
155
149
|
}
|
|
156
150
|
updateStatus(dictionaryKey, type, status) {
|
|
157
151
|
const statusObj = this.dictionariesStatuses.find(
|
|
@@ -189,8 +183,8 @@ class Logger {
|
|
|
189
183
|
state: [newState]
|
|
190
184
|
});
|
|
191
185
|
}
|
|
186
|
+
this.updateAllStatusLines();
|
|
192
187
|
}
|
|
193
|
-
// Rest of the Logger class remains the same...
|
|
194
188
|
getStatusIcon(status) {
|
|
195
189
|
const statusIcons = {
|
|
196
190
|
pending: "\u23F2",
|
|
@@ -204,7 +198,7 @@ class Logger {
|
|
|
204
198
|
}
|
|
205
199
|
getStatusLine(statusObj) {
|
|
206
200
|
const keyPadding = this.maxDictionaryKeyLength - statusObj.dictionaryKey.length;
|
|
207
|
-
const paddedKey = statusObj.dictionaryKey
|
|
201
|
+
const paddedKey = `${statusObj.dictionaryKey}${" ".repeat(keyPadding)}`;
|
|
208
202
|
const states = statusObj.state.map((state) => {
|
|
209
203
|
let colorStart = "";
|
|
210
204
|
let colorEnd = "";
|
|
@@ -229,19 +223,15 @@ class Logger {
|
|
|
229
223
|
return `- ${paddedKey} ${states.join(" ")}`;
|
|
230
224
|
}
|
|
231
225
|
updateAllStatusLines() {
|
|
232
|
-
|
|
233
|
-
for (const statusObj of this.dictionariesStatuses) {
|
|
234
|
-
readline.clearLine(process.stdout, 0);
|
|
235
|
-
if (typeof statusObj?.state === "undefined") {
|
|
236
|
-
return;
|
|
237
|
-
}
|
|
226
|
+
const lines = this.dictionariesStatuses.map((statusObj) => {
|
|
238
227
|
statusObj.state.forEach((state) => {
|
|
239
228
|
if (state.status === "fetching") {
|
|
240
229
|
state.spinnerFrameIndex = (state.spinnerFrameIndex + 1) % this.spinnerFrames.length;
|
|
241
230
|
}
|
|
242
231
|
});
|
|
243
|
-
|
|
244
|
-
}
|
|
232
|
+
return this.getStatusLine(statusObj);
|
|
233
|
+
});
|
|
234
|
+
(0, import_log_update.default)(lines.join("\n"));
|
|
245
235
|
}
|
|
246
236
|
getStatuses() {
|
|
247
237
|
return this.dictionariesStatuses;
|
package/dist/cjs/log.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/log.ts"],"sourcesContent":["import * as readline from 'readline';\n\nexport type State = {\n type: 'local' | 'distant';\n status: 'pending' | 'fetching' | 'fetched' | 'error' | 'imported' | 'built';\n icon?: string;\n error?: Error;\n errorMessage?: string;\n spinnerFrameIndex?: number;\n};\n\nexport type DictionariesStatus = {\n dictionaryKey: string;\n state: State[];\n};\n\nclass Logger {\n private dictionariesStatuses: DictionariesStatus[] = [];\n private spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];\n private spinnerTimer: NodeJS.Timeout | null = null;\n private maxDictionaryKeyLength: number = 0;\n\n // ANSI color codes\n private RESET = '\\x1b[0m';\n private GREEN = '\\x1b[32m';\n private RED = '\\x1b[31m';\n private BLUE = '\\x1b[34m';\n private GREY = '\\x1b[90m';\n private GREY_DARK = '\\x1b[90m';\n\n // Singleton instance\n private static instance: Logger;\n\n private constructor() {}\n\n public static getInstance(): Logger {\n if (!Logger.instance) {\n Logger.instance = new Logger();\n }\n return Logger.instance;\n }\n\n public init(\n localDictionariesKeys: string[],\n distantDictionariesKeys: string[]\n ) {\n const allKeys = Array.from(\n new Set([...localDictionariesKeys, ...distantDictionariesKeys])\n );\n\n this.maxDictionaryKeyLength = allKeys.reduce(\n (max, key) => (key.length > max ? key.length : max),\n 0\n );\n\n this.dictionariesStatuses = allKeys.map((dictionaryKey) => {\n const states: State[] = [];\n if (localDictionariesKeys.includes(dictionaryKey)) {\n states.push({\n type: 'local',\n status: 'pending',\n spinnerFrameIndex: 0,\n });\n }\n if (distantDictionariesKeys.includes(dictionaryKey)) {\n states.push({\n type: 'distant',\n status: 'pending',\n spinnerFrameIndex: 0,\n });\n }\n return {\n dictionaryKey,\n state: states,\n };\n });\n\n // Output initial statuses\n for (const statusObj of this.dictionariesStatuses) {\n process.stdout.write(this.getStatusLine(statusObj) + '\\n');\n }\n\n // Start spinner timer\n this.startSpinner();\n }\n\n // New method to add dictionary keys after initialization\n public addDictionaryKeys(\n type: 'local' | 'distant',\n dictionaryKeys: string[]\n ) {\n for (const dictionaryKey of dictionaryKeys) {\n // Update maxDictionaryKeyLength if the new key is longer\n if (dictionaryKey.length > this.maxDictionaryKeyLength) {\n this.maxDictionaryKeyLength = dictionaryKey.length;\n }\n\n let statusObj = this.dictionariesStatuses.find(\n (ds) => ds.dictionaryKey === dictionaryKey\n );\n\n if (!statusObj) {\n // If the dictionaryKey doesn't exist yet, create a new DictionariesStatus\n statusObj = {\n dictionaryKey,\n state: [],\n };\n this.dictionariesStatuses.push(statusObj);\n\n const newState: State = {\n type,\n status: 'pending',\n spinnerFrameIndex: 0,\n };\n statusObj.state.push(newState);\n\n // Output the new status line\n process.stdout.write(this.getStatusLine(statusObj) + '\\n');\n } else {\n const existingState = statusObj.state.find((s) => s.type === type);\n if (!existingState) {\n // Add new state for the type\n const newState: State = {\n type,\n status: 'pending',\n spinnerFrameIndex: 0,\n };\n statusObj.state.push(newState);\n\n // Update the existing line\n const lineIndex = this.dictionariesStatuses.indexOf(statusObj);\n // Move cursor up to the lineIndex from the bottom\n readline.moveCursor(\n process.stdout,\n 0,\n -(this.dictionariesStatuses.length - lineIndex)\n );\n readline.clearLine(process.stdout, 0);\n process.stdout.write(this.getStatusLine(statusObj) + '\\n');\n // Move cursor back to the bottom\n readline.moveCursor(\n process.stdout,\n 0,\n this.dictionariesStatuses.length - lineIndex - 1\n );\n }\n }\n }\n // No need to redraw all status lines\n }\n\n private startSpinner() {\n if (!this.spinnerTimer) {\n this.spinnerTimer = setInterval(() => {\n this.updateAllStatusLines();\n }, 100); // Update every 100ms\n }\n }\n\n private stopSpinner() {\n if (this.spinnerTimer) {\n clearInterval(this.spinnerTimer);\n this.spinnerTimer = null;\n }\n }\n\n public stop() {\n this.stopSpinner();\n // Update statuses one last time\n this.updateAllStatusLines();\n }\n\n public updateStatus(\n dictionaryKey: string,\n type: 'local' | 'distant',\n status: Partial<State>\n ) {\n const statusObj = this.dictionariesStatuses.find(\n (ds) => ds.dictionaryKey === dictionaryKey\n );\n if (statusObj) {\n const state = statusObj.state.find((s) => s.type === type);\n if (state) {\n // Update existing state\n Object.assign(state, status);\n } else {\n // If the state for this type doesn't exist yet, add it\n if (status.status === undefined) {\n status.status = 'pending'; // Provide default status\n }\n const newState: State = {\n type,\n status: status.status,\n icon: status.icon ?? '',\n error: status.error,\n errorMessage: status.errorMessage,\n spinnerFrameIndex: status.spinnerFrameIndex ?? 0,\n };\n statusObj.state.push(newState);\n }\n } else {\n // If the status object doesn't exist, create it\n const newState: State = {\n type,\n status: status.status ?? 'pending',\n icon: status.icon ?? '',\n error: status.error,\n errorMessage: status.errorMessage,\n spinnerFrameIndex: status.spinnerFrameIndex ?? 0,\n };\n this.dictionariesStatuses.push({\n dictionaryKey,\n state: [newState],\n });\n }\n }\n\n // Rest of the Logger class remains the same...\n\n private getStatusIcon(status: string): string {\n const statusIcons: Record<string, string> = {\n pending: '⏲',\n fetching: '', // Spinner handled separately\n built: '✔',\n imported: '✔',\n error: '✖',\n };\n return statusIcons[status] ?? '';\n }\n\n private getStatusLine(statusObj: DictionariesStatus): string {\n const keyPadding =\n this.maxDictionaryKeyLength - statusObj.dictionaryKey.length;\n const paddedKey = statusObj.dictionaryKey + ' '.repeat(keyPadding);\n\n const states = statusObj.state.map((state) => {\n let colorStart = '';\n let colorEnd = '';\n let icon = this.getStatusIcon(state.status);\n if (state.status === 'fetching') {\n // Use spinner frame\n icon =\n this.spinnerFrames[\n state.spinnerFrameIndex! % this.spinnerFrames.length\n ];\n colorStart = this.BLUE;\n colorEnd = this.RESET;\n } else if (state.status === 'error') {\n colorStart = this.RED;\n colorEnd = this.RESET;\n } else if (state.status === 'imported' || state.status === 'built') {\n colorStart = this.GREEN;\n colorEnd = this.RESET;\n } else {\n colorStart = this.GREY;\n colorEnd = this.RESET;\n }\n\n // Format the status block\n const statusBlock = `${this.GREY_DARK}[${state.type}: ${colorStart}${icon} ${state.status}${this.GREY_DARK}]${colorEnd}`;\n\n return `${colorStart}${statusBlock}${colorEnd}`;\n });\n\n return `- ${paddedKey} ${states.join(' ')}`;\n }\n\n private updateAllStatusLines() {\n // Move cursor up to the first status line\n readline.moveCursor(process.stdout, 0, -this.dictionariesStatuses.length);\n\n for (const statusObj of this.dictionariesStatuses) {\n // Clear the line\n readline.clearLine(process.stdout, 0);\n\n if (typeof statusObj?.state === 'undefined') {\n return;\n }\n\n statusObj.state.forEach((state) => {\n if (state.status === 'fetching') {\n // Update spinner frame\n state.spinnerFrameIndex =\n (state.spinnerFrameIndex! + 1) % this.spinnerFrames.length;\n }\n });\n\n // Write the status line\n process.stdout.write(this.getStatusLine(statusObj) + '\\n');\n }\n }\n\n public getStatuses() {\n return this.dictionariesStatuses;\n }\n}\n\nexport const logger = Logger.getInstance();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,eAA0B;AAgB1B,MAAM,OAAO;AAAA,EACH,uBAA6C,CAAC;AAAA,EAC9C,gBAAgB,CAAC,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,QAAG;AAAA,EACjE,eAAsC;AAAA,EACtC,yBAAiC;AAAA;AAAA,EAGjC,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,OAAO;AAAA,EACP,OAAO;AAAA,EACP,YAAY;AAAA;AAAA,EAGpB,OAAe;AAAA,EAEP,cAAc;AAAA,EAAC;AAAA,EAEvB,OAAc,cAAsB;AAClC,QAAI,CAAC,OAAO,UAAU;AACpB,aAAO,WAAW,IAAI,OAAO;AAAA,IAC/B;AACA,WAAO,OAAO;AAAA,EAChB;AAAA,EAEO,KACL,uBACA,yBACA;AACA,UAAM,UAAU,MAAM;AAAA,MACpB,oBAAI,IAAI,CAAC,GAAG,uBAAuB,GAAG,uBAAuB,CAAC;AAAA,IAChE;AAEA,SAAK,yBAAyB,QAAQ;AAAA,MACpC,CAAC,KAAK,QAAS,IAAI,SAAS,MAAM,IAAI,SAAS;AAAA,MAC/C;AAAA,IACF;AAEA,SAAK,uBAAuB,QAAQ,IAAI,CAAC,kBAAkB;AACzD,YAAM,SAAkB,CAAC;AACzB,UAAI,sBAAsB,SAAS,aAAa,GAAG;AACjD,eAAO,KAAK;AAAA,UACV,MAAM;AAAA,UACN,QAAQ;AAAA,UACR,mBAAmB;AAAA,QACrB,CAAC;AAAA,MACH;AACA,UAAI,wBAAwB,SAAS,aAAa,GAAG;AACnD,eAAO,KAAK;AAAA,UACV,MAAM;AAAA,UACN,QAAQ;AAAA,UACR,mBAAmB;AAAA,QAC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BAAsB;AAEjD,eAAS,UAAU,QAAQ,QAAQ,CAAC;AAEpC,UAAI,OAAO,WAAW,UAAU,aAAa;AAC3C;AAAA,MACF;AAEA,gBAAU,MAAM,QAAQ,CAAC,UAAU;AACjC,YAAI,MAAM,WAAW,YAAY;AAE/B,gBAAM,qBACH,MAAM,oBAAqB,KAAK,KAAK,cAAc;AAAA,QACxD;AAAA,MACF,CAAC;AAGD,cAAQ,OAAO,MAAM,KAAK,cAAc,SAAS,IAAI,IAAI;AAAA,IAC3D;AAAA,EACF;AAAA,EAEO,cAAc;AACnB,WAAO,KAAK;AAAA,EACd;AACF;AAEO,MAAM,SAAS,OAAO,YAAY;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/log.ts"],"sourcesContent":["import logUpdate from 'log-update';\nimport { sortAlphabetically } from './utils';\n\nexport type State = {\n type: 'local' | 'distant';\n status: 'pending' | 'fetching' | 'fetched' | 'error' | 'imported' | 'built';\n icon?: string;\n error?: Error;\n errorMessage?: string;\n spinnerFrameIndex?: number;\n};\n\nexport type DictionariesStatus = {\n dictionaryKey: string;\n state: State[];\n};\n\nclass Logger {\n private dictionariesStatuses: DictionariesStatus[] = [];\n private spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];\n private spinnerTimer: NodeJS.Timeout | null = null;\n private maxDictionaryKeyLength: number = 0;\n\n // ANSI color codes\n private RESET = '\\x1b[0m';\n private GREEN = '\\x1b[32m';\n private RED = '\\x1b[31m';\n private BLUE = '\\x1b[34m';\n private GREY = '\\x1b[90m';\n private GREY_DARK = '\\x1b[90m';\n\n // Singleton instance\n private static instance: Logger;\n\n private constructor() {}\n\n public static getInstance(): Logger {\n if (!Logger.instance) {\n Logger.instance = new Logger();\n }\n return Logger.instance;\n }\n\n public init(\n localDictionariesKeys: string[],\n distantDictionariesKeys: string[]\n ) {\n const allKeys = Array.from(\n new Set(\n [...localDictionariesKeys, ...distantDictionariesKeys].sort(\n sortAlphabetically\n )\n )\n );\n\n this.maxDictionaryKeyLength = allKeys.reduce(\n (max, key) => (key.length > max ? key.length : max),\n 0\n );\n\n this.dictionariesStatuses = allKeys.map((dictionaryKey) => {\n const states: State[] = [];\n\n if (localDictionariesKeys.includes(dictionaryKey)) {\n states.push({\n type: 'local',\n status: 'pending',\n spinnerFrameIndex: 0,\n });\n }\n if (distantDictionariesKeys.includes(dictionaryKey)) {\n states.push({\n type: 'distant',\n status: 'pending',\n spinnerFrameIndex: 0,\n });\n }\n\n return {\n dictionaryKey,\n state: states,\n };\n });\n\n // Start spinner timer\n this.startSpinner();\n\n // Update all status lines (this will output the initial statuses)\n this.updateAllStatusLines();\n }\n\n // New method to add dictionary keys after initialization\n public addDictionaryKeys(\n type: 'local' | 'distant',\n dictionaryKeys: string[]\n ) {\n for (const dictionaryKey of dictionaryKeys) {\n // Update maxDictionaryKeyLength if the new key is longer\n if (dictionaryKey.length > this.maxDictionaryKeyLength) {\n this.maxDictionaryKeyLength = dictionaryKey.length;\n }\n\n let statusObj = this.dictionariesStatuses.find(\n (ds) => ds.dictionaryKey === dictionaryKey\n );\n\n if (!statusObj) {\n // If the dictionaryKey doesn't exist yet, create a new DictionariesStatus\n\n statusObj = {\n dictionaryKey,\n state: [],\n };\n this.dictionariesStatuses.push(statusObj);\n\n const newState: State = {\n type,\n status: 'pending',\n spinnerFrameIndex: 0,\n };\n statusObj.state.push(newState);\n } else {\n const existingState = statusObj.state.find((s) => s.type === type);\n if (!existingState) {\n // Add new state for the type\n\n const newState: State = {\n type,\n status: 'pending',\n spinnerFrameIndex: 0,\n };\n statusObj.state.push(newState);\n }\n }\n }\n\n // Call updateAllStatusLines() to refresh the output\n this.updateAllStatusLines();\n }\n\n private startSpinner() {\n if (!this.spinnerTimer) {\n this.spinnerTimer = setInterval(() => {\n this.updateAllStatusLines();\n }, 100); // Update every 100ms\n }\n }\n\n private stopSpinner() {\n if (this.spinnerTimer) {\n clearInterval(this.spinnerTimer);\n this.spinnerTimer = null;\n }\n }\n\n public stop() {\n this.stopSpinner();\n logUpdate.clear(); // Clear the logUpdate output\n const lines = this.dictionariesStatuses.map((statusObj) =>\n this.getStatusLine(statusObj)\n );\n console.log(lines.join('\\n')); // Output final statuses\n }\n\n public updateStatus(\n dictionaryKey: string,\n type: 'local' | 'distant',\n status: Partial<State>\n ) {\n const statusObj = this.dictionariesStatuses.find(\n (ds) => ds.dictionaryKey === dictionaryKey\n );\n if (statusObj) {\n const state = statusObj.state.find((s) => s.type === type);\n if (state) {\n // Update existing state\n Object.assign(state, status);\n } else {\n // If the state for this type doesn't exist yet, add it\n if (status.status === undefined) {\n status.status = 'pending'; // Provide default status\n }\n const newState: State = {\n type,\n status: status.status,\n icon: status.icon ?? '',\n error: status.error,\n errorMessage: status.errorMessage,\n spinnerFrameIndex: status.spinnerFrameIndex ?? 0,\n };\n statusObj.state.push(newState);\n }\n } else {\n // If the status object doesn't exist, create it\n const newState: State = {\n type,\n status: status.status ?? 'pending',\n icon: status.icon ?? '',\n error: status.error,\n errorMessage: status.errorMessage,\n spinnerFrameIndex: status.spinnerFrameIndex ?? 0,\n };\n this.dictionariesStatuses.push({\n dictionaryKey,\n state: [newState],\n });\n }\n\n // Update the display after status change\n this.updateAllStatusLines();\n }\n\n private getStatusIcon(status: string): string {\n const statusIcons: Record<string, string> = {\n pending: '⏲',\n fetching: '', // Spinner handled separately\n built: '✔',\n imported: '✔',\n error: '✖',\n };\n return statusIcons[status] ?? '';\n }\n\n private getStatusLine(statusObj: DictionariesStatus): string {\n const keyPadding =\n this.maxDictionaryKeyLength - statusObj.dictionaryKey.length;\n const paddedKey = `${statusObj.dictionaryKey}${' '.repeat(keyPadding)}`;\n\n const states = statusObj.state.map((state) => {\n let colorStart = '';\n let colorEnd = '';\n let icon = this.getStatusIcon(state.status);\n if (state.status === 'fetching') {\n // Use spinner frame\n icon =\n this.spinnerFrames[\n state.spinnerFrameIndex! % this.spinnerFrames.length\n ];\n colorStart = this.BLUE;\n colorEnd = this.RESET;\n } else if (state.status === 'error') {\n colorStart = this.RED;\n colorEnd = this.RESET;\n } else if (state.status === 'imported' || state.status === 'built') {\n colorStart = this.GREEN;\n colorEnd = this.RESET;\n } else {\n colorStart = this.GREY;\n colorEnd = this.RESET;\n }\n\n // Format the status block\n const statusBlock = `${this.GREY_DARK}[${state.type}: ${colorStart}${icon} ${state.status}${this.GREY_DARK}]${colorEnd}`;\n\n return `${colorStart}${statusBlock}${colorEnd}`;\n });\n\n return `- ${paddedKey} ${states.join(' ')}`;\n }\n\n private updateAllStatusLines() {\n const lines = this.dictionariesStatuses.map((statusObj) => {\n statusObj.state.forEach((state) => {\n if (state.status === 'fetching') {\n // Update spinner frame\n state.spinnerFrameIndex =\n (state.spinnerFrameIndex! + 1) % this.spinnerFrames.length;\n }\n });\n return this.getStatusLine(statusObj);\n });\n\n logUpdate(lines.join('\\n'));\n }\n\n public getStatuses() {\n return this.dictionariesStatuses;\n }\n}\n\nexport const logger = Logger.getInstance();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAsB;AACtB,mBAAmC;AAgBnC,MAAM,OAAO;AAAA,EACH,uBAA6C,CAAC;AAAA,EAC9C,gBAAgB,CAAC,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,QAAG;AAAA,EACjE,eAAsC;AAAA,EACtC,yBAAiC;AAAA;AAAA,EAGjC,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,OAAO;AAAA,EACP,OAAO;AAAA,EACP,YAAY;AAAA;AAAA,EAGpB,OAAe;AAAA,EAEP,cAAc;AAAA,EAAC;AAAA,EAEvB,OAAc,cAAsB;AAClC,QAAI,CAAC,OAAO,UAAU;AACpB,aAAO,WAAW,IAAI,OAAO;AAAA,IAC/B;AACA,WAAO,OAAO;AAAA,EAChB;AAAA,EAEO,KACL,uBACA,yBACA;AACA,UAAM,UAAU,MAAM;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M,MAAM,GAAG,KAAK,SAAS,IAAI,QAAQ;AAEtH,aAAO,GAAG,UAAU,GAAG,WAAW,GAAG,QAAQ;AAAA,IAC/C,CAAC;AAED,WAAO,KAAK,SAAS,IAAI,OAAO,KAAK,GAAG,CAAC;AAAA,EAC3C;AAAA,EAEQ,uBAAuB;AAC7B,UAAM,QAAQ,KAAK,qBAAqB,IAAI,CAAC,cAAc;AACzD,gBAAU,MAAM,QAAQ,CAAC,UAAU;AACjC,YAAI,MAAM,WAAW,YAAY;AAE/B,gBAAM,qBACH,MAAM,oBAAqB,KAAK,KAAK,cAAc;AAAA,QACxD;AAAA,MACF,CAAC;AACD,aAAO,KAAK,cAAc,SAAS;AAAA,IACrC,CAAC;AAED,0BAAAA,SAAU,MAAM,KAAK,IAAI,CAAC;AAAA,EAC5B;AAAA,EAEO,cAAc;AACnB,WAAO,KAAK;AAAA,EACd;AACF;AAEO,MAAM,SAAS,OAAO,YAAY;","names":["logUpdate"]}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
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
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
var createDictionaryList_exports = {};
|
|
20
30
|
__export(createDictionaryList_exports, {
|
|
@@ -24,7 +34,7 @@ module.exports = __toCommonJS(createDictionaryList_exports);
|
|
|
24
34
|
var import_fs = require("fs");
|
|
25
35
|
var import_path = require("path");
|
|
26
36
|
var import_config = require("@intlayer/config");
|
|
27
|
-
var
|
|
37
|
+
var import_fast_glob = __toESM(require("fast-glob"));
|
|
28
38
|
var import_utils = require('../../utils.cjs');
|
|
29
39
|
const { content } = (0, import_config.getConfiguration)();
|
|
30
40
|
const { dictionariesDir, mainDir } = content;
|
|
@@ -63,7 +73,7 @@ const createDictionaryList = () => {
|
|
|
63
73
|
if (!(0, import_fs.existsSync)(mainDir)) {
|
|
64
74
|
(0, import_fs.mkdirSync)(mainDir, { recursive: true });
|
|
65
75
|
}
|
|
66
|
-
const dictionaries =
|
|
76
|
+
const dictionaries = import_fast_glob.default.sync(`${dictionariesDir}/**/*.json`);
|
|
67
77
|
const cjsContent = generateDictionaryListContent(dictionaries, "cjs");
|
|
68
78
|
(0, import_fs.writeFileSync)((0, import_path.resolve)(mainDir, "dictionaries.cjs"), cjsContent);
|
|
69
79
|
const esmContent = generateDictionaryListContent(dictionaries, "esm");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/transpiler/dictionary_to_main/createDictionaryList.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { basename, extname, relative, resolve } from 'path';\nimport { getConfiguration } from '@intlayer/config';\nimport
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/dictionary_to_main/createDictionaryList.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { basename, extname, relative, resolve } from 'path';\nimport { getConfiguration } from '@intlayer/config';\nimport fg from 'fast-glob';\nimport { getFileHash } from '../../utils';\n\nconst { content } = getConfiguration();\nconst { dictionariesDir, mainDir } = content;\n\n/**\n * This function generates the content of the dictionary list file\n */\nconst generateDictionaryListContent = (\n dictionaries: string[],\n format: 'cjs' | 'esm' = 'esm'\n): string => {\n let content = '';\n\n const dictionariesRef = dictionaries.map((dictionaryPath) => ({\n relativePath: relative(mainDir, dictionaryPath),\n id: basename(dictionaryPath, extname(dictionaryPath)), // Get the base name as the dictionary id\n hash: `_${getFileHash(dictionaryPath)}`, // Get the hash of the dictionary to avoid conflicts\n }));\n\n // Import all dictionaries\n dictionariesRef.forEach((dictionary) => {\n if (format === 'esm')\n content += `import ${dictionary.hash} from '${dictionary.relativePath}';\\n`;\n if (format === 'cjs')\n content += `const ${dictionary.hash} = require('${dictionary.relativePath}');\\n`;\n });\n\n content += '\\n';\n\n // Format Dictionary Map\n const formattedDictionaryMap: string = dictionariesRef\n .map((dictionary) => `\"${dictionary.id}\": ${dictionary.hash}`)\n .join(',\\n');\n\n if (format === 'esm')\n content += `export default {\\n${formattedDictionaryMap}\\n};\\n`;\n if (format === 'cjs')\n content += `module.exports = {\\n${formattedDictionaryMap}\\n};\\n`;\n\n return content;\n};\n\n/**\n * This function generates a list of dictionaries in the main directory\n */\nexport const createDictionaryList = () => {\n // Create main directory if it doesn't exist\n if (!existsSync(mainDir)) {\n mkdirSync(mainDir, { recursive: true });\n }\n\n const dictionaries: string[] = fg.sync(`${dictionariesDir}/**/*.json`);\n\n // Create the dictionary list file\n const cjsContent = generateDictionaryListContent(dictionaries, 'cjs');\n writeFileSync(resolve(mainDir, 'dictionaries.cjs'), cjsContent);\n\n const esmContent = generateDictionaryListContent(dictionaries, 'esm');\n writeFileSync(resolve(mainDir, 'dictionaries.mjs'), esmContent);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;A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A8B,cAAc,KAAK;AACpE,mCAAc,qBAAQ,SAAS,kBAAkB,GAAG,UAAU;AAChE;","names":["content","fg"]}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
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
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
var createModuleAugmentation_exports = {};
|
|
20
30
|
__export(createModuleAugmentation_exports, {
|
|
@@ -25,7 +35,7 @@ module.exports = __toCommonJS(createModuleAugmentation_exports);
|
|
|
25
35
|
var import_fs = require("fs");
|
|
26
36
|
var import_path = require("path");
|
|
27
37
|
var import_config = require("@intlayer/config");
|
|
28
|
-
var
|
|
38
|
+
var import_fast_glob = __toESM(require("fast-glob"));
|
|
29
39
|
var import_utils = require('../../utils.cjs');
|
|
30
40
|
const { content, internationalization } = (0, import_config.getConfiguration)();
|
|
31
41
|
const { typesDir, moduleAugmentationDir } = content;
|
|
@@ -78,7 +88,7 @@ const createModuleAugmentation = () => {
|
|
|
78
88
|
if (!(0, import_fs.existsSync)(moduleAugmentationDir)) {
|
|
79
89
|
(0, import_fs.mkdirSync)(moduleAugmentationDir, { recursive: true });
|
|
80
90
|
}
|
|
81
|
-
const dictionaries =
|
|
91
|
+
const dictionaries = import_fast_glob.default.sync(`${typesDir}/**/*.d.ts`);
|
|
82
92
|
const tsContent = generateTypeIndexContent(dictionaries);
|
|
83
93
|
(0, import_fs.writeFileSync)((0, import_path.join)(moduleAugmentationDir, "intlayer.d.ts"), tsContent);
|
|
84
94
|
};
|
|
@@ -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
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/dictionary_to_type/createModuleAugmentation.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { basename, join, relative } from 'path';\nimport { Locales, getConfiguration } from '@intlayer/config';\nimport fg from 'fast-glob';\nimport { getFileHash, transformToCamelCase } from '../../utils';\n\nconst { content, internationalization } = getConfiguration();\nconst { typesDir, moduleAugmentationDir } = content;\nconst { locales, strictMode } = internationalization;\n\nexport const getTypeName = (id: string): string =>\n transformToCamelCase(`${id}Content`);\n\n/**\n * This function generates the content of the module augmentation file\n */\nconst generateTypeIndexContent = (typeFiles: string[]): string => {\n let content = \"/* eslint-disable */\\nimport { Locales } from 'intlayer';\\n\";\n\n const dictionariesRef = typeFiles.map((dictionaryPath) => ({\n relativePath: relative(moduleAugmentationDir, dictionaryPath),\n id: basename(dictionaryPath, '.d.ts'), // Get the base name as the dictionary id\n hash: `_${getFileHash(dictionaryPath)}`, // Get the hash of the dictionary to avoid conflicts\n }));\n\n // Import all dictionaries\n dictionariesRef.forEach((dictionary) => {\n const typeName = getTypeName(dictionary.id);\n content += `import type { ${typeName} as ${dictionary.hash} } from '${dictionary.relativePath}';\\n`;\n });\n\n content += '\\n';\n\n // Format Dictionary Map\n const formattedDictionaryMap: string = dictionariesRef\n .map((dictionary) => ` \"${dictionary.id}\": ${dictionary.hash};`)\n .join('\\n');\n\n const formatLocales = locales\n .map((locale) => {\n for (const key in Locales) {\n if (Locales[key as keyof typeof Locales] === locale) {\n return `Locales.${key}`;\n }\n }\n })\n .join(' | ');\n\n const strictModeRecord =\n strictMode === 'strict'\n ? `interface IConfigLocales<Content> extends Record<ExtractedLocales, Content> {}`\n : strictMode === 'required_only'\n ? `interface IConfigLocales<Content> extends Record<ExtractedLocales, Content>, Partial<Record<ExcludedLocales, Content>> {}`\n : `interface IConfigLocales<Content> extends Partial<Record<Locales, Content>> {}`;\n\n /**\n * Write the module augmentation to extend the intlayer module with the dictionaries types\n * Will suggest the type resulting of the dictionaries\n *\n * declare module 'intlayer' {\n * interface IntlayerDictionaryTypesConnector = {\n * dictionaries: {\n * id: DictionaryType;\n * }\n * }\n *\n * type ConfigLocales = Locales.ENGLISH | Locales.FRENCH | Locales.SPANISH;\n * type ExtractedLocales = Extract<Locales, ConfigLocales>;\n * type ExcludedLocales = Exclude<Locales, ConfigLocales>;\n *\n * interface IConfigLocales<Content> extends Record<ExtractedLocales, Content>, Partial<Record<ExcludedLocales, Content>> {}\n *\n *\n * }\n * See https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation\n */\n content += `declare module 'intlayer' {\\n`;\n content += ` interface IntlayerDictionaryTypesConnector {\\n${formattedDictionaryMap}\\n }\\n\\n`;\n content += ` type ConfigLocales = ${formatLocales};\\n`;\n content += ` type ExtractedLocales = Extract<Locales, ConfigLocales>;\\n`;\n content += ` type ExcludedLocales = Exclude<Locales, ConfigLocales>;\\n\\n`;\n content += ` ${strictModeRecord}\\n`;\n content += `}`;\n\n return content;\n};\n\n/**\n * This function generates a index file merging all the types\n */\nexport const createModuleAugmentation = () => {\n // Create main directory if it doesn't exist\n if (!existsSync(moduleAugmentationDir)) {\n mkdirSync(moduleAugmentationDir, { recursive: true });\n }\n\n const dictionaries: string[] = fg.sync(`${typesDir}/**/*.d.ts`);\n // Create the dictionary list file\n\n const tsContent = generateTypeIndexContent(dictionaries);\n writeFileSync(join(moduleAugmentationDir, 'intlayer.d.ts'), tsContent);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAqD;AACrD,kBAAyC;AACzC,oBAA0C;AAC1C,uBAAe;AACf,mBAAkD;AAElD,MAAM,EAAE,SAAS,qBAAqB,QAAI,gCAAiB;AAC3D,MAAM,EAAE,UAAU,sBAAsB,IAAI;AAC5C,MAAM,EAAE,SAAS,WAAW,IAAI;AAEzB,MAAM,cAAc,CAAC,WAC1B,mCAAqB,GAAG,EAAE,SAAS;AAKrC,MAAM,2BAA2B,CAAC,cAAgC;AAChE,MAAIA,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,eAAyB,iBAAAC,QAAG,KAAK,GAAG,QAAQ,YAAY;AAG9D,QAAM,YAAY,yBAAyB,YAAY;AACvD,mCAAc,kBAAK,uBAAuB,eAAe,GAAG,SAAS;AACvE;","names":["content","fg"]}
|
package/dist/cjs/utils.cjs
CHANGED
|
@@ -29,6 +29,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
29
29
|
var utils_exports = {};
|
|
30
30
|
__export(utils_exports, {
|
|
31
31
|
getFileHash: () => getFileHash,
|
|
32
|
+
sortAlphabetically: () => sortAlphabetically,
|
|
32
33
|
transformToCamelCase: () => transformToCamelCase
|
|
33
34
|
});
|
|
34
35
|
module.exports = __toCommonJS(utils_exports);
|
|
@@ -47,9 +48,11 @@ const transformToCamelCase = (string) => {
|
|
|
47
48
|
});
|
|
48
49
|
return camelCasedWords.join("");
|
|
49
50
|
};
|
|
51
|
+
const sortAlphabetically = (a, b) => a.localeCompare(b);
|
|
50
52
|
// Annotate the CommonJS export names for ESM import in node:
|
|
51
53
|
0 && (module.exports = {
|
|
52
54
|
getFileHash,
|
|
55
|
+
sortAlphabetically,
|
|
53
56
|
transformToCamelCase
|
|
54
57
|
});
|
|
55
58
|
//# sourceMappingURL=utils.cjs.map
|
package/dist/cjs/utils.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils.ts"],"sourcesContent":["import crypto from 'crypto-js';\n\nexport const getFileHash = (filePath: string) => {\n const hash = crypto.SHA3(filePath);\n\n return hash\n .toString(crypto.enc.Base64)\n .replace(/[^A-Z\\d]/gi, '')\n .substring(0, 20);\n};\n\nexport const transformToCamelCase = (string: string): string => {\n // Split the string into words using a regex that finds spaces, hyphens, and underscores\n const words = string.split(/[\\s\\-_]+/);\n\n // Transform each word except the first to have its first letter uppercase\n const camelCasedWords = words.map((word, index) => {\n if (index === 0) {\n return word[0].toUpperCase() + word.slice(1);\n }\n return word.charAt(0).toUpperCase() + word.slice(1);\n });\n\n // Join the words back together\n return camelCasedWords.join('');\n};\n"],"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"]}
|
|
1
|
+
{"version":3,"sources":["../../src/utils.ts"],"sourcesContent":["import crypto from 'crypto-js';\n\nexport const getFileHash = (filePath: string) => {\n const hash = crypto.SHA3(filePath);\n\n return hash\n .toString(crypto.enc.Base64)\n .replace(/[^A-Z\\d]/gi, '')\n .substring(0, 20);\n};\n\nexport const transformToCamelCase = (string: string): string => {\n // Split the string into words using a regex that finds spaces, hyphens, and underscores\n const words = string.split(/[\\s\\-_]+/);\n\n // Transform each word except the first to have its first letter uppercase\n const camelCasedWords = words.map((word, index) => {\n if (index === 0) {\n return word[0].toUpperCase() + word.slice(1);\n }\n return word.charAt(0).toUpperCase() + word.slice(1);\n });\n\n // Join the words back together\n return camelCasedWords.join('');\n};\n\nexport const sortAlphabetically = (a: string, b: string) => a.localeCompare(b);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAmB;AAEZ,MAAM,cAAc,CAAC,aAAqB;AAC/C,QAAM,OAAO,iBAAAA,QAAO,KAAK,QAAQ;AAEjC,SAAO,KACJ,SAAS,iBAAAA,QAAO,IAAI,MAAM,EAC1B,QAAQ,cAAc,EAAE,EACxB,UAAU,GAAG,EAAE;AACpB;AAEO,MAAM,uBAAuB,CAAC,WAA2B;AAE9D,QAAM,QAAQ,OAAO,MAAM,UAAU;AAGrC,QAAM,kBAAkB,MAAM,IAAI,CAAC,MAAM,UAAU;AACjD,QAAI,UAAU,GAAG;AACf,aAAO,KAAK,CAAC,EAAE,YAAY,IAAI,KAAK,MAAM,CAAC;AAAA,IAC7C;AACA,WAAO,KAAK,OAAO,CAAC,EAAE,YAAY,IAAI,KAAK,MAAM,CAAC;AAAA,EACpD,CAAC;AAGD,SAAO,gBAAgB,KAAK,EAAE;AAChC;AAEO,MAAM,qBAAqB,CAAC,GAAW,MAAc,EAAE,cAAc,CAAC;","names":["crypto"]}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { relative } from "path";
|
|
2
2
|
import { getConfiguration } from "@intlayer/config";
|
|
3
3
|
import { watch as chokidarWatch } from "chokidar";
|
|
4
|
-
import
|
|
4
|
+
import fg from "fast-glob";
|
|
5
|
+
import { cleanOutputDir } from '../cleanOutputDir.mjs';
|
|
5
6
|
import { loadDictionaries } from '../loadDictionaries/loadDictionaries.mjs';
|
|
6
7
|
import { loadLocalDictionaries } from '../loadDictionaries/loadLocalDictionaries.mjs';
|
|
7
8
|
import { buildDictionary } from '../transpiler/declaration_file_to_dictionary/index.mjs';
|
|
@@ -16,24 +17,23 @@ const watch = (options) => {
|
|
|
16
17
|
verbose: true
|
|
17
18
|
});
|
|
18
19
|
const { watchedFilesPatternWithPath, baseDir } = content;
|
|
19
|
-
const files = sync(watchedFilesPatternWithPath);
|
|
20
|
+
const files = fg.sync(watchedFilesPatternWithPath);
|
|
20
21
|
return chokidarWatch(watchedFilesPatternWithPath, {
|
|
21
|
-
persistent:
|
|
22
|
+
persistent: false,
|
|
22
23
|
// Make the watcher persistent
|
|
23
24
|
ignoreInitial: true,
|
|
24
25
|
// Process existing files
|
|
25
26
|
...options
|
|
26
27
|
}).on("ready", async () => {
|
|
28
|
+
cleanOutputDir();
|
|
27
29
|
const dictionaries = await loadDictionaries(files);
|
|
28
30
|
const dictionariesPaths = await buildDictionary(dictionaries);
|
|
29
31
|
await createTypes(dictionariesPaths);
|
|
30
|
-
console.info(
|
|
32
|
+
console.info(
|
|
33
|
+
`${LOG_PREFIX}${dictionariesPaths.length} dictionaries built`
|
|
34
|
+
);
|
|
31
35
|
createModuleAugmentation();
|
|
32
|
-
console.info(`${LOG_PREFIX}Intlayer module augmentation built`);
|
|
33
36
|
createDictionaryList();
|
|
34
|
-
console.info(`${LOG_PREFIX}Intlayer dictionary list built`);
|
|
35
|
-
}).on("unlink", (filePath) => {
|
|
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: `,
|
|
@@ -42,9 +42,7 @@ const watch = (options) => {
|
|
|
42
42
|
const localeDictionaries = await loadLocalDictionaries(filePath);
|
|
43
43
|
const dictionaries = await buildDictionary(localeDictionaries);
|
|
44
44
|
await createTypes(dictionaries);
|
|
45
|
-
console.info(`${LOG_PREFIX}TypeScript types built`);
|
|
46
45
|
createModuleAugmentation();
|
|
47
|
-
console.info(`${LOG_PREFIX}Intlayer module augmentation built`);
|
|
48
46
|
createDictionaryList();
|
|
49
47
|
}).on("change", async (filePath) => {
|
|
50
48
|
console.info("Change detected: ", relative(baseDir, filePath));
|
|
@@ -1 +1 @@
|
|
|
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 {
|
|
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 fg from 'fast-glob';\nimport { cleanOutputDir } from '../cleanOutputDir';\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[] = fg.sync(watchedFilesPatternWithPath);\n\n /** @ts-ignore remove error Expected 0-1 arguments, but got 2. */\n return chokidarWatch(watchedFilesPatternWithPath, {\n persistent: false, // Make the watcher persistent\n ignoreInitial: true, // Process existing files\n ...options,\n })\n .on('ready', async () => {\n cleanOutputDir();\n\n const dictionaries = await loadDictionaries(files);\n\n // Build locale dictionaries\n const dictionariesPaths = await buildDictionary(dictionaries);\n\n await createTypes(dictionariesPaths);\n\n console.info(\n `${LOG_PREFIX}${dictionariesPaths.length} dictionaries built`\n );\n\n createModuleAugmentation();\n\n createDictionaryList();\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\n const dictionaries = await buildDictionary(localeDictionaries);\n\n await createTypes(dictionaries);\n\n createModuleAugmentation();\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,OAAO,QAAQ;AACf,SAAS,sBAAsB;AAC/B,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,GAAG,KAAK,2BAA2B;AAG3D,SAAO,cAAc,6BAA6B;AAAA,IAChD,YAAY;AAAA;AAAA,IACZ,eAAe;AAAA;AAAA,IACf,GAAG;AAAA,EACL,CAAC,EACE,GAAG,SAAS,YAAY;AACvB,mBAAe;AAEf,UAAM,eAAe,MAAM,iBAAiB,KAAK;AAGjD,UAAM,oBAAoB,MAAM,gBAAgB,YAAY;AAE5D,UAAM,YAAY,iBAAiB;AAEnC,YAAQ;AAAA,MACN,GAAG,UAAU,GAAG,kBAAkB,MAAM;AAAA,IAC1C;AAEA,6BAAyB;AAEzB,yBAAqB;AAAA,EACvB,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;AAE/D,UAAM,eAAe,MAAM,gBAAgB,kBAAkB;AAE7D,UAAM,YAAY,YAAY;AAE9B,6BAAyB;AAEzB,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,14 @@
|
|
|
1
|
+
import { existsSync, rmSync, mkdirSync } from "fs";
|
|
2
|
+
import { getConfiguration } from "@intlayer/config";
|
|
3
|
+
const cleanOutputDir = () => {
|
|
4
|
+
const { content } = getConfiguration();
|
|
5
|
+
const { resultDir } = content;
|
|
6
|
+
if (existsSync(resultDir)) {
|
|
7
|
+
rmSync(resultDir, { recursive: true });
|
|
8
|
+
}
|
|
9
|
+
mkdirSync(resultDir);
|
|
10
|
+
};
|
|
11
|
+
export {
|
|
12
|
+
cleanOutputDir
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=cleanOutputDir.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/cleanOutputDir.ts"],"sourcesContent":["import { existsSync, rmSync, mkdirSync } from 'fs';\nimport { getConfiguration } from '@intlayer/config';\n\nexport const cleanOutputDir = () => {\n const { content } = getConfiguration();\n\n const { resultDir } = content;\n\n // Delete the dictionary directory dictionariesDir\n if (existsSync(resultDir)) {\n rmSync(resultDir, { recursive: true });\n }\n\n // Create the dictionary directory dictionariesDir\n mkdirSync(resultDir);\n};\n"],"mappings":"AAAA,SAAS,YAAY,QAAQ,iBAAiB;AAC9C,SAAS,wBAAwB;AAE1B,MAAM,iBAAiB,MAAM;AAClC,QAAM,EAAE,QAAQ,IAAI,iBAAiB;AAErC,QAAM,EAAE,UAAU,IAAI;AAGtB,MAAI,WAAW,SAAS,GAAG;AACzB,WAAO,WAAW,EAAE,WAAW,KAAK,CAAC;AAAA,EACvC;AAGA,YAAU,SAAS;AACrB;","names":[]}
|
|
@@ -3,14 +3,13 @@ import merge from "deepmerge";
|
|
|
3
3
|
import { fetchDistantDictionaryKeys } from '../fetchDistantDictionaryKeys.mjs';
|
|
4
4
|
import { logger } from '../log.mjs';
|
|
5
5
|
import { mergeByKey } from '../mergeDictionaries.mjs';
|
|
6
|
+
import { sortAlphabetically } from '../utils.mjs';
|
|
6
7
|
import { loadContentDeclarations } from './loadContentDeclaration.mjs';
|
|
7
8
|
import { loadDistantDictionaries } from './loadDistantDictionaries.mjs';
|
|
8
9
|
const LOG_PREFIX = "[intlayer] ";
|
|
9
10
|
const loadDictionaries = async (contentDeclarationsPaths) => {
|
|
10
11
|
try {
|
|
11
|
-
const { editor } = getConfiguration(
|
|
12
|
-
verbose: true
|
|
13
|
-
});
|
|
12
|
+
const { editor } = getConfiguration();
|
|
14
13
|
console.info(`${LOG_PREFIX}Dictionaries:`);
|
|
15
14
|
const files = Array.isArray(contentDeclarationsPaths) ? contentDeclarationsPaths : [contentDeclarationsPaths];
|
|
16
15
|
const localDictionaries = await loadContentDeclarations(files);
|
|
@@ -23,25 +22,29 @@ const loadDictionaries = async (contentDeclarationsPaths) => {
|
|
|
23
22
|
let distantDictionaryKeys = [];
|
|
24
23
|
let mergedDictionaries = localDictionaries;
|
|
25
24
|
if (editor.clientId && editor.clientSecret) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
mergedDictionaries = merge(localDictionaries, distantDictionaries, {
|
|
33
|
-
arrayMerge: mergeByKey("key")
|
|
34
|
-
});
|
|
35
|
-
} else {
|
|
36
|
-
mergedDictionaries = merge(distantDictionaries, localDictionaries, {
|
|
37
|
-
arrayMerge: mergeByKey("key")
|
|
25
|
+
try {
|
|
26
|
+
distantDictionaryKeys = await fetchDistantDictionaryKeys();
|
|
27
|
+
const orderedDistantDictionaryKeys = distantDictionaryKeys.sort(sortAlphabetically);
|
|
28
|
+
logger.addDictionaryKeys("distant", orderedDistantDictionaryKeys);
|
|
29
|
+
distantDictionaries = await loadDistantDictionaries({
|
|
30
|
+
dictionaryKeys: orderedDistantDictionaryKeys
|
|
38
31
|
});
|
|
32
|
+
if (editor.dictionaryPriorityStrategy === "distant_first") {
|
|
33
|
+
mergedDictionaries = merge(localDictionaries, distantDictionaries, {
|
|
34
|
+
arrayMerge: mergeByKey("key")
|
|
35
|
+
});
|
|
36
|
+
} else {
|
|
37
|
+
mergedDictionaries = merge(distantDictionaries, localDictionaries, {
|
|
38
|
+
arrayMerge: mergeByKey("key")
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
} catch (error) {
|
|
42
|
+
console.error("Error during fetching distant dictionaries");
|
|
39
43
|
}
|
|
40
44
|
}
|
|
41
45
|
logger.stop();
|
|
42
46
|
return mergedDictionaries;
|
|
43
47
|
} catch (error) {
|
|
44
|
-
console.error(error);
|
|
45
48
|
logger.stop();
|
|
46
49
|
throw error;
|
|
47
50
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/loadDictionaries/loadDictionaries.ts"],"sourcesContent":["// @ts-ignore @intlayer/backend not build yet\nimport { type DictionaryAPI } from '@intlayer/backend';\nimport { getConfiguration } from '@intlayer/config';\nimport { Dictionary } from '@intlayer/core';\nimport merge from 'deepmerge';\nimport { fetchDistantDictionaryKeys } from '../fetchDistantDictionaryKeys';\nimport { logger } from '../log';\nimport { mergeByKey } from '../mergeDictionaries';\nimport { loadContentDeclarations } from './loadContentDeclaration';\nimport { loadDistantDictionaries } from './loadDistantDictionaries';\n\nconst LOG_PREFIX = '[intlayer] ';\n\nexport const loadDictionaries = async (\n contentDeclarationsPaths: string[] | string\n): Promise<Dictionary[]> => {\n try {\n const { editor } = getConfiguration(
|
|
1
|
+
{"version":3,"sources":["../../../src/loadDictionaries/loadDictionaries.ts"],"sourcesContent":["// @ts-ignore @intlayer/backend not build yet\nimport { type DictionaryAPI } from '@intlayer/backend';\nimport { getConfiguration } from '@intlayer/config';\nimport { Dictionary } from '@intlayer/core';\nimport merge from 'deepmerge';\nimport { fetchDistantDictionaryKeys } from '../fetchDistantDictionaryKeys';\nimport { logger } from '../log';\nimport { mergeByKey } from '../mergeDictionaries';\nimport { sortAlphabetically } from '../utils';\nimport { loadContentDeclarations } from './loadContentDeclaration';\nimport { loadDistantDictionaries } from './loadDistantDictionaries';\n\nconst LOG_PREFIX = '[intlayer] ';\n\nexport const loadDictionaries = async (\n contentDeclarationsPaths: string[] | string\n): Promise<Dictionary[]> => {\n try {\n const { editor } = getConfiguration();\n\n console.info(`${LOG_PREFIX}Dictionaries:`);\n\n const files = Array.isArray(contentDeclarationsPaths)\n ? contentDeclarationsPaths\n : [contentDeclarationsPaths];\n\n const localDictionaries: Dictionary[] =\n await loadContentDeclarations(files);\n const localDictionaryKeys = localDictionaries.map((dict) => dict.key);\n\n // Initialize the logger with both local and distant dictionaries\n logger.init(localDictionaryKeys, []);\n\n // Update logger statuses for local dictionaries\n for (const dict of localDictionaries) {\n logger.updateStatus(dict.key, 'local', { status: 'built' });\n }\n\n let distantDictionaries: DictionaryAPI[] = [];\n let distantDictionaryKeys: string[] = [];\n let mergedDictionaries = localDictionaries;\n\n if (editor.clientId && editor.clientSecret) {\n try {\n // Fetch distant dictionary keys\n distantDictionaryKeys = await fetchDistantDictionaryKeys();\n\n const orderedDistantDictionaryKeys =\n distantDictionaryKeys.sort(sortAlphabetically);\n // Add distant dictionaries to the logger\n logger.addDictionaryKeys('distant', orderedDistantDictionaryKeys);\n\n // Fetch distant dictionaries\n distantDictionaries = await loadDistantDictionaries({\n dictionaryKeys: orderedDistantDictionaryKeys,\n });\n if (editor.dictionaryPriorityStrategy === 'distant_first') {\n // Merge the dictionaries\n mergedDictionaries = merge(localDictionaries, distantDictionaries, {\n arrayMerge: mergeByKey('key'),\n });\n } else {\n // Merge the dictionaries\n mergedDictionaries = merge(distantDictionaries, localDictionaries, {\n arrayMerge: mergeByKey('key'),\n });\n }\n } catch (error) {\n console.error('Error during fetching distant dictionaries');\n }\n }\n\n // Ensure the logger is stopped\n logger.stop();\n\n return mergedDictionaries;\n } catch (error) {\n // Ensure the logger is stopped\n logger.stop();\n\n throw error; // Re-throw the error after logging\n }\n};\n"],"mappings":"AAEA,SAAS,wBAAwB;AAEjC,OAAO,WAAW;AAClB,SAAS,kCAAkC;AAC3C,SAAS,cAAc;AACvB,SAAS,kBAAkB;AAC3B,SAAS,0BAA0B;AACnC,SAAS,+BAA+B;AACxC,SAAS,+BAA+B;AAExC,MAAM,aAAa;AAEZ,MAAM,mBAAmB,OAC9B,6BAC0B;AAC1B,MAAI;AACF,UAAM,EAAE,OAAO,IAAI,iBAAiB;AAEpC,YAAQ,KAAK,GAAG,UAAU,eAAe;AAEzC,UAAM,QAAQ,MAAM,QAAQ,wBAAwB,IAChD,2BACA,CAAC,wBAAwB;AAE7B,UAAM,oBACJ,MAAM,wBAAwB,KAAK;AACrC,UAAM,sBAAsB,kBAAkB,IAAI,CAAC,SAAS,KAAK,GAAG;AAGpE,WAAO,KAAK,qBAAqB,CAAC,CAAC;AAGnC,eAAW,QAAQ,mBAAmB;AACpC,aAAO,aAAa,KAAK,KAAK,SAAS,EAAE,QAAQ,QAAQ,CAAC;AAAA,IAC5D;AAEA,QAAI,sBAAuC,CAAC;AAC5C,QAAI,wBAAkC,CAAC;AACvC,QAAI,qBAAqB;AAEzB,QAAI,OAAO,YAAY,OAAO,cAAc;AAC1C,UAAI;AAEF,gCAAwB,MAAM,2BAA2B;AAEzD,cAAM,+BACJ,sBAAsB,KAAK,kBAAkB;AAE/C,eAAO,kBAAkB,WAAW,4BAA4B;AAGhE,8BAAsB,MAAM,wBAAwB;AAAA,UAClD,gBAAgB;AAAA,QAClB,CAAC;AACD,YAAI,OAAO,+BAA+B,iBAAiB;AAEzD,+BAAqB,MAAM,mBAAmB,qBAAqB;AAAA,YACjE,YAAY,WAAW,KAAK;AAAA,UAC9B,CAAC;AAAA,QACH,OAAO;AAEL,+BAAqB,MAAM,qBAAqB,mBAAmB;AAAA,YACjE,YAAY,WAAW,KAAK;AAAA,UAC9B,CAAC;AAAA,QACH;AAAA,MACF,SAAS,OAAO;AACd,gBAAQ,MAAM,4CAA4C;AAAA,MAC5D;AAAA,IACF;AAGA,WAAO,KAAK;AAEZ,WAAO;AAAA,EACT,SAAS,OAAO;AAEd,WAAO,KAAK;AAEZ,UAAM;AAAA,EACR;AACF;","names":[]}
|
package/dist/esm/log.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import logUpdate from "log-update";
|
|
2
|
+
import { sortAlphabetically } from './utils.mjs';
|
|
2
3
|
class Logger {
|
|
3
4
|
dictionariesStatuses = [];
|
|
4
5
|
spinnerFrames = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
@@ -23,7 +24,11 @@ class Logger {
|
|
|
23
24
|
}
|
|
24
25
|
init(localDictionariesKeys, distantDictionariesKeys) {
|
|
25
26
|
const allKeys = Array.from(
|
|
26
|
-
|
|
27
|
+
new Set(
|
|
28
|
+
[...localDictionariesKeys, ...distantDictionariesKeys].sort(
|
|
29
|
+
sortAlphabetically
|
|
30
|
+
)
|
|
31
|
+
)
|
|
27
32
|
);
|
|
28
33
|
this.maxDictionaryKeyLength = allKeys.reduce(
|
|
29
34
|
(max, key) => key.length > max ? key.length : max,
|
|
@@ -50,10 +55,8 @@ class Logger {
|
|
|
50
55
|
state: states
|
|
51
56
|
};
|
|
52
57
|
});
|
|
53
|
-
for (const statusObj of this.dictionariesStatuses) {
|
|
54
|
-
process.stdout.write(this.getStatusLine(statusObj) + "\n");
|
|
55
|
-
}
|
|
56
58
|
this.startSpinner();
|
|
59
|
+
this.updateAllStatusLines();
|
|
57
60
|
}
|
|
58
61
|
// New method to add dictionary keys after initialization
|
|
59
62
|
addDictionaryKeys(type, dictionaryKeys) {
|
|
@@ -76,7 +79,6 @@ class Logger {
|
|
|
76
79
|
spinnerFrameIndex: 0
|
|
77
80
|
};
|
|
78
81
|
statusObj.state.push(newState);
|
|
79
|
-
process.stdout.write(this.getStatusLine(statusObj) + "\n");
|
|
80
82
|
} else {
|
|
81
83
|
const existingState = statusObj.state.find((s) => s.type === type);
|
|
82
84
|
if (!existingState) {
|
|
@@ -86,22 +88,10 @@ class Logger {
|
|
|
86
88
|
spinnerFrameIndex: 0
|
|
87
89
|
};
|
|
88
90
|
statusObj.state.push(newState);
|
|
89
|
-
const lineIndex = this.dictionariesStatuses.indexOf(statusObj);
|
|
90
|
-
readline.moveCursor(
|
|
91
|
-
process.stdout,
|
|
92
|
-
0,
|
|
93
|
-
-(this.dictionariesStatuses.length - lineIndex)
|
|
94
|
-
);
|
|
95
|
-
readline.clearLine(process.stdout, 0);
|
|
96
|
-
process.stdout.write(this.getStatusLine(statusObj) + "\n");
|
|
97
|
-
readline.moveCursor(
|
|
98
|
-
process.stdout,
|
|
99
|
-
0,
|
|
100
|
-
this.dictionariesStatuses.length - lineIndex - 1
|
|
101
|
-
);
|
|
102
91
|
}
|
|
103
92
|
}
|
|
104
93
|
}
|
|
94
|
+
this.updateAllStatusLines();
|
|
105
95
|
}
|
|
106
96
|
startSpinner() {
|
|
107
97
|
if (!this.spinnerTimer) {
|
|
@@ -118,7 +108,11 @@ class Logger {
|
|
|
118
108
|
}
|
|
119
109
|
stop() {
|
|
120
110
|
this.stopSpinner();
|
|
121
|
-
|
|
111
|
+
logUpdate.clear();
|
|
112
|
+
const lines = this.dictionariesStatuses.map(
|
|
113
|
+
(statusObj) => this.getStatusLine(statusObj)
|
|
114
|
+
);
|
|
115
|
+
console.log(lines.join("\n"));
|
|
122
116
|
}
|
|
123
117
|
updateStatus(dictionaryKey, type, status) {
|
|
124
118
|
const statusObj = this.dictionariesStatuses.find(
|
|
@@ -156,8 +150,8 @@ class Logger {
|
|
|
156
150
|
state: [newState]
|
|
157
151
|
});
|
|
158
152
|
}
|
|
153
|
+
this.updateAllStatusLines();
|
|
159
154
|
}
|
|
160
|
-
// Rest of the Logger class remains the same...
|
|
161
155
|
getStatusIcon(status) {
|
|
162
156
|
const statusIcons = {
|
|
163
157
|
pending: "\u23F2",
|
|
@@ -171,7 +165,7 @@ class Logger {
|
|
|
171
165
|
}
|
|
172
166
|
getStatusLine(statusObj) {
|
|
173
167
|
const keyPadding = this.maxDictionaryKeyLength - statusObj.dictionaryKey.length;
|
|
174
|
-
const paddedKey = statusObj.dictionaryKey
|
|
168
|
+
const paddedKey = `${statusObj.dictionaryKey}${" ".repeat(keyPadding)}`;
|
|
175
169
|
const states = statusObj.state.map((state) => {
|
|
176
170
|
let colorStart = "";
|
|
177
171
|
let colorEnd = "";
|
|
@@ -196,19 +190,15 @@ class Logger {
|
|
|
196
190
|
return `- ${paddedKey} ${states.join(" ")}`;
|
|
197
191
|
}
|
|
198
192
|
updateAllStatusLines() {
|
|
199
|
-
|
|
200
|
-
for (const statusObj of this.dictionariesStatuses) {
|
|
201
|
-
readline.clearLine(process.stdout, 0);
|
|
202
|
-
if (typeof statusObj?.state === "undefined") {
|
|
203
|
-
return;
|
|
204
|
-
}
|
|
193
|
+
const lines = this.dictionariesStatuses.map((statusObj) => {
|
|
205
194
|
statusObj.state.forEach((state) => {
|
|
206
195
|
if (state.status === "fetching") {
|
|
207
196
|
state.spinnerFrameIndex = (state.spinnerFrameIndex + 1) % this.spinnerFrames.length;
|
|
208
197
|
}
|
|
209
198
|
});
|
|
210
|
-
|
|
211
|
-
}
|
|
199
|
+
return this.getStatusLine(statusObj);
|
|
200
|
+
});
|
|
201
|
+
logUpdate(lines.join("\n"));
|
|
212
202
|
}
|
|
213
203
|
getStatuses() {
|
|
214
204
|
return this.dictionariesStatuses;
|
package/dist/esm/log.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/log.ts"],"sourcesContent":["import * as readline from 'readline';\n\nexport type State = {\n type: 'local' | 'distant';\n status: 'pending' | 'fetching' | 'fetched' | 'error' | 'imported' | 'built';\n icon?: string;\n error?: Error;\n errorMessage?: string;\n spinnerFrameIndex?: number;\n};\n\nexport type DictionariesStatus = {\n dictionaryKey: string;\n state: State[];\n};\n\nclass Logger {\n private dictionariesStatuses: DictionariesStatus[] = [];\n private spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];\n private spinnerTimer: NodeJS.Timeout | null = null;\n private maxDictionaryKeyLength: number = 0;\n\n // ANSI color codes\n private RESET = '\\x1b[0m';\n private GREEN = '\\x1b[32m';\n private RED = '\\x1b[31m';\n private BLUE = '\\x1b[34m';\n private GREY = '\\x1b[90m';\n private GREY_DARK = '\\x1b[90m';\n\n // Singleton instance\n private static instance: Logger;\n\n private constructor() {}\n\n public static getInstance(): Logger {\n if (!Logger.instance) {\n Logger.instance = new Logger();\n }\n return Logger.instance;\n }\n\n public init(\n localDictionariesKeys: string[],\n distantDictionariesKeys: string[]\n ) {\n const allKeys = Array.from(\n new Set([...localDictionariesKeys, ...distantDictionariesKeys])\n );\n\n this.maxDictionaryKeyLength = allKeys.reduce(\n (max, key) => (key.length > max ? key.length : max),\n 0\n );\n\n this.dictionariesStatuses = allKeys.map((dictionaryKey) => {\n const states: State[] = [];\n if (localDictionariesKeys.includes(dictionaryKey)) {\n states.push({\n type: 'local',\n status: 'pending',\n spinnerFrameIndex: 0,\n });\n }\n if (distantDictionariesKeys.includes(dictionaryKey)) {\n states.push({\n type: 'distant',\n status: 'pending',\n spinnerFrameIndex: 0,\n });\n }\n return {\n dictionaryKey,\n state: states,\n };\n });\n\n // Output initial statuses\n for (const statusObj of this.dictionariesStatuses) {\n process.stdout.write(this.getStatusLine(statusObj) + '\\n');\n }\n\n // Start spinner timer\n this.startSpinner();\n }\n\n // New method to add dictionary keys after initialization\n public addDictionaryKeys(\n type: 'local' | 'distant',\n dictionaryKeys: string[]\n ) {\n for (const dictionaryKey of dictionaryKeys) {\n // Update maxDictionaryKeyLength if the new key is longer\n if (dictionaryKey.length > this.maxDictionaryKeyLength) {\n this.maxDictionaryKeyLength = dictionaryKey.length;\n }\n\n let statusObj = this.dictionariesStatuses.find(\n (ds) => ds.dictionaryKey === dictionaryKey\n );\n\n if (!statusObj) {\n // If the dictionaryKey doesn't exist yet, create a new DictionariesStatus\n statusObj = {\n dictionaryKey,\n state: [],\n };\n this.dictionariesStatuses.push(statusObj);\n\n const newState: State = {\n type,\n status: 'pending',\n spinnerFrameIndex: 0,\n };\n statusObj.state.push(newState);\n\n // Output the new status line\n process.stdout.write(this.getStatusLine(statusObj) + '\\n');\n } else {\n const existingState = statusObj.state.find((s) => s.type === type);\n if (!existingState) {\n // Add new state for the type\n const newState: State = {\n type,\n status: 'pending',\n spinnerFrameIndex: 0,\n };\n statusObj.state.push(newState);\n\n // Update the existing line\n const lineIndex = this.dictionariesStatuses.indexOf(statusObj);\n // Move cursor up to the lineIndex from the bottom\n readline.moveCursor(\n process.stdout,\n 0,\n -(this.dictionariesStatuses.length - lineIndex)\n );\n readline.clearLine(process.stdout, 0);\n process.stdout.write(this.getStatusLine(statusObj) + '\\n');\n // Move cursor back to the bottom\n readline.moveCursor(\n process.stdout,\n 0,\n this.dictionariesStatuses.length - lineIndex - 1\n );\n }\n }\n }\n // No need to redraw all status lines\n }\n\n private startSpinner() {\n if (!this.spinnerTimer) {\n this.spinnerTimer = setInterval(() => {\n this.updateAllStatusLines();\n }, 100); // Update every 100ms\n }\n }\n\n private stopSpinner() {\n if (this.spinnerTimer) {\n clearInterval(this.spinnerTimer);\n this.spinnerTimer = null;\n }\n }\n\n public stop() {\n this.stopSpinner();\n // Update statuses one last time\n this.updateAllStatusLines();\n }\n\n public updateStatus(\n dictionaryKey: string,\n type: 'local' | 'distant',\n status: Partial<State>\n ) {\n const statusObj = this.dictionariesStatuses.find(\n (ds) => ds.dictionaryKey === dictionaryKey\n );\n if (statusObj) {\n const state = statusObj.state.find((s) => s.type === type);\n if (state) {\n // Update existing state\n Object.assign(state, status);\n } else {\n // If the state for this type doesn't exist yet, add it\n if (status.status === undefined) {\n status.status = 'pending'; // Provide default status\n }\n const newState: State = {\n type,\n status: status.status,\n icon: status.icon ?? '',\n error: status.error,\n errorMessage: status.errorMessage,\n spinnerFrameIndex: status.spinnerFrameIndex ?? 0,\n };\n statusObj.state.push(newState);\n }\n } else {\n // If the status object doesn't exist, create it\n const newState: State = {\n type,\n status: status.status ?? 'pending',\n icon: status.icon ?? '',\n error: status.error,\n errorMessage: status.errorMessage,\n spinnerFrameIndex: status.spinnerFrameIndex ?? 0,\n };\n this.dictionariesStatuses.push({\n dictionaryKey,\n state: [newState],\n });\n }\n }\n\n // Rest of the Logger class remains the same...\n\n private getStatusIcon(status: string): string {\n const statusIcons: Record<string, string> = {\n pending: '⏲',\n fetching: '', // Spinner handled separately\n built: '✔',\n imported: '✔',\n error: '✖',\n };\n return statusIcons[status] ?? '';\n }\n\n private getStatusLine(statusObj: DictionariesStatus): string {\n const keyPadding =\n this.maxDictionaryKeyLength - statusObj.dictionaryKey.length;\n const paddedKey = statusObj.dictionaryKey + ' '.repeat(keyPadding);\n\n const states = statusObj.state.map((state) => {\n let colorStart = '';\n let colorEnd = '';\n let icon = this.getStatusIcon(state.status);\n if (state.status === 'fetching') {\n // Use spinner frame\n icon =\n this.spinnerFrames[\n state.spinnerFrameIndex! % this.spinnerFrames.length\n ];\n colorStart = this.BLUE;\n colorEnd = this.RESET;\n } else if (state.status === 'error') {\n colorStart = this.RED;\n colorEnd = this.RESET;\n } else if (state.status === 'imported' || state.status === 'built') {\n colorStart = this.GREEN;\n colorEnd = this.RESET;\n } else {\n colorStart = this.GREY;\n colorEnd = this.RESET;\n }\n\n // Format the status block\n const statusBlock = `${this.GREY_DARK}[${state.type}: ${colorStart}${icon} ${state.status}${this.GREY_DARK}]${colorEnd}`;\n\n return `${colorStart}${statusBlock}${colorEnd}`;\n });\n\n return `- ${paddedKey} ${states.join(' ')}`;\n }\n\n private updateAllStatusLines() {\n // Move cursor up to the first status line\n readline.moveCursor(process.stdout, 0, -this.dictionariesStatuses.length);\n\n for (const statusObj of this.dictionariesStatuses) {\n // Clear the line\n readline.clearLine(process.stdout, 0);\n\n if (typeof statusObj?.state === 'undefined') {\n return;\n }\n\n statusObj.state.forEach((state) => {\n if (state.status === 'fetching') {\n // Update spinner frame\n state.spinnerFrameIndex =\n (state.spinnerFrameIndex! + 1) % this.spinnerFrames.length;\n }\n });\n\n // Write the status line\n process.stdout.write(this.getStatusLine(statusObj) + '\\n');\n }\n }\n\n public getStatuses() {\n return this.dictionariesStatuses;\n }\n}\n\nexport const logger = Logger.getInstance();\n"],"mappings":"AAAA,YAAY,cAAc;AAgB1B,MAAM,OAAO;AAAA,EACH,uBAA6C,CAA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D;AAAA,MACF,CAAC;AAGD,cAAQ,OAAO,MAAM,KAAK,cAAc,SAAS,IAAI,IAAI;AAAA,IAC3D;AAAA,EACF;AAAA,EAEO,cAAc;AACnB,WAAO,KAAK;AAAA,EACd;AACF;AAEO,MAAM,SAAS,OAAO,YAAY;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/log.ts"],"sourcesContent":["import logUpdate from 'log-update';\nimport { sortAlphabetically } from './utils';\n\nexport type State = {\n type: 'local' | 'distant';\n status: 'pending' | 'fetching' | 'fetched' | 'error' | 'imported' | 'built';\n icon?: string;\n error?: Error;\n errorMessage?: string;\n spinnerFrameIndex?: number;\n};\n\nexport type DictionariesStatus = {\n dictionaryKey: string;\n state: State[];\n};\n\nclass Logger {\n private dictionariesStatuses: DictionariesStatus[] = [];\n private spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];\n private spinnerTimer: NodeJS.Timeout | null = null;\n private maxDictionaryKeyLength: number = 0;\n\n // ANSI color codes\n private RESET = '\\x1b[0m';\n private GREEN = '\\x1b[32m';\n private RED = '\\x1b[31m';\n private BLUE = '\\x1b[34m';\n private GREY = '\\x1b[90m';\n private GREY_DARK = '\\x1b[90m';\n\n // Singleton instance\n private static instance: Logger;\n\n private constructor() {}\n\n public static getInstance(): Logger {\n if (!Logger.instance) {\n Logger.instance = new Logger();\n }\n return Logger.instance;\n }\n\n public init(\n localDictionariesKeys: string[],\n distantDictionariesKeys: string[]\n ) {\n const allKeys = Array.from(\n new Set(\n [...localDictionariesKeys, ...distantDictionariesKeys].sort(\n sortAlphabetically\n )\n )\n );\n\n this.maxDictionaryKeyLength = allKeys.reduce(\n (max, key) => (key.length > max ? key.length : max),\n 0\n );\n\n this.dictionariesStatuses = allKeys.map((dictionaryKey) => {\n const states: State[] = [];\n\n if (localDictionariesKeys.includes(dictionaryKey)) {\n states.push({\n type: 'local',\n status: 'pending',\n spinnerFrameIndex: 0,\n });\n }\n if (distantDictionariesKeys.includes(dictionaryKey)) {\n states.push({\n type: 'distant',\n status: 'pending',\n spinnerFrameIndex: 0,\n });\n }\n\n return {\n dictionaryKey,\n state: states,\n };\n });\n\n // Start spinner timer\n this.startSpinner();\n\n // Update all status lines (this will output the initial statuses)\n this.updateAllStatusLines();\n }\n\n // New method to add dictionary keys after initialization\n public addDictionaryKeys(\n type: 'local' | 'distant',\n dictionaryKeys: string[]\n ) {\n for (const dictionaryKey of dictionaryKeys) {\n // Update maxDictionaryKeyLength if the new key is longer\n if (dictionaryKey.length > this.maxDictionaryKeyLength) {\n this.maxDictionaryKeyLength = dictionaryKey.length;\n }\n\n let statusObj = this.dictionariesStatuses.find(\n (ds) => ds.dictionaryKey === dictionaryKey\n );\n\n if (!statusObj) {\n // If the dictionaryKey doesn't exist yet, create a new DictionariesStatus\n\n statusObj = {\n dictionaryKey,\n state: [],\n };\n this.dictionariesStatuses.push(statusObj);\n\n const newState: State = {\n type,\n status: 'pending',\n spinnerFrameIndex: 0,\n };\n statusObj.state.push(newState);\n } else {\n const existingState = statusObj.state.find((s) => s.type === type);\n if (!existingState) {\n // Add new state for the type\n\n const newState: State = {\n type,\n status: 'pending',\n spinnerFrameIndex: 0,\n };\n statusObj.state.push(newState);\n }\n }\n }\n\n // Call updateAllStatusLines() to refresh the output\n this.updateAllStatusLines();\n }\n\n private startSpinner() {\n if (!this.spinnerTimer) {\n this.spinnerTimer = setInterval(() => {\n this.updateAllStatusLines();\n }, 100); // Update every 100ms\n }\n }\n\n private stopSpinner() {\n if (this.spinnerTimer) {\n clearInterval(this.spinnerTimer);\n this.spinnerTimer = null;\n }\n }\n\n public stop() {\n this.stopSpinner();\n logUpdate.clear(); // Clear the logUpdate output\n const lines = this.dictionariesStatuses.map((statusObj) =>\n this.getStatusLine(statusObj)\n );\n console.log(lines.join('\\n')); // Output final statuses\n }\n\n public updateStatus(\n dictionaryKey: string,\n type: 'local' | 'distant',\n status: Partial<State>\n ) {\n const statusObj = this.dictionariesStatuses.find(\n (ds) => ds.dictionaryKey === dictionaryKey\n );\n if (statusObj) {\n const state = statusObj.state.find((s) => s.type === type);\n if (state) {\n // Update existing state\n Object.assign(state, status);\n } else {\n // If the state for this type doesn't exist yet, add it\n if (status.status === undefined) {\n status.status = 'pending'; // Provide default status\n }\n const newState: State = {\n type,\n status: status.status,\n icon: status.icon ?? '',\n error: status.error,\n errorMessage: status.errorMessage,\n spinnerFrameIndex: status.spinnerFrameIndex ?? 0,\n };\n statusObj.state.push(newState);\n }\n } else {\n // If the status object doesn't exist, create it\n const newState: State = {\n type,\n status: status.status ?? 'pending',\n icon: status.icon ?? '',\n error: status.error,\n errorMessage: status.errorMessage,\n spinnerFrameIndex: status.spinnerFrameIndex ?? 0,\n };\n this.dictionariesStatuses.push({\n dictionaryKey,\n state: [newState],\n });\n }\n\n // Update the display after status change\n this.updateAllStatusLines();\n }\n\n private getStatusIcon(status: string): string {\n const statusIcons: Record<string, string> = {\n pending: '⏲',\n fetching: '', // Spinner handled separately\n built: '✔',\n imported: '✔',\n error: '✖',\n };\n return statusIcons[status] ?? '';\n }\n\n private getStatusLine(statusObj: DictionariesStatus): string {\n const keyPadding =\n this.maxDictionaryKeyLength - statusObj.dictionaryKey.length;\n const paddedKey = `${statusObj.dictionaryKey}${' '.repeat(keyPadding)}`;\n\n const states = statusObj.state.map((state) => {\n let colorStart = '';\n let colorEnd = '';\n let icon = this.getStatusIcon(state.status);\n if (state.status === 'fetching') {\n // Use spinner frame\n icon =\n this.spinnerFrames[\n state.spinnerFrameIndex! % this.spinnerFrames.length\n ];\n colorStart = this.BLUE;\n colorEnd = this.RESET;\n } else if (state.status === 'error') {\n colorStart = this.RED;\n colorEnd = this.RESET;\n } else if (state.status === 'imported' || state.status === 'built') {\n colorStart = this.GREEN;\n colorEnd = this.RESET;\n } else {\n colorStart = this.GREY;\n colorEnd = this.RESET;\n }\n\n // Format the status block\n const statusBlock = `${this.GREY_DARK}[${state.type}: ${colorStart}${icon} ${state.status}${this.GREY_DARK}]${colorEnd}`;\n\n return `${colorStart}${statusBlock}${colorEnd}`;\n });\n\n return `- ${paddedKey} ${states.join(' ')}`;\n }\n\n private updateAllStatusLines() {\n const lines = this.dictionariesStatuses.map((statusObj) => {\n statusObj.state.forEach((state) => {\n if (state.status === 'fetching') {\n // Update spinner frame\n state.spinnerFrameIndex =\n (state.spinnerFrameIndex! + 1) % this.spinnerFrames.length;\n }\n });\n return this.getStatusLine(statusObj);\n });\n\n logUpdate(lines.join('\\n'));\n }\n\n public getStatuses() {\n return this.dictionariesStatuses;\n }\n}\n\nexport const logger = Logger.getInstance();\n"],"mappings":"AAAA,OAAO,eAAe;AACtB,SAAS,0BAA0B;AAgBnC,MAAM,OAAO;AAAA,EACH,uBAA6C,CAAC;AAAA,EAC9C,gBAAgB,CAAC,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,QAAG;AAAA,EACjE,eAAsC;AAAA,EACtC,yBAAiC;AAAA;AAAA,EAGjC,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,OAAO;AAAA,EACP,OAAO;AAAA,EACP,YAAY;AAAA;AAAA,EAGpB,OAAe;AAAA,EAEP,cAAc;AAAA,EAAC;AAAA,EAEvB,OAAc,cAAsB;AAClC,QAAI,CAAC,OAAO,UAAU;AACpB,aAAO,WAAW,IAAI,OAAO;AAAA,IAC/B;AACA,WAAO,OAAO;AAAA,EAChB;AAAA,EAEO,KACL,uBACA,yBACA;AACA,UAAM,UAAU,MAAM;AAAA,MACpB,IAAI;AAAA,QACF,CAAC,GAAG,uBAAuB,GAAG,uBAAuB,EAAE;AAAA,UACrD;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,SAAK,yBAAyB,QAAQ;AAAA,MACpC,CAAC,KAAK,QAAS,IAAI,SAAS,MAAM,IAAI,SAAS;AAAA,MAC/C;AAAA,IACF;AAEA,SAAK,uBAAuB,QAAQ,IAAI,CAAC,kBAAkB;AACzD,YAAM,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YAAI,MAAM,WAAW,YAAY;AAE/B,gBAAM,qBACH,MAAM,oBAAqB,KAAK,KAAK,cAAc;AAAA,QACxD;AAAA,MACF,CAAC;AACD,aAAO,KAAK,cAAc,SAAS;AAAA,IACrC,CAAC;AAED,cAAU,MAAM,KAAK,IAAI,CAAC;AAAA,EAC5B;AAAA,EAEO,cAAc;AACnB,WAAO,KAAK;AAAA,EACd;AACF;AAEO,MAAM,SAAS,OAAO,YAAY;","names":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, writeFileSync } from "fs";
|
|
2
2
|
import { basename, extname, relative, resolve } from "path";
|
|
3
3
|
import { getConfiguration } from "@intlayer/config";
|
|
4
|
-
import
|
|
4
|
+
import fg from "fast-glob";
|
|
5
5
|
import { getFileHash } from '../../utils.mjs';
|
|
6
6
|
const { content } = getConfiguration();
|
|
7
7
|
const { dictionariesDir, mainDir } = content;
|
|
@@ -40,7 +40,7 @@ const createDictionaryList = () => {
|
|
|
40
40
|
if (!existsSync(mainDir)) {
|
|
41
41
|
mkdirSync(mainDir, { recursive: true });
|
|
42
42
|
}
|
|
43
|
-
const dictionaries = sync(`${dictionariesDir}/**/*.json`);
|
|
43
|
+
const dictionaries = fg.sync(`${dictionariesDir}/**/*.json`);
|
|
44
44
|
const cjsContent = generateDictionaryListContent(dictionaries, "cjs");
|
|
45
45
|
writeFileSync(resolve(mainDir, "dictionaries.cjs"), cjsContent);
|
|
46
46
|
const esmContent = generateDictionaryListContent(dictionaries, "esm");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/transpiler/dictionary_to_main/createDictionaryList.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { basename, extname, relative, resolve } from 'path';\nimport { getConfiguration } from '@intlayer/config';\nimport
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/dictionary_to_main/createDictionaryList.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { basename, extname, relative, resolve } from 'path';\nimport { getConfiguration } from '@intlayer/config';\nimport fg from 'fast-glob';\nimport { getFileHash } from '../../utils';\n\nconst { content } = getConfiguration();\nconst { dictionariesDir, mainDir } = content;\n\n/**\n * This function generates the content of the dictionary list file\n */\nconst generateDictionaryListContent = (\n dictionaries: string[],\n format: 'cjs' | 'esm' = 'esm'\n): string => {\n let content = '';\n\n const dictionariesRef = dictionaries.map((dictionaryPath) => ({\n relativePath: relative(mainDir, dictionaryPath),\n id: basename(dictionaryPath, extname(dictionaryPath)), // Get the base name as the dictionary id\n hash: `_${getFileHash(dictionaryPath)}`, // Get the hash of the dictionary to avoid conflicts\n }));\n\n // Import all dictionaries\n dictionariesRef.forEach((dictionary) => {\n if (format === 'esm')\n content += `import ${dictionary.hash} from '${dictionary.relativePath}';\\n`;\n if (format === 'cjs')\n content += `const ${dictionary.hash} = require('${dictionary.relativePath}');\\n`;\n });\n\n content += '\\n';\n\n // Format Dictionary Map\n const formattedDictionaryMap: string = dictionariesRef\n .map((dictionary) => `\"${dictionary.id}\": ${dictionary.hash}`)\n .join(',\\n');\n\n if (format === 'esm')\n content += `export default {\\n${formattedDictionaryMap}\\n};\\n`;\n if (format === 'cjs')\n content += `module.exports = {\\n${formattedDictionaryMap}\\n};\\n`;\n\n return content;\n};\n\n/**\n * This function generates a list of dictionaries in the main directory\n */\nexport const createDictionaryList = () => {\n // Create main directory if it doesn't exist\n if (!existsSync(mainDir)) {\n mkdirSync(mainDir, { recursive: true });\n }\n\n const dictionaries: string[] = fg.sync(`${dictionariesDir}/**/*.json`);\n\n // Create the dictionary list file\n const cjsContent = generateDictionaryListContent(dictionaries, 'cjs');\n writeFileSync(resolve(mainDir, 'dictionaries.cjs'), cjsContent);\n\n const esmContent = generateDictionaryListContent(dictionaries, 'esm');\n writeFileSync(resolve(mainDir, 'dictionaries.mjs'), esmContent);\n};\n"],"mappings":"AAAA,SAAS,YAAY,WAAW,qBAAqB;AACrD,SAAS,U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,QAAQ,SAAS,kBAAkB,GAAG,UAAU;AAChE;","names":["content"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, writeFileSync } from "fs";
|
|
2
2
|
import { basename, join, relative } from "path";
|
|
3
3
|
import { Locales, getConfiguration } from "@intlayer/config";
|
|
4
|
-
import
|
|
4
|
+
import fg from "fast-glob";
|
|
5
5
|
import { getFileHash, transformToCamelCase } from '../../utils.mjs';
|
|
6
6
|
const { content, internationalization } = getConfiguration();
|
|
7
7
|
const { typesDir, moduleAugmentationDir } = content;
|
|
@@ -54,7 +54,7 @@ const createModuleAugmentation = () => {
|
|
|
54
54
|
if (!existsSync(moduleAugmentationDir)) {
|
|
55
55
|
mkdirSync(moduleAugmentationDir, { recursive: true });
|
|
56
56
|
}
|
|
57
|
-
const dictionaries = sync(`${typesDir}/**/*.d.ts`);
|
|
57
|
+
const dictionaries = fg.sync(`${typesDir}/**/*.d.ts`);
|
|
58
58
|
const tsContent = generateTypeIndexContent(dictionaries);
|
|
59
59
|
writeFileSync(join(moduleAugmentationDir, "intlayer.d.ts"), tsContent);
|
|
60
60
|
};
|
|
@@ -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
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/dictionary_to_type/createModuleAugmentation.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { basename, join, relative } from 'path';\nimport { Locales, getConfiguration } from '@intlayer/config';\nimport fg from 'fast-glob';\nimport { getFileHash, transformToCamelCase } from '../../utils';\n\nconst { content, internationalization } = getConfiguration();\nconst { typesDir, moduleAugmentationDir } = content;\nconst { locales, strictMode } = internationalization;\n\nexport const getTypeName = (id: string): string =>\n transformToCamelCase(`${id}Content`);\n\n/**\n * This function generates the content of the module augmentation file\n */\nconst generateTypeIndexContent = (typeFiles: string[]): string => {\n let content = \"/* eslint-disable */\\nimport { Locales } from 'intlayer';\\n\";\n\n const dictionariesRef = typeFiles.map((dictionaryPath) => ({\n relativePath: relative(moduleAugmentationDir, dictionaryPath),\n id: basename(dictionaryPath, '.d.ts'), // Get the base name as the dictionary id\n hash: `_${getFileHash(dictionaryPath)}`, // Get the hash of the dictionary to avoid conflicts\n }));\n\n // Import all dictionaries\n dictionariesRef.forEach((dictionary) => {\n const typeName = getTypeName(dictionary.id);\n content += `import type { ${typeName} as ${dictionary.hash} } from '${dictionary.relativePath}';\\n`;\n });\n\n content += '\\n';\n\n // Format Dictionary Map\n const formattedDictionaryMap: string = dictionariesRef\n .map((dictionary) => ` \"${dictionary.id}\": ${dictionary.hash};`)\n .join('\\n');\n\n const formatLocales = locales\n .map((locale) => {\n for (const key in Locales) {\n if (Locales[key as keyof typeof Locales] === locale) {\n return `Locales.${key}`;\n }\n }\n })\n .join(' | ');\n\n const strictModeRecord =\n strictMode === 'strict'\n ? `interface IConfigLocales<Content> extends Record<ExtractedLocales, Content> {}`\n : strictMode === 'required_only'\n ? `interface IConfigLocales<Content> extends Record<ExtractedLocales, Content>, Partial<Record<ExcludedLocales, Content>> {}`\n : `interface IConfigLocales<Content> extends Partial<Record<Locales, Content>> {}`;\n\n /**\n * Write the module augmentation to extend the intlayer module with the dictionaries types\n * Will suggest the type resulting of the dictionaries\n *\n * declare module 'intlayer' {\n * interface IntlayerDictionaryTypesConnector = {\n * dictionaries: {\n * id: DictionaryType;\n * }\n * }\n *\n * type ConfigLocales = Locales.ENGLISH | Locales.FRENCH | Locales.SPANISH;\n * type ExtractedLocales = Extract<Locales, ConfigLocales>;\n * type ExcludedLocales = Exclude<Locales, ConfigLocales>;\n *\n * interface IConfigLocales<Content> extends Record<ExtractedLocales, Content>, Partial<Record<ExcludedLocales, Content>> {}\n *\n *\n * }\n * See https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation\n */\n content += `declare module 'intlayer' {\\n`;\n content += ` interface IntlayerDictionaryTypesConnector {\\n${formattedDictionaryMap}\\n }\\n\\n`;\n content += ` type ConfigLocales = ${formatLocales};\\n`;\n content += ` type ExtractedLocales = Extract<Locales, ConfigLocales>;\\n`;\n content += ` type ExcludedLocales = Exclude<Locales, ConfigLocales>;\\n\\n`;\n content += ` ${strictModeRecord}\\n`;\n content += `}`;\n\n return content;\n};\n\n/**\n * This function generates a index file merging all the types\n */\nexport const createModuleAugmentation = () => {\n // Create main directory if it doesn't exist\n if (!existsSync(moduleAugmentationDir)) {\n mkdirSync(moduleAugmentationDir, { recursive: true });\n }\n\n const dictionaries: string[] = fg.sync(`${typesDir}/**/*.d.ts`);\n // Create the dictionary list file\n\n const tsContent = generateTypeIndexContent(dictionaries);\n writeFileSync(join(moduleAugmentationDir, 'intlayer.d.ts'), tsContent);\n};\n"],"mappings":"AAAA,SAAS,YAAY,WAAW,qBAAqB;AACrD,SAAS,UAAU,MAAM,gBAAgB;AACzC,SAAS,SAAS,wBAAwB;AAC1C,OAAO,QAAQ;AACf,SAAS,aAAa,4BAA4B;AAElD,MAAM,EAAE,SAAS,qBAAqB,IAAI,iBAAiB;AAC3D,MAAM,EAAE,UAAU,sBAAsB,IAAI;AAC5C,MAAM,EAAE,SAAS,WAAW,IAAI;AAEzB,MAAM,cAAc,CAAC,OAC1B,qBAAqB,GAAG,EAAE,SAAS;AAKrC,MAAM,2BAA2B,CAAC,cAAgC;AAChE,MAAIA,WAAU;AAEd,QAAM,kBAAkB,UAAU,IAAI,CAAC,oBAAoB;AAAA,IACzD,cAAc,SAAS,uBAAuB,cAAc;AAAA,IAC5D,IAAI,SAAS,gBAAgB,OAAO;AAAA;AAAA,IACpC,MAAM,IAAI,YAAY,cAAc,CAAC;AAAA;AAAA,EACvC,EAAE;AAGF,kBAAgB,QAAQ,CAAC,eAAe;AACtC,UAAM,WAAW,YAAY,WAAW,EAAE;AAC1C,IAAAA,YAAW,iBAAiB,QAAQ,OAAO,WAAW,IAAI,YAAY,WAAW,YAAY;AAAA;AAAA,EAC/F,CAAC;AAED,EAAAA,YAAW;AAGX,QAAM,yBAAiC,gBACpC,IAAI,CAAC,eAAe,QAAQ,WAAW,EAAE,MAAM,WAAW,IAAI,GAAG,EACjE,KAAK,IAAI;AAEZ,QAAM,gBAAgB,QACnB,IAAI,CAAC,WAAW;AACf,eAAW,OAAO,SAAS;AACzB,UAAI,QAAQ,GAA2B,MAAM,QAAQ;AACnD,eAAO,WAAW,GAAG;AAAA,MACvB;AAAA,IACF;AAAA,EACF,CAAC,EACA,KAAK,KAAK;AAEb,QAAM,mBACJ,eAAe,WACX,mFACA,eAAe,kBACb,8HACA;AAuBR,EAAAA,YAAW;AAAA;AACX,EAAAA,YAAW;AAAA,EAAmD,sBAAsB;AAAA;AAAA;AAAA;AACpF,EAAAA,YAAW,0BAA0B,aAAa;AAAA;AAClD,EAAAA,YAAW;AAAA;AACX,EAAAA,YAAW;AAAA;AAAA;AACX,EAAAA,YAAW,KAAK,gBAAgB;AAAA;AAChC,EAAAA,YAAW;AAEX,SAAOA;AACT;AAKO,MAAM,2BAA2B,MAAM;AAE5C,MAAI,CAAC,WAAW,qBAAqB,GAAG;AACtC,cAAU,uBAAuB,EAAE,WAAW,KAAK,CAAC;AAAA,EACtD;AAEA,QAAM,eAAyB,GAAG,KAAK,GAAG,QAAQ,YAAY;AAG9D,QAAM,YAAY,yBAAyB,YAAY;AACvD,gBAAc,KAAK,uBAAuB,eAAe,GAAG,SAAS;AACvE;","names":["content"]}
|
package/dist/esm/utils.mjs
CHANGED
|
@@ -13,8 +13,10 @@ const transformToCamelCase = (string) => {
|
|
|
13
13
|
});
|
|
14
14
|
return camelCasedWords.join("");
|
|
15
15
|
};
|
|
16
|
+
const sortAlphabetically = (a, b) => a.localeCompare(b);
|
|
16
17
|
export {
|
|
17
18
|
getFileHash,
|
|
19
|
+
sortAlphabetically,
|
|
18
20
|
transformToCamelCase
|
|
19
21
|
};
|
|
20
22
|
//# sourceMappingURL=utils.mjs.map
|
package/dist/esm/utils.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils.ts"],"sourcesContent":["import crypto from 'crypto-js';\n\nexport const getFileHash = (filePath: string) => {\n const hash = crypto.SHA3(filePath);\n\n return hash\n .toString(crypto.enc.Base64)\n .replace(/[^A-Z\\d]/gi, '')\n .substring(0, 20);\n};\n\nexport const transformToCamelCase = (string: string): string => {\n // Split the string into words using a regex that finds spaces, hyphens, and underscores\n const words = string.split(/[\\s\\-_]+/);\n\n // Transform each word except the first to have its first letter uppercase\n const camelCasedWords = words.map((word, index) => {\n if (index === 0) {\n return word[0].toUpperCase() + word.slice(1);\n }\n return word.charAt(0).toUpperCase() + word.slice(1);\n });\n\n // Join the words back together\n return camelCasedWords.join('');\n};\n"],"mappings":"AAAA,OAAO,YAAY;AAEZ,MAAM,cAAc,CAAC,aAAqB;AAC/C,QAAM,OAAO,OAAO,KAAK,QAAQ;AAEjC,SAAO,KACJ,SAAS,OAAO,IAAI,MAAM,EAC1B,QAAQ,cAAc,EAAE,EACxB,UAAU,GAAG,EAAE;AACpB;AAEO,MAAM,uBAAuB,CAAC,WAA2B;AAE9D,QAAM,QAAQ,OAAO,MAAM,UAAU;AAGrC,QAAM,kBAAkB,MAAM,IAAI,CAAC,MAAM,UAAU;AACjD,QAAI,UAAU,GAAG;AACf,aAAO,KAAK,CAAC,EAAE,YAAY,IAAI,KAAK,MAAM,CAAC;AAAA,IAC7C;AACA,WAAO,KAAK,OAAO,CAAC,EAAE,YAAY,IAAI,KAAK,MAAM,CAAC;AAAA,EACpD,CAAC;AAGD,SAAO,gBAAgB,KAAK,EAAE;AAChC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/utils.ts"],"sourcesContent":["import crypto from 'crypto-js';\n\nexport const getFileHash = (filePath: string) => {\n const hash = crypto.SHA3(filePath);\n\n return hash\n .toString(crypto.enc.Base64)\n .replace(/[^A-Z\\d]/gi, '')\n .substring(0, 20);\n};\n\nexport const transformToCamelCase = (string: string): string => {\n // Split the string into words using a regex that finds spaces, hyphens, and underscores\n const words = string.split(/[\\s\\-_]+/);\n\n // Transform each word except the first to have its first letter uppercase\n const camelCasedWords = words.map((word, index) => {\n if (index === 0) {\n return word[0].toUpperCase() + word.slice(1);\n }\n return word.charAt(0).toUpperCase() + word.slice(1);\n });\n\n // Join the words back together\n return camelCasedWords.join('');\n};\n\nexport const sortAlphabetically = (a: string, b: string) => a.localeCompare(b);\n"],"mappings":"AAAA,OAAO,YAAY;AAEZ,MAAM,cAAc,CAAC,aAAqB;AAC/C,QAAM,OAAO,OAAO,KAAK,QAAQ;AAEjC,SAAO,KACJ,SAAS,OAAO,IAAI,MAAM,EAC1B,QAAQ,cAAc,EAAE,EACxB,UAAU,GAAG,EAAE;AACpB;AAEO,MAAM,uBAAuB,CAAC,WAA2B;AAE9D,QAAM,QAAQ,OAAO,MAAM,UAAU;AAGrC,QAAM,kBAAkB,MAAM,IAAI,CAAC,MAAM,UAAU;AACjD,QAAI,UAAU,GAAG;AACf,aAAO,KAAK,CAAC,EAAE,YAAY,IAAI,KAAK,MAAM,CAAC;AAAA,IAC7C;AACA,WAAO,KAAK,OAAO,CAAC,EAAE,YAAY,IAAI,KAAK,MAAM,CAAC;AAAA,EACpD,CAAC;AAGD,SAAO,gBAAgB,KAAK,EAAE;AAChC;AAEO,MAAM,qBAAqB,CAAC,GAAW,MAAc,EAAE,cAAc,CAAC;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"watcher.d.ts","sourceRoot":"","sources":["../../../src/chokidar/watcher.ts"],"names":[],"mappings":"AAEA,2FAA2F;AAC3F,OAAO,EAAE,KAAK,eAAe,EAA0B,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"watcher.d.ts","sourceRoot":"","sources":["../../../src/chokidar/watcher.ts"],"names":[],"mappings":"AAEA,2FAA2F;AAC3F,OAAO,EAAE,KAAK,eAAe,EAA0B,MAAM,UAAU,CAAC;AAexE,eAAO,MAAM,KAAK,aAAc,eAAe,QA+D9C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cleanOutputDir.d.ts","sourceRoot":"","sources":["../../src/cleanOutputDir.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,cAAc,YAY1B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadDictionaries.d.ts","sourceRoot":"","sources":["../../../src/loadDictionaries/loadDictionaries.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"loadDictionaries.d.ts","sourceRoot":"","sources":["../../../src/loadDictionaries/loadDictionaries.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAW5C,eAAO,MAAM,gBAAgB,6BACD,MAAM,EAAE,GAAG,MAAM,KAC1C,OAAO,CAAC,UAAU,EAAE,CAkEtB,CAAC"}
|
package/dist/types/log.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../../src/log.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../../src/log.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,KAAK,GAAG;IAClB,IAAI,EAAE,OAAO,GAAG,SAAS,CAAC;IAC1B,MAAM,EAAE,SAAS,GAAG,UAAU,GAAG,SAAS,GAAG,OAAO,GAAG,UAAU,GAAG,OAAO,CAAC;IAC5E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,k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"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,WAAW,aAAc,MAAM,WAO3C,CAAC;AAEF,eAAO,MAAM,oBAAoB,WAAY,MAAM,KAAG,MAcrD,CAAC;AAEF,eAAO,MAAM,kBAAkB,MAAO,MAAM,KAAK,MAAM,WAAuB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/chokidar",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Chokidar application for IntLayer - Transpile IntLayer declaration files into dictionaries.",
|
|
6
6
|
"keywords": [
|
|
@@ -61,41 +61,42 @@
|
|
|
61
61
|
"deepmerge": "^4.3.1",
|
|
62
62
|
"esbuild": "^0.24.0",
|
|
63
63
|
"esbuild-loader": "^4.2.2",
|
|
64
|
-
"glob": "^
|
|
64
|
+
"fast-glob": "^3.3.2",
|
|
65
|
+
"log-update": "^6.1.0",
|
|
65
66
|
"node-loader": "^2.1.0",
|
|
66
67
|
"p-limit": "^3.1.0",
|
|
67
68
|
"quicktype-core": "^23.0.170",
|
|
68
69
|
"react": "^18.3.1",
|
|
69
70
|
"rimraf": "^6.0.1",
|
|
70
|
-
"@intlayer/backend": "^3.
|
|
71
|
-
"@intlayer/config": "^3.
|
|
72
|
-
"@intlayer/core": "^3.
|
|
73
|
-
"@intlayer/design-system": "^3.
|
|
74
|
-
"intlayer": "^3.
|
|
71
|
+
"@intlayer/backend": "^3.3.3",
|
|
72
|
+
"@intlayer/config": "^3.3.3",
|
|
73
|
+
"@intlayer/core": "^3.3.3",
|
|
74
|
+
"@intlayer/design-system": "^3.3.3",
|
|
75
|
+
"intlayer": "^3.3.3"
|
|
75
76
|
},
|
|
76
77
|
"devDependencies": {
|
|
77
|
-
"@changesets/cli": "2.27.
|
|
78
|
+
"@changesets/cli": "2.27.10",
|
|
78
79
|
"@types/crypto-js": "^4.2.2",
|
|
79
|
-
"@types/node": "^22.
|
|
80
|
+
"@types/node": "^22.10.1",
|
|
80
81
|
"concurrently": "^9.1.0",
|
|
81
|
-
"eslint": "^9.
|
|
82
|
+
"eslint": "^9.16.0",
|
|
82
83
|
"node-polyfill-webpack-plugin": "^4.0.0",
|
|
83
|
-
"prettier": "^3.
|
|
84
|
+
"prettier": "^3.4.1",
|
|
84
85
|
"tsc-alias": "^1.8.10",
|
|
85
86
|
"tsup": "^8.3.5",
|
|
86
|
-
"typescript": "^5.
|
|
87
|
+
"typescript": "^5.7.2",
|
|
87
88
|
"webpack-watch-files-plugin": "^1.2.1",
|
|
88
|
-
"@utils/ts-config": "^1.0.4",
|
|
89
89
|
"@utils/eslint-config": "^1.0.4",
|
|
90
|
+
"@utils/ts-config-types": "^1.0.4",
|
|
90
91
|
"@utils/tsup-config": "^1.0.4",
|
|
91
|
-
"@utils/ts-config
|
|
92
|
+
"@utils/ts-config": "^1.0.4"
|
|
92
93
|
},
|
|
93
94
|
"peerDependencies": {
|
|
94
|
-
"@intlayer/backend": "^3.
|
|
95
|
-
"@intlayer/config": "^3.
|
|
96
|
-
"@intlayer/
|
|
97
|
-
"@intlayer/
|
|
98
|
-
"intlayer": "^3.
|
|
95
|
+
"@intlayer/backend": "^3.3.3",
|
|
96
|
+
"@intlayer/config": "^3.3.3",
|
|
97
|
+
"@intlayer/core": "^3.3.3",
|
|
98
|
+
"@intlayer/design-system": "^3.3.3",
|
|
99
|
+
"intlayer": "^3.3.3"
|
|
99
100
|
},
|
|
100
101
|
"engines": {
|
|
101
102
|
"node": ">=14.18"
|