-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplopfile.js
162 lines (162 loc) · 3.51 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
const ACTIONS = {
addClass: {
prompts: [
{
type: "input",
name: "name",
message: "class name",
},
],
actions: [
{
type: "add",
path: "php/{{camelCase name}}.php",
templateFile: "plop-templates/Class.hbs",
},
],
},
addInterface: {
prompts: [
{
type: "input",
name: "name",
message: "interface name",
},
],
actions: [
{
type: "add",
path: "php/Contracts/{{camelCase name}}.php",
templateFile: "plop-templates/Interface.hbs",
},
],
},
addMetabox: {
prompts: [
{
type: "input",
name: "name",
message: "class name",
},
],
actions: [
{
type: "add",
path: "php/Metaboxes/{{camelCase name}}.php",
templateFile: "plop-templates/Metabox.hbs",
},
],
},
};
const GENERATORS = [
function phpClass(plop) {
plop.setGenerator("class", {
description: "Add a php class",
...ACTIONS.addClass,
});
},
function event(plop) {
plop.setGenerator("event", {
description: "application controller logic",
prompts: [
ACTIONS.addClass.prompts[0],
//id
{
type: "input",
name: "id",
message: "slug case unique id for event",
},
//Title
{
type: "input",
name: "title",
message: "Label for event",
},
//Hook name
{
type: "input",
name: "hook",
message: "WordPress hook name",
},
],
actions: [
{
type: "add",
path: "php/Events/{{camelCase name}}.php",
templateFile: "plop-templates/Event.hbs",
},
],
});
},
function endpoint(plop) {
// controller generator
plop.setGenerator("endpoint", {
description: "application controller logic",
prompts: [
ACTIONS.addClass.prompts[0],
{
type: "input",
name: "route",
message: "endpoint",
},
],
actions: [
{
type: "add",
path: "php/Endpoints/{{camelCase name}}.php",
templateFile: "plop-templates/Endpoint.hbs",
},
],
});
},
function addInterface(plop) {
plop.setGenerator("interface", {
description: "Add a php interface",
...ACTIONS.addInterface,
});
},
//Metabox
function (plop) {
plop.setGenerator("metabox", {
description: "Add a post editor metabox",
...ACTIONS.addMetabox,
});
}
];
const PARTIALS = [
//Link to WordPress reference for a class
//Usage: {{> wpDocsClass }}
function (plop) {
plop.setPartial('wpDocsClass', '@see https://developer.wordpress.org/reference/classes/{{class}}/');
},
//Link to WordPress reference for a function
//Usage: {{> wpDocsFunction }}
function (plop) {
plop.setPartial('wpDocsFunction', '@see https://developer.wordpress.org/reference/functions/{{function}}/');
},
//Link to WordPress reference for a hook
//Usage: {{> wpDocsHook }}
function (plop) {
plop.setPartial('wpDocsHook', '@see https://developer.wordpress.org/reference/hooks/{{hook}}/');
},
];
module.exports = function (plop) {
//To uppercase
plop.setHelper("upperCase", function (text) {
return text.toUpperCase();
});
//To CamelCase
plop.setHelper("camelCase", function (text) {
return (
text.substring(0, 1).toUpperCase() +
text
.substring(1)
.replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) {
return index === 0 ? word.toLowerCase() : word.toUpperCase();
})
.replace(/\s+/g, "")
);
});
GENERATORS.forEach(generator => generator(plop));
PARTIALS.forEach(partial => partial(plop));
};