Merge branch 'master' into feature/312-plugin-test-and-list

This commit is contained in:
Mateus Marquezini
2020-03-20 10:35:18 -03:00
26 changed files with 182 additions and 86 deletions
@@ -14,14 +14,15 @@
* limitations under the License.
*/
import { Command } from 'commander';
import { run } from '../../helpers/run';
export default async (cmd: Command) => {
const args = ['lint', '--max-warnings=0', '--format=codeframe'];
if (cmd.fix) {
args.push('--fix');
}
export default async () => {
const args = ['build'];
await run('web-scripts', args);
await run('react-scripts', args, {
env: {
EXTEND_ESLINT: 'true',
SKIP_PREFLIGHT_CHECK: 'true',
},
});
};
+31
View File
@@ -0,0 +1,31 @@
/*
* 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 { run } from '../../helpers/run';
import { watchDeps } from '../watch-deps';
export default async () => {
const args = ['start'];
// Start dynamic watch and build of dependencies, then serve the app
await watchDeps();
await run('react-scripts', args, {
env: {
EXTEND_ESLINT: 'true',
SKIP_PREFLIGHT_CHECK: 'true',
},
});
};
@@ -15,7 +15,7 @@
*/
import { Command } from 'commander';
import { run } from '../../helpers/run';
import { run } from '../helpers/run';
export default async (cmd: Command) => {
const args = ['lint', '--max-warnings=0', '--format=codeframe'];
+36
View File
@@ -0,0 +1,36 @@
/*
* 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 { resolve as resolvePath } from 'path';
import { run } from '../helpers/run';
export default async (cmd: Command) => {
const args = [
'test',
'--config',
resolvePath(__dirname, '../../config/jest.js'),
];
if (cmd.watch) {
args.push('--watch');
}
if (cmd.coverage) {
args.push('--coverage');
}
await run('web-scripts', args, { stdio: 'inherit' });
};
+16 -10
View File
@@ -31,16 +31,9 @@ const PACKAGE_BLACKLIST = [
const WATCH_LOCATIONS = ['package.json', 'src', 'assets'];
/*
* The watch-deps command is meant to improve iteration speed while working in a large monorepo
* with packages that are built independently, meaning packages depends on each other's build output.
*
* The command traverses all dependencies of the current package within the monorepo, and starts
* watching for updates in all those packages. If a change is detected, we stop listening for changes,
* and instead start up watch mode for that package. Starting watch mode means running the first
* available yarn script out of "build:watch", "watch", or "build" --watch.
*/
export default async (_command: any, args: string[]) => {
// Start watching for dependency changes.
// The returned promise resolves when watchers have started for all current dependencies.
export async function watchDeps() {
const localPackagePath = resolvePath('package.json');
// Rotate through different prefix colors to make it easier to differenciate between different deps
@@ -66,6 +59,19 @@ export default async (_command: any, args: string[]) => {
const newDeps = await getPackageDeps(localPackagePath, PACKAGE_BLACKLIST);
await watcher.update(newDeps);
});
}
/*
* The watch-deps command is meant to improve iteration speed while working in a large monorepo
* with packages that are built independently, meaning packages depends on each other's build output.
*
* The command traverses all dependencies of the current package within the monorepo, and starts
* watching for updates in all those packages. If a change is detected, we stop listening for changes,
* and instead start up watch mode for that package. Starting watch mode means running the first
* available yarn script out of "build:watch", "watch", or "build" --watch.
*/
export default async (_command: any, args: string[]) => {
await watchDeps();
if (args?.length) {
await waitForExit(startChild(args));
+6 -2
View File
@@ -14,14 +14,18 @@
* limitations under the License.
*/
import { SpawnSyncOptions, spawn, ChildProcess } from 'child_process';
import { SpawnOptions, spawn, ChildProcess } from 'child_process';
import { ExitCodeError } from './errors';
type SpawnOptionsPartialEnv = Omit<SpawnOptions, 'env'> & {
env?: Partial<NodeJS.ProcessEnv>;
};
// Runs a child command, returning a promise that is only resolved if the child exits with code 0.
export async function run(
name: string,
args: string[] = [],
options: SpawnSyncOptions = {},
options: SpawnOptionsPartialEnv = {},
) {
const env: NodeJS.ProcessEnv = {
...process.env,
+21 -16
View File
@@ -19,11 +19,12 @@ import chalk from 'chalk';
import fs from 'fs';
import createPluginCommand from './commands/createPlugin';
import watch from './commands/watch-deps';
import appLint from './commands/app/lint';
import lintCommand from './commands/lint';
import testCommand from './commands/testCommand';
import appBuild from './commands/app/build';
import appServe from './commands/app/serve';
import pluginBuild from './commands/plugin/build';
import pluginLint from './commands/plugin/lint';
import pluginServe from './commands/plugin/serve';
import pluginTest from './commands/plugin/testCommand';
import { exitWithError } from './helpers/errors';
const main = (argv: string[]) => {
@@ -32,10 +33,14 @@ const main = (argv: string[]) => {
program.name('backstage-cli').version(packageJson.version ?? '0.0.0');
program
.command('app:lint')
.option('--fix', 'Attempt to automatically fix violations')
.description('Lint an app')
.action(actionHandler(appLint));
.command('app:build')
.description('Build an app for a production release')
.action(actionHandler(appBuild));
program
.command('app:serve')
.description('Serve an app for local development')
.action(actionHandler(appServe));
program
.command('create-plugin')
@@ -48,23 +53,23 @@ const main = (argv: string[]) => {
.description('Build a plugin')
.action(actionHandler(pluginBuild));
program
.command('plugin:lint')
.option('--fix', 'Attempt to automatically fix violations')
.description('Lint a plugin')
.action(actionHandler(pluginLint));
program
.command('plugin:serve')
.description('Serves the dev/ folder of a plugin')
.action(actionHandler(pluginServe));
program
.command('plugin:test')
.command('lint')
.option('--fix', 'Attempt to automatically fix violations')
.description('Lint a package')
.action(actionHandler(lintCommand));
program
.command('test')
.option('--watch', 'Enable watch mode')
.option('--coverage', 'Report test coverage')
.description('Run all tests for a plugin')
.action(actionHandler(pluginTest));
.description('Run all tests for package')
.action(actionHandler(testCommand));
program
.command('watch-deps')