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
This commit is contained in:
+11
@@ -41,6 +41,9 @@ async function initProject() {
|
|||||||
fs.writeFileSync('README.md', `# ${projectName}\n\nBuilt with Next.js, Tailwind CSS and @zen/core.`);
|
fs.writeFileSync('README.md', `# ${projectName}\n\nBuilt with Next.js, Tailwind CSS and @zen/core.`);
|
||||||
packageJson.scripts ??= {};
|
packageJson.scripts ??= {};
|
||||||
packageJson.scripts['make-favicon'] = 'node dev/icons/make-favicon.js';
|
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 });
|
fs.writeJsonSync(packageJsonPath, packageJson, { spaces: 2 });
|
||||||
}
|
}
|
||||||
done('Updated README and package.json');
|
done('Updated README and package.json');
|
||||||
@@ -53,6 +56,14 @@ async function initProject() {
|
|||||||
fs.copySync(templatesPath, './', { overwrite: true });
|
fs.copySync(templatesPath, './', { overwrite: true });
|
||||||
done('Copied template files');
|
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');
|
step('Installing @zen/core');
|
||||||
execSync('npm install @zen/core', { stdio: 'inherit' });
|
execSync('npm install @zen/core', { stdio: 'inherit' });
|
||||||
done('@zen/core installed');
|
done('@zen/core installed');
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
// AUTO-GÉNÉRÉ par `npx zen-modules sync` — ne pas modifier à la main.
|
||||||
|
|
||||||
|
export const modules = [];
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import "@styles/globals.css";
|
import "@styles/globals.css";
|
||||||
|
import './.zen/modules.generated.js';
|
||||||
import { ZenProvider } from '@zen/core/features/provider';
|
import { ZenProvider } from '@zen/core/features/provider';
|
||||||
import { THEME_INIT_SCRIPT } from '@zen/core/themes';
|
import { THEME_INIT_SCRIPT } from '@zen/core/themes';
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
export async function register() {
|
export async function register() {
|
||||||
if (process.env.NEXT_RUNTIME === 'nodejs') {
|
if (process.env.NEXT_RUNTIME === 'nodejs') {
|
||||||
const { initializeZen } = await import('@zen/core');
|
const { initializeZen } = await import('@zen/core');
|
||||||
await initializeZen();
|
const { modules } = await import('./app/.zen/modules.generated.js');
|
||||||
|
await initializeZen({ modules });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user