forked from reactplay/react-play
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplopfile.js
110 lines (104 loc) · 3.21 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
String.prototype.replaceAll = String.prototype.replaceAll || function(string, replaced) {
return this.replace(new RegExp(string, 'g'), replaced);
};
module.exports = plop => {
plop.setHelper('trim', str => str.trim());
plop.setHelper('removeAllSpaces', str => str.replaceAll(/\s/g,''));
plop.setHelper('generateId', str => `pl-${str.trim().replaceAll(/\s/g,'-').toLowerCase()}`);
plop.setHelper('generateFolderName', str => `${str.trim().replaceAll(/\s/g,'-').toLowerCase()}`);
const insertIf = (condition, ...elements) => (condition ? elements : []);
// demo generator
plop.setGenerator('play', {
description: 'Steps to add a new play',
prompts: [
{
type: 'input',
name: 'name',
message: 'Please provide the name of the play(Example: Identity Card):',
},
{
type: 'input',
name: 'description',
message: 'Tell us more about the play(Max 1024 characters):',
},
{
type: 'list',
name: 'language',
message: 'Language to be used (javascript/typescript):',
choices: ['js', 'ts']
},
{
type: 'list',
name: 'style',
message: 'Style to be used (css/scss):',
choices: ['css', 'scss']
},
{
type: 'list',
name: 'level',
message: 'What is the level of this play?(Example: Intermediate):',
choices: ['Beginner', 'Intermediate', 'Advanced']
},
{
type: 'input',
name: 'tags',
message: 'Provide maximum of 5 tags(Example: JSX, Hooks):',
},
{
type: 'input',
name: 'github',
message: 'Enter your github username(Example: atapas):',
},
{
type: 'input',
name: 'cover',
message: 'Please provide the path(URL) to cover image(When the image is hosted publicly):',
},
{
type: 'input',
name: 'blog',
message: 'Enter your blog url(Example: https://blog.greenroots.info):',
},
{
type: 'input',
name: 'video',
message: 'Enter your video url(Example: https://www.youtube.com/watch?v=dQw4w9WgXcQ):',
},
],
actions: [
{
type: 'add',
path: 'src/plays/{{generateFolderName name}}/{{pascalCase name}}.{{language}}x',
templateFile: 'plop-templates/component_{{language}}.hbs',
},
{
type: 'add',
path: 'src/plays/{{generateFolderName name}}/{{camelCase name}}.{{style}}',
templateFile: 'plop-templates/style_{{style}}.hbs',
},
{
type: 'add',
path: 'src/plays/{{generateFolderName name}}/Readme.md',
templateFile: 'plop-templates/play-readme.hbs',
},
{
type: 'modify',
path: 'src/plays/index.js',
pattern: /\/\/add export here/gi,
templateFile: 'plop-templates/exportPlay.hbs',
},
{
type: 'modify',
path: 'src/meta/play-meta.js',
pattern: /\/\/import play here/gi,
templateFile: 'plop-templates/importToMeta.hbs',
},
{
type: 'modify',
path: 'src/meta/play-meta.js',
pattern: /\/\/replace new play item here/gi,
templateFile: 'plop-templates/play.hbs',
},
],
});
};