-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
executable file
·68 lines (57 loc) · 2.09 KB
/
index.js
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
#!/usr/bin/env node
import { Command } from 'commander';
import path from 'path';
import { fileURLToPath } from 'url';
import chalk from 'chalk';
// Version handlers
import { UpdateNotifier } from './lib/update-notifier.js';
// Command handlers
import { handleInitCommand } from './lib/commands.js';
// Constants
import { PROGRAM_VERSION, PROGRAM_DESCRIPTION } from './lib/constants.js';
import { checkRequirements } from './lib/requirements.js';
// Fix for __dirname in ES modules
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Main CLI function
async function initializeCLI() {
console.log(PROGRAM_DESCRIPTION);
console.log(`Version: ${PROGRAM_VERSION}`);
// Set up the CLI program
const program = new Command('jangular')
.version(PROGRAM_VERSION)
.description(PROGRAM_DESCRIPTION);
// Asynchronous version check - run in background
const notifier = new UpdateNotifier('jangular-cli', true);
notifier.checkForUpdate().catch(console.error);
program.option('--test', 'Run a test check for JAngular CLI');
// Initialize command
program
.command('init <projectName>')
.description('Initialize a new Java + Angular project')
.option('-g, --group-id <groupId>', 'Java group ID', 'com.example')
.option('-a, --artifact-id <artifactId>', 'Java artifact ID', 'backend')
.action(async (projectName, options) => {
try {
// Move requirements check to be more selective
checkRequirements();
await handleInitCommand(projectName, options, __dirname);
} catch (error) {
console.error(chalk.red('Error during project initialization:'), error);
process.exit(1);
}
});
program.parse(process.argv);
// Handle `--test` option
const options = program.opts();
if (options.test) {
console.log(chalk.green("✅ JAngular CLI test executed successfully!"));
console.log(chalk.blue("CLI is working as expected."));
process.exit(0);
}
}
// Execute CLI
initializeCLI().catch(error => {
console.error(chalk.red('CLI initialization error:'), error);
process.exit(1);
});