-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathupdate-frameworks.js
More file actions
77 lines (62 loc) · 2.69 KB
/
Copy pathupdate-frameworks.js
File metadata and controls
77 lines (62 loc) · 2.69 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
import { execSync } from 'child_process';
import { readdirSync, existsSync, readFileSync } from 'fs';
import { join, dirname, basename } from 'path';
import { fileURLToPath } from 'url';
const __dirname = dirname(fileURLToPath(import.meta.url));
const FRAMEWORKS_DIR = join(__dirname, 'frameworks');
const frameworkDirs = readdirSync(FRAMEWORKS_DIR, { withFileTypes: true })
.filter(d => d.isDirectory())
.map(d => join(FRAMEWORKS_DIR, d.name));
let totalUpdated = 0;
for (const frameworkDir of frameworkDirs) {
const name = basename(frameworkDir);
const pkgPath = join(frameworkDir, 'package.json');
if (!existsSync(pkgPath)) {
console.log(`Skipping ${name} — no package.json`);
continue;
}
const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'));
const deps = pkg.dependencies || {};
const devDeps = pkg.devDependencies || {};
// Collect @lightningjs/* packages, excluding file: local paths
const lightningProdDeps = Object.entries(deps)
.filter(([n, v]) => n.startsWith('@lightningjs/') && !v.startsWith('file:'))
.map(([n]) => n);
const lightningDevDeps = Object.entries(devDeps)
.filter(([n, v]) => n.startsWith('@lightningjs/') && !v.startsWith('file:'))
.map(([n]) => n);
if (lightningProdDeps.length === 0 && lightningDevDeps.length === 0) {
console.log(`Skipping ${name} — no @lightningjs packages`);
continue;
}
console.log(`\n[${name}]`);
if (lightningProdDeps.length > 0) {
const pkgArgs = lightningProdDeps.map(p => `${p}@latest`).join(' ');
console.log(` Installing (prod): ${pkgArgs}`);
execSync(`npm install --save-exact ${pkgArgs}`, {
cwd: frameworkDir,
stdio: 'inherit',
});
}
if (lightningDevDeps.length > 0) {
const pkgArgs = lightningDevDeps.map(p => `${p}@latest`).join(' ');
console.log(` Installing (dev): ${pkgArgs}`);
execSync(`npm install --save-dev --save-exact ${pkgArgs}`, {
cwd: frameworkDir,
stdio: 'inherit',
});
}
// Read back installed versions and report changes
const updatedPkg = JSON.parse(readFileSync(pkgPath, 'utf8'));
for (const pkgName of [...lightningProdDeps, ...lightningDevDeps]) {
const oldVer = deps[pkgName] ?? devDeps[pkgName];
const newVer = updatedPkg.dependencies?.[pkgName] ?? updatedPkg.devDependencies?.[pkgName];
if (oldVer !== newVer) {
console.log(` ${pkgName}: ${oldVer} -> ${newVer}`);
} else {
console.log(` ${pkgName}: already at latest (${newVer})`);
}
}
totalUpdated++;
}
console.log(`\nDone. Updated ${totalUpdated} framework(s).`);