-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
58 lines (50 loc) · 1.92 KB
/
index.js
File metadata and controls
58 lines (50 loc) · 1.92 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
#!/usr/bin/env node
import { Command } from 'commander';
import path from 'path';
import { fileURLToPath } from 'url';
import { createProject } from './src/commands/createProject.js';
import { input } from '@inquirer/prompts';
import { ExitPromptError } from '@inquirer/core';
import chalk from 'chalk';
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
const pkg = require('./package.json');
// Get dirname
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const program = new Command();
program
.version(pkg.version)
.argument('[project-name]', 'The name for your new project')
.description('Scaffold a new Express.js project')
.option('-t, --typescript', 'Scaffold a TypeScript project')
.option('-c, --commonjs', 'Use CommonJS module system')
.option('-T, --traditional', 'Use traditional MVC folder structure')
.option('--zod', 'Include Zod for schema validation')
.option('-y, --yes', 'Use default options for all prompts')
.option('--no-git', 'Do not initialize a git repository')
.action(async (projectName, options) => {
try {
let finalProjectName = projectName;
// If the project name wasn't provided, prompt the user for it
if (!finalProjectName) {
finalProjectName = await input({
message: 'What would you like to name your project?',
validate: value =>
value.length > 0 ? true : 'Project name cannot be empty.',
});
}
options.dirname = path.join(__dirname, 'src', 'commands');
await createProject(finalProjectName, options);
} catch (err) {
if (err instanceof ExitPromptError) {
console.log(
chalk.yellow('\n👋 Project creation cancelled. See you next time!')
);
process.exit(0);
} else {
console.error(chalk.red('An unexpected error occurred:'), err);
process.exit(1);
}
}
});
program.parse(process.argv);