@baseplate-dev/sync
Version:
Library for syncing Baseplate descriptions
27 lines • 1.06 kB
JavaScript
import path from 'node:path';
import { fileURLToPath } from 'node:url';
/**
* Helper utility to create a generator with a standard format for customizable children
*
* @param config Configuration of the generator
* @returns A function that given a descriptor returns the generator bundle
*/
export function createGenerator(config) {
const generatorFilePath = fileURLToPath(config.generatorFileUrl);
const generatorDirectory = path.dirname(generatorFilePath);
return ({ children, ...rest }) => {
const validatedDescriptor = config.descriptorSchema?.parse(rest) ??
{};
const tasks = config.buildTasks(validatedDescriptor);
return {
name: config.name,
instanceName: config.getInstanceName?.(validatedDescriptor),
directory: generatorDirectory,
scopes: config.scopes ?? [],
children: children ?? {},
tasks,
preRegisteredPhases: config.preRegisteredPhases ?? [],
};
};
}
//# sourceMappingURL=create-generator.js.map