@enspirit/emb
Version:
A replacement for our Makefile-for-monorepos
48 lines (47 loc) • 1.51 kB
JavaScript
import { getContext } from '../../../index.js';
import * as z from 'zod';
import { ExecuteLocalCommandOperation, taskManagerFactory } from '../../../monorepo/index.js';
import { AbstractOperation } from '../../../operations/index.js';
/**
* https://docs.docker.com/reference/cli/docker/compose/up/
*/
const schema = z
.object({
components: z
.array(z.string())
.optional()
.describe('The list of service to up'),
forceRecreate: z
.boolean()
.optional()
.describe("Recreate containers even if their configuration and image haven't changed"),
})
.optional();
export class ComposeUpOperation extends AbstractOperation {
constructor() {
super(schema);
}
async _run(input) {
const { monorepo } = getContext();
const manager = taskManagerFactory();
const command = ['docker', 'compose', 'up', '-d'];
if (input?.components) {
command.push(...input.components);
}
if (input?.forceRecreate) {
command.push('--force-recreate');
}
manager.add([
{
async task(ctx, task) {
return monorepo.run(new ExecuteLocalCommandOperation(task.stdout()), {
script: command.join(' '),
workingDir: monorepo.rootDir,
});
},
title: 'Starting project',
},
]);
await manager.runAll();
}
}