|
| 1 | +const { spawnSync } = require('child_process'); |
| 2 | +const path = require('path'); |
| 3 | +const getPackageJson = require('./get-package-json'); |
| 4 | + |
| 5 | +const REPO_ROOT = path.join(__dirname, '../..'); |
| 6 | +const RUSHX_SCRIPT = path.join(REPO_ROOT, 'common/scripts/install-run-rushx.js'); |
| 7 | + |
| 8 | +const TAGGED_PACKAGE_BUILD_ORDER = [ |
| 9 | + '@visactor/vrender-core', |
| 10 | + '@visactor/vrender-animate', |
| 11 | + '@visactor/vrender-kits', |
| 12 | + '@visactor/vrender-components', |
| 13 | + '@visactor/vrender', |
| 14 | + '@visactor/react-vrender', |
| 15 | + '@visactor/react-vrender-utils' |
| 16 | +]; |
| 17 | + |
| 18 | +function assertTaggedPackageCoverage() { |
| 19 | + const rushJson = getPackageJson(path.join(REPO_ROOT, 'rush.json')); |
| 20 | + const taggedPackages = rushJson.projects |
| 21 | + .filter(project => Array.isArray(project.tags) && project.tags.includes('package')) |
| 22 | + .map(project => project.packageName); |
| 23 | + |
| 24 | + const missing = taggedPackages.filter(packageName => !TAGGED_PACKAGE_BUILD_ORDER.includes(packageName)); |
| 25 | + const extra = TAGGED_PACKAGE_BUILD_ORDER.filter(packageName => !taggedPackages.includes(packageName)); |
| 26 | + |
| 27 | + if (missing.length || extra.length) { |
| 28 | + throw new Error([ |
| 29 | + 'TAGGED_PACKAGE_BUILD_ORDER is out of sync with rush.json package tags.', |
| 30 | + missing.length ? `Missing: ${missing.join(', ')}` : '', |
| 31 | + extra.length ? `Extra: ${extra.join(', ')}` : '' |
| 32 | + ].filter(Boolean).join('\n')); |
| 33 | + } |
| 34 | + |
| 35 | + return rushJson.projects.reduce((projectByName, project) => { |
| 36 | + projectByName[project.packageName] = project; |
| 37 | + return projectByName; |
| 38 | + }, {}); |
| 39 | +} |
| 40 | + |
| 41 | +function runPackageBuild(project) { |
| 42 | + console.log(`\n[release-build] ${project.packageName}`); |
| 43 | + |
| 44 | + // `--clean` avoids stale build handles that can keep some package builds open. |
| 45 | + const result = spawnSync(process.execPath, [RUSHX_SCRIPT, 'build', '--clean'], { |
| 46 | + cwd: path.join(REPO_ROOT, project.projectFolder), |
| 47 | + stdio: 'inherit', |
| 48 | + shell: false |
| 49 | + }); |
| 50 | + |
| 51 | + if (result.error) { |
| 52 | + throw result.error; |
| 53 | + } |
| 54 | + |
| 55 | + if (result.status !== 0) { |
| 56 | + process.exit(result.status || 1); |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +function buildTagPackages() { |
| 61 | + const projectByName = assertTaggedPackageCoverage(); |
| 62 | + |
| 63 | + TAGGED_PACKAGE_BUILD_ORDER.forEach(packageName => { |
| 64 | + runPackageBuild(projectByName[packageName]); |
| 65 | + }); |
| 66 | +} |
| 67 | + |
| 68 | +module.exports = { |
| 69 | + buildTagPackages, |
| 70 | + TAGGED_PACKAGE_BUILD_ORDER |
| 71 | +}; |
0 commit comments