-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplopfile.babel.js
198 lines (189 loc) · 8.99 KB
/
plopfile.babel.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/* eslint-env node */
/* eslint no-sync: 0 */
import fse from 'fs-extra';
import path from 'path';
import { dashCase } from './gulp/utils';
const templatesDir = 'templates/';
const packagesDir = 'packages/';
module.exports = ( plop ) => {
// Register our custom cDashCase helper because the default one is handling some cases
// incorrectly e.g. "M2C Content Constructor" becomes "m-2-c-content-constructor".
plop.addHelper( 'cDashCase', dashCase );
// Generator for component package.
plop.setGenerator( 'Component', {
// Succintly describes what generator does.
description: 'Create a new awesome component.',
prompts: [
{
type: 'input',
name: 'name',
message: 'What creative name did you invent for your component?',
validate: ( name ) => {
const minNameLength = 1;
if ( name && name.length >= minNameLength ) {
return true;
}
return 'Come on, I am sure you can come up with a nice, valid name!';
},
},
{
type: 'input',
name: 'description',
message: 'Could you give me a simple description of your new component?',
},
],
actions: [
( answers ) => {
const seedPath = path.join( templatesDir, 'package' );
const newDashName = plop.renderString( '{{ cDashCase name }}', answers );
const componentPath = path.join( 'packages/components', newDashName );
fse.copySync( seedPath, componentPath );
fse.removeSync( path.join( componentPath, 'src/seed.ts' ) );
fse.removeSync( path.join( componentPath, 'src/seed.scss' ) );
fse.removeSync( path.join( componentPath, 'src/seed.twig' ) );
fse.removeSync( path.join( componentPath, 'src/demo/index.twig' ) );
return 'Generating base package structure.';
},
( answers ) => plop.renderString( 'Generator will add environment for scripts.\r\nIf you don\'t need them, just delete src/{{ cDashCase name }}.ts file and src/tests directory.', answers ),
{
type: 'add',
path: path.join( packagesDir, 'components/{{ cDashCase name }}/src/{{ cDashCase name }}.ts' ),
templateFile: path.join( templatesDir, 'package/src/seed.ts' ),
},
{
type: 'add',
path: path.join( packagesDir, 'components/{{ cDashCase name }}/src/{{ cDashCase name }}.scss' ),
templateFile: path.join( templatesDir, 'package/src/seed.scss' ),
},
{
type: 'add',
path: path.join( packagesDir, 'components/{{ cDashCase name }}/src/{{ cDashCase name }}.twig' ),
templateFile: path.join( templatesDir, 'package/src/seed.twig' ),
},
{
type: 'add',
path: path.join( packagesDir, 'components/{{ cDashCase name }}/src/demo/index.twig' ),
templateFile: path.join( templatesDir, 'package/src/demo/index.twig' ),
},
],
} );
// Generator for utility package.
plop.setGenerator( 'Utility', {
description: 'Create a new awesome utility.',
prompts: [
{
type: 'input',
name: 'name',
message: 'What creative name did you invent for your utility?',
validate: ( name ) => {
const minNameLength = 1;
if ( name && name.length >= minNameLength ) {
return true;
}
return 'Come on, I am sure you can come up with a nice, valid name!';
},
},
{
type: 'input',
name: 'description',
message: 'Could you give me a simple description of your new utility?',
},
],
// List of actions to take.
// Here we "add" new files from our templates.
actions: [
( answers ) => {
const seedPath = path.join( templatesDir, 'package' );
const newDashName = plop.renderString( '{{ cDashCase name }}', answers );
const packagesPath = path.join( 'packages/utilities', newDashName );
fse.copySync( seedPath, packagesPath );
fse.removeSync( path.join( packagesPath, 'src/seed.ts' ) );
fse.removeSync( path.join( packagesPath, 'src/seed.scss' ) );
fse.removeSync( path.join( packagesPath, 'src/seed.twig' ) );
fse.removeSync( path.join( packagesPath, 'src/demo/index.twig' ) );
return 'Generating base package structure.';
},
( answers ) => plop.renderString( 'Generator will add environment for scripts.\r\nIf you don\'t need them, just delete src/{{ cDashCase name }}.ts file.', answers ),
{
type: 'add',
path: path.join( packagesDir, 'utilities/{{ cDashCase name }}/src/{{ cDashCase name }}.ts' ),
templateFile: path.join( templatesDir, 'package/src/seed.ts' ),
},
{
type: 'add',
path: path.join( packagesDir, 'utilities/{{ cDashCase name }}/src/{{ cDashCase name }}.scss' ),
templateFile: path.join( templatesDir, 'package/src/seed.scss' ),
},
{
type: 'add',
path: path.join( packagesDir, 'utilities/{{ cDashCase name }}/src/{{ cDashCase name }}.twig' ),
templateFile: path.join( templatesDir, 'package/src/seed.twig' ),
},
{
type: 'add',
path: path.join( packagesDir, 'utilities/{{ cDashCase name }}/src/demo/index.twig' ),
templateFile: path.join( templatesDir, 'package/src/demo/index.twig' ),
},
],
} );
// Generator for customization package.
plop.setGenerator( 'Customization', {
description: 'Create a new awesome customization.',
prompts: [
{
type: 'input',
name: 'name',
message: 'What creative name did you invent for your customization?',
validate: ( name ) => {
const minNameLength = 1;
if ( name && name.length >= minNameLength ) {
return true;
}
return 'Come on, I am sure you can come up with a nice, valid name!';
},
},
{
type: 'input',
name: 'description',
message: 'Could you give me a simple description of your new customization?',
},
],
// List of actions to take.
// Here we "add" new files from our templates.
actions: [
( answers ) => {
const seedPath = path.join( templatesDir, 'package' );
const newDashName = plop.renderString( '{{ cDashCase name }}', answers );
const packagesPath = path.join( 'packages/customizations', newDashName );
fse.copySync( seedPath, packagesPath );
fse.removeSync( path.join( packagesPath, 'config/main.js' ) );
fse.removeSync( path.join( packagesPath, 'src/seed.ts' ) );
fse.removeSync( path.join( packagesPath, 'src/seed.scss' ) );
fse.removeSync( path.join( packagesPath, 'src/seed.twig' ) );
fse.removeSync( path.join( packagesPath, 'src/demo/index.twig' ) );
return 'Generating base package structure.';
},
( answers ) => plop.renderString( 'Generator will add environment for scripts.\r\nIf you don\'t need them, just delete src/{{ cDashCase name }}.ts file.', answers ),
{
type: 'add',
path: path.join( packagesDir, 'customizations/{{ cDashCase name }}/src/{{ cDashCase name }}.ts' ),
templateFile: path.join( templatesDir, 'package/src/seed.ts' ),
},
{
type: 'add',
path: path.join( packagesDir, 'customizations/{{ cDashCase name }}/src/{{ cDashCase name }}.scss' ),
templateFile: path.join( templatesDir, 'package/src/seed.scss' ),
},
{
type: 'add',
path: path.join( packagesDir, 'customizations/{{ cDashCase name }}/src/{{ cDashCase name }}.twig' ),
templateFile: path.join( templatesDir, 'package/src/seed.twig' ),
},
{
type: 'add',
path: path.join( packagesDir, 'customizations/{{ cDashCase name }}/src/demo/index.twig' ),
templateFile: path.join( templatesDir, 'package/src/demo/index.twig' ),
},
],
} );
};