From d7bfe34bb16a0df50141f2d3c3b3f82bfc1a4739 Mon Sep 17 00:00:00 2001 From: Hyko Date: Sat, 25 Apr 2026 14:26:22 -0400 Subject: [PATCH] feat(cli): integrate zen-modules sync into project initialization - add postinstall, dev, and build scripts to run `zen-modules sync` - append `app/.zen/modules.generated.js` to .gitignore during init - add generated modules file template with empty modules export - import modules.generated.js in app layout and pass modules to initializeZen --- bin/cli.js | 11 +++++++++++ templates/app/.zen/modules.generated.js | 3 +++ templates/app/layout.js | 1 + templates/instrumentation.js | 3 ++- 4 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 templates/app/.zen/modules.generated.js diff --git a/bin/cli.js b/bin/cli.js index b26a878..39a2592 100644 --- a/bin/cli.js +++ b/bin/cli.js @@ -41,6 +41,9 @@ async function initProject() { fs.writeFileSync('README.md', `# ${projectName}\n\nBuilt with Next.js, Tailwind CSS and @zen/core.`); packageJson.scripts ??= {}; packageJson.scripts['make-favicon'] = 'node dev/icons/make-favicon.js'; + packageJson.scripts.postinstall = 'zen-modules sync'; + packageJson.scripts.dev = 'zen-modules sync && next dev'; + packageJson.scripts.build = 'zen-modules sync && next build'; fs.writeJsonSync(packageJsonPath, packageJson, { spaces: 2 }); } done('Updated README and package.json'); @@ -53,6 +56,14 @@ async function initProject() { fs.copySync(templatesPath, './', { overwrite: true }); done('Copied template files'); + const gitignorePath = './.gitignore'; + if (fs.existsSync(gitignorePath)) { + const gitignore = fs.readFileSync(gitignorePath, 'utf-8'); + if (!gitignore.includes('app/.zen/modules.generated.js')) { + fs.appendFileSync(gitignorePath, '\n# Generated by zen-modules sync\napp/.zen/modules.generated.js\n'); + } + } + step('Installing @zen/core'); execSync('npm install @zen/core', { stdio: 'inherit' }); done('@zen/core installed'); diff --git a/templates/app/.zen/modules.generated.js b/templates/app/.zen/modules.generated.js new file mode 100644 index 0000000..b6b9908 --- /dev/null +++ b/templates/app/.zen/modules.generated.js @@ -0,0 +1,3 @@ +// AUTO-GÉNÉRÉ par `npx zen-modules sync` — ne pas modifier à la main. + +export const modules = []; diff --git a/templates/app/layout.js b/templates/app/layout.js index 6b073eb..a925ecb 100644 --- a/templates/app/layout.js +++ b/templates/app/layout.js @@ -1,4 +1,5 @@ import "@styles/globals.css"; +import './.zen/modules.generated.js'; import { ZenProvider } from '@zen/core/features/provider'; import { THEME_INIT_SCRIPT } from '@zen/core/themes'; diff --git a/templates/instrumentation.js b/templates/instrumentation.js index 3085967..ae31422 100644 --- a/templates/instrumentation.js +++ b/templates/instrumentation.js @@ -1,6 +1,7 @@ export async function register() { if (process.env.NEXT_RUNTIME === 'nodejs') { const { initializeZen } = await import('@zen/core'); - await initializeZen(); + const { modules } = await import('./app/.zen/modules.generated.js'); + await initializeZen({ modules }); } }