UNPKG

@enspirit/emb

Version:

A replacement for our Makefile-for-monorepos

36 lines (35 loc) 1.16 kB
import { DockerComposeClient, getContext, setContext } from '../../index.js'; import { Command, Performance } from '@oclif/core'; import Dockerode from 'dockerode'; import { loadConfig } from '../../config/index.js'; import { Monorepo } from '../../monorepo/monorepo.js'; const withMarker = async (owner, name, cb) => { const marker = Performance.mark(owner, name); const res = await cb(); marker?.stop(); return res; }; export class BaseCommand extends Command { context; async init() { await super.init(); if (getContext()) { return; } try { const { rootDir, config } = await withMarker('emb:config', 'load', () => loadConfig()); const monorepo = await withMarker('emb:monorepo', 'init', () => { return new Monorepo(config, rootDir).init(); }); const compose = new DockerComposeClient(monorepo); this.context = setContext({ docker: new Dockerode(), monorepo, compose, }); } catch (error) { this.error(error); } } }