UNPKG

@enspirit/emb

Version:

A replacement for our Makefile-for-monorepos

37 lines (36 loc) 1.14 kB
import { statfs } from 'node:fs/promises'; import { CreateFileOperation, } from '../index.js'; import { ResourceFactory } from './ResourceFactory.js'; export class FileResourceBuilder { context; constructor(context) { this.context = context; } async getReference() { return this.context.component.relative(this.context.config.params?.path || this.context.config.name); } async getPath() { return this.context.component.join(this.context.config.params?.path || this.context.config.name); } async mustBuild() { try { await statfs(await this.getPath()); } catch { return true; } } async build(resource, out) { const input = { path: await this.getPath(), script: resource.params?.script, cwd: this.context.component.join('./'), }; return { input, operation: new CreateFileOperation(out), }; } } // Bring better abstraction and register as part of the plugin initialization ResourceFactory.register('file', FileResourceBuilder);