@intlayer/chokidar
Version:
Uses chokidar to scan and build Intlayer declaration files into dictionaries based on Intlayer configuration.
90 lines • 3.59 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 prepareContentDeclaration_exports = {};
__export(prepareContentDeclaration_exports, {
prepareContentDeclaration: () => prepareContentDeclaration
});
module.exports = __toCommonJS(prepareContentDeclaration_exports);
var import_core = require("@intlayer/core");
var import_fs = require("fs");
var import_path = require("path");
const writeFilePlugin = {
id: "write-file-plugin",
canHandle: (node) => typeof node === "object" && node?.nodeType === import_core.NodeType.File,
transform: (node) => {
const fileContent = node.content;
const filePath = node.fixedPath;
if (typeof fileContent !== "string") {
throw new Error("File content must be a string");
}
if (typeof filePath !== "string") {
throw new Error("File path must be a string");
}
try {
const abolsuteFilePath = (0, import_path.join)(process.cwd(), filePath);
const fileDirectory = (0, import_path.join)(process.cwd(), filePath);
if (!fileDirectory.startsWith(process.cwd())) {
throw new Error("File directory not found");
}
if (!(0, import_fs.existsSync)(fileDirectory)) {
(0, import_fs.mkdirSync)(fileDirectory, { recursive: true });
}
(0, import_fs.writeFileSync)(abolsuteFilePath, fileContent);
} catch (error) {
throw new Error(`Error writing file to ${filePath}: ${error}`);
}
const transformedFileContent = {
nodeType: import_core.NodeType.File,
[import_core.NodeType.File]: node.file
};
return transformedFileContent;
}
};
const mardownFilePlugin = {
id: "markdown-file-plugin",
canHandle: (node) => typeof node === "object" && node?.nodeType === import_core.NodeType.Markdown,
transform: (node, props, deepTransformNode2) => {
const simplifiedMarkdownNode = {
nodeType: import_core.NodeType.Markdown,
[import_core.NodeType.Markdown]: deepTransformNode2(node.markdown, props)
};
return simplifiedMarkdownNode;
}
};
const insertionFilePlugin = {
id: "insertion-file-plugin",
canHandle: (node) => typeof node === "object" && node?.nodeType === import_core.NodeType.Insertion,
transform: (node, props, deepTransformNode2) => {
const simplifiedInsertionNode = {
nodeType: import_core.NodeType.Insertion,
[import_core.NodeType.Insertion]: deepTransformNode2(node.insertion, props)
};
return simplifiedInsertionNode;
}
};
const prepareContentDeclaration = async (dictionary) => (0, import_core.deepTransformNode)(dictionary, {
dictionaryKey: dictionary.key,
keyPath: [],
plugins: [writeFilePlugin, mardownFilePlugin, insertionFilePlugin]
});
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
prepareContentDeclaration
});
//# sourceMappingURL=prepareContentDeclaration.cjs.map