@maizzle/framework 6.0.0-rc.1 → 6.0.0-rc.3
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/bin/maizzle.mjs +1 -1
- package/dist/build.mjs +2 -1
- package/dist/build.mjs.map +1 -1
- package/dist/config/index.mjs +7 -0
- package/dist/config/index.mjs.map +1 -1
- package/dist/plugin.d.mts.map +1 -1
- package/dist/plugin.mjs +13 -0
- package/dist/plugin.mjs.map +1 -1
- package/dist/render/createRenderer.d.mts +2 -0
- package/dist/render/createRenderer.d.mts.map +1 -1
- package/dist/render/createRenderer.mjs +11 -4
- package/dist/render/createRenderer.mjs.map +1 -1
- package/dist/render/index.mjs +2 -1
- package/dist/render/index.mjs.map +1 -1
- package/dist/serve.mjs +2 -1
- package/dist/serve.mjs.map +1 -1
- package/dist/types/config.d.mts +3 -0
- package/dist/types/config.d.mts.map +1 -1
- package/dist/utils/detect.d.mts +5 -0
- package/dist/utils/detect.d.mts.map +1 -0
- package/dist/utils/detect.mjs +11 -0
- package/dist/utils/detect.mjs.map +1 -0
- package/node_modules/@clack/core/CHANGELOG.md +87 -4
- package/node_modules/@clack/core/README.md +1 -1
- package/node_modules/@clack/core/dist/index.d.mts +186 -48
- package/node_modules/@clack/core/dist/index.mjs +10 -14
- package/node_modules/@clack/core/dist/index.mjs.map +1 -1
- package/node_modules/@clack/core/package.json +7 -9
- package/node_modules/@clack/prompts/CHANGELOG.md +171 -7
- package/node_modules/@clack/prompts/README.md +66 -3
- package/node_modules/@clack/prompts/dist/index.d.mts +302 -76
- package/node_modules/@clack/prompts/dist/index.mjs +134 -84
- package/node_modules/@clack/prompts/dist/index.mjs.map +1 -1
- package/node_modules/@clack/prompts/package.json +14 -10
- package/node_modules/citty/LICENSE +0 -15
- package/node_modules/citty/README.md +166 -69
- package/node_modules/citty/dist/index.d.mts +88 -56
- package/node_modules/citty/dist/index.mjs +399 -437
- package/node_modules/citty/package.json +28 -35
- package/node_modules/giget/README.md +59 -11
- package/node_modules/giget/dist/THIRD-PARTY-LICENSES.md +205 -0
- package/node_modules/giget/dist/_chunks/giget.mjs +508 -0
- package/node_modules/giget/dist/_chunks/libs/citty.mjs +269 -0
- package/node_modules/giget/dist/_chunks/libs/nypm.d.mts +1 -0
- package/node_modules/giget/dist/_chunks/libs/nypm.mjs +669 -0
- package/node_modules/giget/dist/_chunks/libs/tar.mjs +2931 -0
- package/node_modules/giget/dist/_chunks/rolldown-runtime.mjs +14 -0
- package/node_modules/giget/dist/cli.d.mts +1 -0
- package/node_modules/giget/dist/cli.mjs +89 -111
- package/node_modules/giget/dist/index.d.mts +46 -35
- package/node_modules/giget/dist/index.mjs +2 -22
- package/node_modules/giget/package.json +32 -45
- package/node_modules/maizzle/README.md +140 -0
- package/node_modules/maizzle/bin/maizzle.mjs +5 -0
- package/node_modules/maizzle/dist/commands/new.d.mts +7 -0
- package/node_modules/maizzle/dist/commands/new.mjs +278 -0
- package/node_modules/{@maizzle/cli → maizzle}/dist/index.d.mts +1 -1
- package/node_modules/maizzle/dist/index.mjs +44 -0
- package/node_modules/{commander → maizzle/node_modules/commander}/Readme.md +94 -67
- package/node_modules/{commander → maizzle/node_modules/commander}/lib/argument.js +5 -4
- package/node_modules/{commander → maizzle/node_modules/commander}/lib/command.js +154 -39
- package/node_modules/{commander → maizzle/node_modules/commander}/lib/help.js +77 -39
- package/node_modules/{commander → maizzle/node_modules/commander}/lib/option.js +16 -3
- package/node_modules/{commander → maizzle/node_modules/commander}/package-support.json +4 -1
- package/node_modules/{commander → maizzle/node_modules/commander}/package.json +8 -8
- package/node_modules/{commander → maizzle/node_modules/commander}/typings/index.d.ts +71 -3
- package/node_modules/{@maizzle/cli → maizzle}/package.json +13 -11
- package/node_modules/tinyexec/README.md +49 -3
- package/node_modules/tinyexec/dist/main.d.mts +25 -14
- package/node_modules/tinyexec/dist/main.mjs +148 -100
- package/node_modules/tinyexec/package.json +9 -8
- package/package.json +3 -3
- package/node_modules/@clack/core/dist/index.cjs +0 -15
- package/node_modules/@clack/core/dist/index.cjs.map +0 -1
- package/node_modules/@clack/core/dist/index.d.cts +0 -211
- package/node_modules/@clack/core/dist/index.d.ts +0 -211
- package/node_modules/@clack/prompts/dist/index.cjs +0 -87
- package/node_modules/@clack/prompts/dist/index.cjs.map +0 -1
- package/node_modules/@clack/prompts/dist/index.d.cts +0 -165
- package/node_modules/@clack/prompts/dist/index.d.ts +0 -165
- package/node_modules/@maizzle/cli/README.md +0 -58
- package/node_modules/@maizzle/cli/dist/index.mjs +0 -42
- package/node_modules/citty/dist/index.cjs +0 -475
- package/node_modules/citty/dist/index.d.cts +0 -80
- package/node_modules/citty/dist/index.d.ts +0 -80
- package/node_modules/consola/LICENSE +0 -47
- package/node_modules/consola/README.md +0 -352
- package/node_modules/consola/basic.d.ts +0 -1
- package/node_modules/consola/browser.d.ts +0 -1
- package/node_modules/consola/core.d.ts +0 -1
- package/node_modules/consola/dist/basic.cjs +0 -32
- package/node_modules/consola/dist/basic.d.cts +0 -23
- package/node_modules/consola/dist/basic.d.mts +0 -21
- package/node_modules/consola/dist/basic.d.ts +0 -23
- package/node_modules/consola/dist/basic.mjs +0 -24
- package/node_modules/consola/dist/browser.cjs +0 -84
- package/node_modules/consola/dist/browser.d.cts +0 -23
- package/node_modules/consola/dist/browser.d.mts +0 -21
- package/node_modules/consola/dist/browser.d.ts +0 -23
- package/node_modules/consola/dist/browser.mjs +0 -76
- package/node_modules/consola/dist/chunks/prompt.cjs +0 -288
- package/node_modules/consola/dist/chunks/prompt.mjs +0 -280
- package/node_modules/consola/dist/core.cjs +0 -517
- package/node_modules/consola/dist/core.d.cts +0 -459
- package/node_modules/consola/dist/core.d.mts +0 -459
- package/node_modules/consola/dist/core.d.ts +0 -459
- package/node_modules/consola/dist/core.mjs +0 -512
- package/node_modules/consola/dist/index.cjs +0 -663
- package/node_modules/consola/dist/index.d.cts +0 -24
- package/node_modules/consola/dist/index.d.mts +0 -22
- package/node_modules/consola/dist/index.d.ts +0 -24
- package/node_modules/consola/dist/index.mjs +0 -651
- package/node_modules/consola/dist/shared/consola.DCGIlDNP.cjs +0 -75
- package/node_modules/consola/dist/shared/consola.DRwqZj3T.mjs +0 -72
- package/node_modules/consola/dist/shared/consola.DXBYu-KD.mjs +0 -288
- package/node_modules/consola/dist/shared/consola.DwRq1yyg.cjs +0 -312
- package/node_modules/consola/dist/utils.cjs +0 -64
- package/node_modules/consola/dist/utils.d.cts +0 -286
- package/node_modules/consola/dist/utils.d.mts +0 -286
- package/node_modules/consola/dist/utils.d.ts +0 -286
- package/node_modules/consola/dist/utils.mjs +0 -54
- package/node_modules/consola/lib/index.cjs +0 -10
- package/node_modules/consola/package.json +0 -136
- package/node_modules/consola/utils.d.ts +0 -1
- package/node_modules/create-maizzle/README.md +0 -86
- package/node_modules/create-maizzle/bin/create-maizzle.mjs +0 -4
- package/node_modules/create-maizzle/node_modules/@clack/core/CHANGELOG.md +0 -340
- package/node_modules/create-maizzle/node_modules/@clack/core/LICENSE +0 -9
- package/node_modules/create-maizzle/node_modules/@clack/core/README.md +0 -22
- package/node_modules/create-maizzle/node_modules/@clack/core/dist/index.d.mts +0 -349
- package/node_modules/create-maizzle/node_modules/@clack/core/dist/index.mjs +0 -11
- package/node_modules/create-maizzle/node_modules/@clack/core/dist/index.mjs.map +0 -1
- package/node_modules/create-maizzle/node_modules/@clack/core/package.json +0 -60
- package/node_modules/create-maizzle/node_modules/@clack/prompts/CHANGELOG.md +0 -576
- package/node_modules/create-maizzle/node_modules/@clack/prompts/LICENSE +0 -9
- package/node_modules/create-maizzle/node_modules/@clack/prompts/README.md +0 -270
- package/node_modules/create-maizzle/node_modules/@clack/prompts/dist/index.d.mts +0 -391
- package/node_modules/create-maizzle/node_modules/@clack/prompts/dist/index.mjs +0 -137
- package/node_modules/create-maizzle/node_modules/@clack/prompts/dist/index.mjs.map +0 -1
- package/node_modules/create-maizzle/node_modules/@clack/prompts/package.json +0 -65
- package/node_modules/create-maizzle/package.json +0 -47
- package/node_modules/create-maizzle/src/index.js +0 -242
- package/node_modules/defu/LICENSE +0 -21
- package/node_modules/defu/README.md +0 -171
- package/node_modules/defu/dist/defu.cjs +0 -77
- package/node_modules/defu/dist/defu.d.cts +0 -31
- package/node_modules/defu/dist/defu.d.mts +0 -29
- package/node_modules/defu/dist/defu.d.ts +0 -31
- package/node_modules/defu/dist/defu.mjs +0 -69
- package/node_modules/defu/lib/defu.cjs +0 -10
- package/node_modules/defu/lib/defu.d.cts +0 -12
- package/node_modules/defu/package.json +0 -48
- package/node_modules/giget/dist/shared/giget.OCaTp9b-.mjs +0 -468
- package/node_modules/node-fetch-native/LICENSE +0 -114
- package/node_modules/node-fetch-native/README.md +0 -225
- package/node_modules/node-fetch-native/dist/chunks/multipart-parser.cjs +0 -2
- package/node_modules/node-fetch-native/dist/chunks/multipart-parser.mjs +0 -2
- package/node_modules/node-fetch-native/dist/index.cjs +0 -1
- package/node_modules/node-fetch-native/dist/index.mjs +0 -1
- package/node_modules/node-fetch-native/dist/native.cjs +0 -1
- package/node_modules/node-fetch-native/dist/native.mjs +0 -1
- package/node_modules/node-fetch-native/dist/node.cjs +0 -19
- package/node_modules/node-fetch-native/dist/node.mjs +0 -19
- package/node_modules/node-fetch-native/dist/polyfill.cjs +0 -1
- package/node_modules/node-fetch-native/dist/polyfill.mjs +0 -1
- package/node_modules/node-fetch-native/dist/proxy-stub.cjs +0 -1
- package/node_modules/node-fetch-native/dist/proxy-stub.mjs +0 -1
- package/node_modules/node-fetch-native/dist/proxy.cjs +0 -58
- package/node_modules/node-fetch-native/dist/shared/node-fetch-native.DfbY2q-x.mjs +0 -1
- package/node_modules/node-fetch-native/dist/shared/node-fetch-native.DhEqb06g.cjs +0 -1
- package/node_modules/node-fetch-native/index.d.ts +0 -1
- package/node_modules/node-fetch-native/lib/empty.cjs +0 -0
- package/node_modules/node-fetch-native/lib/empty.mjs +0 -0
- package/node_modules/node-fetch-native/lib/index.cjs +0 -11
- package/node_modules/node-fetch-native/lib/index.d.cts +0 -10
- package/node_modules/node-fetch-native/lib/index.d.mts +0 -10
- package/node_modules/node-fetch-native/lib/index.d.ts +0 -10
- package/node_modules/node-fetch-native/lib/native.cjs +0 -11
- package/node_modules/node-fetch-native/lib/polyfill.d.cts +0 -1
- package/node_modules/node-fetch-native/lib/polyfill.d.mts +0 -1
- package/node_modules/node-fetch-native/lib/polyfill.d.ts +0 -1
- package/node_modules/node-fetch-native/lib/proxy.d.ts +0 -32
- package/node_modules/node-fetch-native/node.d.ts +0 -1
- package/node_modules/node-fetch-native/package.json +0 -138
- package/node_modules/node-fetch-native/polyfill.d.ts +0 -1
- package/node_modules/node-fetch-native/proxy.d.ts +0 -1
- package/node_modules/nypm/node_modules/citty/LICENSE +0 -21
- package/node_modules/nypm/node_modules/citty/README.md +0 -231
- package/node_modules/nypm/node_modules/citty/dist/index.d.mts +0 -112
- package/node_modules/nypm/node_modules/citty/dist/index.mjs +0 -425
- package/node_modules/nypm/node_modules/citty/package.json +0 -42
- /package/node_modules/{nypm/node_modules/citty → citty}/dist/THIRD-PARTY-LICENSES.md +0 -0
- /package/node_modules/{nypm/node_modules/citty → citty}/dist/_chunks/libs/scule.mjs +0 -0
- /package/node_modules/{@maizzle/cli → maizzle}/LICENSE +0 -0
- /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/component.d.mts +0 -0
- /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/component.mjs +0 -0
- /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/config.d.mts +0 -0
- /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/config.mjs +0 -0
- /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/layout.d.mts +0 -0
- /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/layout.mjs +0 -0
- /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/scaffold.d.mts +0 -0
- /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/scaffold.mjs +0 -0
- /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/stubs/component.vue +0 -0
- /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/stubs/config.ts +0 -0
- /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/stubs/layout.vue +0 -0
- /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/stubs/template.vue +0 -0
- /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/template.d.mts +0 -0
- /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/template.mjs +0 -0
- /package/node_modules/{commander → maizzle/node_modules/commander}/LICENSE +0 -0
- /package/node_modules/{commander → maizzle/node_modules/commander}/esm.mjs +0 -0
- /package/node_modules/{commander → maizzle/node_modules/commander}/index.js +0 -0
- /package/node_modules/{commander → maizzle/node_modules/commander}/lib/error.js +0 -0
- /package/node_modules/{commander → maizzle/node_modules/commander}/lib/suggestSimilar.js +0 -0
- /package/node_modules/{commander → maizzle/node_modules/commander}/typings/esm.d.mts +0 -0
package/bin/maizzle.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import { createJiti } from 'jiti'
|
|
|
4
4
|
import { fileURLToPath } from 'node:url'
|
|
5
5
|
|
|
6
6
|
const jiti = createJiti(fileURLToPath(import.meta.url), { interopDefault: true })
|
|
7
|
-
const { default: bootstrap } = await jiti.import('
|
|
7
|
+
const { default: bootstrap } = await jiti.import('maizzle')
|
|
8
8
|
const framework = await jiti.import('../dist/index.mjs')
|
|
9
9
|
|
|
10
10
|
await bootstrap(framework)
|
package/dist/build.mjs
CHANGED
|
@@ -40,7 +40,8 @@ async function build(options = {}) {
|
|
|
40
40
|
});
|
|
41
41
|
const renderer = await createRenderer({
|
|
42
42
|
markdown: config.markdown,
|
|
43
|
-
root: config.root
|
|
43
|
+
root: config.root,
|
|
44
|
+
componentDirs: [config.components?.source ?? []].flat()
|
|
44
45
|
});
|
|
45
46
|
const outputFiles = [];
|
|
46
47
|
try {
|
package/dist/build.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.mjs","names":[],"sources":["../src/build.ts"],"sourcesContent":["import { readFileSync, writeFileSync, mkdirSync, cpSync, existsSync, rmSync } from 'node:fs'\nimport { resolve, dirname, basename, relative, join } from 'node:path'\nimport { glob } from 'tinyglobby'\nimport ora from 'ora'\nimport { resolveConfig } from './config/index.ts'\nimport { EventManager } from './events/index.ts'\nimport { runTransformers } from './transformers/index.ts'\nimport { createRenderer } from './render/createRenderer.ts'\nimport { createPlaintext } from './plaintext.ts'\nimport type { MaizzleConfig } from './types/index.ts'\n\nexport interface BuildOptions {\n config?: Partial<MaizzleConfig> | string\n}\n\nexport interface BuildResult {\n files: string[]\n config: MaizzleConfig\n}\n\n/**\n * Build all SFC email templates to HTML files.\n *\n * Creates a single Renderer instance, then loops through each template\n * calling render → transformers → write to disk.\n */\nexport async function build(options: BuildOptions = {}): Promise<BuildResult> {\n const start = Date.now()\n const spinner = ora('Building templates...').start()\n\n const config = await resolveConfig(options.config)\n\n const events = new EventManager()\n events.registerConfig(config)\n await events.fireBeforeCreate({ config })\n\n const outputPath = resolve(config.output?.path ?? 'dist')\n const outputExtension = config.output?.extension ?? 'html'\n\n const contentPatterns = config.content ?? ['emails/**/*.vue']\n const contentBase = computeContentBase(contentPatterns)\n const templateFiles = await glob(contentPatterns)\n\n if (templateFiles.length === 0) {\n spinner.succeed('No templates found')\n return { files: [], config }\n }\n\n // Clear the output directory before writing fresh output\n if (existsSync(outputPath)) {\n rmSync(outputPath, { recursive: true, force: true })\n }\n\n const renderer = await createRenderer({ markdown: config.markdown, root: config.root })\n const outputFiles: string[] = []\n\n try {\n for (const templatePath of templateFiles) {\n const absolutePath = resolve(templatePath)\n let template = readFileSync(absolutePath, 'utf-8')\n\n template = await events.fireBeforeRender({ config, template })\n\n const rendered = await renderer.render(absolutePath, config)\n\n let html = await events.fireAfterRender({ config, template, html: rendered.html })\n\n // Use the per-template merged config (from defineConfig() in the SFC) so that\n // template-level overrides like css.safe: false are respected by transformers.\n const templateConfig = rendered.templateConfig\n\n if (templateConfig.useTransformers !== false) {\n html = await runTransformers(html, templateConfig, absolutePath)\n }\n\n html = await events.fireAfterTransform({ config, template, html })\n\n const doctype = rendered.doctype ?? templateConfig.doctype ?? '<!DOCTYPE html>'\n html = `${doctype}\\n${html}`\n\n const outputFilePath = resolveOutputPath(templatePath, outputPath, outputExtension, contentBase)\n mkdirSync(dirname(outputFilePath), { recursive: true })\n writeFileSync(outputFilePath, html)\n outputFiles.push(outputFilePath)\n\n // Generate plaintext version if configured\n const globalPlaintext = templateConfig.plaintext\n const sfcPlaintext = rendered.plaintext\n\n if (globalPlaintext || sfcPlaintext) {\n const stripOptions = typeof globalPlaintext === 'object' ? globalPlaintext : {}\n const plaintext = createPlaintext(html, stripOptions)\n const ptExtension = sfcPlaintext?.extension ?? 'txt'\n\n let ptOutputPath: string\n\n if (sfcPlaintext?.destination) {\n const name = basename(templatePath).replace(/\\.(vue|md)$/, '')\n ptOutputPath = join(resolve(sfcPlaintext.destination), `${name}.${ptExtension}`)\n } else if (typeof globalPlaintext === 'string') {\n ptOutputPath = resolveOutputPath(templatePath, resolve(globalPlaintext), ptExtension, contentBase)\n } else {\n ptOutputPath = resolveOutputPath(templatePath, outputPath, ptExtension, contentBase)\n }\n\n mkdirSync(dirname(ptOutputPath), { recursive: true })\n writeFileSync(ptOutputPath, plaintext)\n }\n\n // Register SFC event handlers that were collected during render\n for (const { name, handler } of rendered.sfcEventHandlers) {\n events.on(name, handler)\n }\n\n events.clearSfcHandlers()\n }\n\n await copyStatic(config, outputPath)\n await events.fireAfterBuild({ files: outputFiles, config })\n } finally {\n await renderer.close()\n }\n\n const duration = ((Date.now() - start) / 1000).toFixed(2)\n const count = outputFiles.length\n spinner.stopAndPersist({\n symbol: '✅',\n text: `Built ${count} template${count !== 1 ? 's' : ''} in ${duration}s`,\n })\n\n return { files: outputFiles, config }\n}\n\n/**\n * Extract the static (non-glob) prefix from content patterns.\n *\n * For example, `['/abs/path/emails/**\\/*.vue']` → `'/abs/path/emails'`\n *\n * This is used to strip the content base from template paths\n * so the output preserves only the subdirectory structure.\n */\nfunction computeContentBase(patterns: string[]): string {\n // Use the first non-negated pattern\n const pattern = patterns.find(p => !p.startsWith('!')) ?? patterns[0]\n\n // Split on first glob character (* { ? [) and take the directory part\n const staticPart = pattern.split(/[*{?[]/)[0]\n\n // Ensure we have a clean directory path (not a partial segment)\n return resolve(staticPart.endsWith('/') ? staticPart : dirname(staticPart))\n}\n\nfunction resolveOutputPath(templatePath: string, outputDir: string, extension: string, contentBase: string): string {\n const name = basename(templatePath).replace(/\\.(vue|md)$/, '')\n const absTemplate = resolve(templatePath)\n const rel = relative(contentBase, dirname(absTemplate))\n\n return join(outputDir, rel, `${name}.${extension}`)\n}\n\nasync function copyStatic(config: MaizzleConfig, outputPath: string): Promise<void> {\n const sources = config.static?.source ?? ['public/**/*.*']\n const destination = config.static?.destination ?? 'public'\n\n const files = await glob(sources)\n\n for (const file of files) {\n const destPath = join(outputPath, destination, relative(dirname(sources[0]).replace(/\\*.*$/, ''), file))\n const destDir = dirname(destPath)\n\n if (!existsSync(destDir)) {\n mkdirSync(destDir, { recursive: true })\n }\n\n cpSync(file, destPath)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA0BA,eAAsB,MAAM,UAAwB,EAAE,EAAwB;CAC5E,MAAM,QAAQ,KAAK,KAAK;CACxB,MAAM,UAAU,IAAI,wBAAwB,CAAC,OAAO;CAEpD,MAAM,SAAS,MAAM,cAAc,QAAQ,OAAO;CAElD,MAAM,SAAS,IAAI,cAAc;AACjC,QAAO,eAAe,OAAO;AAC7B,OAAM,OAAO,iBAAiB,EAAE,QAAQ,CAAC;CAEzC,MAAM,aAAa,QAAQ,OAAO,QAAQ,QAAQ,OAAO;CACzD,MAAM,kBAAkB,OAAO,QAAQ,aAAa;CAEpD,MAAM,kBAAkB,OAAO,WAAW,CAAC,kBAAkB;CAC7D,MAAM,cAAc,mBAAmB,gBAAgB;CACvD,MAAM,gBAAgB,MAAM,KAAK,gBAAgB;AAEjD,KAAI,cAAc,WAAW,GAAG;AAC9B,UAAQ,QAAQ,qBAAqB;AACrC,SAAO;GAAE,OAAO,EAAE;GAAE;GAAQ;;AAI9B,KAAI,WAAW,WAAW,CACxB,QAAO,YAAY;EAAE,WAAW;EAAM,OAAO;EAAM,CAAC;CAGtD,MAAM,WAAW,MAAM,eAAe;EAAE,UAAU,OAAO;EAAU,MAAM,OAAO;EAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"build.mjs","names":[],"sources":["../src/build.ts"],"sourcesContent":["import { readFileSync, writeFileSync, mkdirSync, cpSync, existsSync, rmSync } from 'node:fs'\nimport { resolve, dirname, basename, relative, join } from 'node:path'\nimport { glob } from 'tinyglobby'\nimport ora from 'ora'\nimport { resolveConfig } from './config/index.ts'\nimport { EventManager } from './events/index.ts'\nimport { runTransformers } from './transformers/index.ts'\nimport { createRenderer } from './render/createRenderer.ts'\nimport { createPlaintext } from './plaintext.ts'\nimport type { MaizzleConfig } from './types/index.ts'\n\nexport interface BuildOptions {\n config?: Partial<MaizzleConfig> | string\n}\n\nexport interface BuildResult {\n files: string[]\n config: MaizzleConfig\n}\n\n/**\n * Build all SFC email templates to HTML files.\n *\n * Creates a single Renderer instance, then loops through each template\n * calling render → transformers → write to disk.\n */\nexport async function build(options: BuildOptions = {}): Promise<BuildResult> {\n const start = Date.now()\n const spinner = ora('Building templates...').start()\n\n const config = await resolveConfig(options.config)\n\n const events = new EventManager()\n events.registerConfig(config)\n await events.fireBeforeCreate({ config })\n\n const outputPath = resolve(config.output?.path ?? 'dist')\n const outputExtension = config.output?.extension ?? 'html'\n\n const contentPatterns = config.content ?? ['emails/**/*.vue']\n const contentBase = computeContentBase(contentPatterns)\n const templateFiles = await glob(contentPatterns)\n\n if (templateFiles.length === 0) {\n spinner.succeed('No templates found')\n return { files: [], config }\n }\n\n // Clear the output directory before writing fresh output\n if (existsSync(outputPath)) {\n rmSync(outputPath, { recursive: true, force: true })\n }\n\n const renderer = await createRenderer({ markdown: config.markdown, root: config.root, componentDirs: [config.components?.source ?? []].flat() })\n const outputFiles: string[] = []\n\n try {\n for (const templatePath of templateFiles) {\n const absolutePath = resolve(templatePath)\n let template = readFileSync(absolutePath, 'utf-8')\n\n template = await events.fireBeforeRender({ config, template })\n\n const rendered = await renderer.render(absolutePath, config)\n\n let html = await events.fireAfterRender({ config, template, html: rendered.html })\n\n // Use the per-template merged config (from defineConfig() in the SFC) so that\n // template-level overrides like css.safe: false are respected by transformers.\n const templateConfig = rendered.templateConfig\n\n if (templateConfig.useTransformers !== false) {\n html = await runTransformers(html, templateConfig, absolutePath)\n }\n\n html = await events.fireAfterTransform({ config, template, html })\n\n const doctype = rendered.doctype ?? templateConfig.doctype ?? '<!DOCTYPE html>'\n html = `${doctype}\\n${html}`\n\n const outputFilePath = resolveOutputPath(templatePath, outputPath, outputExtension, contentBase)\n mkdirSync(dirname(outputFilePath), { recursive: true })\n writeFileSync(outputFilePath, html)\n outputFiles.push(outputFilePath)\n\n // Generate plaintext version if configured\n const globalPlaintext = templateConfig.plaintext\n const sfcPlaintext = rendered.plaintext\n\n if (globalPlaintext || sfcPlaintext) {\n const stripOptions = typeof globalPlaintext === 'object' ? globalPlaintext : {}\n const plaintext = createPlaintext(html, stripOptions)\n const ptExtension = sfcPlaintext?.extension ?? 'txt'\n\n let ptOutputPath: string\n\n if (sfcPlaintext?.destination) {\n const name = basename(templatePath).replace(/\\.(vue|md)$/, '')\n ptOutputPath = join(resolve(sfcPlaintext.destination), `${name}.${ptExtension}`)\n } else if (typeof globalPlaintext === 'string') {\n ptOutputPath = resolveOutputPath(templatePath, resolve(globalPlaintext), ptExtension, contentBase)\n } else {\n ptOutputPath = resolveOutputPath(templatePath, outputPath, ptExtension, contentBase)\n }\n\n mkdirSync(dirname(ptOutputPath), { recursive: true })\n writeFileSync(ptOutputPath, plaintext)\n }\n\n // Register SFC event handlers that were collected during render\n for (const { name, handler } of rendered.sfcEventHandlers) {\n events.on(name, handler)\n }\n\n events.clearSfcHandlers()\n }\n\n await copyStatic(config, outputPath)\n await events.fireAfterBuild({ files: outputFiles, config })\n } finally {\n await renderer.close()\n }\n\n const duration = ((Date.now() - start) / 1000).toFixed(2)\n const count = outputFiles.length\n spinner.stopAndPersist({\n symbol: '✅',\n text: `Built ${count} template${count !== 1 ? 's' : ''} in ${duration}s`,\n })\n\n return { files: outputFiles, config }\n}\n\n/**\n * Extract the static (non-glob) prefix from content patterns.\n *\n * For example, `['/abs/path/emails/**\\/*.vue']` → `'/abs/path/emails'`\n *\n * This is used to strip the content base from template paths\n * so the output preserves only the subdirectory structure.\n */\nfunction computeContentBase(patterns: string[]): string {\n // Use the first non-negated pattern\n const pattern = patterns.find(p => !p.startsWith('!')) ?? patterns[0]\n\n // Split on first glob character (* { ? [) and take the directory part\n const staticPart = pattern.split(/[*{?[]/)[0]\n\n // Ensure we have a clean directory path (not a partial segment)\n return resolve(staticPart.endsWith('/') ? staticPart : dirname(staticPart))\n}\n\nfunction resolveOutputPath(templatePath: string, outputDir: string, extension: string, contentBase: string): string {\n const name = basename(templatePath).replace(/\\.(vue|md)$/, '')\n const absTemplate = resolve(templatePath)\n const rel = relative(contentBase, dirname(absTemplate))\n\n return join(outputDir, rel, `${name}.${extension}`)\n}\n\nasync function copyStatic(config: MaizzleConfig, outputPath: string): Promise<void> {\n const sources = config.static?.source ?? ['public/**/*.*']\n const destination = config.static?.destination ?? 'public'\n\n const files = await glob(sources)\n\n for (const file of files) {\n const destPath = join(outputPath, destination, relative(dirname(sources[0]).replace(/\\*.*$/, ''), file))\n const destDir = dirname(destPath)\n\n if (!existsSync(destDir)) {\n mkdirSync(destDir, { recursive: true })\n }\n\n cpSync(file, destPath)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA0BA,eAAsB,MAAM,UAAwB,EAAE,EAAwB;CAC5E,MAAM,QAAQ,KAAK,KAAK;CACxB,MAAM,UAAU,IAAI,wBAAwB,CAAC,OAAO;CAE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AM,cAHU,SAAS,MAAK,MAAK,CAAC,EAAE,WAAW,IAAI,CAAC,IAAI,SAAS,IAGxC,MAAM,SAAS,CAAC;AAG3C,QAAO,QAAQ,WAAW,SAAS,IAAI,GAAG,aAAa,QAAQ,WAAW,CAAC;;AAG7E,SAAS,kBAAkB,cAAsB,WAAmB,WAAmB,aAA6B;CAClH,MAAM,OAAO,SAAS,aAAa,CAAC,QAAQ,eAAe,GAAG;AAI9D,QAAO,KAAK,WAFA,SAAS,aAAa,QADd,QAAQ,aAAa,CACa,CAAC,EAE3B,GAAG,KAAK,GAAG,YAAY;;AAGrD,eAAe,WAAW,QAAuB,YAAmC;CAClF,MAAM,UAAU,OAAO,QAAQ,UAAU,CAAC,gBAAgB;CAC1D,MAAM,cAAc,OAAO,QAAQ,eAAe;CAElD,MAAM,QAAQ,MAAM,KAAK,QAAQ;AAEjC,MAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,WAAW,KAAK,YAAY,aAAa,SAAS,QAAQ,QAAQ,GAAG,CAAC,QAAQ,SAAS,GAAG,EAAE,KAAK,CAAC;EACxG,MAAM,UAAU,QAAQ,SAAS;AAEjC,MAAI,CAAC,WAAW,QAAQ,CACtB,WAAU,SAAS,EAAE,WAAW,MAAM,CAAC;AAGzC,SAAO,MAAM,SAAS"}
|
package/dist/config/index.mjs
CHANGED
|
@@ -35,6 +35,13 @@ async function resolveConfig(config, cwd = process.cwd()) {
|
|
|
35
35
|
if (p.startsWith("/") || p.startsWith("!")) return p;
|
|
36
36
|
return resolve(root, p).replace(/\\/g, "/");
|
|
37
37
|
});
|
|
38
|
+
if (merged.components?.source) {
|
|
39
|
+
const dirs = Array.isArray(merged.components.source) ? merged.components.source : [merged.components.source];
|
|
40
|
+
merged.components.source = dirs.map((p) => {
|
|
41
|
+
if (p.startsWith("/")) return p;
|
|
42
|
+
return resolve(cwd, p);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
38
45
|
if (hasExplicitRoot && !merged.css?.base) {
|
|
39
46
|
if (!merged.css) merged.css = {};
|
|
40
47
|
merged.css.base = root;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/config/index.ts"],"sourcesContent":["import { existsSync } from 'node:fs'\nimport { resolve } from 'node:path'\nimport { createJiti } from 'jiti'\nimport { fileURLToPath } from 'node:url'\nimport { createDefu } from 'defu'\n\n// defu that replaces arrays: if user provides content: ['x'], it replaces the default, not appends\nconst merge = createDefu((obj, key, value) => {\n if (Array.isArray(obj[key])) {\n obj[key] = value\n return true\n }\n})\nimport { defaults } from './defaults.ts'\nimport type { MaizzleConfig } from '../types/index.ts'\n\nexport { defineConfig } from '../composables/defineConfig.ts'\nexport { defaults } from './defaults.ts'\n\nconst CONFIG_FILES = [\n 'maizzle.config.ts',\n 'maizzle.config.js',\n]\n\n/**\n * Resolve the Maizzle config.\n *\n * Always loads from the config file on disk (maizzle.config.{ts,js}),\n * then merges the programmatic config on top, then fills in defaults.\n */\nexport async function resolveConfig(\n config?: Partial<MaizzleConfig> | string,\n cwd: string = process.cwd(),\n): Promise<MaizzleConfig> {\n // If a string path was provided, load that specific file\n const fileConfig = await loadConfig(\n typeof config === 'string' ? config : undefined,\n cwd,\n )\n\n // Programmatic config (object) overrides file config, which overrides defaults\n const programmaticConfig = typeof config === 'object' && config !== null ? config : {}\n\n const merged = merge(programmaticConfig, fileConfig, defaults) as MaizzleConfig\n\n // Check if root was explicitly provided before resolving\n const hasExplicitRoot = !!(programmaticConfig.root ?? fileConfig.root)\n\n // Resolve root to an absolute path (defaults to cwd)\n const root = resolve(cwd, merged.root ?? '.')\n merged.root = root\n\n // Resolve content patterns relative to root\n if (merged.content) {\n merged.content = merged.content.map(p => {\n // Skip already-absolute or negated patterns\n if (p.startsWith('/') || p.startsWith('!')) return p\n return resolve(root, p).replace(/\\\\/g, '/')\n })\n }\n\n // Resolve static source patterns relative to root\n if (merged.static?.source) {\n merged.static.source = merged.static.source.map(p => {\n if (p.startsWith('/') || p.startsWith('!')) return p\n return resolve(root, p).replace(/\\\\/g, '/')\n })\n }\n\n // Default css.base to root when root is explicitly set,\n // so Tailwind resolves @source from the right directory.\n // When root is not set, leave css.base undefined so Tailwind\n // uses its own default (the template file's directory).\n if (hasExplicitRoot && !merged.css?.base) {\n if (!merged.css) merged.css = {}\n merged.css.base = root\n }\n\n return merged\n}\n\nasync function loadConfig(\n configPath?: string,\n cwd: string = process.cwd(),\n): Promise<MaizzleConfig> {\n const jiti = createJiti(fileURLToPath(import.meta.url), { moduleCache: false })\n\n // If an explicit path was provided, use it directly\n if (configPath) {\n const absolutePath = resolve(cwd, configPath)\n\n if (!existsSync(absolutePath)) {\n throw new Error(`Config file not found: ${absolutePath}`)\n }\n\n const mod = await jiti.import(absolutePath) as any\n return mod.default ?? mod\n }\n\n // Otherwise scan cwd for known config file names\n for (const filename of CONFIG_FILES) {\n const filepath = resolve(cwd, filename)\n\n if (existsSync(filepath)) {\n const mod = await jiti.import(filepath) as any\n return mod.default ?? mod\n }\n }\n\n // No config file found, return empty (defaults will be applied by resolveConfig)\n return {}\n}\n"],"mappings":";;;;;;;;;AAOA,MAAM,QAAQ,YAAY,KAAK,KAAK,UAAU;AAC5C,KAAI,MAAM,QAAQ,IAAI,KAAK,EAAE;AAC3B,MAAI,OAAO;AACX,SAAO;;EAET;AAOF,MAAM,eAAe,CACnB,qBACA,oBACD;;;;;;;AAQD,eAAsB,cACpB,QACA,MAAc,QAAQ,KAAK,EACH;CAExB,MAAM,aAAa,MAAM,WACvB,OAAO,WAAW,WAAW,SAAS,QACtC,IACD;CAGD,MAAM,qBAAqB,OAAO,WAAW,YAAY,WAAW,OAAO,SAAS,EAAE;CAEtF,MAAM,SAAS,MAAM,oBAAoB,YAAY,SAAS;CAG9D,MAAM,kBAAkB,CAAC,EAAE,mBAAmB,QAAQ,WAAW;CAGjE,MAAM,OAAO,QAAQ,KAAK,OAAO,QAAQ,IAAI;AAC7C,QAAO,OAAO;AAGd,KAAI,OAAO,QACT,QAAO,UAAU,OAAO,QAAQ,KAAI,MAAK;AAEvC,MAAI,EAAE,WAAW,IAAI,IAAI,EAAE,WAAW,IAAI,CAAE,QAAO;AACnD,SAAO,QAAQ,MAAM,EAAE,CAAC,QAAQ,OAAO,IAAI;GAC3C;AAIJ,KAAI,OAAO,QAAQ,OACjB,QAAO,OAAO,SAAS,OAAO,OAAO,OAAO,KAAI,MAAK;AACnD,MAAI,EAAE,WAAW,IAAI,IAAI,EAAE,WAAW,IAAI,CAAE,QAAO;AACnD,SAAO,QAAQ,MAAM,EAAE,CAAC,QAAQ,OAAO,IAAI;GAC3C;AAOJ,KAAI,mBAAmB,CAAC,OAAO,KAAK,MAAM;AACxC,MAAI,CAAC,OAAO,IAAK,QAAO,MAAM,EAAE;AAChC,SAAO,IAAI,OAAO;;AAGpB,QAAO;;AAGT,eAAe,WACb,YACA,MAAc,QAAQ,KAAK,EACH;CACxB,MAAM,OAAO,WAAW,cAAc,OAAO,KAAK,IAAI,EAAE,EAAE,aAAa,OAAO,CAAC;AAG/E,KAAI,YAAY;EACd,MAAM,eAAe,QAAQ,KAAK,WAAW;AAE7C,MAAI,CAAC,WAAW,aAAa,CAC3B,OAAM,IAAI,MAAM,0BAA0B,eAAe;EAG3D,MAAM,MAAM,MAAM,KAAK,OAAO,aAAa;AAC3C,SAAO,IAAI,WAAW;;AAIxB,MAAK,MAAM,YAAY,cAAc;EACnC,MAAM,WAAW,QAAQ,KAAK,SAAS;AAEvC,MAAI,WAAW,SAAS,EAAE;GACxB,MAAM,MAAM,MAAM,KAAK,OAAO,SAAS;AACvC,UAAO,IAAI,WAAW;;;AAK1B,QAAO,EAAE"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/config/index.ts"],"sourcesContent":["import { existsSync } from 'node:fs'\nimport { resolve } from 'node:path'\nimport { createJiti } from 'jiti'\nimport { fileURLToPath } from 'node:url'\nimport { createDefu } from 'defu'\n\n// defu that replaces arrays: if user provides content: ['x'], it replaces the default, not appends\nconst merge = createDefu((obj, key, value) => {\n if (Array.isArray(obj[key])) {\n obj[key] = value\n return true\n }\n})\nimport { defaults } from './defaults.ts'\nimport type { MaizzleConfig } from '../types/index.ts'\n\nexport { defineConfig } from '../composables/defineConfig.ts'\nexport { defaults } from './defaults.ts'\n\nconst CONFIG_FILES = [\n 'maizzle.config.ts',\n 'maizzle.config.js',\n]\n\n/**\n * Resolve the Maizzle config.\n *\n * Always loads from the config file on disk (maizzle.config.{ts,js}),\n * then merges the programmatic config on top, then fills in defaults.\n */\nexport async function resolveConfig(\n config?: Partial<MaizzleConfig> | string,\n cwd: string = process.cwd(),\n): Promise<MaizzleConfig> {\n // If a string path was provided, load that specific file\n const fileConfig = await loadConfig(\n typeof config === 'string' ? config : undefined,\n cwd,\n )\n\n // Programmatic config (object) overrides file config, which overrides defaults\n const programmaticConfig = typeof config === 'object' && config !== null ? config : {}\n\n const merged = merge(programmaticConfig, fileConfig, defaults) as MaizzleConfig\n\n // Check if root was explicitly provided before resolving\n const hasExplicitRoot = !!(programmaticConfig.root ?? fileConfig.root)\n\n // Resolve root to an absolute path (defaults to cwd)\n const root = resolve(cwd, merged.root ?? '.')\n merged.root = root\n\n // Resolve content patterns relative to root\n if (merged.content) {\n merged.content = merged.content.map(p => {\n // Skip already-absolute or negated patterns\n if (p.startsWith('/') || p.startsWith('!')) return p\n return resolve(root, p).replace(/\\\\/g, '/')\n })\n }\n\n // Resolve static source patterns relative to root\n if (merged.static?.source) {\n merged.static.source = merged.static.source.map(p => {\n if (p.startsWith('/') || p.startsWith('!')) return p\n return resolve(root, p).replace(/\\\\/g, '/')\n })\n }\n\n // Resolve components.source paths relative to cwd (not root),\n // since extra component dirs often live outside the root directory\n if (merged.components?.source) {\n const dirs = Array.isArray(merged.components.source)\n ? merged.components.source\n : [merged.components.source]\n\n merged.components.source = dirs.map(p => {\n if (p.startsWith('/')) return p\n return resolve(cwd, p)\n })\n }\n\n // Default css.base to root when root is explicitly set,\n // so Tailwind resolves @source from the right directory.\n // When root is not set, leave css.base undefined so Tailwind\n // uses its own default (the template file's directory).\n if (hasExplicitRoot && !merged.css?.base) {\n if (!merged.css) merged.css = {}\n merged.css.base = root\n }\n\n return merged\n}\n\nasync function loadConfig(\n configPath?: string,\n cwd: string = process.cwd(),\n): Promise<MaizzleConfig> {\n const jiti = createJiti(fileURLToPath(import.meta.url), { moduleCache: false })\n\n // If an explicit path was provided, use it directly\n if (configPath) {\n const absolutePath = resolve(cwd, configPath)\n\n if (!existsSync(absolutePath)) {\n throw new Error(`Config file not found: ${absolutePath}`)\n }\n\n const mod = await jiti.import(absolutePath) as any\n return mod.default ?? mod\n }\n\n // Otherwise scan cwd for known config file names\n for (const filename of CONFIG_FILES) {\n const filepath = resolve(cwd, filename)\n\n if (existsSync(filepath)) {\n const mod = await jiti.import(filepath) as any\n return mod.default ?? mod\n }\n }\n\n // No config file found, return empty (defaults will be applied by resolveConfig)\n return {}\n}\n"],"mappings":";;;;;;;;;AAOA,MAAM,QAAQ,YAAY,KAAK,KAAK,UAAU;AAC5C,KAAI,MAAM,QAAQ,IAAI,KAAK,EAAE;AAC3B,MAAI,OAAO;AACX,SAAO;;EAET;AAOF,MAAM,eAAe,CACnB,qBACA,oBACD;;;;;;;AAQD,eAAsB,cACpB,QACA,MAAc,QAAQ,KAAK,EACH;CAExB,MAAM,aAAa,MAAM,WACvB,OAAO,WAAW,WAAW,SAAS,QACtC,IACD;CAGD,MAAM,qBAAqB,OAAO,WAAW,YAAY,WAAW,OAAO,SAAS,EAAE;CAEtF,MAAM,SAAS,MAAM,oBAAoB,YAAY,SAAS;CAG9D,MAAM,kBAAkB,CAAC,EAAE,mBAAmB,QAAQ,WAAW;CAGjE,MAAM,OAAO,QAAQ,KAAK,OAAO,QAAQ,IAAI;AAC7C,QAAO,OAAO;AAGd,KAAI,OAAO,QACT,QAAO,UAAU,OAAO,QAAQ,KAAI,MAAK;AAEvC,MAAI,EAAE,WAAW,IAAI,IAAI,EAAE,WAAW,IAAI,C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
|
|
1
|
-
{"version":3,"file":"plugin.d.mts","names":[],"sources":["../src/plugin.ts"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"plugin.d.mts","names":[],"sources":["../src/plugin.ts"],"mappings":";;;;;;;AAaA;;;;;;iBAAgB,OAAA,CAAQ,WAAA,GAAc,OAAA,CAAQ,aAAA,IAAiB,MAAA"}
|
package/dist/plugin.mjs
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { isLaravel } from "./utils/detect.mjs";
|
|
2
|
+
|
|
1
3
|
//#region src/plugin.ts
|
|
2
4
|
/**
|
|
3
5
|
* Maizzle Vite plugin for use inside an existing Vite project.
|
|
@@ -10,6 +12,17 @@
|
|
|
10
12
|
*/
|
|
11
13
|
function maizzle(configInput) {
|
|
12
14
|
let maizzleServer = null;
|
|
15
|
+
if (isLaravel()) {
|
|
16
|
+
const existing = configInput?.components?.source;
|
|
17
|
+
const laravelComponentDir = "resources/js/components/email";
|
|
18
|
+
if (!existing) configInput = {
|
|
19
|
+
...configInput,
|
|
20
|
+
components: {
|
|
21
|
+
...configInput?.components,
|
|
22
|
+
source: [laravelComponentDir]
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
13
26
|
return [{
|
|
14
27
|
name: "maizzle",
|
|
15
28
|
async configureServer(hostServer) {
|
package/dist/plugin.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.mjs","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["import type { Plugin, ViteDevServer } from 'vite'\nimport type { MaizzleConfig } from './types/index.ts'\n\n/**\n * Maizzle Vite plugin for use inside an existing Vite project.\n *\n * - During `vite dev`: starts a separate Maizzle dev server on its own port\n * - During `vite build`: builds email templates alongside the host app\n *\n * Does NOT inject Vue, Tailwind, or any other plugins into the host's pipeline.\n * The host app manages its own stack. Maizzle runs in its own process.\n */\nexport function maizzle(configInput?: Partial<MaizzleConfig>): Plugin[] {\n let maizzleServer: ViteDevServer | null = null\n\n return [{\n name: 'maizzle',\n\n async configureServer(hostServer) {\n const { serve, printBanner } = await import('./serve.ts')\n maizzleServer = await serve({ config: configInput, silent: true })\n\n // Print Maizzle banner after the host server prints its URLs\n hostServer.httpServer?.on('listening', () => {\n printBanner(maizzleServer!)\n })\n },\n\n async closeBundle() {\n if (this.meta.watchMode) return\n\n const { build } = await import('./build.ts')\n await build({ config: configInput })\n },\n\n async buildEnd() {\n if (maizzleServer) {\n await maizzleServer.close()\n maizzleServer = null\n }\n },\n }]\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"plugin.mjs","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["import type { Plugin, ViteDevServer } from 'vite'\nimport type { MaizzleConfig } from './types/index.ts'\nimport { isLaravel } from './utils/detect.ts'\n\n/**\n * Maizzle Vite plugin for use inside an existing Vite project.\n *\n * - During `vite dev`: starts a separate Maizzle dev server on its own port\n * - During `vite build`: builds email templates alongside the host app\n *\n * Does NOT inject Vue, Tailwind, or any other plugins into the host's pipeline.\n * The host app manages its own stack. Maizzle runs in its own process.\n */\nexport function maizzle(configInput?: Partial<MaizzleConfig>): Plugin[] {\n let maizzleServer: ViteDevServer | null = null\n\n // Auto-configure defaults for Laravel projects\n if (isLaravel()) {\n const existing = configInput?.components?.source\n const laravelComponentDir = 'resources/js/components/email'\n\n if (!existing) {\n configInput = {\n ...configInput,\n components: {\n ...configInput?.components,\n source: [laravelComponentDir],\n },\n }\n }\n }\n\n return [{\n name: 'maizzle',\n\n async configureServer(hostServer) {\n const { serve, printBanner } = await import('./serve.ts')\n maizzleServer = await serve({ config: configInput, silent: true })\n\n // Print Maizzle banner after the host server prints its URLs\n hostServer.httpServer?.on('listening', () => {\n printBanner(maizzleServer!)\n })\n },\n\n async closeBundle() {\n if (this.meta.watchMode) return\n\n const { build } = await import('./build.ts')\n await build({ config: configInput })\n },\n\n async buildEnd() {\n if (maizzleServer) {\n await maizzleServer.close()\n maizzleServer = null\n }\n },\n }]\n}\n"],"mappings":";;;;;;;;;;;;AAaA,SAAgB,QAAQ,aAAgD;CACtE,IAAI,gBAAsC;AAG1C,KAAI,WAAW,EAAE;EACf,MAAM,WAAW,aAAa,YAAY;EAC1C,MAAM,sBAAsB;AAE5B,MAAI,CAAC,SACH,eAAc;GACZ,GAAG;GACH,YAAY;IACV,GAAG,aAAa;IAChB,QAAQ,CAAC,oBAAoB;IAC9B;GACF;;AAIL,QAAO,CAAC;EACN,MAAM;EAEN,MAAM,gBAAgB,YAAY;GAChC,MAAM,EAAE,OAAO,gBAAgB,MAAM,OAAO;AAC5C,mBAAgB,MAAM,MAAM;IAAE,QAAQ;IAAa,QAAQ;IAAM,CAAC;AAGlE,cAAW,YAAY,GAAG,mBAAmB;AAC3C,gBAAY,cAAe;KAC3B;;EAGJ,MAAM,cAAc;AAClB,OAAI,KAAK,KAAK,UAAW;GAEzB,MAAM,EAAE,UAAU,MAAM,OAAO;AAC/B,SAAM,MAAM,EAAE,QAAQ,aAAa,CAAC;;EAGtC,MAAM,WAAW;AACf,OAAI,eAAe;AACjB,UAAM,cAAc,OAAO;AAC3B,oBAAgB;;;EAGrB,CAAC"}
|
|
@@ -23,6 +23,8 @@ interface CreateRendererOptions {
|
|
|
23
23
|
markdown?: Options;
|
|
24
24
|
/** Root directory for resolving user component dirs and .d.ts output */
|
|
25
25
|
root?: string;
|
|
26
|
+
/** Additional component directories to register for auto-import */
|
|
27
|
+
componentDirs?: string[];
|
|
26
28
|
}
|
|
27
29
|
/**
|
|
28
30
|
* Lightweight Vite SSR loader for rendering Vue SFC email templates.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRenderer.d.mts","names":[],"sources":["../../src/render/createRenderer.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"createRenderer.d.mts","names":[],"sources":["../../src/render/createRenderer.ts"],"mappings":";;;;;;UA2BiB,gBAAA;EACf,IAAA;EACA,OAAA;EACA,cAAA,EAAgB,aAAA;EAChB,gBAAA,EAAkB,aAAA;EAClB,SAAA,GAAY,aAAA;AAAA;AAAA,UAGG,QAAA;EACf,MAAA,CAAO,KAAA,WAAgB,SAAA,EAAW,MAAA,EAAQ,aAAA,GAAgB,OAAA,CAAQ,gBAAA;EAClE,UAAA,CAAW,QAAA,WAAmB,OAAA;EAC9B,KAAA,IAAS,OAAA;AAAA;AAAA,UAGM,qBAAA;EAXf;EAaA,GAAA;EAZA;EAcA,QAAA,GAAW,OAAA;EAbX;EAeA,IAAA;EAfyB;EAiBzB,aAAA;AAAA;;;;;;;iBASoB,cAAA,CACpB,OAAA,GAAS,qBAAA,GACR,OAAA,CAAQ,QAAA"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { MaizzleConfigKey } from "../composables/useConfig.mjs";
|
|
2
2
|
import { RenderContextKey } from "../composables/renderContext.mjs";
|
|
3
|
+
import { isLaravel } from "../utils/detect.mjs";
|
|
3
4
|
import { dirname, resolve } from "node:path";
|
|
4
5
|
import { fileURLToPath } from "node:url";
|
|
5
6
|
import { defu } from "defu";
|
|
@@ -26,7 +27,8 @@ const vueRouterPkgDir = dirname(fileURLToPath(import.meta.resolve("vue-router/pa
|
|
|
26
27
|
* Tailwind CSS compilation is handled by the transformer pipeline.
|
|
27
28
|
*/
|
|
28
29
|
async function createRenderer(options = {}) {
|
|
29
|
-
const { dts = false, markdown: markdownOptions, root = process.cwd() } = options;
|
|
30
|
+
const { dts = false, markdown: markdownOptions, root = process.cwd(), componentDirs = [] } = options;
|
|
31
|
+
const dtsDir = isLaravel() ? resolve(process.cwd(), "resources/js/types/maizzle") : resolve(root, ".maizzle");
|
|
30
32
|
const VIRTUAL_SFC_ID = "virtual:maizzle-sfc.vue";
|
|
31
33
|
let virtualSfcSource = "";
|
|
32
34
|
const server = await createServer({
|
|
@@ -52,7 +54,7 @@ async function createRenderer(options = {}) {
|
|
|
52
54
|
AutoImport({
|
|
53
55
|
dirs: [resolve(__dirname, "../composables"), resolve(__dirname, "../filters")],
|
|
54
56
|
imports: ["vue", unheadVueComposablesImports],
|
|
55
|
-
dts: dts ? resolve(
|
|
57
|
+
dts: dts ? resolve(dtsDir, "auto-imports.d.ts") : false
|
|
56
58
|
}),
|
|
57
59
|
Components({
|
|
58
60
|
extensions: ["vue", "md"],
|
|
@@ -61,8 +63,12 @@ async function createRenderer(options = {}) {
|
|
|
61
63
|
/\.vue\?vue/,
|
|
62
64
|
/\.md$/
|
|
63
65
|
],
|
|
64
|
-
dirs: [
|
|
65
|
-
|
|
66
|
+
dirs: [
|
|
67
|
+
resolve(__dirname, "../components"),
|
|
68
|
+
resolve(root, "components"),
|
|
69
|
+
...componentDirs
|
|
70
|
+
],
|
|
71
|
+
dts: dts ? resolve(dtsDir, "components.d.ts") : false
|
|
66
72
|
})
|
|
67
73
|
],
|
|
68
74
|
resolve: { alias: {
|
|
@@ -79,6 +85,7 @@ async function createRenderer(options = {}) {
|
|
|
79
85
|
fs: { allow: [
|
|
80
86
|
process.cwd(),
|
|
81
87
|
root,
|
|
88
|
+
...componentDirs,
|
|
82
89
|
vuePkgDir,
|
|
83
90
|
vueServerRendererPkgDir,
|
|
84
91
|
unheadVuePkgDir,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRenderer.mjs","names":["merge"],"sources":["../../src/render/createRenderer.ts"],"sourcesContent":["import { dirname, resolve } from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport { createServer } from 'vite'\nimport vue from '@vitejs/plugin-vue'\nimport Markdown from 'unplugin-vue-markdown/vite'\nimport AutoImport from 'unplugin-auto-import/vite'\nimport Components from 'unplugin-vue-components/vite'\nimport { unheadVueComposablesImports } from '@unhead/vue'\nimport { defu as merge } from 'defu'\nimport { createSSRApp } from 'vue'\nimport { renderToString } from 'vue/server-renderer'\nimport { createHead, renderSSRHead } from '@unhead/vue/server'\nimport { MaizzleConfigKey } from '../composables/useConfig.ts'\nimport { RenderContextKey } from '../composables/renderContext.ts'\nimport type { Component, InjectionKey } from 'vue'\nimport type { MaizzleConfig } from '../types/index.ts'\nimport type { Options as MarkdownOptions } from 'unplugin-vue-markdown/types'\nimport type { RenderContext } from '../composables/renderContext.ts'\n\nconst __dirname = dirname(fileURLToPath(import.meta.url))\n\nconst vuePkgDir = dirname(fileURLToPath(import.meta.resolve('vue/package.json')))\nconst vueServerRendererPkgDir = dirname(fileURLToPath(import.meta.resolve('@vue/server-renderer/package.json')))\nconst unheadVuePkgDir = resolve(dirname(fileURLToPath(import.meta.resolve('@unhead/vue'))), '..')\nconst vueRouterPkgDir = dirname(fileURLToPath(import.meta.resolve('vue-router/package.json')))\n\nexport interface RenderedTemplate {\n html: string\n doctype?: string\n templateConfig: MaizzleConfig\n sfcEventHandlers: RenderContext['sfcEventHandlers']\n plaintext?: RenderContext['plaintext']\n}\n\nexport interface Renderer {\n render(input: string | Component, config: MaizzleConfig): Promise<RenderedTemplate>\n invalidate(filePath: string): Promise<void>\n close(): Promise<void>\n}\n\nexport interface CreateRendererOptions {\n /** Generate .d.ts files for auto-imports and components (default: false) */\n dts?: boolean\n /** Options passed to unplugin-vue-markdown */\n markdown?: MarkdownOptions\n /** Root directory for resolving user component dirs and .d.ts output */\n root?: string\n}\n\n/**\n * Lightweight Vite SSR loader for rendering Vue SFC email templates.\n *\n * Uses only Vue + unplugin for component/auto-import resolution.\n * Tailwind CSS compilation is handled by the transformer pipeline.\n */\nexport async function createRenderer(\n options: CreateRendererOptions = {},\n): Promise<Renderer> {\n const { dts = false, markdown: markdownOptions, root = process.cwd() } = options\n\n const VIRTUAL_SFC_ID = 'virtual:maizzle-sfc.vue'\n let virtualSfcSource = ''\n\n const server = await createServer({\n configFile: false,\n plugins: [\n {\n name: 'maizzle:virtual-sfc',\n resolveId(id) {\n if (id === VIRTUAL_SFC_ID) return id\n },\n load(id) {\n if (id === VIRTUAL_SFC_ID) return virtualSfcSource\n },\n },\n vue({\n include: [/\\.vue$/, /\\.md$/],\n template: {\n transformAssetUrls: false,\n },\n }),\n Markdown(merge(markdownOptions ?? {}, {\n headEnabled: true,\n wrapperDiv: false,\n })),\n AutoImport({\n dirs: [\n resolve(__dirname, '../composables'),\n resolve(__dirname, '../filters'),\n ],\n imports: ['vue', unheadVueComposablesImports],\n dts: dts ? resolve(root, 'types/auto-imports.d.ts') : false,\n }),\n Components({\n extensions: ['vue', 'md'],\n include: [/\\.vue$/, /\\.vue\\?vue/, /\\.md$/],\n dirs: [\n resolve(__dirname, '../components'),\n resolve(root, 'components'),\n ],\n dts: dts ? resolve(root, 'types/components.d.ts') : false,\n }),\n ],\n resolve: {\n alias: {\n 'vue/server-renderer': resolve(vueServerRendererPkgDir, 'dist/server-renderer.esm-bundler.js'),\n 'vue': resolve(vuePkgDir, 'dist/vue.runtime.esm-bundler.js'),\n 'vue-router': vueRouterPkgDir,\n '@unhead/vue/server': resolve(unheadVuePkgDir, 'dist/server.mjs'),\n '@unhead/vue': resolve(unheadVuePkgDir, 'dist/index.mjs'),\n },\n },\n server: {\n middlewareMode: true,\n hmr: false,\n watch: null,\n fs: {\n allow: [process.cwd(), root, vuePkgDir, vueServerRendererPkgDir, unheadVuePkgDir, vueRouterPkgDir],\n },\n },\n appType: 'custom',\n logLevel: 'silent',\n optimizeDeps: {\n noDiscovery: true,\n },\n })\n\n return {\n async render(input: string | Component, config: MaizzleConfig): Promise<RenderedTemplate> {\n let component: Component\n let configKey: InjectionKey<MaizzleConfig>\n let contextKey: InjectionKey<RenderContext>\n\n if (typeof input === 'string') {\n // String input goes through Vite — must use ssrLoadModule for injection keys\n // so they share the same module instance as the SFC\n const configModule = await server.ssrLoadModule(resolve(__dirname, '../composables/useConfig'))\n const contextModule = await server.ssrLoadModule(resolve(__dirname, '../composables/renderContext'))\n configKey = configModule.MaizzleConfigKey\n contextKey = contextModule.RenderContextKey\n\n if (input.includes('<template') || input.includes('<script')) {\n virtualSfcSource = input\n const mod = server.moduleGraph.getModuleById(VIRTUAL_SFC_ID)\n if (mod) server.moduleGraph.invalidateModule(mod)\n component = (await server.ssrLoadModule(VIRTUAL_SFC_ID)).default\n } else {\n component = (await server.ssrLoadModule(input)).default\n }\n } else {\n // Pre-compiled component — use directly imported keys\n component = input\n configKey = MaizzleConfigKey\n contextKey = RenderContextKey\n }\n\n const renderContext: RenderContext = {\n doctype: undefined,\n sfcConfig: undefined,\n sfcEventHandlers: [],\n }\n\n const head = createHead({ disableDefaults: true })\n const app = createSSRApp(component)\n app.use(head)\n app.provide(configKey, config)\n app.provide(contextKey, renderContext)\n\n let html: string = await renderToString(app)\n\n const { headTags, bodyTags, bodyTagsOpen, htmlAttrs, bodyAttrs } = await renderSSRHead(head)\n\n // Inject head entries into the rendered HTML\n if (htmlAttrs) {\n html = html.replace(/<html([^>]*)>/, `<html$1 ${htmlAttrs}>`)\n }\n if (headTags) {\n html = html.replace('</head>', `${headTags}\\n</head>`)\n }\n if (bodyAttrs) {\n html = html.replace(/<body([^>]*)>/, `<body$1 ${bodyAttrs}>`)\n }\n if (bodyTagsOpen) {\n html = html.replace(/<body([^>]*)>/, `<body$1>\\n${bodyTagsOpen}`)\n }\n if (bodyTags) {\n html = html.replace('</body>', `${bodyTags}\\n</body>`)\n }\n\n return {\n html,\n doctype: renderContext.doctype,\n templateConfig: renderContext.sfcConfig ?? config,\n sfcEventHandlers: renderContext.sfcEventHandlers,\n plaintext: renderContext.plaintext,\n }\n },\n\n async invalidate(filePath: string): Promise<void> {\n const mod = await server.moduleGraph.getModuleByUrl(filePath)\n if (mod) {\n server.moduleGraph.invalidateModule(mod)\n }\n },\n\n async close(): Promise<void> {\n await server.close()\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAmBA,MAAM,YAAY,QAAQ,cAAc,OAAO,KAAK,IAAI,CAAC;AAEzD,MAAM,YAAY,QAAQ,cAAc,OAAO,KAAK,QAAQ,mBAAmB,CAAC,CAAC;AACjF,MAAM,0BAA0B,QAAQ,cAAc,OAAO,KAAK,QAAQ,oCAAoC,CAAC,CAAC;AAChH,MAAM,kBAAkB,QAAQ,Q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,UACF,QAAO,KAAK,QAAQ,iBAAiB,WAAW,UAAU,GAAG;AAE/D,OAAI,aACF,QAAO,KAAK,QAAQ,iBAAiB,aAAa,eAAe;AAEnE,OAAI,SACF,QAAO,KAAK,QAAQ,WAAW,GAAG,SAAS,WAAW;AAGxD,UAAO;IACL;IACA,SAAS,cAAc;IACvB,gBAAgB,cAAc,aAAa;IAC3C,kBAAkB,cAAc;IAChC,WAAW,cAAc;IAC1B;;EAGH,MAAM,WAAW,UAAiC;GAChD,MAAM,MAAM,MAAM,OAAO,YAAY,eAAe,SAAS;AAC7D,OAAI,IACF,QAAO,YAAY,iBAAiB,IAAI;;EAI5C,MAAM,QAAuB;AAC3B,SAAM,OAAO,OAAO;;EAEvB"}
|
|
1
|
+
{"version":3,"file":"createRenderer.mjs","names":["merge"],"sources":["../../src/render/createRenderer.ts"],"sourcesContent":["import { dirname, resolve } from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport { isLaravel } from '../utils/detect.ts'\nimport { createServer } from 'vite'\nimport vue from '@vitejs/plugin-vue'\nimport Markdown from 'unplugin-vue-markdown/vite'\nimport AutoImport from 'unplugin-auto-import/vite'\nimport Components from 'unplugin-vue-components/vite'\nimport { unheadVueComposablesImports } from '@unhead/vue'\nimport { defu as merge } from 'defu'\nimport { createSSRApp } from 'vue'\nimport { renderToString } from 'vue/server-renderer'\nimport { createHead, renderSSRHead } from '@unhead/vue/server'\nimport { MaizzleConfigKey } from '../composables/useConfig.ts'\nimport { RenderContextKey } from '../composables/renderContext.ts'\nimport type { Component, InjectionKey } from 'vue'\nimport type { MaizzleConfig } from '../types/index.ts'\nimport type { Options as MarkdownOptions } from 'unplugin-vue-markdown/types'\nimport type { RenderContext } from '../composables/renderContext.ts'\n\nconst __dirname = dirname(fileURLToPath(import.meta.url))\n\nconst vuePkgDir = dirname(fileURLToPath(import.meta.resolve('vue/package.json')))\nconst vueServerRendererPkgDir = dirname(fileURLToPath(import.meta.resolve('@vue/server-renderer/package.json')))\nconst unheadVuePkgDir = resolve(dirname(fileURLToPath(import.meta.resolve('@unhead/vue'))), '..')\nconst vueRouterPkgDir = dirname(fileURLToPath(import.meta.resolve('vue-router/package.json')))\n\nexport interface RenderedTemplate {\n html: string\n doctype?: string\n templateConfig: MaizzleConfig\n sfcEventHandlers: RenderContext['sfcEventHandlers']\n plaintext?: RenderContext['plaintext']\n}\n\nexport interface Renderer {\n render(input: string | Component, config: MaizzleConfig): Promise<RenderedTemplate>\n invalidate(filePath: string): Promise<void>\n close(): Promise<void>\n}\n\nexport interface CreateRendererOptions {\n /** Generate .d.ts files for auto-imports and components (default: false) */\n dts?: boolean\n /** Options passed to unplugin-vue-markdown */\n markdown?: MarkdownOptions\n /** Root directory for resolving user component dirs and .d.ts output */\n root?: string\n /** Additional component directories to register for auto-import */\n componentDirs?: string[]\n}\n\n/**\n * Lightweight Vite SSR loader for rendering Vue SFC email templates.\n *\n * Uses only Vue + unplugin for component/auto-import resolution.\n * Tailwind CSS compilation is handled by the transformer pipeline.\n */\nexport async function createRenderer(\n options: CreateRendererOptions = {},\n): Promise<Renderer> {\n const { dts = false, markdown: markdownOptions, root = process.cwd(), componentDirs = [] } = options\n\n const dtsDir = isLaravel()\n ? resolve(process.cwd(), 'resources/js/types/maizzle')\n : resolve(root, '.maizzle')\n\n const VIRTUAL_SFC_ID = 'virtual:maizzle-sfc.vue'\n let virtualSfcSource = ''\n\n const server = await createServer({\n configFile: false,\n plugins: [\n {\n name: 'maizzle:virtual-sfc',\n resolveId(id) {\n if (id === VIRTUAL_SFC_ID) return id\n },\n load(id) {\n if (id === VIRTUAL_SFC_ID) return virtualSfcSource\n },\n },\n vue({\n include: [/\\.vue$/, /\\.md$/],\n template: {\n transformAssetUrls: false,\n },\n }),\n Markdown(merge(markdownOptions ?? {}, {\n headEnabled: true,\n wrapperDiv: false,\n })),\n AutoImport({\n dirs: [\n resolve(__dirname, '../composables'),\n resolve(__dirname, '../filters'),\n ],\n imports: ['vue', unheadVueComposablesImports],\n dts: dts ? resolve(dtsDir, 'auto-imports.d.ts') : false,\n }),\n Components({\n extensions: ['vue', 'md'],\n include: [/\\.vue$/, /\\.vue\\?vue/, /\\.md$/],\n dirs: [\n resolve(__dirname, '../components'),\n resolve(root, 'components'),\n ...componentDirs,\n ],\n dts: dts ? resolve(dtsDir, 'components.d.ts') : false,\n }),\n ],\n resolve: {\n alias: {\n 'vue/server-renderer': resolve(vueServerRendererPkgDir, 'dist/server-renderer.esm-bundler.js'),\n 'vue': resolve(vuePkgDir, 'dist/vue.runtime.esm-bundler.js'),\n 'vue-router': vueRouterPkgDir,\n '@unhead/vue/server': resolve(unheadVuePkgDir, 'dist/server.mjs'),\n '@unhead/vue': resolve(unheadVuePkgDir, 'dist/index.mjs'),\n },\n },\n server: {\n middlewareMode: true,\n hmr: false,\n watch: null,\n fs: {\n allow: [process.cwd(), root, ...componentDirs, vuePkgDir, vueServerRendererPkgDir, unheadVuePkgDir, vueRouterPkgDir],\n },\n },\n appType: 'custom',\n logLevel: 'silent',\n optimizeDeps: {\n noDiscovery: true,\n },\n })\n\n return {\n async render(input: string | Component, config: MaizzleConfig): Promise<RenderedTemplate> {\n let component: Component\n let configKey: InjectionKey<MaizzleConfig>\n let contextKey: InjectionKey<RenderContext>\n\n if (typeof input === 'string') {\n // String input goes through Vite — must use ssrLoadModule for injection keys\n // so they share the same module instance as the SFC\n const configModule = await server.ssrLoadModule(resolve(__dirname, '../composables/useConfig'))\n const contextModule = await server.ssrLoadModule(resolve(__dirname, '../composables/renderContext'))\n configKey = configModule.MaizzleConfigKey\n contextKey = contextModule.RenderContextKey\n\n if (input.includes('<template') || input.includes('<script')) {\n virtualSfcSource = input\n const mod = server.moduleGraph.getModuleById(VIRTUAL_SFC_ID)\n if (mod) server.moduleGraph.invalidateModule(mod)\n component = (await server.ssrLoadModule(VIRTUAL_SFC_ID)).default\n } else {\n component = (await server.ssrLoadModule(input)).default\n }\n } else {\n // Pre-compiled component — use directly imported keys\n component = input\n configKey = MaizzleConfigKey\n contextKey = RenderContextKey\n }\n\n const renderContext: RenderContext = {\n doctype: undefined,\n sfcConfig: undefined,\n sfcEventHandlers: [],\n }\n\n const head = createHead({ disableDefaults: true })\n const app = createSSRApp(component)\n app.use(head)\n app.provide(configKey, config)\n app.provide(contextKey, renderContext)\n\n let html: string = await renderToString(app)\n\n const { headTags, bodyTags, bodyTagsOpen, htmlAttrs, bodyAttrs } = await renderSSRHead(head)\n\n // Inject head entries into the rendered HTML\n if (htmlAttrs) {\n html = html.replace(/<html([^>]*)>/, `<html$1 ${htmlAttrs}>`)\n }\n if (headTags) {\n html = html.replace('</head>', `${headTags}\\n</head>`)\n }\n if (bodyAttrs) {\n html = html.replace(/<body([^>]*)>/, `<body$1 ${bodyAttrs}>`)\n }\n if (bodyTagsOpen) {\n html = html.replace(/<body([^>]*)>/, `<body$1>\\n${bodyTagsOpen}`)\n }\n if (bodyTags) {\n html = html.replace('</body>', `${bodyTags}\\n</body>`)\n }\n\n return {\n html,\n doctype: renderContext.doctype,\n templateConfig: renderContext.sfcConfig ?? config,\n sfcEventHandlers: renderContext.sfcEventHandlers,\n plaintext: renderContext.plaintext,\n }\n },\n\n async invalidate(filePath: string): Promise<void> {\n const mod = await server.moduleGraph.getModuleByUrl(filePath)\n if (mod) {\n server.moduleGraph.invalidateModule(mod)\n }\n },\n\n async close(): Promise<void> {\n await server.close()\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAoBA,MAAM,YAAY,QAAQ,cAAc,OAAO,KAAK,IAAI,CAAC;AAEzD,MAAM,YAAY,QAAQ,cAAc,OAAO,KAAK,QAAQ,mBAAmB,CAAC,CAAC;AACjF,MAAM,0BAA0B,QAAQ,cAAc,OAAO,KAAK,QAAQ,oCAAoC,CAAC,CAAC;AAChH,MAAM,kBAAkB,QAAQ,QAAQ,cAAc,OAAO,KAAK,QAAQ,cAAc,CAAC,CAAC,EAAE,KAAK;AACjG,MAAM,kBAAkB,QAAQ,cAAc,OAAO,KAAK,QAAQ,0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SAAS,WAAW;AAExD,OAAI,UACF,QAAO,KAAK,QAAQ,iBAAiB,WAAW,UAAU,GAAG;AAE/D,OAAI,aACF,QAAO,KAAK,QAAQ,iBAAiB,aAAa,eAAe;AAEnE,OAAI,SACF,QAAO,KAAK,QAAQ,WAAW,GAAG,SAAS,WAAW;AAGxD,UAAO;IACL;IACA,SAAS,cAAc;IACvB,gBAAgB,cAAc,aAAa;IAC3C,kBAAkB,cAAc;IAChC,WAAW,cAAc;IAC1B;;EAGH,MAAM,WAAW,UAAiC;GAChD,MAAM,MAAM,MAAM,OAAO,YAAY,eAAe,SAAS;AAC7D,OAAI,IACF,QAAO,YAAY,iBAAiB,IAAI;;EAI5C,MAAM,QAAuB;AAC3B,SAAM,OAAO,OAAO;;EAEvB"}
|
package/dist/render/index.mjs
CHANGED
|
@@ -15,7 +15,8 @@ async function render(template, options = {}) {
|
|
|
15
15
|
const config = await resolveConfig(options.config);
|
|
16
16
|
const renderer = options._renderer ?? await createRenderer({
|
|
17
17
|
markdown: config.markdown,
|
|
18
|
-
root: config.root
|
|
18
|
+
root: config.root,
|
|
19
|
+
componentDirs: [config.components?.source ?? []].flat()
|
|
19
20
|
});
|
|
20
21
|
const ownsRenderer = !options._renderer;
|
|
21
22
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/render/index.ts"],"sourcesContent":["import { resolve, extname } from 'node:path'\nimport { resolveConfig } from '../config/index.ts'\nimport { runTransformers } from '../transformers/index.ts'\nimport { createPlaintext } from '../plaintext.ts'\nimport type { Component } from 'vue'\nimport type { MaizzleConfig } from '../types/index.ts'\nimport { createRenderer, type Renderer } from './createRenderer.ts'\n\nexport type { Renderer, RenderedTemplate, CreateRendererOptions } from './createRenderer.ts'\nexport { createRenderer } from './createRenderer.ts'\n\nexport interface RenderOptions {\n /** Already-resolved or partial config. If not provided, resolves from disk + defaults. */\n config?: Partial<MaizzleConfig>\n /** Reuse an existing renderer (used internally by build/serve to avoid creating one per template) */\n _renderer?: Renderer\n}\n\nexport interface RenderResult {\n html: string\n config: MaizzleConfig\n plaintext?: string\n}\n\n/**\n * Render a Vue SFC email template to a fully-transformed HTML string.\n *\n * Accepts a file path, a raw SFC source string, or an imported Vue component.\n * Runs the full pipeline: SSR render → transformers → doctype.\n */\nexport async function render(\n template: string | Component,\n options: RenderOptions = {},\n): Promise<RenderResult> {\n const config = await resolveConfig(options.config)\n\n // Reuse provided renderer or create a temporary one\n const renderer = options._renderer ?? await createRenderer({ markdown: config.markdown, root: config.root })\n const ownsRenderer = !options._renderer\n\n try {\n const isFile = typeof template === 'string'\n && ['.vue', '.md'].includes(extname(template))\n && !template.includes('\\n')\n\n const rendered = await renderer.render(isFile ? resolve(template) : template, config)\n let html = rendered.html\n\n // Run transformers\n if (rendered.templateConfig.useTransformers !== false) {\n html = await runTransformers(html, rendered.templateConfig, isFile ? resolve(template) : undefined)\n }\n\n // Prepend doctype\n const doctype = rendered.doctype ?? rendered.templateConfig.doctype ?? '<!DOCTYPE html>'\n html = `${doctype}\\n${html}`\n\n const globalPlaintext = rendered.templateConfig.plaintext\n const sfcPlaintext = rendered.plaintext\n\n let plaintextResult: string | undefined\n\n if (globalPlaintext || sfcPlaintext) {\n const stripOptions = typeof globalPlaintext === 'object' ? globalPlaintext : {}\n plaintextResult = createPlaintext(html, stripOptions)\n }\n\n return { html, config: rendered.templateConfig, plaintext: plaintextResult }\n } finally {\n if (ownsRenderer) {\n await renderer.close()\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;AA8BA,eAAsB,OACpB,UACA,UAAyB,EAAE,EACJ;CACvB,MAAM,SAAS,MAAM,cAAc,QAAQ,OAAO;CAGlD,MAAM,WAAW,QAAQ,aAAa,MAAM,eAAe;EAAE,UAAU,OAAO;EAAU,MAAM,OAAO;EAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/render/index.ts"],"sourcesContent":["import { resolve, extname } from 'node:path'\nimport { resolveConfig } from '../config/index.ts'\nimport { runTransformers } from '../transformers/index.ts'\nimport { createPlaintext } from '../plaintext.ts'\nimport type { Component } from 'vue'\nimport type { MaizzleConfig } from '../types/index.ts'\nimport { createRenderer, type Renderer } from './createRenderer.ts'\n\nexport type { Renderer, RenderedTemplate, CreateRendererOptions } from './createRenderer.ts'\nexport { createRenderer } from './createRenderer.ts'\n\nexport interface RenderOptions {\n /** Already-resolved or partial config. If not provided, resolves from disk + defaults. */\n config?: Partial<MaizzleConfig>\n /** Reuse an existing renderer (used internally by build/serve to avoid creating one per template) */\n _renderer?: Renderer\n}\n\nexport interface RenderResult {\n html: string\n config: MaizzleConfig\n plaintext?: string\n}\n\n/**\n * Render a Vue SFC email template to a fully-transformed HTML string.\n *\n * Accepts a file path, a raw SFC source string, or an imported Vue component.\n * Runs the full pipeline: SSR render → transformers → doctype.\n */\nexport async function render(\n template: string | Component,\n options: RenderOptions = {},\n): Promise<RenderResult> {\n const config = await resolveConfig(options.config)\n\n // Reuse provided renderer or create a temporary one\n const renderer = options._renderer ?? await createRenderer({ markdown: config.markdown, root: config.root, componentDirs: [config.components?.source ?? []].flat() })\n const ownsRenderer = !options._renderer\n\n try {\n const isFile = typeof template === 'string'\n && ['.vue', '.md'].includes(extname(template))\n && !template.includes('\\n')\n\n const rendered = await renderer.render(isFile ? resolve(template) : template, config)\n let html = rendered.html\n\n // Run transformers\n if (rendered.templateConfig.useTransformers !== false) {\n html = await runTransformers(html, rendered.templateConfig, isFile ? resolve(template) : undefined)\n }\n\n // Prepend doctype\n const doctype = rendered.doctype ?? rendered.templateConfig.doctype ?? '<!DOCTYPE html>'\n html = `${doctype}\\n${html}`\n\n const globalPlaintext = rendered.templateConfig.plaintext\n const sfcPlaintext = rendered.plaintext\n\n let plaintextResult: string | undefined\n\n if (globalPlaintext || sfcPlaintext) {\n const stripOptions = typeof globalPlaintext === 'object' ? globalPlaintext : {}\n plaintextResult = createPlaintext(html, stripOptions)\n }\n\n return { html, config: rendered.templateConfig, plaintext: plaintextResult }\n } finally {\n if (ownsRenderer) {\n await renderer.close()\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;AA8BA,eAAsB,OACpB,UACA,UAAyB,EAAE,EACJ;CACvB,MAAM,SAAS,MAAM,cAAc,QAAQ,OAAO;CAGlD,MAAM,WAAW,QAAQ,aAAa,MAAM,eAAe;EAAE,UAAU,OAAO;EAAU,MAAM,OAAO;EAAM,eAAe,CAAC,OAAO,YAAY,UAAU,EAAE,CAAC,CAAC,MAAM;EAAE,CAAC;CACrK,MAAM,eAAe,CAAC,QAAQ;AAE9B,KAAI;EACF,MAAM,SAAS,OAAO,aAAa,YAC9B,CAAC,QAAQ,MAAM,CAAC,SAAS,QAAQ,SAAS,CAAC,IAC3C,CAAC,SAAS,SAAS,KAAK;EAE7B,MAAM,WAAW,MAAM,SAAS,OAAO,SAAS,QAAQ,SAAS,GAAG,UAAU,OAAO;EACrF,IAAI,OAAO,SAAS;AAGpB,MAAI,SAAS,eAAe,oBAAoB,MAC9C,QAAO,MAAM,gBAAgB,MAAM,SAAS,gBAAgB,SAAS,QAAQ,SAAS,GAAG,OAAU;AAKrG,SAAO,GADS,SAAS,WAAW,SAAS,eAAe,WAAW,kBACrD,IAAI;EAEtB,MAAM,kBAAkB,SAAS,eAAe;EAChD,MAAM,eAAe,SAAS;EAE9B,IAAI;AAEJ,MAAI,mBAAmB,aAErB,mBAAkB,gBAAgB,MADb,OAAO,oBAAoB,WAAW,kBAAkB,EAAE,CAC1B;AAGvD,SAAO;GAAE;GAAM,QAAQ,SAAS;GAAgB,WAAW;GAAiB;WACpE;AACR,MAAI,aACF,OAAM,SAAS,OAAO"}
|
package/dist/serve.mjs
CHANGED
|
@@ -35,7 +35,8 @@ async function serve(options = {}) {
|
|
|
35
35
|
const renderer = await createRenderer({
|
|
36
36
|
dts: true,
|
|
37
37
|
markdown: config.markdown,
|
|
38
|
-
root: config.root
|
|
38
|
+
root: config.root,
|
|
39
|
+
componentDirs: [config.components?.source ?? []].flat()
|
|
39
40
|
});
|
|
40
41
|
const server = await createServer({
|
|
41
42
|
configFile: false,
|
package/dist/serve.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serve.mjs","names":[],"sources":["../src/serve.ts"],"sourcesContent":["import { readFileSync } from 'node:fs'\nimport { dirname, resolve, basename } from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport { createRequire } from 'node:module'\nimport { createServer, createLogger, type ViteDevServer } from 'vite'\nimport vue from '@vitejs/plugin-vue'\nimport tailwindcss from '@tailwindcss/vite'\nimport { glob } from 'tinyglobby'\nimport { createHighlighter, type Highlighter } from 'shiki'\nimport { createPlaintext } from './plaintext.ts'\nimport { resolveConfig } from './config/index.ts'\nimport { runTransformers } from './transformers/index.ts'\nimport { createRenderer, type Renderer } from './render/createRenderer.ts'\nimport { serveCompatibility } from './server/compatibility.ts'\nimport { serveLint } from './server/linter.ts'\nimport type { MaizzleConfig } from './types/index.ts'\n\nconst __dirname = dirname(fileURLToPath(import.meta.url))\nconst devUIDir = resolve(__dirname, 'server/ui')\n\nconst require = createRequire(import.meta.url)\nconst frameworkNodeModules = resolve(dirname(require.resolve('vue/package.json')), '..')\nconst vuePkgDir = dirname(require.resolve('vue/package.json'))\n\nexport interface ServeOptions {\n config?: Partial<MaizzleConfig> | string\n /** Expose the server on the network (e.g. --host) */\n host?: boolean | string\n /** When true, suppresses the banner/URL output (used by the Vite plugin, which prints its own) */\n silent?: boolean\n}\n\n/**\n * Start the Maizzle dev server.\n *\n * Creates two things:\n * 1. A Vite dev server for the dev UI (sidebar + preview, with Vue + Tailwind for the UI itself)\n * 2. A Renderer instance for SSR rendering email templates\n *\n * Template rendering goes through the Renderer, not the Vite dev server.\n */\nexport async function serve(options: ServeOptions = {}) {\n const start = performance.now()\n\n let config = await resolveConfig(options.config)\n const port = config.server?.port ?? 3000\n\n // Create a renderer for SSR rendering email templates (with dts for dev)\n const renderer = await createRenderer({ dts: true, markdown: config.markdown, root: config.root })\n\n const server = await createServer({\n configFile: false,\n plugins: [\n // Vue and Tailwind are only for the dev UI SPA, not for email templates\n vue(),\n tailwindcss(),\n maizzleDevPlugin(config, renderer, options.config),\n ],\n resolve: {\n dedupe: ['vue'],\n alias: [\n { find: '@', replacement: devUIDir },\n { find: 'vue', replacement: resolve(vuePkgDir, 'dist/vue.runtime.esm-bundler.js') },\n { find: 'vue-router', replacement: resolve(frameworkNodeModules, 'vue-router') },\n { find: 'reka-ui', replacement: resolve(frameworkNodeModules, 'reka-ui') },\n { find: '@vueuse/core', replacement: resolve(frameworkNodeModules, '@vueuse/core') },\n { find: '@vueuse/shared', replacement: resolve(frameworkNodeModules, '@vueuse/shared') },\n { find: 'lucide-vue-next', replacement: resolve(frameworkNodeModules, 'lucide-vue-next') },\n { find: 'class-variance-authority', replacement: resolve(frameworkNodeModules, 'class-variance-authority') },\n { find: 'clsx', replacement: resolve(frameworkNodeModules, 'clsx') },\n { find: 'tailwind-merge', replacement: resolve(frameworkNodeModules, 'tailwind-merge') },\n ],\n },\n cacheDir: resolve(devUIDir, '.vite'),\n optimizeDeps: {\n noDiscovery: true,\n include: [\n 'vue',\n 'vue-router',\n 'lucide-vue-next',\n '@vueuse/core',\n '@vueuse/shared',\n 'reka-ui',\n 'class-variance-authority',\n 'clsx',\n 'tailwind-merge',\n ],\n },\n server: {\n port,\n host: options.host,\n fs: {\n allow: [process.cwd(), config.root ?? process.cwd(), devUIDir, frameworkNodeModules],\n },\n },\n customLogger: customLogger(),\n })\n\n // Store renderer ref on server for cleanup\n const originalClose = server.close.bind(server)\n server.close = async () => {\n await renderer.close()\n return originalClose()\n }\n\n await server.listen()\n\n const startupTime = Math.round(performance.now() - start)\n\n if (!options.silent) {\n printBanner(server, startupTime)\n }\n\n // Expose startup time so the plugin can print it later\n ; (server as any)._maizzleStartupTime = startupTime\n\n return server\n}\n\n/**\n * Internal Vite plugin that adds Maizzle middleware and file watching to the dev UI server.\n */\nfunction maizzleDevPlugin(\n config: MaizzleConfig,\n renderer: Renderer,\n configInput: Partial<MaizzleConfig> | string | undefined,\n) {\n return {\n name: 'maizzle:dev',\n enforce: 'pre' as const,\n\n hotUpdate: {\n order: 'pre' as const,\n handler({ file }: { file: string }) {\n // Prevent Tailwind/Vue from triggering a full reload for email template files.\n // Maizzle handles these via custom HMR events in the watcher below.\n if (isTemplateFile(file)) {\n return []\n }\n },\n },\n\n configureServer(server: ViteDevServer) {\n // File watching\n const defaultWatchPaths = [\n 'maizzle.config.js',\n 'maizzle.config.ts',\n 'tailwind.config.js',\n 'tailwind.config.ts',\n ]\n\n const userWatchPaths = config.server?.watch ?? []\n const watchPaths = [...defaultWatchPaths, ...userWatchPaths]\n\n for (const watchPath of watchPaths) {\n server.watcher.add(watchPath)\n }\n\n server.watcher.on('add', (file) => {\n if (isTemplateFile(file)) {\n server.ws.send({ type: 'custom', event: 'maizzle:templates-changed' })\n }\n })\n\n server.watcher.on('unlink', (file) => {\n if (isTemplateFile(file)) {\n server.ws.send({ type: 'custom', event: 'maizzle:templates-changed' })\n }\n })\n\n server.watcher.on('change', async (file) => {\n if (watchPaths.some(p => file.endsWith(p))) {\n config = await resolveConfig(configInput)\n }\n\n if (\n isTemplateFile(file)\n || watchPaths.some(p => file.endsWith(p))\n ) {\n server.ws.send({ type: 'custom', event: 'maizzle:template-updated', data: { file } })\n }\n })\n\n // API middleware (before Vite's middleware)\n server.middlewares.use(async (req: any, res: any, next: any) => {\n const url = req.url || '/'\n\n if (url === '/__maizzle/templates') {\n return serveTemplateList(config, res)\n }\n\n if (url.startsWith('/__maizzle/render/')) {\n return await serveRenderedTemplate(url, config, renderer, res)\n }\n\n if (url.startsWith('/__maizzle/source/')) {\n return await serveHighlightedSource(url, config, renderer, res)\n }\n\n if (url.startsWith('/__maizzle/compatibility/')) {\n return await serveCompatibility(url, config, res)\n }\n\n if (url.startsWith('/__maizzle/lint/')) {\n return await serveLint(url, config, res)\n }\n\n if (url.startsWith('/__maizzle/vue-source/')) {\n return await serveVueSource(url, config, res)\n }\n\n if (url.startsWith('/__maizzle/plaintext/')) {\n return await servePlaintext(url, config, renderer, res)\n }\n\n if (url.startsWith('/__maizzle/stats/')) {\n return await serveStats(url, config, renderer, res)\n }\n\n next()\n })\n\n // Dev UI fallback (after Vite's middleware)\n return () => {\n server.middlewares.use(async (req: any, res: any, next: any) => {\n if (isNavigationRequest(req)) {\n return await serveDevUI(server, res, req.url || '/')\n }\n\n next()\n })\n }\n },\n }\n}\n\nfunction isTemplateFile(file: string): boolean {\n return (file.endsWith('.vue') || file.endsWith('.md')) && !file.includes('server/ui')\n}\n\nfunction isNavigationRequest(req: any): boolean {\n const accept = req.headers?.accept || ''\n return req.method === 'GET' && accept.includes('text/html')\n}\n\nasync function serveDevUI(server: ViteDevServer, res: any, url: string) {\n let indexHtml = readFileSync(resolve(devUIDir, 'index.html'), 'utf-8')\n\n indexHtml = indexHtml.replace('./main.ts', `/@fs/${resolve(devUIDir, 'main.ts')}`)\n indexHtml = indexHtml.replace('./favicon.svg', `/@fs/${resolve(devUIDir, 'favicon.svg')}`)\n\n const transformed = await server.transformIndexHtml(url, indexHtml)\n\n res.setHeader('Content-Type', 'text/html')\n res.end(transformed)\n}\n\nasync function serveTemplateList(config: MaizzleConfig, res: any) {\n const contentPatterns = config.content ?? ['emails/**/*.vue']\n const templates = await glob(contentPatterns)\n\n const data = templates.map(t => ({\n name: basename(t).replace(/\\.(vue|md)$/, ''),\n path: t,\n href: '/' + t.replace(/\\.(vue|md)$/, ''),\n }))\n\n res.setHeader('Content-Type', 'application/json')\n res.end(JSON.stringify(data))\n}\n\n/**\n * SSR render a .vue template using the Renderer (not the dev UI server).\n */\nasync function serveRenderedTemplate(url: string, config: MaizzleConfig, renderer: Renderer, res: any) {\n const templateSlug = url.replace('/__maizzle/render/', '').replace(/\\?.*$/, '')\n\n const contentPatterns = config.content ?? ['emails/**/*.vue']\n const templates = await glob(contentPatterns)\n const match = templates.find(t => t.replace(/\\.(vue|md)$/, '') === templateSlug)\n\n if (!match) {\n res.statusCode = 404\n res.end('Template not found')\n return\n }\n\n try {\n const absolutePath = resolve(match)\n\n // Invalidate the module so changes are picked up\n await renderer.invalidate(absolutePath)\n\n const rendered = await renderer.render(absolutePath, config)\n let html = rendered.html\n\n const templateConfig = rendered.templateConfig\n\n html = await runTransformers(html, templateConfig, absolutePath)\n\n const doctype = rendered.doctype ?? templateConfig.doctype ?? '<!DOCTYPE html>'\n html = `${doctype}\\n${html}`\n\n res.setHeader('Content-Type', 'text/html')\n res.end(html)\n } catch (error: any) {\n res.statusCode = 500\n res.end(`<pre>${error.stack || error.message}</pre>`)\n }\n}\n\nlet highlighter: Highlighter | null = null\n\nasync function getHighlighter() {\n if (!highlighter) {\n highlighter = await createHighlighter({\n themes: ['laserwave'],\n langs: ['html', 'vue'],\n })\n }\n return highlighter\n}\n\nasync function serveHighlightedSource(url: string, config: MaizzleConfig, renderer: Renderer, res: any) {\n const templateSlug = url.replace('/__maizzle/source/', '').replace(/\\?.*$/, '')\n\n const contentPatterns = config.content ?? ['emails/**/*.vue']\n const templates = await glob(contentPatterns)\n const match = templates.find(t => t.replace(/\\.(vue|md)$/, '') === templateSlug)\n\n if (!match) {\n res.statusCode = 404\n res.end('Template not found')\n return\n }\n\n try {\n const absolutePath = resolve(match)\n\n await renderer.invalidate(absolutePath)\n\n const rendered = await renderer.render(absolutePath, config)\n let html = rendered.html\n\n const templateConfig = rendered.templateConfig\n html = await runTransformers(html, templateConfig, absolutePath)\n\n const doctype = rendered.doctype ?? templateConfig.doctype ?? '<!DOCTYPE html>'\n html = `${doctype}\\n${html}`\n\n const hl = await getHighlighter()\n const highlighted = hl.codeToHtml(html, {\n lang: 'html',\n theme: 'laserwave',\n transformers: [{\n line(node, line) {\n node.properties['data-line'] = line\n },\n }],\n })\n\n res.setHeader('Content-Type', 'text/html')\n res.end(highlighted)\n } catch (error: any) {\n res.statusCode = 500\n res.end(`<pre>${error.stack || error.message}</pre>`)\n }\n}\n\nasync function serveVueSource(url: string, config: MaizzleConfig, res: any) {\n const templateSlug = url.replace('/__maizzle/vue-source/', '').replace(/\\?.*$/, '')\n\n const contentPatterns = config.content ?? ['emails/**/*.vue']\n const templates = await glob(contentPatterns)\n const match = templates.find(t => t.replace(/\\.(vue|md)$/, '') === templateSlug)\n\n if (!match) {\n res.statusCode = 404\n res.end('Template not found')\n return\n }\n\n try {\n const source = readFileSync(resolve(match), 'utf-8')\n const lang = match.endsWith('.md') ? 'html' : 'vue'\n\n const hl = await getHighlighter()\n const highlighted = hl.codeToHtml(source, {\n lang,\n theme: 'laserwave',\n transformers: [{\n line(node, line) {\n node.properties['data-line'] = line\n },\n }],\n })\n\n res.setHeader('Content-Type', 'text/html')\n res.end(highlighted)\n } catch (error: any) {\n res.statusCode = 500\n res.end(`<pre>${error.stack || error.message}</pre>`)\n }\n}\n\nasync function servePlaintext(url: string, config: MaizzleConfig, renderer: Renderer, res: any) {\n const templateSlug = url.replace('/__maizzle/plaintext/', '').replace(/\\?.*$/, '')\n\n const contentPatterns = config.content ?? ['emails/**/*.vue']\n const templates = await glob(contentPatterns)\n const match = templates.find(t => t.replace(/\\.(vue|md)$/, '') === templateSlug)\n\n if (!match) {\n res.statusCode = 404\n res.end('Template not found')\n return\n }\n\n try {\n const absolutePath = resolve(match)\n await renderer.invalidate(absolutePath)\n\n const rendered = await renderer.render(absolutePath, config)\n let html = rendered.html\n const templateConfig = rendered.templateConfig\n html = await runTransformers(html, templateConfig, absolutePath)\n\n const plaintext = createPlaintext(html)\n\n res.setHeader('Content-Type', 'text/plain')\n res.end(plaintext)\n } catch (error: any) {\n res.statusCode = 500\n res.end(error.message)\n }\n}\n\nfunction humanFileSize(bytes: number, si = false, dp = 2) {\n const threshold = si ? 1000 : 1024\n\n if (Math.abs(bytes) < threshold) {\n return bytes + ' B'\n }\n\n const units = ['KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']\n let u = -1\n const r = 10 ** dp\n\n do {\n bytes /= threshold\n ++u\n } while (Math.round(Math.abs(bytes) * r) / r >= threshold && u < units.length - 1)\n\n return bytes.toFixed(dp) + ' ' + units[u]\n}\n\nasync function serveStats(url: string, config: MaizzleConfig, renderer: Renderer, res: any) {\n const templateSlug = url.replace('/__maizzle/stats/', '').replace(/\\?.*$/, '')\n\n const contentPatterns = config.content ?? ['emails/**/*.vue']\n const templates = await glob(contentPatterns)\n const match = templates.find(t => t.replace(/\\.(vue|md)$/, '') === templateSlug)\n\n if (!match) {\n res.statusCode = 404\n res.end(JSON.stringify({ error: 'Template not found' }))\n return\n }\n\n try {\n const absolutePath = resolve(match)\n await renderer.invalidate(absolutePath)\n\n const rendered = await renderer.render(absolutePath, config)\n let html = rendered.html\n const templateConfig = rendered.templateConfig\n html = await runTransformers(html, templateConfig, absolutePath)\n\n const sizeBytes = Buffer.byteLength(html, 'utf-8')\n\n // Count images: <img> tags and CSS background images\n const imgTags = (html.match(/<img\\b[^>]*>/gi) || []).length\n const bgImages = (html.match(/url\\s*\\([^)]+\\)/gi) || []).length\n const totalImages = imgTags + bgImages\n\n // Count links\n const links = (html.match(/<a\\b[^>]*href\\s*=/gi) || []).length\n\n res.setHeader('Content-Type', 'application/json')\n res.end(JSON.stringify({\n size: {\n bytes: sizeBytes,\n formatted: humanFileSize(sizeBytes),\n },\n images: totalImages,\n links,\n }))\n } catch (error: any) {\n res.statusCode = 500\n res.end(JSON.stringify({ error: error.message }))\n }\n}\n\nexport function printBanner(server: ViteDevServer, startupTime?: number) {\n const info = server.config.logger.info\n const time = startupTime ?? (server as any)._maizzleStartupTime\n\n info('')\n info(` \\x1b[32m\\x1b[1mMAIZZLE\\x1b[0m\\x1b[32m v6.0.0\\x1b[0m \\x1b[2mready in\\x1b[0m \\x1b[1m${time}\\x1b[0m ms`)\n info('')\n server.printUrls()\n info('')\n}\n\nfunction customLogger() {\n const logger = createLogger('info')\n const warn = logger.warn\n\n logger.warn = (message, options) => {\n if (typeof message === 'string' && message.includes('<tr> cannot be child of <table>')) {\n return\n }\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M;AACnC,QAAM,SAAS,WAAW,aAAa;EAEvC,MAAM,WAAW,MAAM,SAAS,OAAO,cAAc,OAAO;EAC5D,IAAI,OAAO,SAAS;EACpB,MAAM,iBAAiB,SAAS;AAChC,SAAO,MAAM,gBAAgB,MAAM,gBAAgB,aAAa;EAEhE,MAAM,YAAY,OAAO,WAAW,MAAM,QAAQ;EAKlD,MAAM,eAFW,KAAK,MAAM,iBAAiB,IAAI,EAAE,EAAE,UACnC,KAAK,MAAM,oBAAoB,IAAI,EAAE,EAAE;EAIzD,MAAM,SAAS,KAAK,MAAM,sBAAsB,IAAI,EAAE,EAAE;AAExD,MAAI,UAAU,gBAAgB,mBAAmB;AACjD,MAAI,IAAI,KAAK,UAAU;GACrB,MAAM;IACJ,OAAO;IACP,WAAW,cAAc,UAAU;IACpC;GACD,QAAQ;GACR;GACD,CAAC,CAAC;UACI,OAAY;AACnB,MAAI,aAAa;AACjB,MAAI,IAAI,KAAK,UAAU,EAAE,OAAO,MAAM,SAAS,CAAC,CAAC;;;AAIrD,SAAgB,YAAY,QAAuB,aAAsB;CACvE,MAAM,OAAO,OAAO,OAAO,OAAO;CAClC,MAAM,OAAO,eAAgB,OAAe;AAE5C,MAAK,GAAG;AACR,MAAK,wFAAwF,KAAK,YAAY;AAC9G,MAAK,GAAG;AACR,QAAO,WAAW;AAClB,MAAK,GAAG;;AAGV,SAAS,eAAe;CACtB,MAAM,SAAS,aAAa,OAAO;CACnC,MAAM,OAAO,OAAO;AAEpB,QAAO,QAAQ,SAAS,YAAY;AAClC,MAAI,OAAO,YAAY,YAAY,QAAQ,SAAS,kCAAkC,CACpF;AAGF,OAAK,SAAS,QAAQ;;AAGxB,QAAO"}
|
|
1
|
+
{"version":3,"file":"serve.mjs","names":[],"sources":["../src/serve.ts"],"sourcesContent":["import { readFileSync } from 'node:fs'\nimport { dirname, resolve, basename } from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport { createRequire } from 'node:module'\nimport { createServer, createLogger, type ViteDevServer } from 'vite'\nimport vue from '@vitejs/plugin-vue'\nimport tailwindcss from '@tailwindcss/vite'\nimport { glob } from 'tinyglobby'\nimport { createHighlighter, type Highlighter } from 'shiki'\nimport { createPlaintext } from './plaintext.ts'\nimport { resolveConfig } from './config/index.ts'\nimport { runTransformers } from './transformers/index.ts'\nimport { createRenderer, type Renderer } from './render/createRenderer.ts'\nimport { serveCompatibility } from './server/compatibility.ts'\nimport { serveLint } from './server/linter.ts'\nimport type { MaizzleConfig } from './types/index.ts'\n\nconst __dirname = dirname(fileURLToPath(import.meta.url))\nconst devUIDir = resolve(__dirname, 'server/ui')\n\nconst require = createRequire(import.meta.url)\nconst frameworkNodeModules = resolve(dirname(require.resolve('vue/package.json')), '..')\nconst vuePkgDir = dirname(require.resolve('vue/package.json'))\n\nexport interface ServeOptions {\n config?: Partial<MaizzleConfig> | string\n /** Expose the server on the network (e.g. --host) */\n host?: boolean | string\n /** When true, suppresses the banner/URL output (used by the Vite plugin, which prints its own) */\n silent?: boolean\n}\n\n/**\n * Start the Maizzle dev server.\n *\n * Creates two things:\n * 1. A Vite dev server for the dev UI (sidebar + preview, with Vue + Tailwind for the UI itself)\n * 2. A Renderer instance for SSR rendering email templates\n *\n * Template rendering goes through the Renderer, not the Vite dev server.\n */\nexport async function serve(options: ServeOptions = {}) {\n const start = performance.now()\n\n let config = await resolveConfig(options.config)\n const port = config.server?.port ?? 3000\n\n // Create a renderer for SSR rendering email templates (with dts for dev)\n const renderer = await createRenderer({ dts: true, markdown: config.markdown, root: config.root, componentDirs: [config.components?.source ?? []].flat() })\n\n const server = await createServer({\n configFile: false,\n plugins: [\n // Vue and Tailwind are only for the dev UI SPA, not for email templates\n vue(),\n tailwindcss(),\n maizzleDevPlugin(config, renderer, options.config),\n ],\n resolve: {\n dedupe: ['vue'],\n alias: [\n { find: '@', replacement: devUIDir },\n { find: 'vue', replacement: resolve(vuePkgDir, 'dist/vue.runtime.esm-bundler.js') },\n { find: 'vue-router', replacement: resolve(frameworkNodeModules, 'vue-router') },\n { find: 'reka-ui', replacement: resolve(frameworkNodeModules, 'reka-ui') },\n { find: '@vueuse/core', replacement: resolve(frameworkNodeModules, '@vueuse/core') },\n { find: '@vueuse/shared', replacement: resolve(frameworkNodeModules, '@vueuse/shared') },\n { find: 'lucide-vue-next', replacement: resolve(frameworkNodeModules, 'lucide-vue-next') },\n { find: 'class-variance-authority', replacement: resolve(frameworkNodeModules, 'class-variance-authority') },\n { find: 'clsx', replacement: resolve(frameworkNodeModules, 'clsx') },\n { find: 'tailwind-merge', replacement: resolve(frameworkNodeModules, 'tailwind-merge') },\n ],\n },\n cacheDir: resolve(devUIDir, '.vite'),\n optimizeDeps: {\n noDiscovery: true,\n include: [\n 'vue',\n 'vue-router',\n 'lucide-vue-next',\n '@vueuse/core',\n '@vueuse/shared',\n 'reka-ui',\n 'class-variance-authority',\n 'clsx',\n 'tailwind-merge',\n ],\n },\n server: {\n port,\n host: options.host,\n fs: {\n allow: [process.cwd(), config.root ?? process.cwd(), devUIDir, frameworkNodeModules],\n },\n },\n customLogger: customLogger(),\n })\n\n // Store renderer ref on server for cleanup\n const originalClose = server.close.bind(server)\n server.close = async () => {\n await renderer.close()\n return originalClose()\n }\n\n await server.listen()\n\n const startupTime = Math.round(performance.now() - start)\n\n if (!options.silent) {\n printBanner(server, startupTime)\n }\n\n // Expose startup time so the plugin can print it later\n ; (server as any)._maizzleStartupTime = startupTime\n\n return server\n}\n\n/**\n * Internal Vite plugin that adds Maizzle middleware and file watching to the dev UI server.\n */\nfunction maizzleDevPlugin(\n config: MaizzleConfig,\n renderer: Renderer,\n configInput: Partial<MaizzleConfig> | string | undefined,\n) {\n return {\n name: 'maizzle:dev',\n enforce: 'pre' as const,\n\n hotUpdate: {\n order: 'pre' as const,\n handler({ file }: { file: string }) {\n // Prevent Tailwind/Vue from triggering a full reload for email template files.\n // Maizzle handles these via custom HMR events in the watcher below.\n if (isTemplateFile(file)) {\n return []\n }\n },\n },\n\n configureServer(server: ViteDevServer) {\n // File watching\n const defaultWatchPaths = [\n 'maizzle.config.js',\n 'maizzle.config.ts',\n 'tailwind.config.js',\n 'tailwind.config.ts',\n ]\n\n const userWatchPaths = config.server?.watch ?? []\n const watchPaths = [...defaultWatchPaths, ...userWatchPaths]\n\n for (const watchPath of watchPaths) {\n server.watcher.add(watchPath)\n }\n\n server.watcher.on('add', (file) => {\n if (isTemplateFile(file)) {\n server.ws.send({ type: 'custom', event: 'maizzle:templates-changed' })\n }\n })\n\n server.watcher.on('unlink', (file) => {\n if (isTemplateFile(file)) {\n server.ws.send({ type: 'custom', event: 'maizzle:templates-changed' })\n }\n })\n\n server.watcher.on('change', async (file) => {\n if (watchPaths.some(p => file.endsWith(p))) {\n config = await resolveConfig(configInput)\n }\n\n if (\n isTemplateFile(file)\n || watchPaths.some(p => file.endsWith(p))\n ) {\n server.ws.send({ type: 'custom', event: 'maizzle:template-updated', data: { file } })\n }\n })\n\n // API middleware (before Vite's middleware)\n server.middlewares.use(async (req: any, res: any, next: any) => {\n const url = req.url || '/'\n\n if (url === '/__maizzle/templates') {\n return serveTemplateList(config, res)\n }\n\n if (url.startsWith('/__maizzle/render/')) {\n return await serveRenderedTemplate(url, config, renderer, res)\n }\n\n if (url.startsWith('/__maizzle/source/')) {\n return await serveHighlightedSource(url, config, renderer, res)\n }\n\n if (url.startsWith('/__maizzle/compatibility/')) {\n return await serveCompatibility(url, config, res)\n }\n\n if (url.startsWith('/__maizzle/lint/')) {\n return await serveLint(url, config, res)\n }\n\n if (url.startsWith('/__maizzle/vue-source/')) {\n return await serveVueSource(url, config, res)\n }\n\n if (url.startsWith('/__maizzle/plaintext/')) {\n return await servePlaintext(url, config, renderer, res)\n }\n\n if (url.startsWith('/__maizzle/stats/')) {\n return await serveStats(url, config, renderer, res)\n }\n\n next()\n })\n\n // Dev UI fallback (after Vite's middleware)\n return () => {\n server.middlewares.use(async (req: any, res: any, next: any) => {\n if (isNavigationRequest(req)) {\n return await serveDevUI(server, res, req.url || '/')\n }\n\n next()\n })\n }\n },\n }\n}\n\nfunction isTemplateFile(file: string): boolean {\n return (file.endsWith('.vue') || file.endsWith('.md')) && !file.includes('server/ui')\n}\n\nfunction isNavigationRequest(req: any): boolean {\n const accept = req.headers?.accept || ''\n return req.method === 'GET' && accept.includes('text/html')\n}\n\nasync function serveDevUI(server: ViteDevServer, res: any, url: string) {\n let indexHtml = readFileSync(resolve(devUIDir, 'index.html'), 'utf-8')\n\n indexHtml = indexHtml.replace('./main.ts', `/@fs/${resolve(devUIDir, 'main.ts')}`)\n indexHtml = indexHtml.replace('./favicon.svg', `/@fs/${resolve(devUIDir, 'favicon.svg')}`)\n\n const transformed = await server.transformIndexHtml(url, indexHtml)\n\n res.setHeader('Content-Type', 'text/html')\n res.end(transformed)\n}\n\nasync function serveTemplateList(config: MaizzleConfig, res: any) {\n const contentPatterns = config.content ?? ['emails/**/*.vue']\n const templates = await glob(contentPatterns)\n\n const data = templates.map(t => ({\n name: basename(t).replace(/\\.(vue|md)$/, ''),\n path: t,\n href: '/' + t.replace(/\\.(vue|md)$/, ''),\n }))\n\n res.setHeader('Content-Type', 'application/json')\n res.end(JSON.stringify(data))\n}\n\n/**\n * SSR render a .vue template using the Renderer (not the dev UI server).\n */\nasync function serveRenderedTemplate(url: string, config: MaizzleConfig, renderer: Renderer, res: any) {\n const templateSlug = url.replace('/__maizzle/render/', '').replace(/\\?.*$/, '')\n\n const contentPatterns = config.content ?? ['emails/**/*.vue']\n const templates = await glob(contentPatterns)\n const match = templates.find(t => t.replace(/\\.(vue|md)$/, '') === templateSlug)\n\n if (!match) {\n res.statusCode = 404\n res.end('Template not found')\n return\n }\n\n try {\n const absolutePath = resolve(match)\n\n // Invalidate the module so changes are picked up\n await renderer.invalidate(absolutePath)\n\n const rendered = await renderer.render(absolutePath, config)\n let html = rendered.html\n\n const templateConfig = rendered.templateConfig\n\n html = await runTransformers(html, templateConfig, absolutePath)\n\n const doctype = rendered.doctype ?? templateConfig.doctype ?? '<!DOCTYPE html>'\n html = `${doctype}\\n${html}`\n\n res.setHeader('Content-Type', 'text/html')\n res.end(html)\n } catch (error: any) {\n res.statusCode = 500\n res.end(`<pre>${error.stack || error.message}</pre>`)\n }\n}\n\nlet highlighter: Highlighter | null = null\n\nasync function getHighlighter() {\n if (!highlighter) {\n highlighter = await createHighlighter({\n themes: ['laserwave'],\n langs: ['html', 'vue'],\n })\n }\n return highlighter\n}\n\nasync function serveHighlightedSource(url: string, config: MaizzleConfig, renderer: Renderer, res: any) {\n const templateSlug = url.replace('/__maizzle/source/', '').replace(/\\?.*$/, '')\n\n const contentPatterns = config.content ?? ['emails/**/*.vue']\n const templates = await glob(contentPatterns)\n const match = templates.find(t => t.replace(/\\.(vue|md)$/, '') === templateSlug)\n\n if (!match) {\n res.statusCode = 404\n res.end('Template not found')\n return\n }\n\n try {\n const absolutePath = resolve(match)\n\n await renderer.invalidate(absolutePath)\n\n const rendered = await renderer.render(absolutePath, config)\n let html = rendered.html\n\n const templateConfig = rendered.templateConfig\n html = await runTransformers(html, templateConfig, absolutePath)\n\n const doctype = rendered.doctype ?? templateConfig.doctype ?? '<!DOCTYPE html>'\n html = `${doctype}\\n${html}`\n\n const hl = await getHighlighter()\n const highlighted = hl.codeToHtml(html, {\n lang: 'html',\n theme: 'laserwave',\n transformers: [{\n line(node, line) {\n node.properties['data-line'] = line\n },\n }],\n })\n\n res.setHeader('Content-Type', 'text/html')\n res.end(highlighted)\n } catch (error: any) {\n res.statusCode = 500\n res.end(`<pre>${error.stack || error.message}</pre>`)\n }\n}\n\nasync function serveVueSource(url: string, config: MaizzleConfig, res: any) {\n const templateSlug = url.replace('/__maizzle/vue-source/', '').replace(/\\?.*$/, '')\n\n const contentPatterns = config.content ?? ['emails/**/*.vue']\n const templates = await glob(contentPatterns)\n const match = templates.find(t => t.replace(/\\.(vue|md)$/, '') === templateSlug)\n\n if (!match) {\n res.statusCode = 404\n res.end('Template not found')\n return\n }\n\n try {\n const source = readFileSync(resolve(match), 'utf-8')\n const lang = match.endsWith('.md') ? 'html' : 'vue'\n\n const hl = await getHighlighter()\n const highlighted = hl.codeToHtml(source, {\n lang,\n theme: 'laserwave',\n transformers: [{\n line(node, line) {\n node.properties['data-line'] = line\n },\n }],\n })\n\n res.setHeader('Content-Type', 'text/html')\n res.end(highlighted)\n } catch (error: any) {\n res.statusCode = 500\n res.end(`<pre>${error.stack || error.message}</pre>`)\n }\n}\n\nasync function servePlaintext(url: string, config: MaizzleConfig, renderer: Renderer, res: any) {\n const templateSlug = url.replace('/__maizzle/plaintext/', '').replace(/\\?.*$/, '')\n\n const contentPatterns = config.content ?? ['emails/**/*.vue']\n const templates = await glob(contentPatterns)\n const match = templates.find(t => t.replace(/\\.(vue|md)$/, '') === templateSlug)\n\n if (!match) {\n res.statusCode = 404\n res.end('Template not found')\n return\n }\n\n try {\n const absolutePath = resolve(match)\n await renderer.invalidate(absolutePath)\n\n const rendered = await renderer.render(absolutePath, config)\n let html = rendered.html\n const templateConfig = rendered.templateConfig\n html = await runTransformers(html, templateConfig, absolutePath)\n\n const plaintext = createPlaintext(html)\n\n res.setHeader('Content-Type', 'text/plain')\n res.end(plaintext)\n } catch (error: any) {\n res.statusCode = 500\n res.end(error.message)\n }\n}\n\nfunction humanFileSize(bytes: number, si = false, dp = 2) {\n const threshold = si ? 1000 : 1024\n\n if (Math.abs(bytes) < threshold) {\n return bytes + ' B'\n }\n\n const units = ['KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']\n let u = -1\n const r = 10 ** dp\n\n do {\n bytes /= threshold\n ++u\n } while (Math.round(Math.abs(bytes) * r) / r >= threshold && u < units.length - 1)\n\n return bytes.toFixed(dp) + ' ' + units[u]\n}\n\nasync function serveStats(url: string, config: MaizzleConfig, renderer: Renderer, res: any) {\n const templateSlug = url.replace('/__maizzle/stats/', '').replace(/\\?.*$/, '')\n\n const contentPatterns = config.content ?? ['emails/**/*.vue']\n const templates = await glob(contentPatterns)\n const match = templates.find(t => t.replace(/\\.(vue|md)$/, '') === templateSlug)\n\n if (!match) {\n res.statusCode = 404\n res.end(JSON.stringify({ error: 'Template not found' }))\n return\n }\n\n try {\n const absolutePath = resolve(match)\n await renderer.invalidate(absolutePath)\n\n const rendered = await renderer.render(absolutePath, config)\n let html = rendered.html\n const templateConfig = rendered.templateConfig\n html = await runTransformers(html, templateConfig, absolutePath)\n\n const sizeBytes = Buffer.byteLength(html, 'utf-8')\n\n // Count images: <img> tags and CSS background images\n const imgTags = (html.match(/<img\\b[^>]*>/gi) || []).length\n const bgImages = (html.match(/url\\s*\\([^)]+\\)/gi) || []).length\n const totalImages = imgTags + bgImages\n\n // Count links\n const links = (html.match(/<a\\b[^>]*href\\s*=/gi) || []).length\n\n res.setHeader('Content-Type', 'application/json')\n res.end(JSON.stringify({\n size: {\n bytes: sizeBytes,\n formatted: humanFileSize(sizeBytes),\n },\n images: totalImages,\n links,\n }))\n } catch (error: any) {\n res.statusCode = 500\n res.end(JSON.stringify({ error: error.message }))\n }\n}\n\nexport function printBanner(server: ViteDevServer, startupTime?: number) {\n const info = server.config.logger.info\n const time = startupTime ?? (server as any)._maizzleStartupTime\n\n info('')\n info(` \\x1b[32m\\x1b[1mMAIZZLE\\x1b[0m\\x1b[32m v6.0.0\\x1b[0m \\x1b[2mready in\\x1b[0m \\x1b[1m${time}\\x1b[0m ms`)\n info('')\n server.printUrls()\n info('')\n}\n\nfunction customLogger() {\n const logger = createLogger('info')\n const warn = logger.warn\n\n logger.warn = (message, options) => {\n if (typeof message === 'string' && message.includes('<tr> cannot be child of <table>')) {\n return\n }\n\n warn(message, options)\n }\n\n return logger\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAkBA,MAAM,WAAW,QADC,QAAQ,cAAc,OAAO,KAAK,IAAI,CAAC,EACrB,YAAY;AAEhD,MAAM,UAAU,cAAc,OAAO,KAAK,IAAI;AAC9C,MAAM,uBAAuB,QAAQ,QAAQ,QAAQ,QAAQ,mBAAmB,CAAC,EAAE,KAAK;AACxF,MAAM,YAAY,Q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AA,EAAQ,aAAA;IAAe,QAAA;IAAkB,IAAA;EAAA,sBAAmC,OAAA;EACxG,UAAA,IAAc,MAAA;IAAU,KAAA;IAAiB,MAAA,EAAQ,aAAA;EAAA,aAA2B,OAAA;EAAA,CAG3E,GAAA;AAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detect.d.mts","names":[],"sources":["../../src/utils/detect.ts"],"mappings":";iBAGgB,SAAA,CAAU,GAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/detect.ts
|
|
5
|
+
function isLaravel(cwd = process.cwd()) {
|
|
6
|
+
return existsSync(resolve(cwd, "artisan"));
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
//#endregion
|
|
10
|
+
export { isLaravel };
|
|
11
|
+
//# sourceMappingURL=detect.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detect.mjs","names":[],"sources":["../../src/utils/detect.ts"],"sourcesContent":["import { existsSync } from 'node:fs'\nimport { resolve } from 'node:path'\n\nexport function isLaravel(cwd: string = process.cwd()): boolean {\n return existsSync(resolve(cwd, 'artisan'))\n}\n"],"mappings":";;;;AAGA,SAAgB,UAAU,MAAc,QAAQ,KAAK,EAAW;AAC9D,QAAO,WAAW,QAAQ,KAAK,UAAU,CAAC"}
|
|
@@ -1,12 +1,95 @@
|
|
|
1
1
|
# @clack/core
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## 1.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 9786226: Externalize `fast-string-width` and `fast-wrap-ansi` to avoid double dependencies
|
|
8
|
+
- 090902c: Adds `date` prompt with `format` support (YMD, MDY, DMY)
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- bdf89a5: Adds `placeholder` option to `autocomplete`. When the placeholder is set and the input is empty, pressing `tab` will set the value to `placeholder`.
|
|
13
|
+
- 417b451: Only apply autocomplete default filter if it has been explicitly set or if options is not a getter.
|
|
14
|
+
|
|
15
|
+
## 1.1.0
|
|
16
|
+
|
|
17
|
+
### Minor Changes
|
|
18
|
+
|
|
19
|
+
- e3333fb: Replaces `picocolors` with Node.js built-in `styleText`.
|
|
20
|
+
|
|
21
|
+
## 1.0.1
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- 6404dc1: Disallows selection of `disabled` options in autocomplete.
|
|
26
|
+
- 2533180: Updates the documentation to mention `userInputWithCursor` when using the `TextPrompt` primitive.
|
|
27
|
+
|
|
28
|
+
## 1.0.0
|
|
29
|
+
|
|
30
|
+
### Major Changes
|
|
31
|
+
|
|
32
|
+
- c713fd5: The package is now distributed as ESM-only. In `v0` releases, the package was dual-published as CJS and ESM.
|
|
33
|
+
|
|
34
|
+
For existing CJS projects using Node v20+, please see Node's guide on [Loading ECMAScript modules using `require()`](https://nodejs.org/docs/latest-v20.x/api/modules.html#loading-ecmascript-modules-using-require).
|
|
35
|
+
|
|
36
|
+
### Minor Changes
|
|
37
|
+
|
|
38
|
+
- 7bc3301: Prompts now have a `userInput` stored separately from their `value`.
|
|
39
|
+
- 2837845: Adds suggestion and path prompts
|
|
40
|
+
- 729bbb6: Add support for customizable spinner cancel and error messages. Users can now customize these messages either per spinner instance or globally via the `updateSettings` function to support multilingual CLIs.
|
|
41
|
+
|
|
42
|
+
This update also improves the architecture by exposing the core settings to the prompts package, enabling more consistent default message handling across the codebase.
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
// Per-instance customization
|
|
46
|
+
const spinner = prompts.spinner({
|
|
47
|
+
cancelMessage: "Operación cancelada", // "Operation cancelled" in Spanish
|
|
48
|
+
errorMessage: "Se produjo un error", // "An error occurred" in Spanish
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// Global customization via updateSettings
|
|
52
|
+
prompts.updateSettings({
|
|
53
|
+
messages: {
|
|
54
|
+
cancel: "Operación cancelada", // "Operation cancelled" in Spanish
|
|
55
|
+
error: "Se produjo un error", // "An error occurred" in Spanish
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// Settings can now be accessed directly
|
|
60
|
+
console.log(prompts.settings.messages.cancel); // "Operación cancelada"
|
|
61
|
+
|
|
62
|
+
// Direct options take priority over global settings
|
|
63
|
+
const spinner = prompts.spinner({
|
|
64
|
+
cancelMessage: "Cancelled", // This will be used instead of the global setting
|
|
65
|
+
});
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
- 55645c2: Support wrapping autocomplete and select prompts.
|
|
69
|
+
- f2c2b89: Adds `AutocompletePrompt` to core with comprehensive tests and implement both `autocomplete` and `autocomplete-multiselect` components in prompts package.
|
|
70
|
+
- df4eea1: Remove `suggestion` prompt and change `path` prompt to be an autocomplete prompt.
|
|
71
|
+
- 1604f97: Add `clearOnError` option to password prompt to automatically clear input when validation fails
|
|
4
72
|
|
|
5
73
|
### Patch Changes
|
|
6
74
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
75
|
+
- 0718b07: fix: export `*Options` types for prompts.
|
|
76
|
+
- bfe0dd3: Prevents placeholder from being used as input value in text prompts
|
|
77
|
+
- 6868c1c: Adds a new `selectableGroups` boolean to the group multi-select prompt. Using `selectableGroups: false` will disable the ability to select a top-level group, but still allow every child to be selected individually.
|
|
78
|
+
- 7df841d: Removed all trailing space in prompt output and fixed various padding rendering bugs.
|
|
79
|
+
- a4f5034: Fixes an edge case for placeholder values. Previously, when pressing `enter` on an empty prompt, placeholder values would be ignored. Now, placeholder values are treated as the prompt value.
|
|
80
|
+
- b103ad3: Allow disabled options in multi-select and select prompts.
|
|
81
|
+
- 71b5029: Add missing nullish checks around values.
|
|
82
|
+
- a36292b: Fix "TTY initialization failed: uv_tty_init returned EBADF (bad file descriptor)" error happening on Windows for non-tty terminals.
|
|
83
|
+
- 1a45f93: Switched from wrap-ansi to fast-wrap-ansi
|
|
84
|
+
- 4ba2d78: Support short terminal windows when re-rendering by accounting for off-screen lines
|
|
85
|
+
- 34f52fe: Validates initial values immediately when using text prompts with initialValue and validate props.
|
|
86
|
+
- 94fee2a: Changes `placeholder` to be a visual hint rather than a tabbable value.
|
|
87
|
+
- 4f6b3c2: Set initial values of auto complete prompt to first option when multiple is false.
|
|
88
|
+
- 8ead5d3: Avoid passing initial values to core when using auto complete prompt
|
|
89
|
+
- acc4c3a: Add a new `withGuide` option to all prompts to disable the default clack border
|
|
90
|
+
- 68dbf9b: select-key: Fixed wrapping and added new `caseSensitive` option
|
|
91
|
+
- 2310b43: Allow custom writables as output stream.
|
|
92
|
+
- d98e033: add invert selection for multiselect prompt
|
|
10
93
|
|
|
11
94
|
## 0.4.1
|
|
12
95
|
|