forked from maplelabs/FOSS-Hub-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplopfile.js
150 lines (148 loc) · 4.32 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
const {
uniqueNamesGenerator,
adjectives,
animals,
} = require('unique-names-generator');
const inquirer = require('inquirer');
const config = {
length: 2,
separator: '',
dictionaries: [adjectives, animals],
style: 'capital',
};
module.exports = function (plop) {
plop.setGenerator('Templates', {
description:
'Creates template files : Component, styles, types and storybook',
prompts: async function (inquirer) {
const negative = 'Give me something different...';
let { type } = await inquirer.prompt({
type: 'list',
name: 'type',
choices: ['Sections', 'Headers', 'Footers', 'Pages'],
message: 'Please select the type of template',
});
let nameAns = negative;
while (nameAns == negative) {
let { name } = await inquirer.prompt({
type: 'list',
name: 'name',
message: 'Do you want template created by name',
choices: () => [
uniqueNamesGenerator(config),
new inquirer.Separator(),
negative,
],
});
nameAns = name;
}
let { category } =
type == 'Sections'
? await inquirer.prompt({
type: 'checkbox',
name: 'category',
choices: [
'Cards',
'Banner',
'Covers',
'Lists',
'Tables',
'Grids',
new inquirer.Separator(),
'Others',
],
message: 'Select what your templates contain (max 2)',
loop: false,
})
: { category: [] };
if (category.includes('Others')) {
category = category.filter((i) => i != 'Others');
let { otherDesc } = await inquirer.prompt({
type: 'input',
name: 'otherDesc',
message: 'Specify what others mean',
});
otherDesc && category.unshift(otherDesc);
}
return {
type,
name: nameAns,
tags: category.slice(0, 2),
};
},
actions: (data) => {
const pattern_module = new RegExp(
`// ${data.type.toUpperCase()} EXPORTS`,
'g'
);
const pattern_config = new RegExp(
`// ${data.type.toUpperCase()} SCHEMAS`,
'g'
);
return [
{
type: 'add',
path: 'templates/{{lowerCase type}}/{{pascalCase name}}/index.tsx',
templateFile: '.plop-templates/templates.sections.index.tsx.hbs',
},
{
type: 'add',
path: 'templates/{{lowerCase type}}/{{pascalCase name}}/config.d.ts',
templateFile: '.plop-templates/templates.sections.config.d.ts.hbs',
},
{
type: 'add',
path: 'templates/{{lowerCase type}}/{{pascalCase name}}/styles.module.css',
},
{
type: 'add',
path: 'templates/{{lowerCase type}}/{{pascalCase name}}/{{pascalCase name}}.stories.tsx',
templateFile: '.plop-templates/templates.sections.stories.tsx.hbs',
},
{
path: 'templates/templates.module.ts',
pattern: /(\/\/ COMPONENT IMPORTS)/g,
template:
"import {{pascalCase name}} from './{{lowerCase type}}/{{pascalCase name}}';",
type: 'append',
},
{
path: 'templates/templates.module.ts',
pattern: pattern_module,
template: '\t\t{{pascalCase name}},',
type: 'append',
},
{
path: 'config.d.ts',
pattern: /(\/\/ SCHEMAS IMPORTS)/g,
template:
"import { {{pascalCase name}}Schema } from './templates/{{lowerCase type}}/{{pascalCase name}}/config';",
type: 'append',
},
{
path: 'config.d.ts',
pattern: pattern_config,
template: '\t{{pascalCase name}}Schema |',
type: 'append',
},
];
},
});
plop.setGenerator('Components', {
description: 'Creates React components with styles module',
prompts: [
// {
// type: 'input',
// name: 'name',
// message: 'controller name pleasekjnkj',
// },
],
actions: [
// {
// type: 'add',
// path: 'src/{{name}}.js',
// templateFile: '.plop-templates/controller.hbs',
// },
],
});
};