import { createImplementation } from "@webiny/di"; import { CliCommandFactory } from "@webiny/cli-core/abstractions/index.js"; import { StdioService } from "@webiny/cli-core/abstractions/index.js"; import { UiService } from "@webiny/cli-core/abstractions/index.js"; import { ManuallyReportedError } from "@webiny/cli-core/utils/ManuallyReportedError.js"; import { IBaseAppParams } from "@webiny/cli-core/abstractions/features/types.js"; import { createBaseAppOptions } from "@webiny/cli-core/features/common/index.js"; import { GetAwsProjectSdkService } from "~/abstractions/GetAwsProjectSdkService.js"; export interface IPulumiCommandParams extends IBaseAppParams { command: string[]; } export class PulumiCommand implements CliCommandFactory.Interface { constructor( private getAwsProjectSdkService: GetAwsProjectSdkService.Interface, private uiService: UiService.Interface, private stdioService: StdioService.Interface ) {} async execute(): Promise> { const projectSdk = await this.getAwsProjectSdkService.execute(); return { name: "pulumi", description: 'Runs a Pulumi command in the provided project application folder. Note: make sure to use "--" before the actual Pulumi command', examples: ["$0 pulumi api --env dev -- config set foo bar --secret"], params: [ { name: "app", description: "Name of the app (core, admin, or api)", type: "string", required: true } ], options: createBaseAppOptions(projectSdk), handler: async (params: IPulumiCommandParams) => { const projectSdk = await this.getAwsProjectSdkService.execute(); try { const [, ...command] = params._ || []; const { pulumiProcess } = await projectSdk.runPulumiCommand({ ...params, command }); pulumiProcess.stdin?.pipe(this.stdioService.getStdin()); pulumiProcess.stdout?.pipe(this.stdioService.getStdout()); pulumiProcess.stderr?.pipe(this.stdioService.getStderr()); } catch (error) { throw ManuallyReportedError.from(error); } } }; } } export const pulumiCommand = createImplementation({ abstraction: CliCommandFactory, implementation: PulumiCommand, dependencies: [GetAwsProjectSdkService, UiService, StdioService] });