UNPKG

@enspirit/emb

Version:

A replacement for our Makefile-for-monorepos

47 lines (46 loc) 1.52 kB
import { getContext } from '../../../index.js'; import * as z from 'zod'; import { ExecuteLocalCommandOperation } from '../../../monorepo/index.js'; import { AbstractOperation } from '../../../operations/index.js'; /** * https://docs.docker.com/reference/cli/docker/compose/restart/ */ const schema = z .object({ services: z .array(z.string()) .optional() .describe('The list of service to restart'), noDeps: z.boolean().optional().describe("Don't restart dependent services"), }) .optional(); export class ComposeRestartOperation extends AbstractOperation { constructor() { super(schema); } async _run(input) { const { monorepo } = getContext(); const manager = monorepo.taskManager(); const command = ['docker', 'compose', 'restart']; if (input?.services) { command.push(...input.services); } if (input?.noDeps) { command.push('--no-deps'); } manager.add([ { async task(ctx, task) { return monorepo.run(new ExecuteLocalCommandOperation(task.stdout()), { script: command.join(' '), workingDir: monorepo.rootDir, }); }, title: input?.services ? `Restarting ${input.services.join(', ')}` : 'Restarting project', }, ]); await manager.runAll(); } }