@intlayer/chokidar
Version:
Uses chokidar to scan and build Intlayer declaration files into dictionaries based on Intlayer configuration.
89 lines • 3.85 kB
JavaScript
;
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 loadDictionaries_exports = {};
__export(loadDictionaries_exports, {
loadDictionaries: () => loadDictionaries
});
module.exports = __toCommonJS(loadDictionaries_exports);
var import_config = require("@intlayer/config");
var import_fetchDistantDictionaryKeys = require('../fetchDistantDictionaryKeys.cjs');
var import_log = require('../log.cjs');
var import_sortAlphabetically = require('../utils/sortAlphabetically.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 appLogger = (0, import_config.getAppLogger)(configuration);
const { editor } = configuration;
appLogger("Dictionaries:", { isVerbose: true });
const files = Array.isArray(contentDeclarationsPaths) ? contentDeclarationsPaths : [contentDeclarationsPaths];
const localDictionaries = await (0, import_loadContentDeclaration.loadContentDeclarations)(
files,
projectRequire
);
const filteredLocalDictionaries = localDictionaries.filter((dict) => {
const hasKey = Boolean(dict.key);
const hasContent = Boolean(dict.content);
if (!hasContent) {
console.error(
"Content declaration has no exported content",
dict.filePath
);
} else if (!hasKey) {
console.error("Content declaration has no key", dict.filePath);
}
return hasKey && hasContent;
});
const localDictionaryKeys = filteredLocalDictionaries.map((dict) => dict.key).filter(Boolean);
import_log.logger.init(localDictionaryKeys, []);
import_log.logger.updateStatus(
filteredLocalDictionaries.map((dict) => ({
dictionaryKey: dict.key,
type: "local",
status: { status: "built" }
}))
);
let distantDictionaries = [];
let distantDictionaryKeys = [];
if (editor.clientId && editor.clientSecret) {
try {
distantDictionaryKeys = await (0, import_fetchDistantDictionaryKeys.fetchDistantDictionaryKeys)();
const orderedDistantDictionaryKeys = distantDictionaryKeys.sort(import_sortAlphabetically.sortAlphabetically);
import_log.logger.addDictionaryKeys("distant", orderedDistantDictionaryKeys);
distantDictionaries = await (0, import_loadDistantDictionaries.loadDistantDictionaries)({
dictionaryKeys: orderedDistantDictionaryKeys
});
} catch (_error) {
appLogger("Error during fetching distant dictionaries", {
level: "error"
});
}
}
import_log.logger.stop();
return [...filteredLocalDictionaries, ...distantDictionaries];
} 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