From aeb5fb782bc3f735358f1a2844f60231f2963728 Mon Sep 17 00:00:00 2001 From: Hyko Date: Wed, 15 Apr 2026 17:53:07 -0400 Subject: [PATCH] refactor: move inline templates to files and bump version to 1.3.8 --- bin/cli.js | 70 ------------------- package.json | 2 +- templates/.npmrc | 1 + .../app/(admin)/admin/[...admin]/page.js | 1 + templates/app/(admin)/admin/page.js | 5 ++ templates/app/(auth)/auth/[...auth]/page.js | 1 + templates/app/(auth)/auth/page.js | 5 ++ templates/app/zen/[...zen]/page.js | 1 + templates/app/zen/api/[...path]/route.js | 1 + templates/instrumentation.js | 6 ++ templates/jsconfig.json | 8 +++ templates/next.config.mjs | 6 ++ 12 files changed, 36 insertions(+), 71 deletions(-) create mode 100644 templates/.npmrc create mode 100644 templates/app/(admin)/admin/[...admin]/page.js create mode 100644 templates/app/(admin)/admin/page.js create mode 100644 templates/app/(auth)/auth/[...auth]/page.js create mode 100644 templates/app/(auth)/auth/page.js create mode 100644 templates/app/zen/[...zen]/page.js create mode 100644 templates/app/zen/api/[...path]/route.js create mode 100644 templates/instrumentation.js create mode 100644 templates/jsconfig.json create mode 100644 templates/next.config.mjs diff --git a/bin/cli.js b/bin/cli.js index 0307542..b26a878 100644 --- a/bin/cli.js +++ b/bin/cli.js @@ -21,54 +21,6 @@ const step = (msg) => process.stdout.write(` ${c.dim}◆${c.reset} ${msg}...\n` const done = (msg) => process.stdout.write(` ${c.green}✓${c.reset} ${msg}\n`); const fail = (msg) => process.stdout.write(` ${c.red}✗${c.reset} ${msg}\n`); -// Templates zen (inline pour éviter des dépendances externes) -const zenTemplates = { - instrumentation: `export async function register() { - if (process.env.NEXT_RUNTIME === 'nodejs') { - const { initializeZen } = await import('@zen/core'); - await initializeZen(); - } -} -`, - authRedirect: `import { redirect } from 'next/navigation'; - -export default function Redirect() { - redirect('/auth/login/'); -} -`, - authCatchAll: `export { default } from '@zen/core/features/auth/page'; -`, - adminRedirect: `import { redirect } from 'next/navigation'; - -export default function Redirect() { - redirect('/admin/dashboard'); -} -`, - adminCatchAll: `export { default } from '@zen/core/features/admin/page'; -`, - zenApiRoute: `export { GET, POST, PUT, DELETE, PATCH } from '@zen/core/zen/api'; -`, - zenPageRoute: `export { default, generateMetadata } from '@zen/core/modules/page'; -`, -}; - -// Fichiers zen à créer dans le projet cible -const zenFiles = [ - { path: 'instrumentation.js', template: 'instrumentation' }, - { path: 'app/(auth)/auth/page.js', template: 'authRedirect' }, - { path: 'app/(auth)/auth/[...auth]/page.js', template: 'authCatchAll' }, - { path: 'app/(admin)/admin/page.js', template: 'adminRedirect' }, - { path: 'app/(admin)/admin/[...admin]/page.js', template: 'adminCatchAll' }, - { path: 'app/zen/api/[...path]/route.js', template: 'zenApiRoute' }, - { path: 'app/zen/[...zen]/page.js', template: 'zenPageRoute' }, -]; - -async function createZenFile(filePath, content) { - const fullPath = path.resolve(process.cwd(), filePath); - await fs.ensureDir(path.dirname(fullPath)); - await fs.writeFile(fullPath, content, 'utf-8'); -} - async function initProject() { try { console.log(`\n ${c.bold}${c.cyan}zen-start${c.reset}\n`); @@ -82,20 +34,6 @@ async function initProject() { } done('Cleaned default /app directory'); - fs.writeJsonSync('./jsconfig.json', { - compilerOptions: { paths: { '@styles/*': ['./styles/*'], '@components/*': ['./components/*'] } }, - }, { spaces: 2 }); - done('Configured path aliases'); - - fs.writeFileSync('./next.config.mjs', `/** @type {import('next').NextConfig} */ -const nextConfig = { -\tdevIndicators: false, -}; - -export default nextConfig; -`); - done('Configured next.config.mjs'); - const packageJsonPath = './package.json'; if (fs.existsSync(packageJsonPath)) { const packageJson = fs.readJsonSync(packageJsonPath); @@ -115,14 +53,6 @@ export default nextConfig; fs.copySync(templatesPath, './', { overwrite: true }); done('Copied template files'); - for (const file of zenFiles) { - await createZenFile(file.path, zenTemplates[file.template]); - } - done('Created @zen/core route files'); - - fs.writeFileSync('./.npmrc', '@zen:registry=https://git.hyko.cx/api/packages/zen/npm/\n'); - done('Configured npm registry'); - step('Installing @zen/core'); execSync('npm install @zen/core', { stdio: 'inherit' }); done('@zen/core installed'); diff --git a/package.json b/package.json index 65b7a91..f899c91 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@zen/start", - "version": "1.3.7", + "version": "1.3.8", "description": "CLI pour créer un projet Next.js avec le CMS @zen/core", "repository": { "type": "git", diff --git a/templates/.npmrc b/templates/.npmrc new file mode 100644 index 0000000..c3811cd --- /dev/null +++ b/templates/.npmrc @@ -0,0 +1 @@ +@zen:registry=https://git.hyko.cx/api/packages/zen/npm/ diff --git a/templates/app/(admin)/admin/[...admin]/page.js b/templates/app/(admin)/admin/[...admin]/page.js new file mode 100644 index 0000000..3089fa5 --- /dev/null +++ b/templates/app/(admin)/admin/[...admin]/page.js @@ -0,0 +1 @@ +export { default } from '@zen/core/features/admin/page'; diff --git a/templates/app/(admin)/admin/page.js b/templates/app/(admin)/admin/page.js new file mode 100644 index 0000000..c8ce167 --- /dev/null +++ b/templates/app/(admin)/admin/page.js @@ -0,0 +1,5 @@ +import { redirect } from 'next/navigation'; + +export default function Redirect() { + redirect('/admin/dashboard'); +} diff --git a/templates/app/(auth)/auth/[...auth]/page.js b/templates/app/(auth)/auth/[...auth]/page.js new file mode 100644 index 0000000..f77c87f --- /dev/null +++ b/templates/app/(auth)/auth/[...auth]/page.js @@ -0,0 +1 @@ +export { default } from '@zen/core/features/auth/page'; diff --git a/templates/app/(auth)/auth/page.js b/templates/app/(auth)/auth/page.js new file mode 100644 index 0000000..67b39cf --- /dev/null +++ b/templates/app/(auth)/auth/page.js @@ -0,0 +1,5 @@ +import { redirect } from 'next/navigation'; + +export default function Redirect() { + redirect('/auth/login/'); +} diff --git a/templates/app/zen/[...zen]/page.js b/templates/app/zen/[...zen]/page.js new file mode 100644 index 0000000..c54b421 --- /dev/null +++ b/templates/app/zen/[...zen]/page.js @@ -0,0 +1 @@ +export { default, generateMetadata } from '@zen/core/modules/page'; diff --git a/templates/app/zen/api/[...path]/route.js b/templates/app/zen/api/[...path]/route.js new file mode 100644 index 0000000..c2bc8ca --- /dev/null +++ b/templates/app/zen/api/[...path]/route.js @@ -0,0 +1 @@ +export { GET, POST, PUT, DELETE, PATCH } from '@zen/core/zen/api'; diff --git a/templates/instrumentation.js b/templates/instrumentation.js new file mode 100644 index 0000000..3085967 --- /dev/null +++ b/templates/instrumentation.js @@ -0,0 +1,6 @@ +export async function register() { + if (process.env.NEXT_RUNTIME === 'nodejs') { + const { initializeZen } = await import('@zen/core'); + await initializeZen(); + } +} diff --git a/templates/jsconfig.json b/templates/jsconfig.json new file mode 100644 index 0000000..ba28c8c --- /dev/null +++ b/templates/jsconfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "paths": { + "@styles/*": ["./styles/*"], + "@components/*": ["./components/*"] + } + } +} diff --git a/templates/next.config.mjs b/templates/next.config.mjs new file mode 100644 index 0000000..461a1cb --- /dev/null +++ b/templates/next.config.mjs @@ -0,0 +1,6 @@ +/** @type {import('next').NextConfig} */ +const nextConfig = { + devIndicators: false, +}; + +export default nextConfig;