packages/cli: add output format option to build command
This commit is contained in:
@@ -14,10 +14,24 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { buildPackage } from '../lib/packager';
|
||||
import { buildPackage, Output } from '../lib/packager';
|
||||
import { Command } from 'commander';
|
||||
|
||||
export default async () => {
|
||||
await buildPackage({
|
||||
outputs: new Set(['types', 'esm', 'cjs']),
|
||||
});
|
||||
export default async (cmd: Command) => {
|
||||
let outputs = new Set<Output>();
|
||||
|
||||
const { outputs: outputsStr } = cmd as { outputs?: string };
|
||||
if (outputsStr) {
|
||||
for (const output of outputsStr.split(',') as (keyof typeof Output)[]) {
|
||||
if (output in Output) {
|
||||
outputs.add(Output[output]);
|
||||
} else {
|
||||
throw new Error(`Unknown output format: ${output}`);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
outputs = new Set([Output.types, Output.esm, Output.cjs]);
|
||||
}
|
||||
|
||||
await buildPackage({ outputs });
|
||||
};
|
||||
|
||||
@@ -14,10 +14,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { buildPackage } from '../../lib/packager';
|
||||
import { buildPackage, Output } from '../../lib/packager';
|
||||
|
||||
export default async () => {
|
||||
await buildPackage({
|
||||
outputs: new Set(['esm', 'types']),
|
||||
outputs: new Set([Output.esm, Output.types]),
|
||||
});
|
||||
};
|
||||
|
||||
@@ -81,6 +81,7 @@ const main = (argv: string[]) => {
|
||||
program
|
||||
.command('build')
|
||||
.description('Build a package for publishing')
|
||||
.option('--outputs <formats>', 'List of formats to output [types,cjs,esm]')
|
||||
.action(actionHandler(() => require('./commands/build')));
|
||||
|
||||
program
|
||||
|
||||
@@ -26,7 +26,7 @@ import dts from 'rollup-plugin-dts';
|
||||
import json from '@rollup/plugin-json';
|
||||
import { RollupOptions, OutputOptions } from 'rollup';
|
||||
|
||||
import { BuildOptions } from './types';
|
||||
import { BuildOptions, Output } from './types';
|
||||
import { paths } from '../paths';
|
||||
|
||||
export const makeConfigs = async (
|
||||
@@ -48,16 +48,16 @@ export const makeConfigs = async (
|
||||
|
||||
const configs = new Array<RollupOptions>();
|
||||
|
||||
if (options.outputs.has('cjs') || options.outputs.has('esm')) {
|
||||
if (options.outputs.has(Output.cjs) || options.outputs.has(Output.esm)) {
|
||||
const output = new Array<OutputOptions>();
|
||||
|
||||
if (options.outputs.has('cjs')) {
|
||||
if (options.outputs.has(Output.cjs)) {
|
||||
output.push({
|
||||
file: 'dist/index.cjs.js',
|
||||
format: 'commonjs',
|
||||
});
|
||||
}
|
||||
if (options.outputs.has('esm')) {
|
||||
if (options.outputs.has(Output.esm)) {
|
||||
output.push({
|
||||
file: 'dist/index.esm.js',
|
||||
format: 'module',
|
||||
@@ -88,7 +88,7 @@ export const makeConfigs = async (
|
||||
});
|
||||
}
|
||||
|
||||
if (options.outputs.has('types')) {
|
||||
if (options.outputs.has(Output.types)) {
|
||||
configs.push({
|
||||
input: typesInput,
|
||||
output: {
|
||||
|
||||
@@ -15,4 +15,5 @@
|
||||
*/
|
||||
|
||||
export { buildPackage } from './packager';
|
||||
export type { BuildOptions, OutputFormat } from './types';
|
||||
export { Output } from './types';
|
||||
export type { BuildOptions } from './types';
|
||||
|
||||
@@ -14,8 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export type OutputFormat = 'esm' | 'cjs' | 'types';
|
||||
export enum Output {
|
||||
esm,
|
||||
cjs,
|
||||
types,
|
||||
}
|
||||
|
||||
export type BuildOptions = {
|
||||
outputs: Set<OutputFormat>;
|
||||
outputs: Set<Output>;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user