-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplopfile.js
170 lines (155 loc) · 3.57 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// Add node file system
const fs = require('fs');
// Require pkg for us to read useful information
// Like all our projects
const pkg = require('./package.json');
const promptDirectory = require('inquirer-directory');
module.exports = function(plop) {
plop.setPrompt('directory', promptDirectory);
/**
* Generates a Vue Component
*
* Prompts for:
* - Directory
* - If a store is needed or not
* - Component name
*/
plop.setGenerator('Vue component', {
description: 'Generates a Vue component',
prompts: [
{
type: 'input',
name: 'name',
message: 'Name your component:',
},
{
type: 'directory',
name: 'directory',
message: 'Choose parent directory',
basePath: './frontend/src',
},
{
type: 'confirm',
name: 'seperate',
message: 'Add component in its own folder?',
default: true,
},
{
type: 'confirm',
name: 'store',
message: 'Add store?',
default: false,
},
],
actions(data) {
const actions = [];
const templatePath = 'frontend/misc/plop-templates/vue';
const componentPath = (data.seperate)
? 'frontend/src/{{directory}}/{{properCase name}}'
: 'frontend/src/{{directory}}';
// If component has a store
// add all files from store template folder
if (data.store) {
actions.push({
type: 'addMany',
destination: componentPath,
base: templatePath,
templateFiles: `${templatePath}/store/*.js`,
});
}
// Add index.js if in seperate folder
if (data.seperate) {
actions.push({
type: 'add',
path: `${componentPath}/index.js`,
templateFile: `${templatePath}/index.hbs`,
});
}
// Files for all components
actions.push({
type: 'add',
path: `${componentPath}/{{properCase name}}.vue`,
templateFile: `${templatePath}/component.hbs`,
});
actions.push({
type: 'add',
path: `${componentPath}/{{properCase name}}.html`,
templateFile: `${templatePath}/template.hbs`,
});
actions.push({
type: 'add',
path: `${componentPath}/{{properCase name}}.scss`,
templateFile: `${templatePath}/styles.hbs`,
});
return actions;
},
});
/**
* Generates a vue plugin
*
* Prompts for:
* - Directory
* - Service name
*/
plop.setGenerator('Vue plugin', {
description: 'Generates a Vue plugin',
prompts: [
{
type: 'input',
name: 'name',
message: 'Name your Vue plugin:',
},
{
type: 'directory',
name: 'directory',
message: 'Choose parent directory',
basePath: './frontend/src',
},
],
actions(data) {
const actions = [];
const templatePath = 'frontend/misc/plop-templates/vue-plugin';
const destination = 'frontend/src/{{directory}}';
actions.push({
type: 'add',
path: `${destination}/{{properCase name}}/index.js`,
templateFile: `${templatePath}/index.hbs`,
});
return actions;
},
});
/**
* Generates a service
*
* Prompts for:
* - Directory
* - Service name
*/
plop.setGenerator('js module', {
description: 'Generates a simple js module',
prompts: [
{
type: 'input',
name: 'name',
message: 'Name your module:',
},
{
type: 'directory',
name: 'directory',
message: 'Choose parent directory',
basePath: './frontend/src',
},
],
actions(data) {
const actions = [];
const templatePath = 'frontend/misc/plop-templates/js-module';
const destination = 'frontend/src/{{directory}}';
actions.push({
type: 'add',
path: `${destination}/{{properCase name}}/index.js`,
templateFile: `${templatePath}/index.hbs`,
});
return actions;
},
});
};