UNPKG

@intlayer/chokidar

Version:

Uses chokidar to scan and build Intlayer declaration files into dictionaries based on Intlayer configuration.

63 lines 2.64 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var generateDictionaryListContent_exports = {}; __export(generateDictionaryListContent_exports, { generateDictionaryListContent: () => generateDictionaryListContent }); module.exports = __toCommonJS(generateDictionaryListContent_exports); var import_config = require("@intlayer/config"); var import_path = require("path"); var import_getFileHash = require('../../utils/getFileHash.cjs'); const generateDictionaryListContent = (dictionaries, format = "esm", configuration = (0, import_config.getConfiguration)()) => { const { mainDir } = configuration.content; let content = ""; const dictionariesRef = dictionaries.map((dictionaryPath) => ({ relativePath: (0, import_config.normalizePath)((0, import_path.relative)(mainDir, dictionaryPath)), id: (0, import_path.basename)(dictionaryPath, (0, import_path.extname)(dictionaryPath)), // Get the base name as the dictionary id hash: `_${(0, import_getFileHash.getFileHash)(dictionaryPath)}` // Get the hash of the dictionary to avoid conflicts })); dictionariesRef.forEach((dictionary) => { if (format === "esm") content += `import ${dictionary.hash} from '${dictionary.relativePath}' with { type: 'json' }; `; if (format === "cjs") content += `const ${dictionary.hash} = require('${dictionary.relativePath}'); `; }); content += "\n"; const formattedDictionaryMap = dictionariesRef.map((dictionary) => ` "${dictionary.id}": ${dictionary.hash}`).join(",\n"); if (format === "esm") content += `export default { ${formattedDictionaryMap} }; `; if (format === "cjs") content += `module.exports = { ${formattedDictionaryMap} }; `; return content; }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { generateDictionaryListContent }); //# sourceMappingURL=generateDictionaryListContent.cjs.map