diff --git a/package.json b/package.json index b0e46c0..f1fbdc1 100644 --- a/package.json +++ b/package.json @@ -23,8 +23,8 @@ "prepublishOnly": "npm run build" }, "bin": { - "zen-db": "./dist/core/database/cli.js", - "zen-setup": "./dist/features/setup/cli.js" + "zen-db": "./dist/cli/database.js", + "zen-setup": "./dist/cli/setup.js" }, "dependencies": { "@headlessui/react": "^2.0.0", diff --git a/src/core/database/cli.js b/src/cli/database.js similarity index 96% rename from src/core/database/cli.js rename to src/cli/database.js index f8278b5..2a9a1fe 100644 --- a/src/core/database/cli.js +++ b/src/cli/database.js @@ -16,7 +16,7 @@ dotenv.config({ path: resolve(process.cwd(), '.env.local') }); // The CLI always runs locally, so default to development to use ZEN_DATABASE_URL_DEV if set process.env.NODE_ENV = process.env.NODE_ENV || 'development'; -import { initDatabase, dropAuthTables, testConnection, closePool } from './index.js'; +import { initDatabase, dropAuthTables, testConnection, closePool } from '../core/database/index.js'; import readline from 'readline'; async function runCLI() { @@ -63,13 +63,12 @@ Example: case 'drop': console.log('⚠️ WARNING: This will delete all authentication tables!\n'); console.log('Type "yes" to confirm or Ctrl+C to cancel...'); - - // Simple confirmation (in production, you'd use a proper readline) + const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); - + rl.question('Confirm (yes/no): ', async (answer) => { if (answer.toLowerCase() === 'yes') { await dropAuthTables(); @@ -124,4 +123,3 @@ if (isMainModule) { } export { runCLI }; - diff --git a/src/features/setup/cli.js b/src/cli/setup.js similarity index 99% rename from src/features/setup/cli.js rename to src/cli/setup.js index f9352d4..10da70d 100644 --- a/src/features/setup/cli.js +++ b/src/cli/setup.js @@ -90,7 +90,7 @@ const files = [ async function createFile(filePath, content, force = false) { const fullPath = resolve(process.cwd(), filePath); - + // Check if file already exists if (existsSync(fullPath) && !force) { console.log(`⏭️ Skipped (already exists): ${filePath}`); @@ -104,13 +104,13 @@ async function createFile(filePath, content, force = false) { // Write the file await writeFile(fullPath, content, 'utf-8'); console.log(`✅ Created: ${filePath}`); - + return { created: true, skipped: false }; } async function setupZen(options = {}) { const { force = false } = options; - + console.log('🚀 Setting up Zen for your Next.js project...\n'); let created = 0; @@ -122,7 +122,7 @@ async function setupZen(options = {}) { templates[file.template], force ); - + if (result.created) created++; if (result.skipped) skipped++; } @@ -134,7 +134,7 @@ async function setupZen(options = {}) { // Check if next.config.js needs updating const nextConfigPath = resolve(process.cwd(), 'next.config.js'); const nextConfigExists = existsSync(nextConfigPath); - + if (!nextConfigExists) { console.log('\n⚠️ Note: next.config.js not found.'); console.log(' Make sure to enable instrumentation in your Next.js config:'); @@ -153,14 +153,14 @@ async function setupZen(options = {}) { async function listFiles() { console.log('📋 Files that will be created:\n'); - + for (const file of files) { const exists = existsSync(resolve(process.cwd(), file.path)); const status = exists ? '✓ exists' : '✗ missing'; console.log(` ${status} ${file.path}`); console.log(` ${file.description}`); } - + console.log('\nRun "npx zen-setup init" to create missing files.'); } @@ -198,12 +198,12 @@ Examples: if (force) { console.log('⚠️ WARNING: --force flag will overwrite existing files!\n'); console.log('Type "yes" to confirm or Ctrl+C to cancel...'); - + const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); - + rl.question('Confirm (yes/no): ', async (answer) => { if (answer.toLowerCase() === 'yes') { await setupZen({ force: true }); diff --git a/tsup.config.js b/tsup.config.js index 9188923..d964472 100644 --- a/tsup.config.js +++ b/tsup.config.js @@ -16,9 +16,9 @@ export default defineConfig([ 'src/core/api/index.js', 'src/core/api/nx-route.js', 'src/core/database/index.js', - 'src/core/database/cli.js', 'src/features/setup/index.js', - 'src/features/setup/cli.js', + 'src/cli/database.js', + 'src/cli/setup.js', 'src/core/email/index.js', 'src/core/email/templates/index.js', 'src/core/storage/index.js',