-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate-channels.js
More file actions
378 lines (308 loc) · 11.3 KB
/
Copy pathvalidate-channels.js
File metadata and controls
378 lines (308 loc) · 11.3 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
#!/usr/bin/env node
import { readFileSync, existsSync } from 'fs';
import { execSync, spawn } from 'child_process';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
class ChannelValidator {
constructor() {
this.channels = {
core: 'core-package.json',
full: 'full-package.json',
module: 'module-package.json',
experimental: 'experimental-package.json'
};
this.buildScripts = {
core: 'build-core.js',
full: 'build-full.js',
module: 'build-module.js',
experimental: 'build-experimental.js'
};
this.results = {
files: {},
scripts: {},
dependencies: {},
builds: {},
errors: [],
warnings: []
};
}
validate() {
console.log('🔍 Validating 9th.js Release Channel System...\n');
this.validateFiles();
this.validateScripts();
this.validateDependencies();
this.validateBuildSystem();
this.printResults();
return this.results.errors.length === 0;
}
validateFiles() {
console.log('📁 Validating package files...');
Object.entries(this.channels).forEach(([channel, packageFile]) => {
const exists = existsSync(packageFile);
this.results.files[channel] = exists;
if (exists) {
try {
const data = JSON.parse(readFileSync(packageFile, 'utf8'));
const hasValidStructure = this.validatePackageStructure(data, channel);
this.results.files[`${channel}_valid`] = hasValidStructure;
if (hasValidStructure) {
console.log(` ✅ ${channel}: Valid package.json (${data.version})`);
} else {
console.log(` ⚠️ ${channel}: Package.json exists but has issues`);
this.results.warnings.push(`${channel}: Package structure issues`);
}
} catch (error) {
console.log(` ❌ ${channel}: Invalid JSON in package.json`);
this.results.errors.push(`${channel}: Invalid JSON - ${error.message}`);
}
} else {
console.log(` ❌ ${channel}: Missing ${packageFile}`);
this.results.errors.push(`${channel}: Missing ${packageFile}`);
}
});
console.log('');
}
validatePackageStructure(data, channel) {
const requiredFields = ['name', 'version', 'description', 'scripts'];
const hasRequired = requiredFields.every(field => data[field]);
if (!hasRequired) {
this.results.errors.push(`${channel}: Missing required fields`);
return false;
}
// Validate build scripts exist
const buildScript = data.scripts.build || data.scripts['build:channel'];
if (!buildScript) {
this.results.warnings.push(`${channel}: No build script found`);
}
return true;
}
validateScripts() {
console.log('📜 Validating build scripts...');
Object.entries(this.buildScripts).forEach(([channel, scriptFile]) => {
const exists = existsSync(scriptFile);
this.results.scripts[channel] = exists;
if (exists) {
console.log(` ✅ ${channel}: ${scriptFile} exists`);
} else {
console.log(` ❌ ${channel}: Missing ${scriptFile}`);
this.results.errors.push(`${channel}: Missing ${scriptFile}`);
}
});
console.log('');
}
validateDependencies() {
console.log('📦 Validating dependencies...');
// Check for concurrently in devDependencies
try {
const mainPackage = JSON.parse(readFileSync('package.json', 'utf8'));
const hasConcurrently = mainPackage.devDependencies &&
mainPackage.devDependencies.concurrently;
this.results.dependencies.concurrently = hasConcurrently;
if (hasConcurrently) {
console.log(' ✅ concurrently: Available for parallel builds');
} else {
console.log(' ⚠️ concurrently: Missing (recommended for channel:dev:all)');
this.results.warnings.push('concurrently: Missing from devDependencies');
}
} catch (error) {
console.log(' ❌ Could not validate dependencies');
this.results.errors.push(`Dependencies validation failed: ${error.message}`);
}
console.log('');
}
validateBuildSystem() {
console.log('🔨 Validating build system...');
// Check main rollup config
const hasMainRollup = existsSync('rollup.config.js');
this.results.builds.mainRollup = hasMainRollup;
if (hasMainRollup) {
console.log(' ✅ rollup.config.js: Main build configuration exists');
} else {
console.log(' ❌ rollup.config.js: Missing main build configuration');
this.results.errors.push('Main rollup configuration missing');
}
// Check module rollup config
const hasModuleRollup = existsSync('rollup.module.config.js');
this.results.builds.moduleRollup = hasModuleRollup;
if (hasModuleRollup) {
console.log(' ✅ rollup.module.config.js: Module build configuration exists');
} else {
console.log(' ❌ rollup.module.config.js: Missing module build configuration');
this.results.errors.push('Module rollup configuration missing');
}
// Check TypeScript configs
const tsConfigs = ['tsconfig.core.json', 'tsconfig.module.json', 'tsconfig.experimental.json'];
tsConfigs.forEach(config => {
const exists = existsSync(config);
this.results.builds[config] = exists;
if (exists) {
console.log(` ✅ ${config}: TypeScript configuration exists`);
} else {
console.log(` ⚠️ ${config}: Missing (recommended)`);
this.results.warnings.push(`${config}: Missing TypeScript configuration`);
}
});
console.log('');
}
async testBuildCommands() {
console.log('🧪 Testing build commands...');
const testCommands = [
'npm run channel:version:list',
'npm run channel:sync:versions --dry-run --matrix',
];
for (const command of testCommands) {
try {
console.log(` 🔄 Testing: ${command}`);
execSync(command, { stdio: 'pipe', timeout: 30000 });
console.log(` ✅ ${command}: Success`);
} catch (error) {
console.log(` ❌ ${command}: Failed`);
this.results.errors.push(`Command failed: ${command} - ${error.message}`);
}
}
console.log('');
}
printResults() {
console.log('📊 Validation Results:');
console.log('═'.repeat(60));
// Files
console.log('\n📁 Package Files:');
Object.entries(this.results.files).forEach(([key, value]) => {
const status = value ? '✅' : '❌';
console.log(` ${status} ${key}`);
});
// Scripts
console.log('\n📜 Build Scripts:');
Object.entries(this.results.scripts).forEach(([key, value]) => {
const status = value ? '✅' : '❌';
console.log(` ${status} ${key}`);
});
// Dependencies
console.log('\n📦 Dependencies:');
Object.entries(this.results.dependencies).forEach(([key, value]) => {
const status = value ? '✅' : '⚠️';
console.log(` ${status} ${key}`);
});
// Build System
console.log('\n🔨 Build System:');
Object.entries(this.results.builds).forEach(([key, value]) => {
const status = value ? '✅' : '❌';
console.log(` ${status} ${key}`);
});
// Summary
console.log('\n📈 Summary:');
console.log(` ✅ Valid: ${this.getValidCount()}`);
console.log(` ❌ Errors: ${this.results.errors.length}`);
console.log(` ⚠️ Warnings: ${this.results.warnings.length}`);
if (this.results.errors.length > 0) {
console.log('\n❌ Errors:');
this.results.errors.forEach(error => {
console.log(` • ${error}`);
});
}
if (this.results.warnings.length > 0) {
console.log('\n⚠️ Warnings:');
this.results.warnings.forEach(warning => {
console.log(` • ${warning}`);
});
}
console.log('═'.repeat(60));
if (this.results.errors.length === 0) {
console.log('\n🎉 All release channels are properly configured!');
console.log('\n📋 Next steps:');
console.log(' 1. Test individual builds: npm run channel:build:core');
console.log(' 2. Sync versions: npm run channel:sync:versions --dry-run');
console.log(' 3. Run full release: npm run channel:release');
} else {
console.log('\n❌ Please fix the errors before proceeding.');
console.log('\n🛠️ Common solutions:');
console.log(' • Run npm install to ensure all dependencies are installed');
console.log(' • Check that all package files and build scripts exist');
console.log(' • Verify TypeScript configurations are correct');
}
}
getValidCount() {
let validCount = 0;
// Count valid files
Object.values(this.results.files).forEach(value => {
if (value === true) validCount++;
});
// Count valid scripts
Object.values(this.results.scripts).forEach(value => {
if (value === true) validCount++;
});
// Count valid dependencies
Object.values(this.results.dependencies).forEach(value => {
if (value === true) validCount++;
});
// Count valid build configs
Object.values(this.results.builds).forEach(value => {
if (value === true) validCount++;
});
return validCount;
}
generateReport() {
const report = {
timestamp: new Date().toISOString(),
channels: Object.keys(this.channels),
validation: this.results,
system: {
node: process.version,
platform: process.platform,
architecture: process.arch
}
};
return report;
}
}
// CLI interface
const args = process.argv.slice(2);
const validator = new ChannelValidator();
if (args.includes('--help') || args.includes('-h')) {
console.log(`
🔍 9th.js Release Channel Validator
Usage:
node validate-channels.js [options]
Options:
--test-builds Test basic build commands
--report Generate detailed validation report
--json Output results in JSON format
--help, -h Show this help message
Examples:
node validate-channels.js
node validate-channels.js --test-builds --report
node validate-channels.js --json
`);
process.exit(0);
}
async function main() {
const isValid = validator.validate();
if (args.includes('--test-builds')) {
await validator.testBuildCommands();
}
if (args.includes('--report')) {
const report = validator.generateReport();
const reportFile = `channel-validation-report-${Date.now()}.json`;
try {
const fs = await import('fs');
fs.writeFileSync(reportFile, JSON.stringify(report, null, 2));
console.log(`\n📄 Report saved: ${reportFile}`);
} catch (error) {
console.log(`\n⚠️ Could not save report: ${error.message}`);
}
}
if (args.includes('--json')) {
console.log('\n📄 JSON Output:');
console.log(JSON.stringify(validator.results, null, 2));
}
if (args.includes('--report')) {
console.log('\n📄 Validation Report Generated');
}
process.exit(isValid ? 0 : 1);
}
main().catch((error) => {
console.error('💥 Validation failed:', error.message);
process.exit(1);
});