UNPKG

@intlayer/chokidar

Version:

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

62 lines 2.7 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 getContentDeclarationFileTemplate_exports = {}; __export(getContentDeclarationFileTemplate_exports, { getContentDeclarationFileTemplate: () => getContentDeclarationFileTemplate }); module.exports = __toCommonJS(getContentDeclarationFileTemplate_exports); var import_promises = require("fs/promises"); var import_path = require("path"); var import_url = require("url"); var import_kebabCaseToCamelCase = require('../utils/kebabCaseToCamelCase.cjs'); const import_meta = {}; const getContentDeclarationFileTemplate = async (key, format, fileParams = {}) => { const dirname = __dirname ?? (0, import_url.fileURLToPath)(import_meta.url); let fileTemplate = "./esmTemplate.md"; if (format === "ts") { fileTemplate = "./tsTemplate.md"; } else if (format === "cjs") { fileTemplate = "./cjsTemplate.md"; } const fileContent = await (0, import_promises.readFile)((0, import_path.join)(dirname, fileTemplate), "utf-8"); const camelCaseKey = (0, import_kebabCaseToCamelCase.kebabCaseToCamelCase)(key); const nonCapitalizedCamelCaseKey = camelCaseKey.charAt(0).toLowerCase() + camelCaseKey.slice(1); const fileParmsString = Object.entries(fileParams).filter(([, value]) => value !== void 0).map(([key2, value]) => { if (typeof value === "object") { return ` ${key2}: ${JSON.stringify(value)},`; } if (typeof value === "boolean" || typeof value === "number") { return ` ${key2}: ${value},`; } if (typeof value === "string") { return ` ${key2}: '${value}',`; } return ` ${key2}: ${value},`; }).join(""); return fileContent.replace("{{key}}", key).replaceAll("{{name}}", nonCapitalizedCamelCaseKey).replace("{{fileParams}}", fileParmsString); }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { getContentDeclarationFileTemplate }); //# sourceMappingURL=getContentDeclarationFileTemplate.cjs.map