Skip to content

Commit

Permalink
cli: add experimental backend:bundle command
Browse files Browse the repository at this point in the history
  • Loading branch information
Rugvip committed Nov 23, 2020
1 parent 514c269 commit 31d8b69
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/orange-cherries-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@backstage/cli': patch
---

Add experimental backend:bundle command
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ typings/
.nuxt
dist
dist-types
dist-workspace

# Gatsby files
.cache/
Expand Down
39 changes: 39 additions & 0 deletions packages/cli/src/commands/backend/bundle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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 { Command } from 'commander';
import fs from 'fs-extra';
import { createDistWorkspace } from '../../lib/packager';
import { paths } from '../../lib/paths';
import { parseParallel, PARALLEL_ENV_VAR } from '../../lib/parallel';

const PKG_PATH = 'package.json';
const TARGET_DIR = 'dist-workspace';

export default async (cmd: Command) => {
const targetDir = paths.resolveTarget(TARGET_DIR);
const pkgPath = paths.resolveTarget(PKG_PATH);
const pkg = await fs.readJson(pkgPath);

await fs.remove(targetDir);
await fs.mkdir(targetDir);
await createDistWorkspace([pkg.name], {
targetDir: targetDir,
buildDependencies: Boolean(cmd.build),
parallel: parseParallel(process.env[PARALLEL_ENV_VAR]),
skeleton: 'skeleton.tar',
});
};
5 changes: 5 additions & 0 deletions packages/cli/src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ export function registerCommands(program: CommanderStatic) {
.description('Build a backend plugin')
.action(lazy(() => import('./backend/build').then(m => m.default)));

program
.command('backend:__experimental__bundle__', { hidden: true })
.description('Bundle all backend packages into dist-workspace')
.action(lazy(() => import('./backend/bundle').then(m => m.default)));

program
.command('backend:build-image')
.allowUnknownOption(true)
Expand Down

0 comments on commit 31d8b69

Please sign in to comment.