plop icon indicating copy to clipboard operation
plop copied to clipboard

How to call a generator from another generator

Open AboyL opened this issue 3 years ago • 0 comments

I want to do a function to upgrade one project, for this I need to create a temporary project first, and then move the content of this project from the temporary folder to the project folder, so I need to create a custom generator call other generators, or call a method to process the template, is there a corresponding way?

like


  import { execSync } from 'child_process';
  import chalk from 'chalk';
  
  import path from 'path';
  import { ActionType, CustomActionFunction, NodePlopAPI } from 'plop';
  import { getPackageVersions } from '../utils';
  
  export default function (plop: NodePlopAPI) {
  
      plop.setActionType('migration', async function (answers, config, plop) {
          const v = execSync('git status').toString()
          if (!v.includes('working tree clean')) {
              process.exit()
          }
  
          // call ohter generator
  
          return 'success status message';
      });
  
      plop.setGenerator('migration', {
          description: 'migration',
          prompts: [],
          actions: [{
              type: 'migration'
          }]
      });
  }

AboyL avatar Sep 15 '22 05:09 AboyL