Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function getPlopGenerator(plopfilePath: string, destBasePath: string, stackName: string) {
const plopfile = path.join(plopfilePath, 'plopfile.js');
const plop = nodePlop(plopfile, { destBasePath, force: false });
// Automatically inject some plop helpers
const justPlopHelpers = require.resolve('just-plop-helpers');
(plop as any).load(justPlopHelpers);
let generator = plop.getGenerator(`repo:${stackName}`) as any;
// Automatically inject a task of running the repo:parent actions
if (generator.parent) {
plop.setActionType('repo:parent', async (answers, _config, _plop) => {
const parentPlopPath = (await downloadPackage(generator.parent))!;
const parentPlopFilePath = path.join(parentPlopPath, 'plopfile.js');
const parentPlop = nodePlop(parentPlopFilePath, { destBasePath, force: false });
(parentPlop as any).load(justPlopHelpers);
export const handler = async argv => {
const plopPath = path.resolve(__dirname, './plopfile.js');
const plop = nodePlop(plopPath);
const generator = plop.getGenerator('source');
generator
.runPrompts(argv.name ? [argv.name] : [])
.then(generator.runActions)
.then(obj => {
obj.changes.forEach(({ path }) => console.log('[SUCCESS]', path));
obj.failures.forEach(({ error }) => console.log('[FAIL]', error));
console.log(`Created data-source-${argv.name}`);
});
};
plop.setActionType('repo:parent', async (answers, _config, _plop) => {
const parentPlopPath = (await downloadPackage(generator.parent))!;
const parentPlopFilePath = path.join(parentPlopPath, 'plopfile.js');
const parentPlop = nodePlop(parentPlopFilePath, { destBasePath, force: false });
(parentPlop as any).load(justPlopHelpers);
const parentGenerator = parentPlop.getGenerator(`repo:${generator.parent}`) as any;
const results = await parentGenerator.runActions(answers);
if (results.changes) {
return results.changes.map(change => change.path).join('\n');
}
});
}