| 1 | #!/usr/bin/env node |
| 2 | |
| 3 | 'use strict'; |
| 4 | |
| 5 | // IMPORTANT: |
| 6 | // Changes below should be mirrored in ../ci-add-build-info-json.js |
| 7 | |
| 8 | const {existsSync} = require('fs'); |
| 9 | const {writeJson, readJson} = require('fs-extra'); |
| 10 | const {join} = require('path'); |
| 11 | const {getPublicPackages, logPromise} = require('../utils'); |
| 12 | const theme = require('../theme'); |
| 13 | |
| 14 | const run = async ({branch, checksum, commit, reactVersion, tempDirectory}) => { |
| 15 | const isExperimental = reactVersion.includes('experimental'); |
| 16 | const packages = getPublicPackages(isExperimental); |
| 17 | const packagesDir = join(tempDirectory, 'packages'); |
| 18 | |
| 19 | const buildInfoJSON = { |
| 20 | branch, |
| 21 | buildNumber: null, |
| 22 | checksum, |
| 23 | commit, |
| 24 | environment: 'local', |
| 25 | reactVersion, |
| 26 | }; |
| 27 | |
| 28 | for (let i = 0; i < packages.length; i++) { |
| 29 | const packageName = packages[i]; |
| 30 | const packagePath = join(packagesDir, packageName); |
| 31 | const packageJSON = await readJson(join(packagePath, 'package.json')); |
| 32 | |
| 33 | // Verify all public packages include "build-info.json" in the files array. |
| 34 | if (!packageJSON.files.includes('build-info.json')) { |
| 35 | console.error( |
| 36 | theme`{error ${packageName} must include "build-info.json" in files array.}` |
| 37 | ); |
| 38 | process.exit(1); |
| 39 | } |
| 40 | |
| 41 | // Add build info JSON to package. |
| 42 | if (existsSync(join(packagePath, 'npm'))) { |
| 43 | const buildInfoJSONPath = join(packagePath, 'npm', 'build-info.json'); |
| 44 | await writeJson(buildInfoJSONPath, buildInfoJSON, {spaces: 2}); |
| 45 | } |
| 46 | } |
| 47 | }; |
| 48 | |
| 49 | module.exports = async params => { |
| 50 | return logPromise(run(params), 'Adding build metadata to packages'); |
| 51 | }; |