39 lines
1006 B
TypeScript
39 lines
1006 B
TypeScript
import { defineCommand } from "citty";
|
|
import { Listr } from "listr2";
|
|
import { apiRequest, type ApiRequestInit } from "../lib/api";
|
|
import { ctx } from "../lib/context";
|
|
|
|
type LifecycleResponse = { deployments: string[] };
|
|
export type StopApiRequest = <T>(
|
|
path: string,
|
|
init?: ApiRequestInit,
|
|
) => Promise<T>;
|
|
|
|
export function runStop(
|
|
project: string,
|
|
request: StopApiRequest = apiRequest,
|
|
): Promise<LifecycleResponse> {
|
|
return request<LifecycleResponse>(
|
|
`/workspaces/${encodeURIComponent(project)}/lifecycle`,
|
|
{ method: "POST", json: { action: "stop" } },
|
|
);
|
|
}
|
|
|
|
export const stop = defineCommand({
|
|
meta: {
|
|
name: "stop",
|
|
description: "Scale managed deployments to zero",
|
|
},
|
|
async run() {
|
|
await new Listr([
|
|
{
|
|
title: "Scale deployments",
|
|
task: async (_ctx, task) => {
|
|
const { deployments } = await runStop(ctx().project);
|
|
task.output = `${deployments.length} deployments queued`;
|
|
},
|
|
},
|
|
]).run();
|
|
},
|
|
});
|