diff --git a/packages/cli/src/commands/plugin/build.ts b/packages/cli/src/commands/plugin/build.ts new file mode 100644 index 0000000000..31c542ff27 --- /dev/null +++ b/packages/cli/src/commands/plugin/build.ts @@ -0,0 +1,25 @@ +import chalk from 'chalk'; +import { Command } from 'commander'; +import { spawnSync } from 'child_process'; + +export default async (cmd: Command) => { + const args = [ + '--outDir', + 'dist/cjs', + '--noEmit', + 'false', + '--module', + 'CommonJS', + ]; + + if (cmd.watch) { + args.push('--watch'); + } + + try { + spawnSync('tsc', args, { stdio: 'inherit' }); + } catch (error) { + process.stderr.write(`${chalk.red(error.message)}\n`); + process.exit(1); + } +}; diff --git a/packages/cli/src/commands/plugin/lint.ts b/packages/cli/src/commands/plugin/lint.ts new file mode 100644 index 0000000000..133f449313 --- /dev/null +++ b/packages/cli/src/commands/plugin/lint.ts @@ -0,0 +1,13 @@ +import chalk from 'chalk'; +import { spawnSync } from 'child_process'; + +export default async () => { + const args = ['lint']; + + try { + spawnSync('web-scripts', args, { stdio: 'inherit' }); + } catch (error) { + process.stderr.write(`${chalk.red(error.message)}\n`); + process.exit(1); + } +}; diff --git a/packages/cli/src/commands/serve/config.ts b/packages/cli/src/commands/plugin/serve/config.ts similarity index 100% rename from packages/cli/src/commands/serve/config.ts rename to packages/cli/src/commands/plugin/serve/config.ts diff --git a/packages/cli/src/commands/serve/index.ts b/packages/cli/src/commands/plugin/serve/index.ts similarity index 100% rename from packages/cli/src/commands/serve/index.ts rename to packages/cli/src/commands/plugin/serve/index.ts diff --git a/packages/cli/src/commands/serve/paths.ts b/packages/cli/src/commands/plugin/serve/paths.ts similarity index 100% rename from packages/cli/src/commands/serve/paths.ts rename to packages/cli/src/commands/plugin/serve/paths.ts diff --git a/packages/cli/src/commands/serve/server.ts b/packages/cli/src/commands/plugin/serve/server.ts similarity index 100% rename from packages/cli/src/commands/serve/server.ts rename to packages/cli/src/commands/plugin/serve/server.ts diff --git a/packages/cli/src/commands/plugin/test.ts b/packages/cli/src/commands/plugin/test.ts new file mode 100644 index 0000000000..c881bbdfcb --- /dev/null +++ b/packages/cli/src/commands/plugin/test.ts @@ -0,0 +1,18 @@ +import chalk from 'chalk'; +import { Command } from 'commander'; +import { spawnSync } from 'child_process'; + +export default async (cmd: Command) => { + const args = ['test']; + + if (cmd.watch) { + args.push('--watch'); + } + + try { + spawnSync('web-scripts', args, { stdio: 'inherit' }); + } catch (error) { + process.stderr.write(`${chalk.red(error.message)}\n`); + process.exit(1); + } +}; diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts index 2c0f6c0ce6..f8277756d9 100644 --- a/packages/cli/src/index.ts +++ b/packages/cli/src/index.ts @@ -3,7 +3,10 @@ import chalk from 'chalk'; import fs from 'fs'; import createPluginCommand from './commands/createPlugin'; import watch from './commands/watch-deps'; -import serve from './commands/serve'; +import pluginBuild from './commands/plugin/build'; +import pluginLint from './commands/plugin/lint'; +import pluginServe from './commands/plugin/serve'; +import pluginTest from './commands/plugin/test'; process.on('unhandledRejection', err => { throw err; @@ -20,9 +23,26 @@ const main = (argv: string[]) => { .action(createPluginCommand); program - .command('serve') - .description('Serves the dev/ folder of a package') - .action(serve); + .command('plugin:build') + .option('--watch', 'Enable watch mode') + .description('Build a plugin') + .action(pluginBuild); + + program + .command('plugin:lint') + .description('Lint a plugin') + .action(pluginLint); + + program + .command('plugin:serve') + .description('Serves the dev/ folder of a plugin') + .action(pluginServe); + + program + .command('plugin:test') + .option('--watch', 'Enable watch mode') + .description('Run all tests for a plugin') + .action(pluginTest); program .command('watch-deps') diff --git a/packages/cli/templates/default-plugin/package.json.hbs b/packages/cli/templates/default-plugin/package.json.hbs index 709b65a7f9..2acd60ca26 100644 --- a/packages/cli/templates/default-plugin/package.json.hbs +++ b/packages/cli/templates/default-plugin/package.json.hbs @@ -5,13 +5,12 @@ "license": "Apache-2.0", "private": false, "scripts": { - "build": "tsc --outDir dist/cjs --noEmit false --module CommonJS", - "lint": "web-scripts lint", - "test": "web-scripts test" + "build": "backstage-cli plugin:build", + "lint": "backstage-cli plugin:lint", + "test": "backstage-cli plugin:test" }, "devDependencies": { - "@spotify-backstage/cli": "^1.2.0", - "@spotify/web-scripts": "^6.0.0" + "@spotify-backstage/cli": "^1.2.0" }, "dependencies": { "@material-ui/lab": "4.0.0-alpha.45" diff --git a/packages/plugins/hello-world/package.json b/packages/plugins/hello-world/package.json index a1d1222a6a..0fa2e21355 100644 --- a/packages/plugins/hello-world/package.json +++ b/packages/plugins/hello-world/package.json @@ -7,7 +7,6 @@ "@spotify-backstage/core": "1.0.0", "@material-ui/core": "^4.9.1", "@material-ui/icons": "^4.9.1", - "@spotify/web-scripts": "^6.0.0", "@testing-library/jest-dom": "^4.2.4", "@testing-library/react": "^9.3.2", "@testing-library/user-event": "^7.1.2", @@ -21,9 +20,9 @@ "react-dom": "^16.12.0" }, "scripts": { - "build": "tsc --outDir dist/cjs --noEmit false --module CommonJS", - "lint": "web-scripts lint", - "test": "web-scripts test" + "build": "backstage-cli plugin:build", + "lint": "backstage-cli plugin:lint", + "test": "backstage-cli plugin:test" }, "license": "Apache-2.0" } diff --git a/packages/plugins/home-page/package.json b/packages/plugins/home-page/package.json index 0d32c64015..2aa002c109 100644 --- a/packages/plugins/home-page/package.json +++ b/packages/plugins/home-page/package.json @@ -5,7 +5,6 @@ "devDependencies": { "@spotify-backstage/cli": "^1.2.0", "@spotify-backstage/core": "1.0.0", - "@spotify/web-scripts": "^6.0.0", "@testing-library/jest-dom": "^4.2.4", "@testing-library/react": "^9.3.2", "@testing-library/user-event": "^7.1.2", @@ -19,9 +18,9 @@ "@material-ui/icons": "^4.9.1" }, "scripts": { - "build": "tsc --outDir dist/cjs --noEmit false --module CommonJS", - "lint": "web-scripts lint", - "test": "web-scripts test" + "build": "backstage-cli plugin:build", + "lint": "backstage-cli plugin:lint", + "test": "backstage-cli plugin:test" }, "license": "Apache-2.0" }