@intlayer/chokidar
Version:
Uses chokidar to scan and build Intlayer declaration files into dictionaries based on Intlayer configuration.
97 lines • 4.5 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var loadDictionaries_exports = {};
__export(loadDictionaries_exports, {
loadDictionaries: () => loadDictionaries
});
module.exports = __toCommonJS(loadDictionaries_exports);
var import_config = require("@intlayer/config");
var import_deepmerge = __toESM(require("deepmerge"));
var import_fetchDistantDictionaryKeys = require('../fetchDistantDictionaryKeys.cjs');
var import_log = require('../log.cjs');
var import_mergeDictionaries = require('../mergeDictionaries.cjs');
var import_utils = require('../utils.cjs');
var import_loadContentDeclaration = require('./loadContentDeclaration.cjs');
var import_loadDistantDictionaries = require('./loadDistantDictionaries.cjs');
const loadDictionaries = async (contentDeclarationsPaths, configuration = (0, import_config.getConfiguration)(), projectRequire = import_config.ESMxCJSRequire) => {
try {
const { editor } = configuration;
(0, import_config.appLogger)("Dictionaries:", { isVerbose: true });
const files = Array.isArray(contentDeclarationsPaths) ? contentDeclarationsPaths : [contentDeclarationsPaths];
const localDictionaries = await (0, import_loadContentDeclaration.loadContentDeclarations)(
files,
projectRequire
);
const localDictionaryKeys = localDictionaries.map((dict) => dict.key).filter(Boolean);
import_log.logger.init(localDictionaryKeys, []);
import_log.logger.updateStatus(
localDictionaries.map((dict) => ({
dictionaryKey: dict.key,
type: "local",
status: { status: "built" }
}))
);
let distantDictionaries = [];
let distantDictionaryKeys = [];
let mergedDictionaries = localDictionaries;
if (editor.clientId && editor.clientSecret) {
try {
distantDictionaryKeys = await (0, import_fetchDistantDictionaryKeys.fetchDistantDictionaryKeys)();
const orderedDistantDictionaryKeys = distantDictionaryKeys.sort(import_utils.sortAlphabetically);
import_log.logger.addDictionaryKeys("distant", orderedDistantDictionaryKeys);
distantDictionaries = await (0, import_loadDistantDictionaries.loadDistantDictionaries)({
dictionaryKeys: orderedDistantDictionaryKeys
});
if (editor.dictionaryPriorityStrategy === "distant_first") {
mergedDictionaries = (0, import_deepmerge.default)(localDictionaries, distantDictionaries, {
arrayMerge: (0, import_mergeDictionaries.mergeByKey)("key")
});
} else {
mergedDictionaries = (0, import_deepmerge.default)(distantDictionaries, localDictionaries, {
arrayMerge: (0, import_mergeDictionaries.mergeByKey)("key")
});
}
} catch (_error) {
(0, import_config.appLogger)("Error during fetching distant dictionaries", {
level: "error"
});
}
}
import_log.logger.stop();
return mergedDictionaries;
} catch (error) {
import_log.logger.stop();
throw error;
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
loadDictionaries
});
//# sourceMappingURL=loadDictionaries.cjs.map