forked from silexlabs/Silex
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-packages.js
More file actions
executable file
·78 lines (64 loc) · 2.33 KB
/
build-packages.js
File metadata and controls
executable file
·78 lines (64 loc) · 2.33 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
#!/usr/bin/env node
/**
* Builds packages in dependency order after yarn install
* This ensures that packages requiring other packages' dist/ folders are built correctly
* Uses scripts/sort-internal-deps.js to get the correct dependency order
*/
import { execSync } from 'child_process';
import { existsSync } from 'fs';
import path from 'path';
function getPackagesToBuild() {
try {
// Get dependency-sorted packages from sort-internal-deps.js
const output = execSync('node scripts/sort-internal-deps.js', {
encoding: 'utf-8',
cwd: process.cwd()
});
// Parse the output to get package names
const packages = output
.split('\n')
.filter(line => line.startsWith('- '))
.map(line => line.replace('- ', '').trim())
.filter(pkg => pkg.length > 0);
return packages;
} catch (error) {
console.error('❌ Failed to get dependency order:', error.message);
console.log('📦 Falling back to all packages...');
// Fallback: get all packages from packages directory
try {
const output = execSync('ls packages', { encoding: 'utf-8' });
return output.split('\n').filter(pkg => pkg.trim().length > 0);
} catch (fallbackError) {
console.error('❌ Failed to list packages:', fallbackError.message);
return [];
}
}
}
function buildPackage(packageName) {
const packagePath = path.join('packages', packageName);
const packageJsonPath = path.join(packagePath, 'package.json');
if (!existsSync(packageJsonPath)) {
console.log(`⚠️ Skipping ${packageName} - package.json not found`);
return;
}
console.log(`🔨 Building ${packageName}...`);
try {
// Try to run build script if it exists
execSync('npm run build --if-present', {
cwd: packagePath,
stdio: 'inherit',
env: { ...process.env, npm_execpath: 'yarn' }
});
console.log(`✅ ${packageName} built successfully`);
} catch (error) {
console.error(`❌ Failed to build ${packageName}:`, error.message);
// Don't exit - continue with other packages
}
}
console.log('📦 Building packages in dependency order...');
const packages = getPackagesToBuild();
console.log(`📋 Found ${packages.length} packages to build`);
for (const packageName of packages) {
buildPackage(packageName);
}
console.log('🎉 Package build process completed');