cli: add buildPackages for building multiple packages at once

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2022-01-29 12:31:16 +01:00
parent 03b39bbcc3
commit fe571d2b06
2 changed files with 27 additions and 2 deletions
+1 -1
View File
@@ -14,6 +14,6 @@
* limitations under the License.
*/
export { buildPackage } from './packager';
export { buildPackage, buildPackages } from './packager';
export { Output } from './types';
export type { BuildOptions } from './types';
+26 -1
View File
@@ -17,7 +17,7 @@
import fs from 'fs-extra';
import { rollup, RollupOptions } from 'rollup';
import chalk from 'chalk';
import { relative as relativePath } from 'path';
import { relative as relativePath, resolve as resolvePath } from 'path';
import { paths } from '../paths';
import { makeRollupConfigs } from './config';
import { BuildOptions, Output } from './types';
@@ -116,3 +116,28 @@ export const buildPackage = async (options: BuildOptions) => {
await Promise.all(buildTasks);
};
export const buildPackages = async (
options: (BuildOptions & { targetDir: string })[],
) => {
const rollupConfigs = await Promise.all(options.map(makeRollupConfigs));
await Promise.all(
options.map(({ targetDir }) => fs.remove(resolvePath(targetDir, 'dist'))),
);
const buildTasks = rollupConfigs.flat().map(rollupBuild);
const typeDefinitionTargetDirs = options
.filter(
({ outputs, useApiExtractor }) =>
outputs.has(Output.types) && useApiExtractor,
)
.map(_ => _.targetDir);
if (typeDefinitionTargetDirs.length > 0) {
buildTasks.push(buildTypeDefinitions(typeDefinitionTargetDirs));
}
await Promise.all(buildTasks);
};