* Builds the target. * @param {string} target - The target to build. * @returns {Promise<void>} - A promise representing the build process.
(target)
| 158 | * @returns {Promise<void>} - A promise representing the build process. |
| 159 | */ |
| 160 | async function build(target) { |
| 161 | const pkgBase = privatePackages.includes(target) |
| 162 | ? `packages-private` |
| 163 | : `packages` |
| 164 | const pkgDir = path.resolve(`${pkgBase}/${target}`) |
| 165 | const pkg = JSON.parse(fs.readFileSync(`${pkgDir}/package.json`, 'utf-8')) |
| 166 | |
| 167 | // if this is a full build (no specific targets), ignore private packages |
| 168 | if ((isRelease || !targets.length) && pkg.private) { |
| 169 | return |
| 170 | } |
| 171 | |
| 172 | // if building a specific format, do not remove dist. |
| 173 | if (!formats && fs.existsSync(`${pkgDir}/dist`)) { |
| 174 | fs.rmSync(`${pkgDir}/dist`, { recursive: true }) |
| 175 | } |
| 176 | |
| 177 | const env = |
| 178 | (pkg.buildOptions && pkg.buildOptions.env) || |
| 179 | (devOnly ? 'development' : 'production') |
| 180 | |
| 181 | await exec( |
| 182 | 'rollup', |
| 183 | [ |
| 184 | '-c', |
| 185 | '--environment', |
| 186 | [ |
| 187 | `COMMIT:${commit}`, |
| 188 | `NODE_ENV:${env}`, |
| 189 | `TARGET:${target}`, |
| 190 | formats ? `FORMATS:${formats}` : ``, |
| 191 | prodOnly ? `PROD_ONLY:true` : ``, |
| 192 | sourceMap ? `SOURCE_MAP:true` : ``, |
| 193 | ] |
| 194 | .filter(Boolean) |
| 195 | .join(','), |
| 196 | ], |
| 197 | { stdio: 'inherit' }, |
| 198 | ) |
| 199 | } |
| 200 | |
| 201 | /** |
| 202 | * Checks the sizes of all targets. |