@intlayer/chokidar
Version:
Uses chokidar to scan and build Intlayer declaration files into dictionaries based on Intlayer configuration.
52 lines (50 loc) • 1.99 kB
JavaScript
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
const require_utils_parallelize = require('./utils/parallelize.cjs');
let _intlayer_config_logger = require("@intlayer/config/logger");
let _intlayer_config_node = require("@intlayer/config/node");
let _intlayer_api = require("@intlayer/api");
//#region src/fetchDistantDictionaries.ts
/**
* Fetch distant dictionaries and update the logger with their statuses.
*/
const fetchDistantDictionaries = async (options, onStatusUpdate) => {
const config = (0, _intlayer_config_node.getConfiguration)();
const appLogger = (0, _intlayer_config_logger.getAppLogger)(config);
try {
const intlayerAPI = (0, _intlayer_api.getIntlayerAPIProxy)(void 0, config);
const distantDictionariesKeys = options.dictionaryKeys;
const processDictionary = async (dictionaryKey) => {
onStatusUpdate?.([{
dictionaryKey,
type: "remote",
status: "fetching"
}]);
try {
const distantDictionary = (await intlayerAPI.dictionary.getDictionary(dictionaryKey)).data;
if (!distantDictionary) throw new Error(`Dictionary ${dictionaryKey} not found on remote`);
onStatusUpdate?.([{
dictionaryKey,
type: "remote",
status: "fetched"
}]);
return distantDictionary;
} catch (error) {
onStatusUpdate?.([{
dictionaryKey,
type: "remote",
status: "error",
error: `Error fetching dictionary ${dictionaryKey}: ${error}`
}]);
return;
}
};
return (await require_utils_parallelize.parallelize(distantDictionariesKeys, async (dictionaryKey) => await processDictionary(dictionaryKey))).filter((dict) => dict !== void 0);
} catch (_error) {
appLogger(`${_intlayer_config_logger.x} Failed to fetch distant dictionaries`, { level: "error" });
return [];
}
};
//#endregion
exports.fetchDistantDictionaries = fetchDistantDictionaries;
//# sourceMappingURL=fetchDistantDictionaries.cjs.map