@enspirit/emb
Version:
A replacement for our Makefile-for-monorepos
17 lines (16 loc) • 520 B
JavaScript
export class ResourceFactory {
static types = {};
static register(type, constructor) {
if (this.types[type]) {
throw new Error(`Resource type \`${type}\` already registered`);
}
this.types[type] = constructor;
}
static factor(type, context) {
const BuilderClass = this.types[type];
if (!BuilderClass) {
throw new Error(`Unknown resource type \`${type}\` (${context.config.id})`);
}
return new BuilderClass(context);
}
}