Merge pull request #1144 from spotify/rugvip/build

packages/cli: add separate build command for non-plugin packages
This commit is contained in:
Patrik Oldsberg
2020-06-05 10:47:30 +02:00
committed by GitHub
14 changed files with 119 additions and 23 deletions
+3 -2
View File
@@ -1,7 +1,8 @@
{
"name": "@backstage/catalog-model",
"version": "0.1.1-alpha.6",
"main": "dist/index.esm.js",
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"main:src": "src/index.ts",
"types": "src/index.ts",
"license": "Apache-2.0",
@@ -10,7 +11,7 @@
"access": "public"
},
"scripts": {
"build": "backstage-cli plugin:build",
"build": "backstage-cli build",
"lint": "backstage-cli lint",
"test": "backstage-cli test",
"prepack": "backstage-cli prepack",
+37
View File
@@ -0,0 +1,37 @@
/*
* Copyright 2020 Spotify AB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { buildPackage, Output } from '../lib/packager';
import { Command } from 'commander';
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 });
};
+4 -2
View File
@@ -14,8 +14,10 @@
* limitations under the License.
*/
import { buildPackage } from '../../lib/packager';
import { buildPackage, Output } from '../../lib/packager';
export default async () => {
await buildPackage();
await buildPackage({
outputs: new Set([Output.esm, Output.types]),
});
};
+6
View File
@@ -78,6 +78,12 @@ const main = (argv: string[]) => {
.description('Diff an existing plugin with the creation template')
.action(actionHandler(() => require('./commands/plugin/diff')));
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
.command('lint')
.option('--fix', 'Attempt to automatically fix violations')
+33 -11
View File
@@ -24,11 +24,14 @@ import esbuild from 'rollup-plugin-esbuild';
import imageFiles from 'rollup-plugin-image-files';
import dts from 'rollup-plugin-dts';
import json from '@rollup/plugin-json';
import { RollupOptions } from 'rollup';
import { RollupOptions, OutputOptions } from 'rollup';
import { BuildOptions, Output } from './types';
import { paths } from '../paths';
export const makeConfigs = async (): Promise<RollupOptions[]> => {
export const makeConfigs = async (
options: BuildOptions,
): Promise<RollupOptions[]> => {
const typesInput = paths.resolveTargetRoot(
'dist',
relativePath(paths.targetRoot, paths.targetDir),
@@ -43,13 +46,27 @@ export const makeConfigs = async (): Promise<RollupOptions[]> => {
);
}
return [
{
input: 'src/index.ts',
output: {
const configs = new Array<RollupOptions>();
if (options.outputs.has(Output.cjs) || options.outputs.has(Output.esm)) {
const output = new Array<OutputOptions>();
if (options.outputs.has(Output.cjs)) {
output.push({
file: 'dist/index.cjs.js',
format: 'commonjs',
});
}
if (options.outputs.has(Output.esm)) {
output.push({
file: 'dist/index.esm.js',
format: 'module',
},
});
}
configs.push({
input: 'src/index.ts',
output,
plugins: [
peerDepsExternal({
includeDependencies: true,
@@ -68,14 +85,19 @@ export const makeConfigs = async (): Promise<RollupOptions[]> => {
target: 'es2019',
}),
],
},
{
});
}
if (options.outputs.has(Output.types)) {
configs.push({
input: typesInput,
output: {
file: 'dist/index.d.ts',
format: 'es',
},
plugins: [dts()],
},
];
});
}
return configs;
};
+2
View File
@@ -15,3 +15,5 @@
*/
export { buildPackage } from './packager';
export { Output } from './types';
export type { BuildOptions } from './types';
+3 -2
View File
@@ -19,6 +19,7 @@ import chalk from 'chalk';
import { relative as relativePath } from 'path';
import { paths } from '../paths';
import { makeConfigs } from './config';
import { BuildOptions } from './types';
function formatErrorMessage(error: any) {
let msg = '';
@@ -80,7 +81,7 @@ async function build(config: RollupOptions) {
}
}
export const buildPackage = async () => {
const configs = await makeConfigs();
export const buildPackage = async (options: BuildOptions) => {
const configs = await makeConfigs(options);
await Promise.all(configs.map(build));
};
+25
View File
@@ -0,0 +1,25 @@
/*
* Copyright 2020 Spotify AB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export enum Output {
esm,
cjs,
types,
}
export type BuildOptions = {
outputs: Set<Output>;
};
+1 -1
View File
@@ -20,7 +20,7 @@
"main:src": "src/index.ts",
"types": "src/index.ts",
"scripts": {
"build": "backstage-cli plugin:build",
"build": "backstage-cli build --outputs types,esm",
"lint": "backstage-cli lint",
"test": "backstage-cli test",
"prepack": "backstage-cli prepack",
+1 -1
View File
@@ -20,7 +20,7 @@
"main:src": "src/index.ts",
"types": "src/index.ts",
"scripts": {
"build": "backstage-cli plugin:build",
"build": "backstage-cli build --outputs types,esm",
"lint": "backstage-cli lint",
"test": "backstage-cli test",
"prepack": "backstage-cli prepack",
+1 -1
View File
@@ -20,7 +20,7 @@
"main:src": "src/index.ts",
"types": "src/index.ts",
"scripts": {
"build": "backstage-cli plugin:build",
"build": "backstage-cli build --outputs types,esm",
"lint": "backstage-cli lint",
"test": "backstage-cli test",
"prepack": "backstage-cli prepack",
+1 -1
View File
@@ -20,7 +20,7 @@
"main:src": "src/index.ts",
"types": "src/index.ts",
"scripts": {
"build": "backstage-cli plugin:build",
"build": "backstage-cli build --outputs types,esm",
"lint": "backstage-cli lint",
"test": "backstage-cli test",
"prepack": "backstage-cli prepack",
+1 -1
View File
@@ -20,7 +20,7 @@
"main:src": "src/index.ts",
"types": "src/index.ts",
"scripts": {
"build": "backstage-cli plugin:build",
"build": "backstage-cli build --outputs types,esm",
"lint": "backstage-cli lint",
"test": "backstage-cli test",
"prepack": "backstage-cli prepack",
+1 -1
View File
@@ -20,7 +20,7 @@
"main:src": "src/index.ts",
"types": "src/index.ts",
"scripts": {
"build": "backstage-cli plugin:build",
"build": "backstage-cli build --outputs types,esm",
"lint": "backstage-cli lint",
"prepack": "backstage-cli prepack",
"postpack": "backstage-cli postpack",