-
Notifications
You must be signed in to change notification settings - Fork 2
/
plopfile.mjs
73 lines (69 loc) · 1.73 KB
/
plopfile.mjs
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
import _ from 'lodash';
export default function (
/** @type {import('plop').NodePlopAPI} */
plop
) {
plop.setHelper('startCase', (txt) => _.startCase(txt));
plop.setHelper('pascalCase', (txt) => _.startCase(_.camelCase(txt)).replace(/ /g, ''));
plop.setGenerator('api', {
description: 'Add a new api endpoint',
prompts: [
{
type: 'input',
name: 'name',
message: 'Endpoint Name please',
},
{
type: 'input',
name: 'path',
message: 'Page Path please (with trailing slash)',
default: '/',
},
],
actions: function(data) {
return [{
type: 'add',
path: 'src/pages/api/{{pathCase path}}{{dashCase name}}.ts',
templateFile: 'plop-templates/api.hbs',
}]
}
});
plop.setGenerator('page', {
description: 'Add a new page',
prompts: [
{
type: 'input',
name: 'name',
message: 'Page Name please',
},
{
type: 'list',
name: 'type',
message: 'Page Type please',
choices: ['Static Page', 'ServerSide Page'],
},
{
type: 'input',
name: 'path',
message: 'Page Path please (with trailing slash)',
default: '/',
},
],
actions: function(data) {
if (data.type === 'Static Page') {
return [{
type: 'add',
path: 'src/pages/{{path}}{{dashCase name}}.tsx',
templateFile: 'plop-templates/page-static.hbs',
}]
}
if (data.type === 'ServerSide Page') {
return [{
type: 'add',
path: 'src/pages/{{pathCase path}}{{dashCase name}}.tsx',
templateFile: 'plop-templates/page-server.hbs',
}]
}
}
});
};