-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplopfile.js
109 lines (102 loc) · 3.36 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
const commonComponentDir = "common/activity";
const adminAttrsListDefineDir = "admin/src/components/editor/attr/activity";
const adminAttrsListDefinePath = "admin/src/components/editor/tools/attrsListDefine.js";
const adminComponentsDefinePath = "admin/src/components/editor/main/componentsDefine.js";
const webComponentDir = "web/components/activity";
const webServiceDir = "web/service";
const webStoreDir = "web/store/modules/activity";
const webComponentsDefinePath = "web/components/common/componentsDefine.js";
function modifyComponentsMap(targetFilePath, componentPath) {
return {
type: 'modify',
path: targetFilePath,
pattern: /const\s+componentsMap\s*=\s*\{([^}]+)\}/,
template: `const componentsMap = {$1 {{componentName}}: () => import('${componentPath}'),\n}`,
};
}
function modifyAttrMap() {
return {
type: 'modify',
path: adminAttrsListDefinePath,
pattern: /(const\s+attrMap\s*=\s*\{)/,
template: "$1\n {{ componentName }}: {\n" +
" componentList: [\n" +
" {\n" +
" name: '{{ componentName }}',\n" +
" attrs: {}\n" +
" }\n" +
" ]\n" +
" },\n"
};
}
module.exports = function (plop) {
plop.setGenerator("resource", {
description: "Generating a new activity resource",
prompts: [
{
type: "input",
name: "activityName",
message: "Activity name:",
},
{
type: "input",
name: "componentName",
message: "Component name:",
},
],
actions: [
/**
* common
* */
// creating activity directory if it doesn't exist
{
type: 'addMany',
destination: `${commonComponentDir}/{{activityName}}`,
templateFiles: 'plop-templates/activity-directory/**',
base: 'plop-templates/activity-directory',
},
// generating component
{
type: "add",
path: `${commonComponentDir}/{{activityName}}/{{componentName}}.vue`,
templateFile: "plop-templates/component.vue.hbs",
},
/**
* admin
*/
// generating component attribute
{
type: "add",
path: `${adminAttrsListDefineDir}/{{activityName}}/{{componentName}}.vue`,
templateFile: "plop-templates/component-attr.vue.hbs",
},
modifyAttrMap(),
modifyComponentsMap(adminAttrsListDefinePath, `~/editor/attr/activity/{{activityName}}/{{componentName}}.vue`),
modifyComponentsMap(adminComponentsDefinePath, `$root/${commonComponentDir}/{{activityName}}/{{componentName}}.vue`),
/**
* web
*/
// generating component
{
type: "add",
path: `${webComponentDir}/{{activityName}}/{{componentName}}.vue`,
templateFile: "plop-templates/component-web.vue.hbs",
},
// generating service
{
type: "add",
path: `${webServiceDir}/{{activityName}}.ts`,
templateFile: "plop-templates/component-service.ts.hbs",
skipIfExists: true,
},
// generating store
{
type: "add",
path: `${webStoreDir}/{{activityName}}/index.ts`,
templateFile: "plop-templates/component-store.ts.hbs",
skipIfExists: true,
},
modifyComponentsMap(webComponentsDefinePath, `@/components/activity/{{activityName}}/{{componentName}}.vue`),
],
});
};