forked from codebdy/rxdrag
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plopfile.js
127 lines (124 loc) · 3.5 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
const Handlebars = require('handlebars');
module.exports = function (plop) {
plop.setHelper('titleCaseWithoutSpace', function (text) {
// Remove spaces in case text is hyphenated
const template = Handlebars.compile('{{titleCase text}}');
const titleCased = template({ text });
return titleCased.split(/\s/).join('');
});
plop.setGenerator('app', {
description: 'Adds a new app to Rxdrag',
prompts: [
{
type: 'input',
name: 'name',
message: 'app package name',
default: 'app-name',
validate: name => {
if (/\s/g.test(name)) {
throw new Error("Name can't have spaces");
}
return true;
},
transformer: name => name.toLowerCase()
},
{
type: 'input',
name: 'description',
message: 'app description',
default: 'Rxdrag Application'
},
{
type: 'input',
name: 'maintainer',
message: 'maintainer name',
default: 'Water.li'
}
],
actions: [
{
type: 'addMany',
destination: 'apps/{{name}}',
base: 'tools/generators/app',
templateFiles: 'tools/generators/app'
},
{
type: 'modify',
path: 'apps/core/package.json',
pattern: /"dependencies":\s*{/,
template: '"dependencies": {\n "@rxdrag/{{name}}": "workspace:*",'
},
{
type: 'modify',
path: 'apps/core/src/App.js',
pattern:
/const CoreApp = React.lazy\(\(\) => import\('\.\/routes'\)\);/,
template: `const CoreApp = React.lazy(() => import('./routes'));
const {{titleCaseWithoutSpace name}}App = React.lazy(() => import('@rxdrag/{{name}}'));`
},
{
type: 'modify',
path: 'apps/core/src/App.js',
pattern: /\{\/\* Applications \*\/\}/,
template: `{/* Applications */}
<Route path="/{{name}}">
<DefaultFallback>
<{{titleCaseWithoutSpace name}}App />
</DefaultFallback>
</Route>
`
},
{
type: 'modify',
path: 'packages/shared/src/constants/apps.js',
pattern: /\/\/ add default apps/,
template: `,{ href: '/{{name}}', icon: HelpIcon, description: '{{description}}', color: '#ffffff', contactEmail: '[email protected]' }
// add default apps`
},
function runPnpmInstall() {
const { spawn } = require('child_process');
const pnpmInstall = spawn('pnpm', ['install']);
pnpmInstall.stdout.pipe(process.stdout);
pnpmInstall.stderr.pipe(process.stderr);
}
]
});
plop.setGenerator('library', {
description: 'Adds a new library to Rxdrag',
prompts: [
{
type: 'input',
name: 'name',
message: 'library package name',
default: 'library-name',
validate: name => {
if (/\s/g.test(name)) {
throw new Error("Name can't have spaces");
}
return true;
},
transformer: name => name.toLowerCase()
},
{
type: 'input',
name: 'description',
message: 'library description',
default: 'Rxdrag Package'
},
{
type: 'input',
name: 'maintainer',
message: 'maintainer name',
default: 'Water.Li'
}
],
actions: [
{
type: 'addMany',
destination: 'packages/{{name}}',
base: 'tools/generators/library',
templateFiles: 'tools/generators/library'
}
]
});
};