-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·176 lines (154 loc) · 5.86 KB
/
index.js
File metadata and controls
executable file
·176 lines (154 loc) · 5.86 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/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';
// Docker commands
import { handleDockerMenu } from './lib/docker_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 {
checkRequirements();
await handleInitCommand(projectName, options, __dirname);
// Only check for update AFTER project scaffolding
const notifier = new UpdateNotifier('jangular-cli', false);
await notifier.checkForUpdate();
} catch (error) {
console.error(chalk.red('Error during project initialization:'), error);
process.exit(1);
}
});
program
.command('docker')
.description('Manage and monitor Docker services')
.action(async () => {
try {
await handleDockerMenu();
} catch (err) {
console.error(chalk.red('Docker command failed:'), err);
process.exit(1);
}
});
program
.command('test')
.description('Run tests for the generated project')
.option('-b, --backend', 'Test only the backend')
.option('-f, --frontend', 'Test only the frontend')
.option('-a, --all', 'Test both backend and frontend (default)')
.action(async (options) => {
try {
console.log(chalk.yellow('Running tests...'));
const backendOpt = options.backend;
const frontendOpt = options.frontend;
const allOpt = options.all !== false; // default to true if not explicitly set to false
if (backendOpt || allOpt) {
console.log(chalk.blue('Testing backend...'));
if (shell.exec('cd backend && ./mvnw test').code !== 0) {
console.error(chalk.red('Backend tests failed'));
process.exit(1);
} else {
console.log(chalk.green('✓ Backend tests passed'));
}
}
if (frontendOpt || allOpt) {
console.log(chalk.blue('Testing frontend...'));
if (shell.exec('cd frontend && npm test -- --watch=false --bail').code !== 0) {
console.error(chalk.red('Frontend tests failed'));
process.exit(1);
} else {
console.log(chalk.green('✓ Frontend tests passed'));
}
}
console.log(chalk.green('✓ All tests completed successfully'));
} catch (err) {
console.error(chalk.red('Test command failed:'), err);
process.exit(1);
}
});
program
.command('build')
.description('Build the project for production')
.option('-b, --backend', 'Build only the backend')
.option('-f, --frontend', 'Build only the frontend')
.option('-a, --all', 'Build both backend and frontend (default)')
.option('-p, --prod', 'Build with production profile')
.action(async (options) => {
try {
console.log(chalk.yellow('Building project...'));
const backendOpt = options.backend;
const frontendOpt = options.frontend;
const allOpt = options.all !== false; // default to true if not explicitly set to false
const prodOpt = options.prod;
if (backendOpt || allOpt) {
console.log(chalk.blue('Building backend...'));
let buildCmd = 'cd backend && ./mvnw clean package';
if (prodOpt) {
buildCmd += ' -Pprod';
}
if (shell.exec(buildCmd).code !== 0) {
console.error(chalk.red('Backend build failed'));
process.exit(1);
} else {
console.log(chalk.green('✓ Backend built successfully'));
}
}
if (frontendOpt || allOpt) {
console.log(chalk.blue('Building frontend...'));
let buildCmd = 'cd frontend && npm run build';
if (prodOpt) {
buildCmd += ' --prod';
}
if (shell.exec(buildCmd).code !== 0) {
console.error(chalk.red('Frontend build failed'));
process.exit(1);
} else {
console.log(chalk.green('✓ Frontend built successfully'));
}
}
console.log(chalk.green('✓ Build completed successfully'));
} catch (err) {
console.error(chalk.red('Build command failed:'), err);
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);
});