Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
32 changes: 26 additions & 6 deletions packages/cli-core/src/features/DeployCommand/DeployCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ export interface IDeployNoAppParams {
}

export interface IDeployWithAppParams extends IDeployNoAppParams {
apps: AppName[];
build?: boolean;
preview?: boolean;
}

export interface IDeploySingleAppParams extends IDeployNoAppParams {
app: AppName;
build?: boolean;
preview?: boolean;
Expand All @@ -43,14 +49,16 @@ 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)",
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.

Do we want to use this weird syntax?

Can't we just make it array: true?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to use array: true property instead of the apps.. syntax. The parameter definition now explicitly declares array: true, which is cleaner and more intuitive. Commit: ada5145 → new commit

description:
"Name of the app(s) to deploy (core, admin, or api). You can specify multiple apps.",
type: "string"
}
],
Expand All @@ -61,7 +69,12 @@ export class DeployCommand implements Command.Interface<IDeployCommandParams> {
type: "string",
default: "dev",
validation: params => {
if ("app" in params && !params.env) {
if (
"apps" in params &&
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 +124,15 @@ export class DeployCommand implements Command.Interface<IDeployCommandParams> {
}
],
handler: async (params: IDeployCommandParams) => {
if ("app" in params) {
await this.deployApp(params);
if ("apps" in params && params.apps && params.apps.length > 0) {
// Deploy specified apps
for (const app of params.apps) {
const appParams = { ...params, app };
ui.info("Deploying %s app...", app.charAt(0).toUpperCase() + app.slice(1));
await this.deployApp(appParams);
ui.newLine();
}
ui.success(`Apps deployed: ${params.apps.join(", ")}`);
} else {
const isCi = projectSdk.isCi();
const coreStack = await projectSdk.getAppStackOutput({
Expand Down Expand Up @@ -195,7 +215,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 @@ -138,8 +138,13 @@ export class DefaultGetCliRunnerService implements GetCliRunnerService.Interface
params.forEach((param: Command.ParamDefinition<unknown>) => {
const { name, required, validation, ...rest } = param;

const yargsParam = yargs.positional(name, {
// Handle variadic parameters (those ending with ..)
const isVariadic = name.endsWith("..");
const positionalName = isVariadic ? name.slice(0, -2) : name;

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

Expand Down
Loading