You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
portainer/plopfile.js

47 lines
1.3 KiB

module.exports = function (plop) {
// use of INIT_CWD instead of process.cwd() because yarn changes the cwd
const cwd = process.env.INIT_CWD;
plop.addHelper('cwd', () => cwd);
plop.setGenerator('component', {
prompts: [
{
type: 'input',
name: 'name',
message: 'component name please',
},
{
type: 'input',
name: 'module',
message: 'module name please',
default: `${getCurrentPortainerModule(cwd)}`,
// when: false
},
], // array of inquirer prompts
actions: [
{
type: 'add',
path: `{{cwd}}/{{dashCase name}}/index.js`,
templateFile: './plop-templates/component.js.hbs',
},
{
type: 'add',
path: `{{cwd}}/{{dashCase name}}/{{camelCase name}}Controller.js`,
templateFile: './plop-templates/component-controller.js.hbs',
},
{
type: 'add',
path: `{{cwd}}/{{dashCase name}}/{{camelCase name}}.html`,
templateFile: './plop-templates/component.html.hbs',
},
], // array of actions
});
};
function getCurrentPortainerModule(cwd) {
const match = cwd.match(/\/app\/([^\/]*)(\/.*)?$/);
if (!match || !match.length || match[1] === 'portainer') {
return 'app';
}
return match[1];
}