refactor: move inline templates to files and bump version to 1.3.8
This commit is contained in:
-70
@@ -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 done = (msg) => process.stdout.write(` ${c.green}✓${c.reset} ${msg}\n`);
|
||||||
const fail = (msg) => process.stdout.write(` ${c.red}✗${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() {
|
async function initProject() {
|
||||||
try {
|
try {
|
||||||
console.log(`\n ${c.bold}${c.cyan}zen-start${c.reset}\n`);
|
console.log(`\n ${c.bold}${c.cyan}zen-start${c.reset}\n`);
|
||||||
@@ -82,20 +34,6 @@ async function initProject() {
|
|||||||
}
|
}
|
||||||
done('Cleaned default /app directory');
|
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';
|
const packageJsonPath = './package.json';
|
||||||
if (fs.existsSync(packageJsonPath)) {
|
if (fs.existsSync(packageJsonPath)) {
|
||||||
const packageJson = fs.readJsonSync(packageJsonPath);
|
const packageJson = fs.readJsonSync(packageJsonPath);
|
||||||
@@ -115,14 +53,6 @@ export default nextConfig;
|
|||||||
fs.copySync(templatesPath, './', { overwrite: true });
|
fs.copySync(templatesPath, './', { overwrite: true });
|
||||||
done('Copied template files');
|
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');
|
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');
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@zen/start",
|
"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",
|
"description": "CLI pour créer un projet Next.js avec le CMS @zen/core",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
@zen:registry=https://git.hyko.cx/api/packages/zen/npm/
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export { default } from '@zen/core/features/admin/page';
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import { redirect } from 'next/navigation';
|
||||||
|
|
||||||
|
export default function Redirect() {
|
||||||
|
redirect('/admin/dashboard');
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export { default } from '@zen/core/features/auth/page';
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import { redirect } from 'next/navigation';
|
||||||
|
|
||||||
|
export default function Redirect() {
|
||||||
|
redirect('/auth/login/');
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export { default, generateMetadata } from '@zen/core/modules/page';
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export { GET, POST, PUT, DELETE, PATCH } from '@zen/core/zen/api';
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
export async function register() {
|
||||||
|
if (process.env.NEXT_RUNTIME === 'nodejs') {
|
||||||
|
const { initializeZen } = await import('@zen/core');
|
||||||
|
await initializeZen();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"paths": {
|
||||||
|
"@styles/*": ["./styles/*"],
|
||||||
|
"@components/*": ["./components/*"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
/** @type {import('next').NextConfig} */
|
||||||
|
const nextConfig = {
|
||||||
|
devIndicators: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default nextConfig;
|
||||||
Reference in New Issue
Block a user