@jakubmazanec/template 2.0.16 → 2.0.17-next.302527c3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/Template.js +3 -4
- package/build/Template.js.map +2 -2
- package/package.json +2 -6
- package/source/Template.ts +3 -4
package/build/Template.js
CHANGED
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
import ejs from "ejs";
|
|
3
3
|
import fs from "fs-extra";
|
|
4
4
|
import matter from "gray-matter";
|
|
5
|
-
import
|
|
6
|
-
import omit from "lodash.omit";
|
|
5
|
+
import _ from "lodash";
|
|
7
6
|
import path from "node:path";
|
|
8
7
|
import prettier from "prettier";
|
|
9
8
|
import yaml from "yaml";
|
|
@@ -59,7 +58,7 @@ export class Template {
|
|
|
59
58
|
path.join(path.dirname(templatePath), rawAttributes.extends),
|
|
60
59
|
options
|
|
61
60
|
);
|
|
62
|
-
rawAttributes = merge(extendedTemplate.attributes, rawAttributes);
|
|
61
|
+
rawAttributes = _.merge(extendedTemplate.attributes, rawAttributes);
|
|
63
62
|
if (!content.trim()) {
|
|
64
63
|
content = extendedTemplate.content;
|
|
65
64
|
}
|
|
@@ -112,7 +111,7 @@ export class Template {
|
|
|
112
111
|
async render(data, options) {
|
|
113
112
|
let renders = [];
|
|
114
113
|
for (let variables of Array.isArray(this.attributes.variables) ? this.attributes.variables : [this.attributes.variables]) {
|
|
115
|
-
let renderedAttributes = omit(this.attributes, ["if"]);
|
|
114
|
+
let renderedAttributes = _.omit(this.attributes, ["if"]);
|
|
116
115
|
let renderedVariables = variables;
|
|
117
116
|
if (renderedVariables) {
|
|
118
117
|
for (let [variableName, variableValue] of Object.entries(renderedVariables)) {
|
package/build/Template.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../source/Template.ts"],
|
|
4
|
-
"sourcesContent": ["import ejs from 'ejs';\nimport fs from 'fs-extra';\nimport matter from 'gray-matter';\nimport merge from 'lodash.merge';\nimport omit from 'lodash.omit';\nimport path from 'node:path';\nimport prettier from 'prettier';\nimport yaml from 'yaml';\nimport {type z, type ZodObject} from 'zod';\n\nimport {NO_INFERRED_PARSER_REGEXP} from './constants.js';\nimport {type TemplateAttributes, templateAttributesSchema} from './TemplateAttributes.js';\nimport {TemplateError} from './TemplateError.js';\nimport {type TemplateFunction} from './TemplateFunction.js';\nimport {type TemplateRender} from './TemplateRender.js';\nimport {type TemplateRenders} from './TemplateRenders.js';\n\nexport type TemplateOptions<\n A extends ZodObject | undefined = undefined,\n D extends ZodObject | undefined = undefined,\n> = {\n /** Template path. */\n path?: string;\n\n /** Template content. */\n content: string;\n\n /** Template attributes. */\n attributes: A extends undefined ? TemplateAttributes\n : TemplateAttributes & z.infer<NonNullable<A>>;\n\n /** Zod schema for custom template attributes. */\n attributesSchema?: A | undefined;\n\n /** Zod schema for template data. */\n dataSchema?: D | undefined;\n};\n\nexport type TemplateReadOptions<\n A extends ZodObject | undefined = undefined,\n D extends ZodObject | undefined = undefined,\n> = {\n /** Zod schema for custom template attributes. */\n attributesSchema?: A | undefined;\n\n /** Zod schema for template data. */\n dataSchema?: D | undefined;\n};\n\nexport type TemplateReadAndRenderOptions<\n A extends ZodObject | undefined = undefined,\n D extends ZodObject | undefined = undefined,\n> = {\n /** Prettier options. */\n prettierOptions?: prettier.Options | undefined;\n\n /** Disable formatting the rendered template using Prettier. */\n disablePrettier?: boolean | undefined;\n\n /** Zod schema for custom template attributes. */\n attributesSchema?: A | undefined;\n\n /** Zod schema for template data. */\n dataSchema?: D | undefined;\n};\n\nexport type TemplateRenderOptions = {\n /** Prettier options. */\n prettierOptions?: prettier.Options | undefined;\n\n /** Disable formatting the rendered template using Prettier. */\n disablePrettier?: boolean | undefined;\n};\n\n/**\n * The `Template` object stores all information about a template and has methods for reading and rendering.\n *\n * ```TypeScript\n * let template = new Template({\n * content: '<%- value %>',\n * attributes: {\n * to: 'value.txt',\n * },\n * dataSchema: z.object({value: z.number()}),\n * });\n *\n * console.log(await template.render({value: 42})); // -> [{attributes: {to: 'value.txt'}, data: {value: 42}, content: '42'}]\n * ```\n *\n * @typeParam A A Zod schema type used to define the custom template attributes type.\n * @typeParam D A Zod schema type used to define the template datatype.\n */\nexport class Template<\n A extends ZodObject | undefined = undefined,\n D extends ZodObject | undefined = undefined,\n> {\n /** Template path. */\n path?: string;\n\n /** Template content. Templates are written in [EJS](https://ejs.co/). */\n readonly content: string;\n\n /** Template attributes. These control how the template is rendered. Some attributes can be written in [EJS](https://ejs.co/) and are rendered before the template content is rendered. It is expected that attribute `if` renders to a string that can be parsed as YAML value; if that value is `false`, the rendering is cancelled. Attribute `to` is also rendered and it represents the path of file the resulting template render is supposed to be written into (by the user). Attribute `variables` is an object that is merged with the data object before rendering. If attribute `variables` is an array of objects, that leads to multiple renders, each with different variables object merged with the data. Each variable that is a string is also rendered. */\n readonly attributes: A extends undefined ? TemplateAttributes\n : TemplateAttributes & z.infer<NonNullable<A>>;\n\n /** Template function. */\n private readonly fn: TemplateFunction;\n\n /** Zod schema for custom template attributes. */\n readonly attributesSchema: A extends ZodObject ? A : null;\n\n /** Zod schema for template data. */\n readonly dataSchema: D extends ZodObject ? D : null;\n\n constructor({\n path: templatePath,\n content,\n attributes,\n attributesSchema,\n dataSchema,\n }: TemplateOptions<A, D>) {\n if (templatePath) {\n this.path = templatePath;\n }\n\n this.content = content;\n this.attributes = attributes;\n this.fn = ejs.compile(this.content);\n\n if (attributesSchema) {\n this.attributesSchema = attributesSchema as A extends ZodObject ? A : null;\n } else {\n this.attributesSchema = null as A extends ZodObject ? A : null;\n }\n\n if (dataSchema) {\n this.dataSchema = dataSchema as D extends ZodObject ? D : null;\n } else {\n this.dataSchema = null as D extends ZodObject ? D : null;\n }\n }\n\n /**\n * Reads a template from a file.\n *\n * @param templatePath Path to the template file.\n */\n static async read<\n A extends ZodObject | undefined = undefined,\n D extends ZodObject | undefined = undefined,\n >(templatePath: string, options?: TemplateReadOptions<A, D>): Promise<Template<A, D>> {\n let {data: rawAttributes, content} = matter(await fs.readFile(templatePath, 'utf8'));\n\n // extending another template\n if (typeof rawAttributes.extends === 'string' && rawAttributes.extends) {\n let extendedTemplate = await Template.read(\n path.join(path.dirname(templatePath), rawAttributes.extends),\n options,\n ); // you can point to any template, but it will be parsed with the same options, including attribute or data schema\n\n // attributes are recursively merged\n rawAttributes = merge(extendedTemplate.attributes, rawAttributes);\n\n // if content is empty, use content from the extended template\n if (!content.trim()) {\n content = extendedTemplate.content;\n }\n }\n\n let attributesSchema =\n options?.attributesSchema ?\n templateAttributesSchema.merge(options.attributesSchema)\n : templateAttributesSchema;\n let attributesParseResult = attributesSchema.safeParse(rawAttributes);\n\n if (!attributesParseResult.success) {\n throw new TemplateError('INVALID_ATTRIBUTES', {\n cause: attributesParseResult.error,\n data: {\n path: templatePath,\n zodIssues: attributesParseResult.error.issues,\n },\n });\n }\n\n let attributes = attributesParseResult.data;\n\n return new this({\n path: templatePath,\n attributes,\n content,\n attributesSchema: options?.attributesSchema,\n dataSchema: options?.dataSchema,\n } as TemplateOptions<A, D>);\n }\n\n /**\n * Reads a template from a file and then renders it.\n *\n * @param templatePath Path to the template file.\n * @param data Data used for rendering the template.\n * @param options Options object.\n * @return Template renders.\n */\n static async readAndRender<\n A extends ZodObject | undefined = undefined,\n D extends ZodObject | undefined = undefined,\n >(\n templatePath: string,\n data: D extends undefined ? null : z.infer<NonNullable<D>>,\n options?: TemplateReadAndRenderOptions<A, D>,\n ) {\n let template = await Template.read<A, D>(templatePath, {\n attributesSchema: options?.attributesSchema,\n dataSchema: options?.dataSchema,\n });\n\n return template.render(data, {\n prettierOptions: options?.prettierOptions,\n disablePrettier: options?.disablePrettier,\n });\n }\n\n /**\n * Renders the template using data.\n *\n * @param data Data used for rendering the template.\n * @param options Options object.\n * @return Template renders.\n */\n async render(\n data: D extends undefined ? null : z.infer<NonNullable<D>>,\n options?: TemplateRenderOptions,\n ): Promise<TemplateRenders<A, D>> {\n let renders: TemplateRenders<A, D> = [];\n\n for (let variables of Array.isArray(this.attributes.variables) ?\n this.attributes.variables\n : [this.attributes.variables]) {\n let renderedAttributes = omit(this.attributes, ['if']);\n let renderedVariables = variables;\n\n if (renderedVariables) {\n for (let [variableName, variableValue] of Object.entries(renderedVariables)) {\n if (typeof variableValue === 'string') {\n renderedVariables[variableName] = ejs.render(variableValue, {...data});\n } else {\n renderedVariables[variableName] = variableValue;\n }\n }\n\n renderedAttributes.variables = renderedVariables;\n }\n\n let dataWithAttributes = {...data, attributes: renderedAttributes};\n\n if (this.attributes.if) {\n let renderedIf = ejs.render(this.attributes.if, dataWithAttributes);\n let parsedIf = yaml.parse(renderedIf) as unknown;\n\n if (parsedIf === false) {\n continue;\n }\n }\n\n renderedAttributes.to = ejs.render(renderedAttributes.to, dataWithAttributes);\n dataWithAttributes.attributes = renderedAttributes;\n\n let content;\n\n try {\n content = this.fn(dataWithAttributes);\n } catch (error: unknown) {\n throw new TemplateError('FAILED_RENDER', {cause: error});\n }\n\n if (!options?.disablePrettier) {\n try {\n content = await prettier.format(content, {\n ...options?.prettierOptions,\n filepath: renderedAttributes.to,\n });\n } catch (error: unknown) {\n if (!NO_INFERRED_PARSER_REGEXP.test((error as Error).message)) {\n throw new TemplateError('FAILED_FORMAT', {cause: error});\n }\n }\n }\n\n renders.push({\n attributes: renderedAttributes,\n data: data ?? null,\n content,\n } as TemplateRender<A, D>);\n }\n\n return renders;\n }\n}\n"],
|
|
5
|
-
"mappings": ";AAAA,OAAO,SAAS;AAChB,OAAO,QAAQ;AACf,OAAO,YAAY;AACnB,OAAO,
|
|
4
|
+
"sourcesContent": ["import ejs from 'ejs';\nimport fs from 'fs-extra';\nimport matter from 'gray-matter';\nimport _ from 'lodash';\nimport path from 'node:path';\nimport prettier from 'prettier';\nimport yaml from 'yaml';\nimport {type z, type ZodObject} from 'zod';\n\nimport {NO_INFERRED_PARSER_REGEXP} from './constants.js';\nimport {type TemplateAttributes, templateAttributesSchema} from './TemplateAttributes.js';\nimport {TemplateError} from './TemplateError.js';\nimport {type TemplateFunction} from './TemplateFunction.js';\nimport {type TemplateRender} from './TemplateRender.js';\nimport {type TemplateRenders} from './TemplateRenders.js';\n\nexport type TemplateOptions<\n A extends ZodObject | undefined = undefined,\n D extends ZodObject | undefined = undefined,\n> = {\n /** Template path. */\n path?: string;\n\n /** Template content. */\n content: string;\n\n /** Template attributes. */\n attributes: A extends undefined ? TemplateAttributes\n : TemplateAttributes & z.infer<NonNullable<A>>;\n\n /** Zod schema for custom template attributes. */\n attributesSchema?: A | undefined;\n\n /** Zod schema for template data. */\n dataSchema?: D | undefined;\n};\n\nexport type TemplateReadOptions<\n A extends ZodObject | undefined = undefined,\n D extends ZodObject | undefined = undefined,\n> = {\n /** Zod schema for custom template attributes. */\n attributesSchema?: A | undefined;\n\n /** Zod schema for template data. */\n dataSchema?: D | undefined;\n};\n\nexport type TemplateReadAndRenderOptions<\n A extends ZodObject | undefined = undefined,\n D extends ZodObject | undefined = undefined,\n> = {\n /** Prettier options. */\n prettierOptions?: prettier.Options | undefined;\n\n /** Disable formatting the rendered template using Prettier. */\n disablePrettier?: boolean | undefined;\n\n /** Zod schema for custom template attributes. */\n attributesSchema?: A | undefined;\n\n /** Zod schema for template data. */\n dataSchema?: D | undefined;\n};\n\nexport type TemplateRenderOptions = {\n /** Prettier options. */\n prettierOptions?: prettier.Options | undefined;\n\n /** Disable formatting the rendered template using Prettier. */\n disablePrettier?: boolean | undefined;\n};\n\n/**\n * The `Template` object stores all information about a template and has methods for reading and rendering.\n *\n * ```TypeScript\n * let template = new Template({\n * content: '<%- value %>',\n * attributes: {\n * to: 'value.txt',\n * },\n * dataSchema: z.object({value: z.number()}),\n * });\n *\n * console.log(await template.render({value: 42})); // -> [{attributes: {to: 'value.txt'}, data: {value: 42}, content: '42'}]\n * ```\n *\n * @typeParam A A Zod schema type used to define the custom template attributes type.\n * @typeParam D A Zod schema type used to define the template datatype.\n */\nexport class Template<\n A extends ZodObject | undefined = undefined,\n D extends ZodObject | undefined = undefined,\n> {\n /** Template path. */\n path?: string;\n\n /** Template content. Templates are written in [EJS](https://ejs.co/). */\n readonly content: string;\n\n /** Template attributes. These control how the template is rendered. Some attributes can be written in [EJS](https://ejs.co/) and are rendered before the template content is rendered. It is expected that attribute `if` renders to a string that can be parsed as YAML value; if that value is `false`, the rendering is cancelled. Attribute `to` is also rendered and it represents the path of file the resulting template render is supposed to be written into (by the user). Attribute `variables` is an object that is merged with the data object before rendering. If attribute `variables` is an array of objects, that leads to multiple renders, each with different variables object merged with the data. Each variable that is a string is also rendered. */\n readonly attributes: A extends undefined ? TemplateAttributes\n : TemplateAttributes & z.infer<NonNullable<A>>;\n\n /** Template function. */\n private readonly fn: TemplateFunction;\n\n /** Zod schema for custom template attributes. */\n readonly attributesSchema: A extends ZodObject ? A : null;\n\n /** Zod schema for template data. */\n readonly dataSchema: D extends ZodObject ? D : null;\n\n constructor({\n path: templatePath,\n content,\n attributes,\n attributesSchema,\n dataSchema,\n }: TemplateOptions<A, D>) {\n if (templatePath) {\n this.path = templatePath;\n }\n\n this.content = content;\n this.attributes = attributes;\n this.fn = ejs.compile(this.content);\n\n if (attributesSchema) {\n this.attributesSchema = attributesSchema as A extends ZodObject ? A : null;\n } else {\n this.attributesSchema = null as A extends ZodObject ? A : null;\n }\n\n if (dataSchema) {\n this.dataSchema = dataSchema as D extends ZodObject ? D : null;\n } else {\n this.dataSchema = null as D extends ZodObject ? D : null;\n }\n }\n\n /**\n * Reads a template from a file.\n *\n * @param templatePath Path to the template file.\n */\n static async read<\n A extends ZodObject | undefined = undefined,\n D extends ZodObject | undefined = undefined,\n >(templatePath: string, options?: TemplateReadOptions<A, D>): Promise<Template<A, D>> {\n let {data: rawAttributes, content} = matter(await fs.readFile(templatePath, 'utf8'));\n\n // extending another template\n if (typeof rawAttributes.extends === 'string' && rawAttributes.extends) {\n let extendedTemplate = await Template.read(\n path.join(path.dirname(templatePath), rawAttributes.extends),\n options,\n ); // you can point to any template, but it will be parsed with the same options, including attribute or data schema\n\n // attributes are recursively merged\n rawAttributes = _.merge(extendedTemplate.attributes, rawAttributes);\n\n // if content is empty, use content from the extended template\n if (!content.trim()) {\n content = extendedTemplate.content;\n }\n }\n\n let attributesSchema =\n options?.attributesSchema ?\n templateAttributesSchema.merge(options.attributesSchema)\n : templateAttributesSchema;\n let attributesParseResult = attributesSchema.safeParse(rawAttributes);\n\n if (!attributesParseResult.success) {\n throw new TemplateError('INVALID_ATTRIBUTES', {\n cause: attributesParseResult.error,\n data: {\n path: templatePath,\n zodIssues: attributesParseResult.error.issues,\n },\n });\n }\n\n let attributes = attributesParseResult.data;\n\n return new this({\n path: templatePath,\n attributes,\n content,\n attributesSchema: options?.attributesSchema,\n dataSchema: options?.dataSchema,\n } as TemplateOptions<A, D>);\n }\n\n /**\n * Reads a template from a file and then renders it.\n *\n * @param templatePath Path to the template file.\n * @param data Data used for rendering the template.\n * @param options Options object.\n * @return Template renders.\n */\n static async readAndRender<\n A extends ZodObject | undefined = undefined,\n D extends ZodObject | undefined = undefined,\n >(\n templatePath: string,\n data: D extends undefined ? null : z.infer<NonNullable<D>>,\n options?: TemplateReadAndRenderOptions<A, D>,\n ) {\n let template = await Template.read<A, D>(templatePath, {\n attributesSchema: options?.attributesSchema,\n dataSchema: options?.dataSchema,\n });\n\n return template.render(data, {\n prettierOptions: options?.prettierOptions,\n disablePrettier: options?.disablePrettier,\n });\n }\n\n /**\n * Renders the template using data.\n *\n * @param data Data used for rendering the template.\n * @param options Options object.\n * @return Template renders.\n */\n async render(\n data: D extends undefined ? null : z.infer<NonNullable<D>>,\n options?: TemplateRenderOptions,\n ): Promise<TemplateRenders<A, D>> {\n let renders: TemplateRenders<A, D> = [];\n\n for (let variables of Array.isArray(this.attributes.variables) ?\n this.attributes.variables\n : [this.attributes.variables]) {\n let renderedAttributes = _.omit(this.attributes, ['if']);\n let renderedVariables = variables;\n\n if (renderedVariables) {\n for (let [variableName, variableValue] of Object.entries(renderedVariables)) {\n if (typeof variableValue === 'string') {\n renderedVariables[variableName] = ejs.render(variableValue, {...data});\n } else {\n renderedVariables[variableName] = variableValue;\n }\n }\n\n renderedAttributes.variables = renderedVariables;\n }\n\n let dataWithAttributes = {...data, attributes: renderedAttributes};\n\n if (this.attributes.if) {\n let renderedIf = ejs.render(this.attributes.if, dataWithAttributes);\n let parsedIf = yaml.parse(renderedIf) as unknown;\n\n if (parsedIf === false) {\n continue;\n }\n }\n\n renderedAttributes.to = ejs.render(renderedAttributes.to, dataWithAttributes);\n dataWithAttributes.attributes = renderedAttributes;\n\n let content;\n\n try {\n content = this.fn(dataWithAttributes);\n } catch (error: unknown) {\n throw new TemplateError('FAILED_RENDER', {cause: error});\n }\n\n if (!options?.disablePrettier) {\n try {\n content = await prettier.format(content, {\n ...options?.prettierOptions,\n filepath: renderedAttributes.to,\n });\n } catch (error: unknown) {\n if (!NO_INFERRED_PARSER_REGEXP.test((error as Error).message)) {\n throw new TemplateError('FAILED_FORMAT', {cause: error});\n }\n }\n }\n\n renders.push({\n attributes: renderedAttributes,\n data: data ?? null,\n content,\n } as TemplateRender<A, D>);\n }\n\n return renders;\n }\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,OAAO,SAAS;AAChB,OAAO,QAAQ;AACf,OAAO,YAAY;AACnB,OAAO,OAAO;AACd,OAAO,UAAU;AACjB,OAAO,cAAc;AACrB,OAAO,UAAU;AAGjB,SAAQ,iCAAgC;AACxC,SAAiC,gCAA+B;AAChE,SAAQ,qBAAoB;AAgFrB,aAAM,SAGX;AAAA;AAAA,EAEA;AAAA;AAAA,EAGS;AAAA;AAAA,EAGA;AAAA;AAAA,EAIQ;AAAA;AAAA,EAGR;AAAA;AAAA,EAGA;AAAA,EAET,YAAY;AAAA,IACV,MAAM;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAA0B;AACxB,QAAI,cAAc;AAChB,WAAK,OAAO;AAAA,IACd;AAEA,SAAK,UAAU;AAC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AAM,IAAI,cAAc,iBAAiB,EAAC,OAAO,MAAK,CAAC;AAAA,MACzD;AAEA,UAAI,CAAC,SAAS,iBAAiB;AAC7B,YAAI;AACF,oBAAU,MAAM,SAAS,OAAO,SAAS;AAAA,YACvC,GAAG,SAAS;AAAA,YACZ,UAAU,mBAAmB;AAAA,UAC/B,CAAC;AAAA,QACH,SAAS,OAAgB;AACvB,cAAI,CAAC,0BAA0B,KAAM,MAAgB,OAAO,GAAG;AAC7D,kBAAM,IAAI,cAAc,iBAAiB,EAAC,OAAO,MAAK,CAAC;AAAA,UACzD;AAAA,QACF;AAAA,MACF;AAEA,cAAQ,KAAK;AAAA,QACX,YAAY;AAAA,QACZ,MAAM,QAAQ;AAAA,QACd;AAAA,MACF,CAAyB;AAAA,IAC3B;AAEA,WAAO;AAAA,EACT;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jakubmazanec/template",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.17-next.302527c3",
|
|
4
4
|
"description": "TypeScript-first library for working with templates using EJS and Zod.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -31,8 +31,7 @@
|
|
|
31
31
|
"ejs": "^3.1.10",
|
|
32
32
|
"fs-extra": "^11.3.2",
|
|
33
33
|
"gray-matter": "^4.0.3",
|
|
34
|
-
"lodash
|
|
35
|
-
"lodash.omit": "^4.5.0",
|
|
34
|
+
"lodash": "^4.17.21",
|
|
36
35
|
"prettier": "^3.6.2",
|
|
37
36
|
"yaml": "^2.8.1",
|
|
38
37
|
"zod": "^4.1.13"
|
|
@@ -42,15 +41,12 @@
|
|
|
42
41
|
"@types/ejs": "^3.1.5",
|
|
43
42
|
"@types/fs-extra": "^11.0.4",
|
|
44
43
|
"@types/lodash": "^4.17.21",
|
|
45
|
-
"@types/lodash.merge": "^4.6.9",
|
|
46
|
-
"@types/lodash.omit": "^4.5.9",
|
|
47
44
|
"@types/node": "^24.0.4",
|
|
48
45
|
"@vitest/coverage-v8": "^3.2.4",
|
|
49
46
|
"concurrently": "^9.2.1",
|
|
50
47
|
"del-cli": "^6.0.0",
|
|
51
48
|
"esbuild": "^0.27.0",
|
|
52
49
|
"eslint": "^9.33.0",
|
|
53
|
-
"lodash": "^4.17.21",
|
|
54
50
|
"prettier-plugin-packagejson": "^2.5.19",
|
|
55
51
|
"typedoc": "^0.28.14",
|
|
56
52
|
"typedoc-plugin-markdown": "^4.9.0",
|
package/source/Template.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import ejs from 'ejs';
|
|
2
2
|
import fs from 'fs-extra';
|
|
3
3
|
import matter from 'gray-matter';
|
|
4
|
-
import
|
|
5
|
-
import omit from 'lodash.omit';
|
|
4
|
+
import _ from 'lodash';
|
|
6
5
|
import path from 'node:path';
|
|
7
6
|
import prettier from 'prettier';
|
|
8
7
|
import yaml from 'yaml';
|
|
@@ -160,7 +159,7 @@ export class Template<
|
|
|
160
159
|
); // you can point to any template, but it will be parsed with the same options, including attribute or data schema
|
|
161
160
|
|
|
162
161
|
// attributes are recursively merged
|
|
163
|
-
rawAttributes = merge(extendedTemplate.attributes, rawAttributes);
|
|
162
|
+
rawAttributes = _.merge(extendedTemplate.attributes, rawAttributes);
|
|
164
163
|
|
|
165
164
|
// if content is empty, use content from the extended template
|
|
166
165
|
if (!content.trim()) {
|
|
@@ -238,7 +237,7 @@ export class Template<
|
|
|
238
237
|
for (let variables of Array.isArray(this.attributes.variables) ?
|
|
239
238
|
this.attributes.variables
|
|
240
239
|
: [this.attributes.variables]) {
|
|
241
|
-
let renderedAttributes = omit(this.attributes, ['if']);
|
|
240
|
+
let renderedAttributes = _.omit(this.attributes, ['if']);
|
|
242
241
|
let renderedVariables = variables;
|
|
243
242
|
|
|
244
243
|
if (renderedVariables) {
|