Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/cli-core/src/abstractions/features/Command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface ICommandParamDefinition<TCommandParams> {
description: string;
type: "boolean" | "number" | "string";
required?: boolean;
array?: boolean;
default?: any;
validation?: (value: TCommandParams) => boolean | string;
}
Expand Down
39 changes: 28 additions & 11 deletions packages/cli-core/src/features/DeployCommand/DeployCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,26 @@ import open from "open";
// TODO: convert to a real service.
import { PrintInfoForEnv } from "~/features/InfoCommand/PrintInfoForEnv.js";

export interface IDeployNoAppParams {
export interface IDeployCommandParams {
apps?: AppName[];
variant?: string;
region?: string;
env: string;
deploymentLogs?: boolean;
build?: boolean;
preview?: boolean;
}

export interface IDeployWithAppParams extends IDeployNoAppParams {
export interface IDeploySingleAppParams {
app: AppName;
variant?: string;
region?: string;
env: string;
deploymentLogs?: boolean;
build?: boolean;
preview?: boolean;
}

export type IDeployCommandParams = IDeployNoAppParams | IDeployWithAppParams;

const sleep = (ms: number = 1500) => setTimeout(ms);

export class DeployCommand implements Command.Interface<IDeployCommandParams> {
Expand All @@ -43,15 +48,18 @@ export class DeployCommand implements Command.Interface<IDeployCommandParams> {
description: "Deploys specified app or all apps in the project",
examples: [
"$0 deploy api --env dev",
"$0 deploy core api --env dev",
"$0 deploy admin --env prod",
"$0 deploy --env prod",
"$0 deploy"
],
params: [
{
name: "app",
description: "Name of the app (core, admin, or api)",
type: "string"
name: "apps",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather have a single app parameter, that is a single app or an array of apps. Or maybe even... Let's have it always be an array? Like apps: AppName[].

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplified to always use apps?: AppName[] as an optional array in a single IDeployCommandParams interface. Removed the separate IDeployNoAppParams and IDeployWithAppParams interfaces. Commit: 2568d72 → new commit

description:
"Name of the app(s) to deploy (core, admin, or api). You can specify multiple apps.",
type: "string",
array: true
}
],
options: [
Expand All @@ -61,7 +69,7 @@ export class DeployCommand implements Command.Interface<IDeployCommandParams> {
type: "string",
default: "dev",
validation: params => {
if ("app" in params && !params.env) {
if (params.apps && params.apps.length > 0 && !params.env) {
throw new Error("Environment name is required when deploying an app.");
}
return true;
Expand Down Expand Up @@ -111,8 +119,17 @@ export class DeployCommand implements Command.Interface<IDeployCommandParams> {
}
],
handler: async (params: IDeployCommandParams) => {
if ("app" in params) {
await this.deployApp(params);
if (params.apps && params.apps.length > 0) {
// Deploy specified apps
for (const app of params.apps) {
const appParams: IDeploySingleAppParams = {
...params,
app
};
ui.info("Deploying %s app...", app.charAt(0).toUpperCase() + app.slice(1));
await this.deployApp(appParams);
ui.newLine();
}
} else {
const isCi = projectSdk.isCi();
const coreStack = await projectSdk.getAppStackOutput({
Expand Down Expand Up @@ -195,7 +212,7 @@ export class DeployCommand implements Command.Interface<IDeployCommandParams> {
};
}

private async deployApp(params: IDeployWithAppParams) {
private async deployApp(params: IDeploySingleAppParams) {
const projectSdk = await this.getProjectSdkService.execute();

const ui = this.uiService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { UiService, StdioService } from "~/abstractions/index.js";
import { IDeployWithAppParams } from "../DeployCommand.js";
import { IDeploySingleAppParams } from "../DeployCommand.js";
import { ExecaChildProcess } from "execa";

export type IDeployProcess = ExecaChildProcess<string>;
Expand All @@ -9,15 +9,15 @@ export interface IBaseDeployOutputParams {
stdio: StdioService.Interface;
ui: UiService.Interface;
showDeploymentLogs: boolean;
deployParams: IDeployWithAppParams;
deployParams: IDeploySingleAppParams;
}

export class BaseDeployOutput {
public readonly deployProcess: IDeployProcess;
public readonly stdio: StdioService.Interface;
public readonly ui: UiService.Interface;
public readonly showDeploymentLogs: boolean;
public readonly deployParams: IDeployWithAppParams;
public readonly deployParams: IDeploySingleAppParams;

public constructor({
deployProcess,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ export class DefaultGetCliRunnerService implements GetCliRunnerService.Interface
" " +
params
.map(param => {
return param.required ? `<${param.name}>` : `[${param.name}]`;
const paramName = param.array ? `${param.name}..` : param.name;
return param.required ? `<${paramName}>` : `[${paramName}]`;
})
.join(" ");
}
Expand All @@ -136,10 +137,11 @@ export class DefaultGetCliRunnerService implements GetCliRunnerService.Interface
description,
yargs => {
params.forEach((param: Command.ParamDefinition<unknown>) => {
const { name, required, validation, ...rest } = param;
const { name, required, validation, array, ...rest } = param;

const yargsParam = yargs.positional(name, {
...rest,
...(array && { array: true }),
demandOption: required
});

Expand Down
8 changes: 4 additions & 4 deletions webiny.config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ export default () => {
Core, API, and Admin Pulumi apps that we deploy by default. */}
<Infra.PulumiResourceNamePrefix prefix={"myproj-"} />
<Infra.ProductionEnvironments environments={["prod", "staging"]} />
<Infra.Api.BeforeDeploy src={"./extensions/myApiBeforeDeploy.ts"} />
<Infra.Api.BeforeBuild src={"./extensions/myApiBeforeBuild.ts"} />
<Infra.Api.AfterDeploy src={"./extensions/myApiAfterDeploy.ts"} />
<Infra.Api.AfterBuild src={"./extensions/myApiAfterBuild.ts"} />
{/*<Infra.Api.BeforeDeploy src={"./extensions/myApiBeforeDeploy.ts"} />*/}
{/*<Infra.Api.BeforeBuild src={"./extensions/myApiBeforeBuild.ts"} />*/}
{/*<Infra.Api.AfterDeploy src={"./extensions/myApiAfterDeploy.ts"} />*/}
{/*<Infra.Api.AfterBuild src={"./extensions/myApiAfterBuild.ts"} />*/}

<Infra.Core.Pulumi src={"./extensions/myCorePulumiHandler2.ts"} />

Expand Down
Loading