| 16 | choices: plop.getGeneratorList().map((v) => v.name), |
| 17 | }), |
| 18 | async handler(args) { |
| 19 | let template: string; |
| 20 | |
| 21 | if (!args.template) { |
| 22 | const res = await inquirer.prompt([ |
| 23 | { |
| 24 | type: 'list', |
| 25 | name: 'template', |
| 26 | message: 'Choose Template', |
| 27 | choices: plop.getGeneratorList().map((v) => ({ |
| 28 | name: `${v.name} (${v.description})`, |
| 29 | value: v.name, |
| 30 | })), |
| 31 | }, |
| 32 | ]); |
| 33 | template = String(res.template); |
| 34 | } else { |
| 35 | template = String(args.template); |
| 36 | } |
| 37 | |
| 38 | const basic = plop.getGenerator(template); |
| 39 | |
| 40 | const answers = await basic.runPrompts(); |
| 41 | const results = await basic.runActions(answers); |
| 42 | |
| 43 | console.log('Changes:'); |
| 44 | console.log(results.changes.map((change) => change.path).join('\n')); |
| 45 | |
| 46 | if (results.failures.length > 0) { |
| 47 | console.log('Operation failed:'); |
| 48 | console.log(results.failures); |
| 49 | } |
| 50 | }, |
| 51 | }; |