UNPKG

@enspirit/emb

Version:

A replacement for our Makefile-for-monorepos

54 lines (53 loc) 1.49 kB
import { toIdentifedHash } from '../index.js'; import deepMerge from '@fastify/deepmerge'; export class MonorepoConfig { project; defaults; env; flavors; plugins; vars; tasks; components; constructor(config) { this.defaults = config.defaults || {}; this.project = config.project; this.vars = config.vars || {}; this.flavors = config.flavors || {}; this.env = config.env || {}; this.plugins = config.plugins || []; this.tasks = toIdentifedHash(config.tasks || {}); this.components = config.components || {}; } component(id) { const config = this.components[id]; if (!config) { throw new Error(`Unknown component ${id}`); } return config; } flavor(name) { const flavor = this.flavors[name]; if (!flavor) { throw new Error(`Unknown flavor: ${name}`); } return flavor; } toJSON() { return structuredClone({ components: this.components, defaults: this.defaults, env: this.env, flavors: this.flavors, plugins: this.plugins, project: this.project, tasks: this.tasks, vars: this.vars, }); } with(overrides) { const oldConfig = this.toJSON(); const newConfig = deepMerge()(oldConfig, overrides); return new MonorepoConfig(newConfig); } }