refactor: consolidate CLI entry points into dedicated cli/ directory
Move `database` and `setup` CLI scripts from their respective feature directories into a unified `src/cli/` directory. Update `tsup.config.js` build entries and `package.json` bin paths to reflect the new locations.
This commit is contained in:
+2
-2
@@ -23,8 +23,8 @@
|
|||||||
"prepublishOnly": "npm run build"
|
"prepublishOnly": "npm run build"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"zen-db": "./dist/core/database/cli.js",
|
"zen-db": "./dist/cli/database.js",
|
||||||
"zen-setup": "./dist/features/setup/cli.js"
|
"zen-setup": "./dist/cli/setup.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@headlessui/react": "^2.0.0",
|
"@headlessui/react": "^2.0.0",
|
||||||
|
|||||||
@@ -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
|
// 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';
|
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';
|
import readline from 'readline';
|
||||||
|
|
||||||
async function runCLI() {
|
async function runCLI() {
|
||||||
@@ -63,13 +63,12 @@ Example:
|
|||||||
case 'drop':
|
case 'drop':
|
||||||
console.log('⚠️ WARNING: This will delete all authentication tables!\n');
|
console.log('⚠️ WARNING: This will delete all authentication tables!\n');
|
||||||
console.log('Type "yes" to confirm or Ctrl+C to cancel...');
|
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({
|
const rl = readline.createInterface({
|
||||||
input: process.stdin,
|
input: process.stdin,
|
||||||
output: process.stdout
|
output: process.stdout
|
||||||
});
|
});
|
||||||
|
|
||||||
rl.question('Confirm (yes/no): ', async (answer) => {
|
rl.question('Confirm (yes/no): ', async (answer) => {
|
||||||
if (answer.toLowerCase() === 'yes') {
|
if (answer.toLowerCase() === 'yes') {
|
||||||
await dropAuthTables();
|
await dropAuthTables();
|
||||||
@@ -124,4 +123,3 @@ if (isMainModule) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export { runCLI };
|
export { runCLI };
|
||||||
|
|
||||||
@@ -90,7 +90,7 @@ const files = [
|
|||||||
|
|
||||||
async function createFile(filePath, content, force = false) {
|
async function createFile(filePath, content, force = false) {
|
||||||
const fullPath = resolve(process.cwd(), filePath);
|
const fullPath = resolve(process.cwd(), filePath);
|
||||||
|
|
||||||
// Check if file already exists
|
// Check if file already exists
|
||||||
if (existsSync(fullPath) && !force) {
|
if (existsSync(fullPath) && !force) {
|
||||||
console.log(`⏭️ Skipped (already exists): ${filePath}`);
|
console.log(`⏭️ Skipped (already exists): ${filePath}`);
|
||||||
@@ -104,13 +104,13 @@ async function createFile(filePath, content, force = false) {
|
|||||||
// Write the file
|
// Write the file
|
||||||
await writeFile(fullPath, content, 'utf-8');
|
await writeFile(fullPath, content, 'utf-8');
|
||||||
console.log(`✅ Created: ${filePath}`);
|
console.log(`✅ Created: ${filePath}`);
|
||||||
|
|
||||||
return { created: true, skipped: false };
|
return { created: true, skipped: false };
|
||||||
}
|
}
|
||||||
|
|
||||||
async function setupZen(options = {}) {
|
async function setupZen(options = {}) {
|
||||||
const { force = false } = options;
|
const { force = false } = options;
|
||||||
|
|
||||||
console.log('🚀 Setting up Zen for your Next.js project...\n');
|
console.log('🚀 Setting up Zen for your Next.js project...\n');
|
||||||
|
|
||||||
let created = 0;
|
let created = 0;
|
||||||
@@ -122,7 +122,7 @@ async function setupZen(options = {}) {
|
|||||||
templates[file.template],
|
templates[file.template],
|
||||||
force
|
force
|
||||||
);
|
);
|
||||||
|
|
||||||
if (result.created) created++;
|
if (result.created) created++;
|
||||||
if (result.skipped) skipped++;
|
if (result.skipped) skipped++;
|
||||||
}
|
}
|
||||||
@@ -134,7 +134,7 @@ async function setupZen(options = {}) {
|
|||||||
// Check if next.config.js needs updating
|
// Check if next.config.js needs updating
|
||||||
const nextConfigPath = resolve(process.cwd(), 'next.config.js');
|
const nextConfigPath = resolve(process.cwd(), 'next.config.js');
|
||||||
const nextConfigExists = existsSync(nextConfigPath);
|
const nextConfigExists = existsSync(nextConfigPath);
|
||||||
|
|
||||||
if (!nextConfigExists) {
|
if (!nextConfigExists) {
|
||||||
console.log('\n⚠️ Note: next.config.js not found.');
|
console.log('\n⚠️ Note: next.config.js not found.');
|
||||||
console.log(' Make sure to enable instrumentation in your Next.js config:');
|
console.log(' Make sure to enable instrumentation in your Next.js config:');
|
||||||
@@ -153,14 +153,14 @@ async function setupZen(options = {}) {
|
|||||||
|
|
||||||
async function listFiles() {
|
async function listFiles() {
|
||||||
console.log('📋 Files that will be created:\n');
|
console.log('📋 Files that will be created:\n');
|
||||||
|
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
const exists = existsSync(resolve(process.cwd(), file.path));
|
const exists = existsSync(resolve(process.cwd(), file.path));
|
||||||
const status = exists ? '✓ exists' : '✗ missing';
|
const status = exists ? '✓ exists' : '✗ missing';
|
||||||
console.log(` ${status} ${file.path}`);
|
console.log(` ${status} ${file.path}`);
|
||||||
console.log(` ${file.description}`);
|
console.log(` ${file.description}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('\nRun "npx zen-setup init" to create missing files.');
|
console.log('\nRun "npx zen-setup init" to create missing files.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,12 +198,12 @@ Examples:
|
|||||||
if (force) {
|
if (force) {
|
||||||
console.log('⚠️ WARNING: --force flag will overwrite existing files!\n');
|
console.log('⚠️ WARNING: --force flag will overwrite existing files!\n');
|
||||||
console.log('Type "yes" to confirm or Ctrl+C to cancel...');
|
console.log('Type "yes" to confirm or Ctrl+C to cancel...');
|
||||||
|
|
||||||
const rl = readline.createInterface({
|
const rl = readline.createInterface({
|
||||||
input: process.stdin,
|
input: process.stdin,
|
||||||
output: process.stdout,
|
output: process.stdout,
|
||||||
});
|
});
|
||||||
|
|
||||||
rl.question('Confirm (yes/no): ', async (answer) => {
|
rl.question('Confirm (yes/no): ', async (answer) => {
|
||||||
if (answer.toLowerCase() === 'yes') {
|
if (answer.toLowerCase() === 'yes') {
|
||||||
await setupZen({ force: true });
|
await setupZen({ force: true });
|
||||||
+2
-2
@@ -16,9 +16,9 @@ export default defineConfig([
|
|||||||
'src/core/api/index.js',
|
'src/core/api/index.js',
|
||||||
'src/core/api/nx-route.js',
|
'src/core/api/nx-route.js',
|
||||||
'src/core/database/index.js',
|
'src/core/database/index.js',
|
||||||
'src/core/database/cli.js',
|
|
||||||
'src/features/setup/index.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/index.js',
|
||||||
'src/core/email/templates/index.js',
|
'src/core/email/templates/index.js',
|
||||||
'src/core/storage/index.js',
|
'src/core/storage/index.js',
|
||||||
|
|||||||
Reference in New Issue
Block a user