forked from huggingfacer04/EMAD
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-integration.js
More file actions
389 lines (327 loc) · 11.6 KB
/
Copy pathbuild-integration.js
File metadata and controls
389 lines (327 loc) · 11.6 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
#!/usr/bin/env node
/**
* BMAD-Augment Integration: Cross-Platform Build Script
* This Node.js script provides cross-platform automation for building and testing
*/
const fs = require('fs');
const path = require('path');
const { execSync, spawn } = require('child_process');
const os = require('os');
// Configuration
const config = {
projectRoot: __dirname,
outputDir: path.join(__dirname, 'out'),
nodeModulesDir: path.join(__dirname, 'node_modules'),
verbose: process.argv.includes('--verbose'),
skipTests: process.argv.includes('--skip-tests'),
cleanBuild: process.argv.includes('--clean'),
packageOnly: process.argv.includes('--package-only')
};
// Colors for console output
const colors = {
reset: '\x1b[0m',
bright: '\x1b[1m',
red: '\x1b[31m',
green: '\x1b[32m',
yellow: '\x1b[33m',
blue: '\x1b[34m',
magenta: '\x1b[35m',
cyan: '\x1b[36m'
};
function colorLog(message, color = 'reset') {
if (os.platform() === 'win32' && !process.env.FORCE_COLOR) {
// Windows console may not support colors
console.log(message);
} else {
console.log(`${colors[color]}${message}${colors.reset}`);
}
}
function logHeader(title) {
console.log('');
colorLog('='.repeat(60), 'magenta');
colorLog(` ${title}`, 'magenta');
colorLog('='.repeat(60), 'magenta');
console.log('');
}
function logSuccess(message) {
colorLog(`✅ ${message}`, 'green');
}
function logWarning(message) {
colorLog(`⚠️ ${message}`, 'yellow');
}
function logError(message) {
colorLog(`❌ ${message}`, 'red');
}
function logInfo(message) {
colorLog(`ℹ️ ${message}`, 'cyan');
}
function execCommand(command, options = {}) {
try {
const result = execSync(command, {
cwd: config.projectRoot,
encoding: 'utf8',
stdio: config.verbose ? 'inherit' : 'pipe',
...options
});
return { success: true, output: result };
} catch (error) {
return {
success: false,
error: error.message,
output: error.stdout || error.stderr || ''
};
}
}
function checkPrerequisites() {
logHeader('Checking Prerequisites');
const checks = [
{ name: 'Node.js', command: 'node --version', required: true },
{ name: 'npm', command: 'npm --version', required: true },
{ name: 'TypeScript', command: 'npx tsc --version', required: false },
{ name: 'VS Code', command: 'code --version', required: false }
];
let allGood = true;
for (const check of checks) {
const result = execCommand(check.command);
if (result.success && result.output) {
logSuccess(`${check.name}: ${result.output.trim()}`);
} else {
if (check.required) {
logError(`${check.name}: Not found or not in PATH`);
allGood = false;
} else {
logWarning(`${check.name}: Not found (will install if needed)`);
}
}
}
return allGood;
}
function installDependencies() {
logHeader('Installing Dependencies');
if (!fs.existsSync(config.nodeModulesDir) || config.cleanBuild) {
if (config.cleanBuild && fs.existsSync(config.nodeModulesDir)) {
logInfo('Cleaning node_modules...');
fs.rmSync(config.nodeModulesDir, { recursive: true, force: true });
}
logInfo('Installing npm dependencies...');
const result = execCommand('npm install');
if (result.success) {
logSuccess('Dependencies installed successfully');
return true;
} else {
logError('npm install failed');
console.log(result.output);
return false;
}
} else {
logSuccess('Dependencies already installed');
return true;
}
}
function buildTypeScript() {
logHeader('Building TypeScript');
if (config.cleanBuild && fs.existsSync(config.outputDir)) {
logInfo('Cleaning output directory...');
fs.rmSync(config.outputDir, { recursive: true, force: true });
}
logInfo('Compiling TypeScript...');
const result = execCommand('npm run compile');
if (!result.success) {
logError('TypeScript compilation failed');
console.log(result.output);
return false;
}
// Verify output files
const requiredFiles = [
'extension.js',
'integration/AugmentIntegration.js',
'integration/AugmentMenuIntegration.js',
'integration/AugmentAPI.js',
'commands/CommandManager.js'
];
const missingFiles = [];
for (const file of requiredFiles) {
const filePath = path.join(config.outputDir, file);
if (!fs.existsSync(filePath)) {
missingFiles.push(file);
}
}
if (missingFiles.length > 0) {
logError('Missing compiled files:');
missingFiles.forEach(file => console.log(` - ${file}`));
return false;
}
logSuccess('TypeScript compilation successful');
logInfo(`Output directory: ${config.outputDir}`);
return true;
}
function testIntegration() {
logHeader('Testing Integration');
if (config.skipTests) {
logWarning('Skipping tests (--skip-tests flag)');
return true;
}
// Test 1: Verify package.json structure
logInfo('Testing package.json structure...');
try {
const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));
const requiredCommands = [
'bmad.activateDocumentationMode',
'bmad.debugCurrentFile',
'bmad.documentCurrentFile',
'bmad.showHelp'
];
const commands = packageJson.contributes?.commands || [];
const foundCommands = commands.filter(cmd =>
requiredCommands.includes(cmd.command)
).length;
if (foundCommands === requiredCommands.length) {
logSuccess('Package.json commands verified');
} else {
logWarning(`Some commands missing in package.json (${foundCommands}/${requiredCommands.length})`);
}
} catch (error) {
logError(`Failed to parse package.json: ${error.message}`);
}
// Test 2: Run integration test script
logInfo('Running integration tests...');
if (fs.existsSync('test-augment-integration.js')) {
const result = execCommand('node test-augment-integration.js');
if (result.success) {
logSuccess('Integration tests passed');
} else {
logWarning('Some integration tests failed');
if (config.verbose) {
console.log(result.output);
}
}
} else {
logWarning('Integration test script not found');
}
// Test 3: Verify file structure
logInfo('Verifying file structure...');
const integrationFiles = [
'src/integration/AugmentIntegration.ts',
'src/integration/AugmentMenuIntegration.ts',
'src/integration/AugmentAPI.ts'
];
const missingSourceFiles = integrationFiles.filter(file =>
!fs.existsSync(file)
);
if (missingSourceFiles.length === 0) {
logSuccess('All integration source files present');
} else {
logError('Missing integration files:');
missingSourceFiles.forEach(file => console.log(` - ${file}`));
}
return true;
}
function createVSIXPackage() {
logHeader('Creating VSIX Package');
// Check if vsce is available
let vsceResult = execCommand('npx vsce --version');
if (!vsceResult.success) {
logInfo('Installing vsce...');
const installResult = execCommand('npm install -g vsce');
if (!installResult.success) {
logWarning('Failed to install vsce globally, trying local install...');
execCommand('npm install vsce --save-dev');
}
}
logInfo('Creating VSIX package...');
const result = execCommand('npx vsce package');
if (result.success) {
// Find the created VSIX file
const files = fs.readdirSync(config.projectRoot);
const vsixFiles = files.filter(file => file.endsWith('.vsix'))
.sort((a, b) => {
const statA = fs.statSync(path.join(config.projectRoot, a));
const statB = fs.statSync(path.join(config.projectRoot, b));
return statB.mtime - statA.mtime;
});
if (vsixFiles.length > 0) {
logSuccess(`VSIX package created: ${vsixFiles[0]}`);
logInfo(`Location: ${path.join(config.projectRoot, vsixFiles[0])}`);
return true;
}
}
logError('Failed to create VSIX package');
if (config.verbose) {
console.log(result.output);
}
return false;
}
function showNextSteps() {
logHeader('Next Steps');
logSuccess('Build and integration setup complete!');
console.log('');
logInfo('To test the integration:');
logInfo('1. Restart VS Code or reload the window (Ctrl+R)');
logInfo('2. Open Command Palette (Ctrl+Shift+P)');
logInfo('3. Search for "BMAD" commands');
logInfo('4. Try "BMAD: Show Help" to verify functionality');
console.log('');
logInfo('To install the extension:');
const files = fs.readdirSync(config.projectRoot);
const vsixFiles = files.filter(file => file.endsWith('.vsix'));
if (vsixFiles.length > 0) {
logInfo(` code --install-extension ${vsixFiles[0]}`);
}
console.log('');
logInfo('Integration files created:');
logInfo(' - src/integration/AugmentIntegration.ts');
logInfo(' - src/integration/AugmentMenuIntegration.ts');
logInfo(' - src/integration/AugmentAPI.ts');
console.log('');
logInfo('Documentation:');
logInfo(' - AUGMENT_INTEGRATION_README.md');
logInfo(' - AUGMENT_INTEGRATION_COMPLETE.md');
}
function main() {
logHeader('BMAD-Augment Integration Builder');
logInfo('🚀 Starting automated build and test process...');
logInfo(`📁 Project directory: ${config.projectRoot}`);
if (config.verbose) {
logInfo('🔍 Verbose mode enabled');
}
// Step 1: Check prerequisites
if (!checkPrerequisites()) {
logError('Prerequisites check failed. Please install missing components.');
process.exit(1);
}
// Step 2: Install dependencies
if (!installDependencies()) {
logError('Dependency installation failed.');
process.exit(1);
}
// Step 3: Build TypeScript
if (!buildTypeScript()) {
logError('TypeScript build failed.');
process.exit(1);
}
// Step 4: Test integration
testIntegration();
// Step 5: Create package (if requested or if all tests passed)
if (config.packageOnly || !config.skipTests) {
createVSIXPackage();
}
// Step 6: Show next steps
showNextSteps();
logSuccess('✅ All automated steps completed successfully!');
}
// Handle command line arguments
if (process.argv.includes('--help') || process.argv.includes('-h')) {
console.log('BMAD-Augment Integration Builder');
console.log('');
console.log('Usage: node build-integration.js [options]');
console.log('');
console.log('Options:');
console.log(' --verbose Enable verbose output');
console.log(' --skip-tests Skip integration tests');
console.log(' --clean Clean build (remove node_modules and out)');
console.log(' --package-only Only create VSIX package');
console.log(' --help, -h Show this help message');
process.exit(0);
}
// Run the main function
main();