diff --git a/package-lock.json b/package-lock.json index 645a204b..49e08539 100644 --- a/package-lock.json +++ b/package-lock.json @@ -49,6 +49,8 @@ "maizzle": "bin/maizzle" }, "devDependencies": { + "@types/js-beautify": "^1.14.0", + "@types/markdown-it": "^13.0.0", "ava": "^5.2.0", "c8": "^8.0.0", "np": "*", @@ -931,6 +933,12 @@ "integrity": "sha512-z/QT1XN4K4KYuslS23k62yDIDLwLFkzxOuMplDtObz0+y7VqJCaO2o+SPwHCvLFZh7xazvvoor2tA/hPz9ee7g==", "dev": true }, + "node_modules/@types/js-beautify": { + "version": "1.14.0", + "resolved": "https://registry.npmjs.org/@types/js-beautify/-/js-beautify-1.14.0.tgz", + "integrity": "sha512-OrJo4dEKd/8YKwGWuRP7qC/NoxNQCVsjAT7aHhgoIrNJaaDudLwX8husFrklktmXKIFbXevxzrLyEhB1842zjg==", + "dev": true + }, "node_modules/@types/json-schema": { "version": "7.0.11", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.11.tgz", @@ -951,6 +959,28 @@ "@types/node": "*" } }, + "node_modules/@types/linkify-it": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/@types/linkify-it/-/linkify-it-3.0.2.tgz", + "integrity": "sha512-HZQYqbiFVWufzCwexrvh694SOim8z2d+xJl5UNamcvQFejLY/2YUtzXHYi3cHdI7PMlS8ejH2slRAOJQ32aNbA==", + "dev": true + }, + "node_modules/@types/markdown-it": { + "version": "13.0.0", + "resolved": "https://registry.npmjs.org/@types/markdown-it/-/markdown-it-13.0.0.tgz", + "integrity": "sha512-mPTaUl5glYfzdJFeCsvhXQwZKdyszNAZcMm5ZTP5SfpTu+vIbog7J3z8Fa4x/Fzv5TB4R6OA/pHBYIYmkYOWGQ==", + "dev": true, + "dependencies": { + "@types/linkify-it": "*", + "@types/mdurl": "*" + } + }, + "node_modules/@types/mdurl": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@types/mdurl/-/mdurl-1.0.2.tgz", + "integrity": "sha512-eC4U9MlIcu2q0KQmXszyn5Akca/0jrQmwDRgpAMJai7qBWq4amIQhZyNau4VYGtCeALvW1/NtjzJJ567aZxfKA==", + "dev": true + }, "node_modules/@types/minimatch": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-5.1.2.tgz", @@ -17694,6 +17724,12 @@ "integrity": "sha512-z/QT1XN4K4KYuslS23k62yDIDLwLFkzxOuMplDtObz0+y7VqJCaO2o+SPwHCvLFZh7xazvvoor2tA/hPz9ee7g==", "dev": true }, + "@types/js-beautify": { + "version": "1.14.0", + "resolved": "https://registry.npmjs.org/@types/js-beautify/-/js-beautify-1.14.0.tgz", + "integrity": "sha512-OrJo4dEKd/8YKwGWuRP7qC/NoxNQCVsjAT7aHhgoIrNJaaDudLwX8husFrklktmXKIFbXevxzrLyEhB1842zjg==", + "dev": true + }, "@types/json-schema": { "version": "7.0.11", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.11.tgz", @@ -17714,6 +17750,28 @@ "@types/node": "*" } }, + "@types/linkify-it": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/@types/linkify-it/-/linkify-it-3.0.2.tgz", + "integrity": "sha512-HZQYqbiFVWufzCwexrvh694SOim8z2d+xJl5UNamcvQFejLY/2YUtzXHYi3cHdI7PMlS8ejH2slRAOJQ32aNbA==", + "dev": true + }, + "@types/markdown-it": { + "version": "13.0.0", + "resolved": "https://registry.npmjs.org/@types/markdown-it/-/markdown-it-13.0.0.tgz", + "integrity": "sha512-mPTaUl5glYfzdJFeCsvhXQwZKdyszNAZcMm5ZTP5SfpTu+vIbog7J3z8Fa4x/Fzv5TB4R6OA/pHBYIYmkYOWGQ==", + "dev": true, + "requires": { + "@types/linkify-it": "*", + "@types/mdurl": "*" + } + }, + "@types/mdurl": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@types/mdurl/-/mdurl-1.0.2.tgz", + "integrity": "sha512-eC4U9MlIcu2q0KQmXszyn5Akca/0jrQmwDRgpAMJai7qBWq4amIQhZyNau4VYGtCeALvW1/NtjzJJ567aZxfKA==", + "dev": true + }, "@types/minimatch": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-5.1.2.tgz", diff --git a/package.json b/package.json index 6f788dcb..9d0d9cfd 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "description": "Maizzle is a framework that helps you quickly build HTML emails with Tailwind CSS.", "license": "MIT", "main": "src/index.js", + "types": "src/index.d.ts", "bin": { "maizzle": "bin/maizzle" }, @@ -77,6 +78,8 @@ "tailwindcss": "^3.2.7" }, "devDependencies": { + "@types/js-beautify": "^1.14.0", + "@types/markdown-it": "^13.0.0", "ava": "^5.2.0", "c8": "^8.0.0", "np": "*", diff --git a/src/index.d.ts b/src/index.d.ts new file mode 100644 index 00000000..2e8b3199 --- /dev/null +++ b/src/index.d.ts @@ -0,0 +1,1731 @@ +import type {CoreBeautifyOptions} from 'js-beautify'; +import type {Options as MarkdownItOptions} from 'markdown-it'; +import type queryString from 'query-string'; + +declare namespace MaizzleFramework { + interface LayoutsConfig { + /** + Encoding to be used when reading a layout file from disk. + + @default 'utf8' + */ + encoding?: string; + + /** + Name of the slot tag, where the content will be injected. + This is typically used in a Layout file, to define the place where to inject a Template. + + @default 'block' + */ + slotTagName?: string; + + /** + Name of the fill tag, inside of which content that will be injected is defined. + This is typically used in a Template file, to extend a Layout. + + @default 'block' + */ + fillTagName?: string; + + /** + Path to the layouts folder, relative to the project root. + + @default 'src/layouts' + */ + root?: string; + + /** + Tag name to be used in HTML when extending a layout. + + @default 'extends' + */ + tagName?: string; + + } + + interface TemplatesConfig { + /** + Directory where Maizzle should look for Templates to compile. + + @default 'src/templates' + + @example + ``` + module.exports = { + build: { + templates: { + source: 'src/templates' + } + } + } + ``` + */ + source?: + | string + | Array + | ((config: Config) => string | string[]); + + /** + Define what file extensions your Templates use. + Maizzle will only compile files from your `source` directory that have these extensions. + + @default 'html' + + @example + ``` + module.exports = { + build: { + templates: { + filetypes: ['html', 'blade.php'] + } + } + } + ``` + */ + filetypes?: string | string[]; + + /** + Define the output path for compiled Templates, and what file extension they should use. + + @example + ``` + module.exports = { + build: { + templates: { + destination: { + path: 'build_production', + extension: 'html' + } + } + } + } + ``` + */ + destination?: { + /** + Directory where Maizzle should output compiled Templates. + + @default 'build_{env}' + */ + path?: string; + /** + File extension to be used for compiled Templates. + + @default 'html' + */ + extension: string; + }; + + /** + Source and destination directories for your asset files. + + @example + ``` + module.exports = { + build: { + templates: { + assets: { + source: 'src/images', + destination: 'images' + } + } + } + } + ``` + */ + assets?: { + /** + Directory where Maizzle should look for asset files. + + @default '' + */ + source?: string; + /** + Directory where asset files should be copied to. + + @default 'assets' + */ + destination?: string; + }; + + /** + Paths to files or directories from your `source` that should _not_ be copied over to the build destination. + + @default [''] + + @example + ``` + module.exports = { + build: { + templates: { + source: 'src/templates', + omit: ['1.html', 'archive/4.html'], + // ... + } + } + } + ``` + */ + omit?: string[]; + + /** + Paths to files relative to your `source` directory that should not be parsed. + They will be copied over to the build destination as-is. + + @default [''] + + @example + ``` + module.exports = { + build: { + templates: { + source: 'src/templates', + skip: ['1.html', 'archive/3.html'], + } + } + } + ``` + */ + skip?: string | string[]; + } + + interface ComponentsConfig { + /** + Root path where to look for folders containing component files. + + @default './' + */ + root?: string; + + /** + Paths where to look for component files. Must be relative to `root`. + + @default ['src/components', 'src/layouts', 'src/templates'] + */ + folders?: string[]; + + /** + Prefix to use for component tags. + + @default 'x-' + */ + tagPrefix?: string; + + /** + Tag name to be used in HTML when using a component. + + @default 'component' + */ + tag?: string; + + /** + Attribute name to be used when referencing a component via its path. + + @default 'src' + */ + attribute?: string; + + /** + File extension that component files must use. + Any other files will be ignored and not be made available as components. + + @default 'html' + */ + fileExtension?: string; + + /** + Name of the tag that will be replaced with the content that is passed to the component. + + @default 'content' + */ + yield?: string; + + /** + Name of the slot tag, where the content will be injected. + + @default 'slot' + */ + slot?: string; + + /** + Name of the fill tag, where the content to be injected is defined. + + @default 'fill' + */ + fill?: string; + + /** + String to use as a separator between the slot tag and its name. + + @default ':' + */ + slotSeparator?: string; + + /** + Tag name for pushing content to a stack. + + @default 'push' + */ + push?: string; + + /** + Tag name for popping (rendering) content from a stack. + + @default 'stack' + */ + stack?: string; + + /** + Name of the props attribute to use in the `