@intlayer/chokidar 3.5.3 → 3.5.4
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 +14 -6
- package/dist/cjs/chokidar/watcher.cjs.map +1 -1
- package/dist/cjs/fetchDistantDictionaries.cjs.map +1 -1
- package/dist/cjs/getDictionariesPath.cjs +50 -0
- package/dist/cjs/getDictionariesPath.cjs.map +1 -0
- package/dist/cjs/transpiler/dictionary_to_main/createDictionaryList.cjs +5 -15
- package/dist/cjs/transpiler/dictionary_to_main/createDictionaryList.cjs.map +1 -1
- package/dist/esm/chokidar/watcher.mjs +14 -6
- package/dist/esm/chokidar/watcher.mjs.map +1 -1
- package/dist/esm/fetchDistantDictionaries.mjs.map +1 -1
- package/dist/esm/getDictionariesPath.mjs +16 -0
- package/dist/esm/getDictionariesPath.mjs.map +1 -0
- package/dist/esm/transpiler/dictionary_to_main/createDictionaryList.mjs +5 -5
- package/dist/esm/transpiler/dictionary_to_main/createDictionaryList.mjs.map +1 -1
- package/dist/types/chokidar/watcher.d.ts.map +1 -1
- package/dist/types/getDictionariesPath.d.ts +5 -0
- package/dist/types/getDictionariesPath.d.ts.map +1 -0
- package/package.json +14 -13
|
@@ -36,6 +36,7 @@ var import_config = require("@intlayer/config");
|
|
|
36
36
|
var import_chokidar = require("chokidar");
|
|
37
37
|
var import_fast_glob = __toESM(require("fast-glob"));
|
|
38
38
|
var import_cleanOutputDir = require('../cleanOutputDir.cjs');
|
|
39
|
+
var import_getDictionariesPath = require('../getDictionariesPath.cjs');
|
|
39
40
|
var import_loadDictionaries = require('../loadDictionaries/loadDictionaries.cjs');
|
|
40
41
|
var import_loadLocalDictionaries = require('../loadDictionaries/loadLocalDictionaries.cjs');
|
|
41
42
|
var import_declaration_file_to_dictionary = require('../transpiler/declaration_file_to_dictionary/index.cjs');
|
|
@@ -62,24 +63,31 @@ const watch = (options) => {
|
|
|
62
63
|
console.info(
|
|
63
64
|
`${LOG_PREFIX}${dictionariesPaths.length} dictionaries built`
|
|
64
65
|
);
|
|
65
|
-
(0, import_dictionary_to_type.createModuleAugmentation)();
|
|
66
66
|
(0, import_createDictionaryList.createDictionaryList)();
|
|
67
|
+
(0, import_dictionary_to_type.createModuleAugmentation)();
|
|
67
68
|
}).on("add", async (filePath) => {
|
|
68
69
|
console.info(
|
|
69
70
|
`${LOG_PREFIX}Additional file detected: `,
|
|
70
71
|
(0, import_path.relative)(baseDir, filePath)
|
|
71
72
|
);
|
|
72
73
|
const localeDictionaries = await (0, import_loadLocalDictionaries.loadLocalDictionaries)(filePath);
|
|
73
|
-
const
|
|
74
|
-
await (0, import_dictionary_to_type.createTypes)(
|
|
75
|
-
(0, import_dictionary_to_type.createModuleAugmentation)();
|
|
74
|
+
const dictionariesPaths = await (0, import_declaration_file_to_dictionary.buildDictionary)(localeDictionaries);
|
|
75
|
+
await (0, import_dictionary_to_type.createTypes)(dictionariesPaths);
|
|
76
76
|
(0, import_createDictionaryList.createDictionaryList)();
|
|
77
|
+
(0, import_dictionary_to_type.createModuleAugmentation)();
|
|
77
78
|
}).on("change", async (filePath) => {
|
|
78
79
|
console.info("Change detected: ", (0, import_path.relative)(baseDir, filePath));
|
|
79
80
|
const localeDictionaries = await (0, import_loadLocalDictionaries.loadLocalDictionaries)(filePath);
|
|
80
|
-
const
|
|
81
|
-
|
|
81
|
+
const updatedDictionariesPaths = await (0, import_declaration_file_to_dictionary.buildDictionary)(localeDictionaries);
|
|
82
|
+
const allDictionariesPaths = (0, import_getDictionariesPath.getDictionariesPath)();
|
|
83
|
+
await (0, import_dictionary_to_type.createTypes)(updatedDictionariesPaths);
|
|
82
84
|
console.info(`${LOG_PREFIX}TypeScript types built`);
|
|
85
|
+
if (updatedDictionariesPaths.some(
|
|
86
|
+
(updatedDictionaryPath) => allDictionariesPaths.includes(updatedDictionaryPath)
|
|
87
|
+
)) {
|
|
88
|
+
(0, import_createDictionaryList.createDictionaryList)();
|
|
89
|
+
(0, import_dictionary_to_type.createModuleAugmentation)();
|
|
90
|
+
}
|
|
83
91
|
}).on("error", (error) => {
|
|
84
92
|
console.error("Watcher error:", error);
|
|
85
93
|
});
|
|
@@ -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 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, watch: isWatchMode } = content;\n\n const files: string[] = fg.sync(watchedFilesPatternWithPath);\n\n /** @ts-ignore remove error Expected 0-1 arguments, but got 2. */\n return chokidarWatch(watchedFilesPatternWithPath, {\n persistent: isWatchMode, // Make the watcher persistent\n ignoreInitial: true, // Process existing files\n ...options,\n })\n .on('ready', async () => {\n cleanOutputDir();\n\n 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
|
|
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 { getDictionariesPath } from '../getDictionariesPath';\nimport { loadDictionaries } from '../loadDictionaries/loadDictionaries';\nimport { loadLocalDictionaries } from '../loadDictionaries/loadLocalDictionaries';\nimport { buildDictionary } from '../transpiler/declaration_file_to_dictionary/index';\nimport { createDictionaryList } from '../transpiler/dictionary_to_main/createDictionaryList';\nimport {\n createTypes,\n createModuleAugmentation,\n} from '../transpiler/dictionary_to_type/index';\n\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, watch: isWatchMode } = content;\n\n const files: string[] = fg.sync(watchedFilesPatternWithPath);\n\n /** @ts-ignore remove error Expected 0-1 arguments, but got 2. */\n return chokidarWatch(watchedFilesPatternWithPath, {\n persistent: isWatchMode, // Make the watcher persistent\n ignoreInitial: true, // Process existing files\n ...options,\n })\n .on('ready', async () => {\n cleanOutputDir();\n\n 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 createDictionaryList();\n createModuleAugmentation();\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 dictionariesPaths = await buildDictionary(localeDictionaries);\n\n await createTypes(dictionariesPaths);\n\n createDictionaryList();\n createModuleAugmentation();\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 updatedDictionariesPaths =\n await buildDictionary(localeDictionaries);\n const allDictionariesPaths: string[] = getDictionariesPath();\n\n await createTypes(updatedDictionariesPaths);\n console.info(`${LOG_PREFIX}TypeScript types built`);\n\n if (\n updatedDictionariesPaths.some((updatedDictionaryPath) =>\n allDictionariesPaths.includes(updatedDictionaryPath)\n )\n ) {\n createDictionaryList();\n createModuleAugmentation();\n }\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,iCAAoC;AACpC,8BAAiC;AACjC,mCAAsC;AACtC,4CAAgC;AAChC,kCAAqC;AACrC,gCAGO;AAEP,MAAM,aAAa;AAGZ,MAAM,QAAQ,CAAC,YAA8B;AAClD,QAAM,EAAE,QAAQ,QAAI,gCAAiB;AAAA,IACnC,SAAS;AAAA,EACX,CAAC;AAED,QAAM,EAAE,6BAA6B,SAAS,OAAO,YAAY,IAAI;AAErE,QAAM,QAAkB,iBAAAA,QAAG,KAAK,2BAA2B;AAG3D,aAAO,gBAAAC,OAAc,6BAA6B;AAAA,IAChD,YAAY;AAAA;AAAA,IACZ,eAAe;AAAA;AAAA,IACf,GAAG;AAAA,EACL,CAAC,EACE,GAAG,SAAS,YAAY;AACvB,8CAAe;AAEf,UAAM,eAAe,UAAM,0CAAiB,KAAK;AAGjD,UAAM,oBAAoB,UAAM,uDAAgB,YAAY;AAE5D,cAAM,uCAAY,iBAAiB;AAEnC,YAAQ;AAAA,MACN,GAAG,UAAU,GAAG,kBAAkB,MAAM;AAAA,IAC1C;AAEA,0DAAqB;AACrB,4DAAyB;AAAA,EAC3B,CAAC,EACA,GAAG,OAAO,OAAO,aAAa;AAE7B,YAAQ;AAAA,MACN,GAAG,UAAU;AAAA,UACb,sBAAS,SAAS,QAAQ;AAAA,IAC5B;AAEA,UAAM,qBAAqB,UAAM,oDAAsB,QAAQ;AAE/D,UAAM,oBAAoB,UAAM,uDAAgB,kBAAkB;AAElE,cAAM,uCAAY,iBAAiB;AAEnC,0DAAqB;AACrB,4DAAyB;AAAA,EAC3B,CAAC,EACA,GAAG,UAAU,OAAO,aAAa;AAEhC,YAAQ,KAAK,yBAAqB,sBAAS,SAAS,QAAQ,CAAC;AAE7D,UAAM,qBAAqB,UAAM,oDAAsB,QAAQ;AAC/D,UAAM,2BACJ,UAAM,uDAAgB,kBAAkB;AAC1C,UAAM,2BAAiC,gDAAoB;AAE3D,cAAM,uCAAY,wBAAwB;AAC1C,YAAQ,KAAK,GAAG,UAAU,wBAAwB;AAElD,QACE,yBAAyB;AAAA,MAAK,CAAC,0BAC7B,qBAAqB,SAAS,qBAAqB;AAAA,IACrD,GACA;AACA,4DAAqB;AACrB,8DAAyB;AAAA,IAC3B;AAAA,EACF,CAAC,EACA,GAAG,SAAS,CAAC,UAAU;AACtB,YAAQ,MAAM,kBAAkB,KAAK;AAAA,EACvC,CAAC;AACL;","names":["fg","chokidarWatch"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/fetchDistantDictionaries.ts"],"sourcesContent":["// @ts-ignore @intlayer/backend not build yet\nimport { type DictionaryAPI } from '@intlayer/backend';\nimport { getConfiguration } from '@intlayer/config';\n// @ts-ignore @intlayer/design-system not build yet\nimport { getIntlayerAPI } from '@intlayer/design-system/libs';\nimport pLimit from 'p-limit';\nimport { logger } from './log';\n\ntype FetchDistantDictionariesOptions = {\n dictionaryKeys: string[];\n newDictionariesPath?: string;\n logPrefix?: string;\n};\n\n/**\n * Fetch distant dictionaries and update the logger with their statuses.\n */\nexport const fetchDistantDictionaries = async (\n options: FetchDistantDictionariesOptions\n): Promise<DictionaryAPI[]> => {\n try {\n const config = getConfiguration();\n const { clientId, clientSecret } = config.editor;\n const intlayerAPI = getIntlayerAPI(undefined, config);\n\n if (!clientId || !clientSecret) {\n throw new Error(\n 'Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project.'\n );\n }\n\n const oAuth2TokenResult = await intlayerAPI.auth.getOAuth2AccessToken();\n\n const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;\n\n const distantDictionariesKeys = options.dictionaryKeys;\n\n // Process dictionaries in parallel with a concurrency limit\n const limit = pLimit(5); //
|
|
1
|
+
{"version":3,"sources":["../../src/fetchDistantDictionaries.ts"],"sourcesContent":["// @ts-ignore @intlayer/backend not build yet\nimport { type DictionaryAPI } from '@intlayer/backend';\nimport { getConfiguration } from '@intlayer/config';\n// @ts-ignore @intlayer/design-system not build yet\nimport { getIntlayerAPI } from '@intlayer/design-system/libs';\nimport pLimit from 'p-limit';\nimport { logger } from './log';\n\ntype FetchDistantDictionariesOptions = {\n dictionaryKeys: string[];\n newDictionariesPath?: string;\n logPrefix?: string;\n};\n\n/**\n * Fetch distant dictionaries and update the logger with their statuses.\n */\nexport const fetchDistantDictionaries = async (\n options: FetchDistantDictionariesOptions\n): Promise<DictionaryAPI[]> => {\n try {\n const config = getConfiguration();\n const { clientId, clientSecret } = config.editor;\n const intlayerAPI = getIntlayerAPI(undefined, config);\n\n if (!clientId || !clientSecret) {\n throw new Error(\n 'Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project.'\n );\n }\n\n const oAuth2TokenResult = await intlayerAPI.auth.getOAuth2AccessToken();\n\n const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;\n\n const distantDictionariesKeys = options.dictionaryKeys;\n\n // Process dictionaries in parallel with a concurrency limit\n const limit = pLimit(5); // Limit the number of concurrent requests\n\n const processDictionary = async (\n dictionaryKey: string\n ): Promise<DictionaryAPI | undefined> => {\n logger.updateStatus([\n {\n dictionaryKey,\n type: 'distant',\n status: { status: 'fetching' },\n },\n ]);\n\n try {\n // Fetch the dictionary\n const getDictionaryResult = await intlayerAPI.dictionary.getDictionary(\n dictionaryKey,\n undefined,\n {\n headers: { Authorization: `Bearer ${oAuth2AccessToken}` },\n }\n );\n\n const distantDictionary = getDictionaryResult.data;\n\n if (!distantDictionary) {\n throw new Error(`Dictionary ${dictionaryKey} not found on remote`);\n }\n\n logger.updateStatus([\n { dictionaryKey, type: 'distant', status: { status: 'imported' } },\n ]);\n\n return distantDictionary;\n } catch (error) {\n logger.updateStatus([\n {\n dictionaryKey,\n type: 'distant',\n status: {\n status: 'error',\n error: error as Error,\n errorMessage: `${options?.logPrefix ?? ''}Error fetching dictionary ${dictionaryKey}: ${error}`,\n },\n },\n ]);\n return undefined;\n }\n };\n\n const fetchPromises = distantDictionariesKeys.map((dictionaryKey) =>\n limit(async () => await processDictionary(dictionaryKey))\n );\n\n const result = await Promise.all(fetchPromises);\n\n // Output any error messages\n const statuses = logger.getStatuses();\n for (const statusObj of statuses) {\n const currentState = statusObj.state.find((s) => s.type === 'distant');\n if (currentState && currentState.errorMessage) {\n console.error(currentState.errorMessage);\n }\n }\n\n // Remove undefined values\n const filteredResult = result.filter(\n (dict): dict is DictionaryAPI => dict !== undefined\n );\n\n return filteredResult;\n } catch (error) {\n console.error(error);\n return [];\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oBAAiC;AAEjC,kBAA+B;AAC/B,qBAAmB;AACnB,iBAAuB;AAWhB,MAAM,2BAA2B,OACtC,YAC6B;AAC7B,MAAI;AACF,UAAM,aAAS,gCAAiB;AAChC,UAAM,EAAE,UAAU,aAAa,IAAI,OAAO;AAC1C,UAAM,kBAAc,4BAAe,QAAW,MAAM;AAEpD,QAAI,CAAC,YAAY,CAAC,cAAc;AAC9B,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,UAAM,oBAAoB,MAAM,YAAY,KAAK,qBAAqB;AAEtE,UAAM,oBAAoB,kBAAkB,MAAM;AAElD,UAAM,0BAA0B,QAAQ;AAGxC,UAAM,YAAQ,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C5B,CAAC,SAAgC,SAAS;AAAA,IAC5C;AAEA,WAAO;AAAA,EACT,SAAS,OAAO;AACd,YAAQ,MAAM,KAAK;AACnB,WAAO,CAAC;AAAA,EACV;AACF;","names":["pLimit"]}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var getDictionariesPath_exports = {};
|
|
30
|
+
__export(getDictionariesPath_exports, {
|
|
31
|
+
getDictionariesPath: () => getDictionariesPath
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(getDictionariesPath_exports);
|
|
34
|
+
var import_fs = require("fs");
|
|
35
|
+
var import_config = require("@intlayer/config");
|
|
36
|
+
var import_fast_glob = __toESM(require("fast-glob"));
|
|
37
|
+
const { content } = (0, import_config.getConfiguration)();
|
|
38
|
+
const { dictionariesDir, mainDir } = content;
|
|
39
|
+
const getDictionariesPath = () => {
|
|
40
|
+
if (!(0, import_fs.existsSync)(mainDir)) {
|
|
41
|
+
(0, import_fs.mkdirSync)(mainDir, { recursive: true });
|
|
42
|
+
}
|
|
43
|
+
const dictionariesPath = import_fast_glob.default.sync(`${dictionariesDir}/**/*.json`);
|
|
44
|
+
return dictionariesPath;
|
|
45
|
+
};
|
|
46
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
47
|
+
0 && (module.exports = {
|
|
48
|
+
getDictionariesPath
|
|
49
|
+
});
|
|
50
|
+
//# sourceMappingURL=getDictionariesPath.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/getDictionariesPath.ts"],"sourcesContent":["import { existsSync, mkdirSync } from 'fs';\nimport { getConfiguration } from '@intlayer/config';\nimport fg from 'fast-glob';\n\nconst { content } = getConfiguration();\nconst { dictionariesDir, mainDir } = content;\n\n/**\n * This function generates a list of dictionaries in the main directory\n */\nexport const getDictionariesPath = () => {\n // Create main directory if it doesn't exist\n if (!existsSync(mainDir)) {\n mkdirSync(mainDir, { recursive: true });\n }\n\n const dictionariesPath: string[] = fg.sync(`${dictionariesDir}/**/*.json`);\n\n return dictionariesPath;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAsC;AACtC,oBAAiC;AACjC,uBAAe;AAEf,MAAM,EAAE,QAAQ,QAAI,gCAAiB;AACrC,MAAM,EAAE,iBAAiB,QAAQ,IAAI;AAK9B,MAAM,sBAAsB,MAAM;AAEvC,MAAI,KAAC,sBAAW,OAAO,GAAG;AACxB,6BAAU,SAAS,EAAE,WAAW,KAAK,CAAC;AAAA,EACxC;AAEA,QAAM,mBAA6B,iBAAAA,QAAG,KAAK,GAAG,eAAe,YAAY;AAEzE,SAAO;AACT;","names":["fg"]}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
var createDictionaryList_exports = {};
|
|
30
20
|
__export(createDictionaryList_exports, {
|
|
@@ -34,10 +24,10 @@ module.exports = __toCommonJS(createDictionaryList_exports);
|
|
|
34
24
|
var import_fs = require("fs");
|
|
35
25
|
var import_path = require("path");
|
|
36
26
|
var import_config = require("@intlayer/config");
|
|
37
|
-
var
|
|
27
|
+
var import_getDictionariesPath = require('../../getDictionariesPath.cjs');
|
|
38
28
|
var import_utils = require('../../utils.cjs');
|
|
39
29
|
const { content } = (0, import_config.getConfiguration)();
|
|
40
|
-
const {
|
|
30
|
+
const { mainDir } = content;
|
|
41
31
|
const generateDictionaryListContent = (dictionaries, format = "esm") => {
|
|
42
32
|
let content2 = "";
|
|
43
33
|
const dictionariesRef = dictionaries.map((dictionaryPath) => ({
|
|
@@ -73,10 +63,10 @@ const createDictionaryList = () => {
|
|
|
73
63
|
if (!(0, import_fs.existsSync)(mainDir)) {
|
|
74
64
|
(0, import_fs.mkdirSync)(mainDir, { recursive: true });
|
|
75
65
|
}
|
|
76
|
-
const
|
|
77
|
-
const cjsContent = generateDictionaryListContent(
|
|
66
|
+
const dictionariesPath = (0, import_getDictionariesPath.getDictionariesPath)();
|
|
67
|
+
const cjsContent = generateDictionaryListContent(dictionariesPath, "cjs");
|
|
78
68
|
(0, import_fs.writeFileSync)((0, import_path.resolve)(mainDir, "dictionaries.cjs"), cjsContent);
|
|
79
|
-
const esmContent = generateDictionaryListContent(
|
|
69
|
+
const esmContent = generateDictionaryListContent(dictionariesPath, "esm");
|
|
80
70
|
(0, import_fs.writeFileSync)((0, import_path.resolve)(mainDir, "dictionaries.mjs"), esmContent);
|
|
81
71
|
};
|
|
82
72
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -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 { getDictionariesPath } from '../../getDictionariesPath';\nimport { getFileHash } from '../../utils';\n\nconst { content } = getConfiguration();\nconst { mainDir } = content;\n\n/**\n * This function generates the content of the dictionary list file\n */\nconst generateDictionaryListContent = (\n dictionaries: string[],\n format: 'cjs' | 'esm' = 'esm'\n): string => {\n let content = '';\n\n const dictionariesRef = dictionaries.map((dictionaryPath) => ({\n relativePath: relative(mainDir, dictionaryPath),\n id: basename(dictionaryPath, extname(dictionaryPath)), // Get the base name as the dictionary id\n hash: `_${getFileHash(dictionaryPath)}`, // Get the hash of the dictionary to avoid conflicts\n }));\n\n // Import all dictionaries\n dictionariesRef.forEach((dictionary) => {\n if (format === 'esm')\n content += `import ${dictionary.hash} from '${dictionary.relativePath}';\\n`;\n if (format === 'cjs')\n content += `const ${dictionary.hash} = require('${dictionary.relativePath}');\\n`;\n });\n\n content += '\\n';\n\n // Format Dictionary Map\n const formattedDictionaryMap: string = dictionariesRef\n .map((dictionary) => `\"${dictionary.id}\": ${dictionary.hash}`)\n .join(',\\n');\n\n if (format === 'esm')\n content += `export default {\\n${formattedDictionaryMap}\\n};\\n`;\n if (format === 'cjs')\n content += `module.exports = {\\n${formattedDictionaryMap}\\n};\\n`;\n\n return content;\n};\n\n/**\n * This function generates a list of dictionaries in the main directory\n */\nexport const createDictionaryList = () => {\n // Create main directory if it doesn't exist\n if (!existsSync(mainDir)) {\n mkdirSync(mainDir, { recursive: true });\n }\n\n const dictionariesPath: string[] = getDictionariesPath();\n\n // Create the dictionary list file\n const cjsContent = generateDictionaryListContent(dictionariesPath, 'cjs');\n writeFileSync(resolve(mainDir, 'dictionaries.cjs'), cjsContent);\n\n const esmContent = generateDictionaryListContent(dictionariesPath, 'esm');\n writeFileSync(resolve(mainDir, 'dictionaries.mjs'), esmContent);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAqD;AACrD,kBAAqD;AACrD,oBAAiC;AAC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,7 @@ import { getConfiguration } from "@intlayer/config";
|
|
|
3
3
|
import { watch as chokidarWatch } from "chokidar";
|
|
4
4
|
import fg from "fast-glob";
|
|
5
5
|
import { cleanOutputDir } from '../cleanOutputDir.mjs';
|
|
6
|
+
import { getDictionariesPath } from '../getDictionariesPath.mjs';
|
|
6
7
|
import { loadDictionaries } from '../loadDictionaries/loadDictionaries.mjs';
|
|
7
8
|
import { loadLocalDictionaries } from '../loadDictionaries/loadLocalDictionaries.mjs';
|
|
8
9
|
import { buildDictionary } from '../transpiler/declaration_file_to_dictionary/index.mjs';
|
|
@@ -32,24 +33,31 @@ const watch = (options) => {
|
|
|
32
33
|
console.info(
|
|
33
34
|
`${LOG_PREFIX}${dictionariesPaths.length} dictionaries built`
|
|
34
35
|
);
|
|
35
|
-
createModuleAugmentation();
|
|
36
36
|
createDictionaryList();
|
|
37
|
+
createModuleAugmentation();
|
|
37
38
|
}).on("add", async (filePath) => {
|
|
38
39
|
console.info(
|
|
39
40
|
`${LOG_PREFIX}Additional file detected: `,
|
|
40
41
|
relative(baseDir, filePath)
|
|
41
42
|
);
|
|
42
43
|
const localeDictionaries = await loadLocalDictionaries(filePath);
|
|
43
|
-
const
|
|
44
|
-
await createTypes(
|
|
45
|
-
createModuleAugmentation();
|
|
44
|
+
const dictionariesPaths = await buildDictionary(localeDictionaries);
|
|
45
|
+
await createTypes(dictionariesPaths);
|
|
46
46
|
createDictionaryList();
|
|
47
|
+
createModuleAugmentation();
|
|
47
48
|
}).on("change", async (filePath) => {
|
|
48
49
|
console.info("Change detected: ", relative(baseDir, filePath));
|
|
49
50
|
const localeDictionaries = await loadLocalDictionaries(filePath);
|
|
50
|
-
const
|
|
51
|
-
|
|
51
|
+
const updatedDictionariesPaths = await buildDictionary(localeDictionaries);
|
|
52
|
+
const allDictionariesPaths = getDictionariesPath();
|
|
53
|
+
await createTypes(updatedDictionariesPaths);
|
|
52
54
|
console.info(`${LOG_PREFIX}TypeScript types built`);
|
|
55
|
+
if (updatedDictionariesPaths.some(
|
|
56
|
+
(updatedDictionaryPath) => allDictionariesPaths.includes(updatedDictionaryPath)
|
|
57
|
+
)) {
|
|
58
|
+
createDictionaryList();
|
|
59
|
+
createModuleAugmentation();
|
|
60
|
+
}
|
|
53
61
|
}).on("error", (error) => {
|
|
54
62
|
console.error("Watcher error:", error);
|
|
55
63
|
});
|
|
@@ -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 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, watch: isWatchMode } = content;\n\n const files: string[] = fg.sync(watchedFilesPatternWithPath);\n\n /** @ts-ignore remove error Expected 0-1 arguments, but got 2. */\n return chokidarWatch(watchedFilesPatternWithPath, {\n persistent: isWatchMode, // Make the watcher persistent\n ignoreInitial: true, // Process existing files\n ...options,\n })\n .on('ready', async () => {\n cleanOutputDir();\n\n 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
|
|
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 { getDictionariesPath } from '../getDictionariesPath';\nimport { loadDictionaries } from '../loadDictionaries/loadDictionaries';\nimport { loadLocalDictionaries } from '../loadDictionaries/loadLocalDictionaries';\nimport { buildDictionary } from '../transpiler/declaration_file_to_dictionary/index';\nimport { createDictionaryList } from '../transpiler/dictionary_to_main/createDictionaryList';\nimport {\n createTypes,\n createModuleAugmentation,\n} from '../transpiler/dictionary_to_type/index';\n\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, watch: isWatchMode } = content;\n\n const files: string[] = fg.sync(watchedFilesPatternWithPath);\n\n /** @ts-ignore remove error Expected 0-1 arguments, but got 2. */\n return chokidarWatch(watchedFilesPatternWithPath, {\n persistent: isWatchMode, // Make the watcher persistent\n ignoreInitial: true, // Process existing files\n ...options,\n })\n .on('ready', async () => {\n cleanOutputDir();\n\n 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 createDictionaryList();\n createModuleAugmentation();\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 dictionariesPaths = await buildDictionary(localeDictionaries);\n\n await createTypes(dictionariesPaths);\n\n createDictionaryList();\n createModuleAugmentation();\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 updatedDictionariesPaths =\n await buildDictionary(localeDictionaries);\n const allDictionariesPaths: string[] = getDictionariesPath();\n\n await createTypes(updatedDictionariesPaths);\n console.info(`${LOG_PREFIX}TypeScript types built`);\n\n if (\n updatedDictionariesPaths.some((updatedDictionaryPath) =>\n allDictionariesPaths.includes(updatedDictionaryPath)\n )\n ) {\n createDictionaryList();\n createModuleAugmentation();\n }\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,2BAA2B;AACpC,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,SAAS,OAAO,YAAY,IAAI;AAErE,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,yBAAqB;AACrB,6BAAyB;AAAA,EAC3B,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,oBAAoB,MAAM,gBAAgB,kBAAkB;AAElE,UAAM,YAAY,iBAAiB;AAEnC,yBAAqB;AACrB,6BAAyB;AAAA,EAC3B,CAAC,EACA,GAAG,UAAU,OAAO,aAAa;AAEhC,YAAQ,KAAK,qBAAqB,SAAS,SAAS,QAAQ,CAAC;AAE7D,UAAM,qBAAqB,MAAM,sBAAsB,QAAQ;AAC/D,UAAM,2BACJ,MAAM,gBAAgB,kBAAkB;AAC1C,UAAM,uBAAiC,oBAAoB;AAE3D,UAAM,YAAY,wBAAwB;AAC1C,YAAQ,KAAK,GAAG,UAAU,wBAAwB;AAElD,QACE,yBAAyB;AAAA,MAAK,CAAC,0BAC7B,qBAAqB,SAAS,qBAAqB;AAAA,IACrD,GACA;AACA,2BAAqB;AACrB,+BAAyB;AAAA,IAC3B;AAAA,EACF,CAAC,EACA,GAAG,SAAS,CAAC,UAAU;AACtB,YAAQ,MAAM,kBAAkB,KAAK;AAAA,EACvC,CAAC;AACL;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/fetchDistantDictionaries.ts"],"sourcesContent":["// @ts-ignore @intlayer/backend not build yet\nimport { type DictionaryAPI } from '@intlayer/backend';\nimport { getConfiguration } from '@intlayer/config';\n// @ts-ignore @intlayer/design-system not build yet\nimport { getIntlayerAPI } from '@intlayer/design-system/libs';\nimport pLimit from 'p-limit';\nimport { logger } from './log';\n\ntype FetchDistantDictionariesOptions = {\n dictionaryKeys: string[];\n newDictionariesPath?: string;\n logPrefix?: string;\n};\n\n/**\n * Fetch distant dictionaries and update the logger with their statuses.\n */\nexport const fetchDistantDictionaries = async (\n options: FetchDistantDictionariesOptions\n): Promise<DictionaryAPI[]> => {\n try {\n const config = getConfiguration();\n const { clientId, clientSecret } = config.editor;\n const intlayerAPI = getIntlayerAPI(undefined, config);\n\n if (!clientId || !clientSecret) {\n throw new Error(\n 'Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project.'\n );\n }\n\n const oAuth2TokenResult = await intlayerAPI.auth.getOAuth2AccessToken();\n\n const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;\n\n const distantDictionariesKeys = options.dictionaryKeys;\n\n // Process dictionaries in parallel with a concurrency limit\n const limit = pLimit(5); //
|
|
1
|
+
{"version":3,"sources":["../../src/fetchDistantDictionaries.ts"],"sourcesContent":["// @ts-ignore @intlayer/backend not build yet\nimport { type DictionaryAPI } from '@intlayer/backend';\nimport { getConfiguration } from '@intlayer/config';\n// @ts-ignore @intlayer/design-system not build yet\nimport { getIntlayerAPI } from '@intlayer/design-system/libs';\nimport pLimit from 'p-limit';\nimport { logger } from './log';\n\ntype FetchDistantDictionariesOptions = {\n dictionaryKeys: string[];\n newDictionariesPath?: string;\n logPrefix?: string;\n};\n\n/**\n * Fetch distant dictionaries and update the logger with their statuses.\n */\nexport const fetchDistantDictionaries = async (\n options: FetchDistantDictionariesOptions\n): Promise<DictionaryAPI[]> => {\n try {\n const config = getConfiguration();\n const { clientId, clientSecret } = config.editor;\n const intlayerAPI = getIntlayerAPI(undefined, config);\n\n if (!clientId || !clientSecret) {\n throw new Error(\n 'Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project.'\n );\n }\n\n const oAuth2TokenResult = await intlayerAPI.auth.getOAuth2AccessToken();\n\n const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;\n\n const distantDictionariesKeys = options.dictionaryKeys;\n\n // Process dictionaries in parallel with a concurrency limit\n const limit = pLimit(5); // Limit the number of concurrent requests\n\n const processDictionary = async (\n dictionaryKey: string\n ): Promise<DictionaryAPI | undefined> => {\n logger.updateStatus([\n {\n dictionaryKey,\n type: 'distant',\n status: { status: 'fetching' },\n },\n ]);\n\n try {\n // Fetch the dictionary\n const getDictionaryResult = await intlayerAPI.dictionary.getDictionary(\n dictionaryKey,\n undefined,\n {\n headers: { Authorization: `Bearer ${oAuth2AccessToken}` },\n }\n );\n\n const distantDictionary = getDictionaryResult.data;\n\n if (!distantDictionary) {\n throw new Error(`Dictionary ${dictionaryKey} not found on remote`);\n }\n\n logger.updateStatus([\n { dictionaryKey, type: 'distant', status: { status: 'imported' } },\n ]);\n\n return distantDictionary;\n } catch (error) {\n logger.updateStatus([\n {\n dictionaryKey,\n type: 'distant',\n status: {\n status: 'error',\n error: error as Error,\n errorMessage: `${options?.logPrefix ?? ''}Error fetching dictionary ${dictionaryKey}: ${error}`,\n },\n },\n ]);\n return undefined;\n }\n };\n\n const fetchPromises = distantDictionariesKeys.map((dictionaryKey) =>\n limit(async () => await processDictionary(dictionaryKey))\n );\n\n const result = await Promise.all(fetchPromises);\n\n // Output any error messages\n const statuses = logger.getStatuses();\n for (const statusObj of statuses) {\n const currentState = statusObj.state.find((s) => s.type === 'distant');\n if (currentState && currentState.errorMessage) {\n console.error(currentState.errorMessage);\n }\n }\n\n // Remove undefined values\n const filteredResult = result.filter(\n (dict): dict is DictionaryAPI => dict !== undefined\n );\n\n return filteredResult;\n } catch (error) {\n console.error(error);\n return [];\n }\n};\n"],"mappings":"AAEA,SAAS,wBAAwB;AAEjC,SAAS,sBAAsB;AAC/B,OAAO,YAAY;AACnB,SAAS,cAAc;AAWhB,MAAM,2BAA2B,OACtC,YAC6B;AAC7B,MAAI;AACF,UAAM,SAAS,iBAAiB;AAChC,UAAM,EAAE,UAAU,aAAa,IAAI,OAAO;AAC1C,UAAM,cAAc,eAAe,QAAW,MAAM;AAEpD,QAAI,CAAC,YAAY,CAAC,cAAc;AAC9B,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,UAAM,oBAAoB,MAAM,YAAY,KAAK,qBAAqB;AAEtE,UAAM,oBAAoB,kBAAkB,MAAM;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;AAGA,UAAM,iBAAiB,OAAO;AAAA,MAC5B,CAAC,SAAgC,SAAS;AAAA,IAC5C;AAEA,WAAO;AAAA,EACT,SAAS,OAAO;AACd,YAAQ,MAAM,KAAK;AACnB,WAAO,CAAC;AAAA,EACV;AACF;","names":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { existsSync, mkdirSync } from "fs";
|
|
2
|
+
import { getConfiguration } from "@intlayer/config";
|
|
3
|
+
import fg from "fast-glob";
|
|
4
|
+
const { content } = getConfiguration();
|
|
5
|
+
const { dictionariesDir, mainDir } = content;
|
|
6
|
+
const getDictionariesPath = () => {
|
|
7
|
+
if (!existsSync(mainDir)) {
|
|
8
|
+
mkdirSync(mainDir, { recursive: true });
|
|
9
|
+
}
|
|
10
|
+
const dictionariesPath = fg.sync(`${dictionariesDir}/**/*.json`);
|
|
11
|
+
return dictionariesPath;
|
|
12
|
+
};
|
|
13
|
+
export {
|
|
14
|
+
getDictionariesPath
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=getDictionariesPath.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/getDictionariesPath.ts"],"sourcesContent":["import { existsSync, mkdirSync } from 'fs';\nimport { getConfiguration } from '@intlayer/config';\nimport fg from 'fast-glob';\n\nconst { content } = getConfiguration();\nconst { dictionariesDir, mainDir } = content;\n\n/**\n * This function generates a list of dictionaries in the main directory\n */\nexport const getDictionariesPath = () => {\n // Create main directory if it doesn't exist\n if (!existsSync(mainDir)) {\n mkdirSync(mainDir, { recursive: true });\n }\n\n const dictionariesPath: string[] = fg.sync(`${dictionariesDir}/**/*.json`);\n\n return dictionariesPath;\n};\n"],"mappings":"AAAA,SAAS,YAAY,iBAAiB;AACtC,SAAS,wBAAwB;AACjC,OAAO,QAAQ;AAEf,MAAM,EAAE,QAAQ,IAAI,iBAAiB;AACrC,MAAM,EAAE,iBAAiB,QAAQ,IAAI;AAK9B,MAAM,sBAAsB,MAAM;AAEvC,MAAI,CAAC,WAAW,OAAO,GAAG;AACxB,cAAU,SAAS,EAAE,WAAW,KAAK,CAAC;AAAA,EACxC;AAEA,QAAM,mBAA6B,GAAG,KAAK,GAAG,eAAe,YAAY;AAEzE,SAAO;AACT;","names":[]}
|
|
@@ -1,10 +1,10 @@
|
|
|
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 { getDictionariesPath } from '../../getDictionariesPath.mjs';
|
|
5
5
|
import { getFileHash } from '../../utils.mjs';
|
|
6
6
|
const { content } = getConfiguration();
|
|
7
|
-
const {
|
|
7
|
+
const { mainDir } = content;
|
|
8
8
|
const generateDictionaryListContent = (dictionaries, format = "esm") => {
|
|
9
9
|
let content2 = "";
|
|
10
10
|
const dictionariesRef = dictionaries.map((dictionaryPath) => ({
|
|
@@ -40,10 +40,10 @@ const createDictionaryList = () => {
|
|
|
40
40
|
if (!existsSync(mainDir)) {
|
|
41
41
|
mkdirSync(mainDir, { recursive: true });
|
|
42
42
|
}
|
|
43
|
-
const
|
|
44
|
-
const cjsContent = generateDictionaryListContent(
|
|
43
|
+
const dictionariesPath = getDictionariesPath();
|
|
44
|
+
const cjsContent = generateDictionaryListContent(dictionariesPath, "cjs");
|
|
45
45
|
writeFileSync(resolve(mainDir, "dictionaries.cjs"), cjsContent);
|
|
46
|
-
const esmContent = generateDictionaryListContent(
|
|
46
|
+
const esmContent = generateDictionaryListContent(dictionariesPath, "esm");
|
|
47
47
|
writeFileSync(resolve(mainDir, "dictionaries.mjs"), esmContent);
|
|
48
48
|
};
|
|
49
49
|
export {
|
|
@@ -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 { getDictionariesPath } from '../../getDictionariesPath';\nimport { getFileHash } from '../../utils';\n\nconst { content } = getConfiguration();\nconst { mainDir } = content;\n\n/**\n * This function generates the content of the dictionary list file\n */\nconst generateDictionaryListContent = (\n dictionaries: string[],\n format: 'cjs' | 'esm' = 'esm'\n): string => {\n let content = '';\n\n const dictionariesRef = dictionaries.map((dictionaryPath) => ({\n relativePath: relative(mainDir, dictionaryPath),\n id: basename(dictionaryPath, extname(dictionaryPath)), // Get the base name as the dictionary id\n hash: `_${getFileHash(dictionaryPath)}`, // Get the hash of the dictionary to avoid conflicts\n }));\n\n // Import all dictionaries\n dictionariesRef.forEach((dictionary) => {\n if (format === 'esm')\n content += `import ${dictionary.hash} from '${dictionary.relativePath}';\\n`;\n if (format === 'cjs')\n content += `const ${dictionary.hash} = require('${dictionary.relativePath}');\\n`;\n });\n\n content += '\\n';\n\n // Format Dictionary Map\n const formattedDictionaryMap: string = dictionariesRef\n .map((dictionary) => `\"${dictionary.id}\": ${dictionary.hash}`)\n .join(',\\n');\n\n if (format === 'esm')\n content += `export default {\\n${formattedDictionaryMap}\\n};\\n`;\n if (format === 'cjs')\n content += `module.exports = {\\n${formattedDictionaryMap}\\n};\\n`;\n\n return content;\n};\n\n/**\n * This function generates a list of dictionaries in the main directory\n */\nexport const createDictionaryList = () => {\n // Create main directory if it doesn't exist\n if (!existsSync(mainDir)) {\n mkdirSync(mainDir, { recursive: true });\n }\n\n const dictionariesPath: string[] = getDictionariesPath();\n\n // Create the dictionary list file\n const cjsContent = generateDictionaryListContent(dictionariesPath, 'cjs');\n writeFileSync(resolve(mainDir, 'dictionaries.cjs'), cjsContent);\n\n const esmContent = generateDictionaryListContent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ACxE,gBAAc,QAAQ,SAAS,kBAAkB,GAAG,UAAU;AAE9D,QAAM,aAAa,8BAA8B,kBAAkB,KAAK;AACxE,gBAAc,QAAQ,SAAS,kBAAkB,GAAG,UAAU;AAChE;","names":["content"]}
|
|
@@ -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;AAgBxE,eAAO,MAAM,KAAK,aAAc,eAAe,QAwE9C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getDictionariesPath.d.ts","sourceRoot":"","sources":["../../src/getDictionariesPath.ts"],"names":[],"mappings":"AAOA;;GAEG;AACH,eAAO,MAAM,mBAAmB,gBAS/B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/chokidar",
|
|
3
|
-
"version": "3.5.
|
|
3
|
+
"version": "3.5.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Chokidar application for IntLayer - Transpile IntLayer declaration files into dictionaries.",
|
|
6
6
|
"keywords": [
|
|
@@ -67,11 +67,11 @@
|
|
|
67
67
|
"quicktype-core": "^23.0.170",
|
|
68
68
|
"react": "^18.3.1",
|
|
69
69
|
"rimraf": "^6.0.1",
|
|
70
|
-
"@intlayer/backend": "^3.5.
|
|
71
|
-
"@intlayer/
|
|
72
|
-
"
|
|
73
|
-
"intlayer": "^3.5.
|
|
74
|
-
"@intlayer/core": "^3.5.
|
|
70
|
+
"@intlayer/backend": "^3.5.4",
|
|
71
|
+
"@intlayer/design-system": "^3.5.4",
|
|
72
|
+
"intlayer": "^3.5.4",
|
|
73
|
+
"@intlayer/config": "^3.5.4",
|
|
74
|
+
"@intlayer/core": "^3.5.4"
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
77
|
"@changesets/cli": "2.27.10",
|
|
@@ -86,16 +86,17 @@
|
|
|
86
86
|
"typescript": "^5.7.2",
|
|
87
87
|
"webpack-watch-files-plugin": "^1.2.1",
|
|
88
88
|
"@utils/eslint-config": "^1.0.4",
|
|
89
|
-
"@utils/
|
|
89
|
+
"@utils/tsup-config": "^1.0.4",
|
|
90
90
|
"@utils/ts-config-types": "^1.0.4",
|
|
91
|
-
"@utils/
|
|
91
|
+
"@utils/ts-config": "^1.0.4"
|
|
92
92
|
},
|
|
93
93
|
"peerDependencies": {
|
|
94
|
-
"
|
|
95
|
-
"@intlayer/
|
|
96
|
-
"intlayer": "^3.5.
|
|
97
|
-
"@intlayer/core": "^3.5.
|
|
98
|
-
"@intlayer/
|
|
94
|
+
"fast-glob": "^3.3.2",
|
|
95
|
+
"@intlayer/config": "^3.5.4",
|
|
96
|
+
"@intlayer/backend": "^3.5.4",
|
|
97
|
+
"@intlayer/core": "^3.5.4",
|
|
98
|
+
"@intlayer/design-system": "^3.5.4",
|
|
99
|
+
"intlayer": "^3.5.4"
|
|
99
100
|
},
|
|
100
101
|
"engines": {
|
|
101
102
|
"node": ">=14.18"
|