Skip to content

Commit

Permalink
feat(cli): add a webstone deploy web CLI command
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Nikles authored and mikenikles committed Oct 9, 2021
1 parent d47bbbb commit 2ecb412
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/wild-fireants-doubt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@webstone/cli": minor
---

Add a `webstone deploy web` CLI command.
4 changes: 2 additions & 2 deletions packages/cli/docs/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ This is then accessible in your plugin's commands as `toolbox.bar`.

# Loading a plugin

To load a particular plugin (which has to start with `cli-*`),
install it to your project using `npm install --save-dev cli-PLUGINNAME`,
To load a particular plugin (which has to start with `webstone-cli-*`),
install it to your project using `pnpm install --save-dev webstone-cli-PLUGINNAME`,
and cli will pick it up automatically.
34 changes: 34 additions & 0 deletions packages/cli/src/commands/deploy/web.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import type { WebstoneToolbox } from "../../extensions/web";

import { GluegunCommand } from "gluegun";

const command: GluegunCommand = {
// @ts-ignore: WebstoneToolbox extends GluegunToolbox, ignore TS error.
run: async (toolbox: WebstoneToolbox) => {
const { parameters, print, system, web } = toolbox;

if (!web.configure.deployment.isAnyAdapterInstalled()) {
print.warning(
"No deployment adapter configured. Please run `pnpm webstone web configure deployment` to fix this before you deploy the application."
);
return;
}

const buildSpinner = print.spin(`Building the web service...`);
await system.run(`pnpm build --filter ./services/web`);
buildSpinner.succeed();

if (parameters.options.preview) {
print.info(`Previewing the web service...`);
await system.exec(`pnpm preview --filter ./services/web`, {
stdout: "inherit",
});
} else {
print.highlight(
`TODO: Link to deployment docs for the ${web.configure.deployment.getInstalledAdapterPackageName()} adapter.`
);
}
},
};

module.exports = command;
6 changes: 2 additions & 4 deletions packages/cli/src/commands/web/configure/deployment.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import type { GluegunCommand, GluegunToolbox } from "gluegun";
import type { WebToolbox } from "../../../extensions/web/types";

interface WebstoneToolbox extends GluegunToolbox, WebToolbox {}
import type { GluegunCommand } from "gluegun";
import type { WebstoneToolbox } from "../../../extensions/web";

const command: GluegunCommand = {
// @ts-ignore: WebstoneToolbox extends GluegunToolbox, ignore TS error.
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/extensions/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import type { WebToolbox } from "./web/types";

import webConfigureDeployment from "./web/configure/deployment";

export interface WebstoneToolbox extends GluegunToolbox, WebToolbox {}

export default (toolbox: GluegunToolbox) => {
const webToolbox: WebToolbox = {
web: {
Expand Down

0 comments on commit 2ecb412

Please sign in to comment.