nicoalbanese / kirimase

Build full-stack Next.js apps, incredibly fast
https://kirimase.dev
MIT License
2.39k stars 107 forks source link

[Feature Request] Create plugin functionality to allow extending generate prompts and templates #143

Open vkefallinos opened 4 months ago

vkefallinos commented 4 months ago

Is your feature request related to a problem? Please describe.

I am trying to add functionality to the generate cli

Describe the solution you'd like

A plugin functionality that allows to add resource types and prompts or add options on the existing resource types. It will then use the prompt answers to scaffold files.

Additional context

A plugin example is

import { select } from 'inquirer'
export default {
  name: 'admin',
  plugin(options) {
    return {
      resources: [{
        name: 'admin_view',
        label: 'Admin View',
        condition: (config) => config.adminView,
        prompt: async (config, resourceTypes,) => {
          const { adminView } = await select({
            name: 'adminView',
            message: 'Which admin view would you like to use?',
            choices: [
              { name: 'Dashboard', value: 'dashboard' },
              { name: 'Entities', value: 'entities' },
            ],
          });
          return { adminView };
        },
        generate: async (config, schema) => {
          if (schema.adminView === 'dashboard') {
            return [{
              path: 'pages/Admin.tsx',
              content: `import ...`
            }]
          }
        }
      }]
    };
  }
};

The beginning of an implementation here: https://github.com/vkefallinos/kirimase/blob/e77574f5e72cee05459f66acd2e3cc6da041d0bc/src/commands/generate/index.ts