-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-versions.js
More file actions
executable file
·120 lines (93 loc) · 3.73 KB
/
install-versions.js
File metadata and controls
executable file
·120 lines (93 loc) · 3.73 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
#!/usr/bin/env node
import { execSync } from 'child_process';
import fs from 'fs';
import path from 'path';
function installExactVersion(version) {
const aliasName = `lighthouse-v${version}`;
try {
console.log(`📦 Installing exact Lighthouse v${version} as ${aliasName}...`);
const installCommand = `npm install ${aliasName}@npm:lighthouse@${version}`;
console.log(`Running: ${installCommand}`);
execSync(installCommand, { stdio: 'inherit' });
console.log(`✅ Successfully installed Lighthouse v${version}`);
return true;
} catch (error) {
console.error(`❌ Failed to install Lighthouse v${version}:`, error.message);
return false;
}
}
function installMajorVersion(majorVersion) {
const aliasName = `lighthouse-v${majorVersion}`;
try {
console.log(`📦 Installing Lighthouse v${majorVersion}.x as ${aliasName}...`);
const installCommand = `npm install ${aliasName}@npm:lighthouse@${majorVersion}`;
console.log(`Running: ${installCommand}`);
execSync(installCommand, { stdio: 'inherit' });
console.log(`✅ Successfully installed Lighthouse v${majorVersion}.x`);
return true;
} catch (error) {
console.error(`❌ Failed to install Lighthouse v${majorVersion}.x:`, error.message);
return false;
}
}
function listInstalledVersions() {
console.log('Installed Lighthouse versions:');
const nodeModulesPath = 'node_modules';
if (!fs.existsSync(nodeModulesPath)) {
console.log(' No node_modules directory found');
return;
}
const dirs = fs.readdirSync(nodeModulesPath);
const lighthouseVersions = dirs.filter(dir => dir.startsWith('lighthouse-v'));
if (lighthouseVersions.length === 0) {
console.log(' No additional Lighthouse versions installed');
console.log(' Only default lighthouse package available');
} else {
lighthouseVersions.forEach(dir => {
const version = dir.replace('lighthouse-v', '');
console.log(` ✅ v${version} (${dir})`);
});
}
// Also show default lighthouse
const defaultExists = fs.existsSync('node_modules/lighthouse');
console.log(` ${defaultExists ? '✅' : '❌'} default lighthouse package`);
}
function installCommonVersions() {
console.log('🚀 Installing common Lighthouse major versions...\n');
const commonVersions = ['8', '9', '10', '11', '12'];
let successCount = 0;
for (const version of commonVersions) {
if (installMajorVersion(version)) {
successCount++;
}
console.log(''); // Add spacing
}
console.log(`📊 Summary: ${successCount}/${commonVersions.length} major versions installed successfully`);
}
// Check command line arguments
const args = process.argv.slice(2);
if (args.length === 0) {
console.log('Usage:');
console.log(' node install-versions.js 12.6.1 10.4.0 # Install exact versions');
console.log(' node install-versions.js 12 10 # Install major versions');
console.log(' node install-versions.js --common # Install common major versions');
console.log(' node install-versions.js --list # List installed versions');
} else if (args[0] === '--list') {
listInstalledVersions();
} else if (args[0] === '--common') {
installCommonVersions();
} else {
// Install specific versions
console.log(`🚀 Installing specific versions: ${args.join(', ')}\n`);
let successCount = 0;
for (const version of args) {
const success = version.includes('.')
? installExactVersion(version) // Exact version like "12.6.1"
: installMajorVersion(version); // Major version like "12"
if (success) {
successCount++;
}
console.log('');
}
console.log(`📊 Summary: ${successCount}/${args.length} versions installed successfully`);
}