forked from portainer/portainer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plopfile.js
46 lines (45 loc) · 1.27 KB
/
plopfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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}}/{{dashCase name}}.controller.js`,
templateFile: './plop-templates/component-controller.js.hbs',
},
{
type: 'add',
path: `{{cwd}}/{{dashCase name}}/{{dashCase 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];
}