| 77 | } |
| 78 | |
| 79 | async function build(target) { |
| 80 | const pkgDir = path.resolve(`packages/${target}`); |
| 81 | const pkg = require(`${pkgDir}/package.json`); |
| 82 | |
| 83 | // only build published packages for release |
| 84 | if (isRelease && pkg.private) { |
| 85 | return; |
| 86 | } |
| 87 | |
| 88 | // if building a specific format, do not remove dist. |
| 89 | // if (!formats) { |
| 90 | // await fs.remove(`${pkgDir}/dist`); |
| 91 | // } |
| 92 | |
| 93 | const env = (pkg.buildOptions && pkg.buildOptions.env) || (devOnly ? 'development' : 'production'); |
| 94 | |
| 95 | await execa( |
| 96 | 'rollup', |
| 97 | [ |
| 98 | '-c', |
| 99 | '--environment', |
| 100 | [ |
| 101 | `COMMIT:${commit}`, |
| 102 | `NODE_ENV:${env}`, |
| 103 | `TARGET:${target}`, |
| 104 | formats ? `FORMATS:${formats}` : '', |
| 105 | buildTypes ? 'TYPES:true' : '', |
| 106 | prodOnly ? 'PROD_ONLY:true' : '', |
| 107 | sourceMap ? 'SOURCE_MAP:true' : '', |
| 108 | ] |
| 109 | .filter(Boolean) |
| 110 | .join(','), |
| 111 | ], |
| 112 | { stdio: 'inherit' }, |
| 113 | ); |
| 114 | |
| 115 | if (buildTypes && pkg.types) { |
| 116 | console.log(); |
| 117 | console.log(chalk.bold(chalk.yellow(`Rolling up type definitions for ${target}...`))); |
| 118 | // build types |
| 119 | const { Extractor, ExtractorConfig } = require('@microsoft/api-extractor'); |
| 120 | |
| 121 | const extractorConfigPath = path.resolve(pkgDir, 'api-extractor.json'); |
| 122 | const extractorConfig = ExtractorConfig.loadFileAndPrepare(extractorConfigPath); |
| 123 | const extractorResult = Extractor.invoke(extractorConfig, { |
| 124 | localBuild: true, |
| 125 | showVerboseMessages: true, |
| 126 | }); |
| 127 | |
| 128 | if (extractorResult.succeeded) { |
| 129 | // @deprecated 曾经联合代码的功能,重设打包路径后此段代码无效 |
| 130 | // concat additional d.ts to rolled-up dts |
| 131 | // const typesDir = path.resolve(pkgDir, 'types'); |
| 132 | // if (await fs.exists(typesDir)) { |
| 133 | // const dtsPath = path.resolve(pkgDir, pkg.types); |
| 134 | // const existing = await fs.readFile(dtsPath, 'utf-8'); |
| 135 | // const typeFiles = await fs.readdir(typesDir); |
| 136 | // const toAdd = await Promise.all( |