plopjs / plop

Consistency Made Simple
http://plopjs.com
MIT License
7.03k stars 276 forks source link

Possible to make a Multi Level Menu / Sub Menu? #421

Open tobiashochguertel opened 5 months ago

tobiashochguertel commented 5 months ago

Is it possible to build a structured menu as following

- React
   | --> Component
   | --> Layout
   | --> Page
   | --> Service
   | --> hook
- TypeSpec (OpenAPI)
   | --> Interface
   | --> Model
- Spring Boot 3
   | --> RestController
   | --> Repository
   | --> ...

When I select React in the first level, that I get then a list of the different plopjs-generators which are sorted under the React menu point?

amwmedia commented 5 months ago

have you tried inquirer tree prompt?

tobiashochguertel commented 4 months ago

inquirer tree prompt helps, but the main question is how to call another generator from inside of a generator?

plop.setGenerator('menu', {
    description: 'Languages / Frameworks',
    prompts: [
        {
            type: 'tree',
            name: 'selection',
            message: 'What would you like to do?',
            validate: (value) => !!value,
            tree: createMenu(frameworks)
        }
    ],
    actions: async function (response) {
        console.log(JSON.stringify(response));
        return await plop.load(`./${response.selection}/generator.js`);
    }
});