-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
102 lines (86 loc) · 2.73 KB
/
Copy pathcli.js
File metadata and controls
102 lines (86 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env node
'use strict';
const path = require('path');
const { generateProject, TEMPLATES } = require('./src/cli/init');
function printHelp() {
console.log(`
express-starter-kit init <projectName> [options]
Generate a new Express project
Options:
--template <type> Template to use (basic | auth | websocket | full) [default: basic]
--db <dialect> Database dialect (postgres | mysql | sqlite) [default: postgres]
--redis Include Redis support [default: false]
--force Overwrite existing directory [default: false]
--help Show this help message
Examples:
express-starter-kit init my-app
express-starter-kit init my-app --template auth --db mysql
express-starter-kit init my-app --template full --redis
express-starter-kit init my-app --force
`);
}
async function main() {
const args = process.argv.slice(2);
if (args.length === 0 || args.includes('--help') || args.includes('-h')) {
printHelp();
process.exit(0);
}
const subcommand = args[0];
if (subcommand !== 'init') {
console.error(`Unknown command: ${subcommand}`);
printHelp();
process.exit(1);
}
const projectName = args[1];
if (!projectName) {
console.error('Error: project name is required');
printHelp();
process.exit(1);
}
const options = {
template: 'basic',
db: 'postgres',
redis: false,
force: false,
};
for (let i = 2; i < args.length; i++) {
switch (args[i]) {
case '--template':
options.template = args[++i] || 'basic';
break;
case '--db':
options.db = args[++i] || 'postgres';
break;
case '--redis':
options.redis = true;
break;
case '--force':
options.force = true;
break;
}
}
if (!TEMPLATES[options.template]) {
console.error(`Error: Unknown template "${options.template}". Available: ${Object.keys(TEMPLATES).join(', ')}`);
process.exit(1);
}
if (!['postgres', 'mysql', 'sqlite'].includes(options.db)) {
console.error('Error: --db must be one of: postgres, mysql, sqlite');
process.exit(1);
}
try {
const targetDir = generateProject(projectName, options);
console.log(`\n✓ Project "${projectName}" created at ${targetDir}`);
console.log(` Template: ${options.template}`);
console.log(` Database: ${options.db}`);
console.log(` Redis: ${options.redis ? 'yes' : 'no'}`);
console.log('\nNext steps:');
console.log(` cd ${projectName}`);
console.log(' npm install');
console.log(' cp .env.example .env');
console.log(' npm run dev\n');
} catch (err) {
console.error(`Error: ${err.message}`);
process.exit(1);
}
}
main();