@intlayer/chokidar
Version:
Uses chokidar to scan and build Intlayer declaration files into dictionaries based on Intlayer configuration.
83 lines (81 loc) • 3.09 kB
JavaScript
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
let _intlayer_config_utils = require("@intlayer/config/utils");
//#region src/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.ts
const getContentDeclarationFileTemplate = async (key, format, fileParams = {}, noMetadata) => {
const camelCaseKey = (0, _intlayer_config_utils.kebabCaseToCamelCase)(key);
const name = camelCaseKey.charAt(0).toLowerCase() + camelCaseKey.slice(1);
const fileParamsString = Object.entries(fileParams).filter(([, value]) => value !== void 0).map(([paramKey, value]) => {
return `\n ${/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(paramKey) ? paramKey : JSON.stringify(paramKey)}: ${typeof value === "object" || typeof value === "string" ? JSON.stringify(value) : value},`;
}).join("");
let content;
if (noMetadata) content = "{}";
else if (format === "json" || format === "jsonc" || format === "json5") content = [
"{",
" \"$schema\": \"https://intlayer.org/schema.json\",",
` "key": "${key}",${fileParamsString}`,
" \"content\": {",
" }",
"}"
].join("\n");
else content = [
"{",
` key: '${key}',${fileParamsString}`,
" content: {",
" },",
"}"
].join("\n");
const jsdoc = `/** @type {import('intlayer').Dictionary${noMetadata ? "['content']" : ""}} **/`;
const satisfiesType = noMetadata ? "Dictionary['content']" : "Dictionary";
switch (format) {
case "yaml": return `${[
`key: ${key}`,
...fileParams.locale ? [`locale: ${fileParams.locale}`] : [],
...fileParams.title ? [`title: ${JSON.stringify(fileParams.title)}`] : [],
...fileParams.description ? [`description: ${JSON.stringify(fileParams.description)}`] : [],
...fileParams.tags?.length ? ["tags:", ...fileParams.tags.map((tag) => ` - ${JSON.stringify(tag)}`)] : [],
"content: {}"
].join("\n")}\n`;
case "md": return [
"---",
...[
`key: ${key}`,
...fileParams.locale ? [`locale: ${fileParams.locale}`] : [],
...fileParams.title ? [`title: ${JSON.stringify(fileParams.title)}`] : [],
...fileParams.description ? [`description: ${JSON.stringify(fileParams.description)}`] : [],
...fileParams.tags?.length ? ["tags:", ...fileParams.tags.map((t) => ` - ${JSON.stringify(t)}`)] : []
],
"---",
"",
""
].join("\n");
case "ts": return [
"import { type Dictionary } from 'intlayer';",
"",
`const ${name}Content = ${content} satisfies ${satisfiesType};`,
"",
`export default ${name}Content;`,
""
].join("\n");
case "cjs": return [
jsdoc,
`const ${name}Content = ${content};`,
"",
`module.exports = ${name}Content;`,
""
].join("\n");
case "json":
case "jsonc":
case "json5": return [content, ""].join("\n");
default: return [
jsdoc,
`const ${name}Content = ${content};`,
"",
`export default ${name}Content;`,
""
].join("\n");
}
};
//#endregion
exports.getContentDeclarationFileTemplate = getContentDeclarationFileTemplate;
//# sourceMappingURL=getContentDeclarationFileTemplate.cjs.map