-
Notifications
You must be signed in to change notification settings - Fork 14
/
plopfile.babel.js
46 lines (42 loc) · 1010 Bytes
/
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
function isNotEmpty(name) {
return (value) => {
if (!value || value.trim() === '') return `${name} is required`;
return true;
};
}
const { assign } = Object;
const BLOCKS = './source/blocks';
const addStyle = {
type: 'add',
templateFile: 'plop-templates/block/block.css',
};
const addMarkup = {
type: 'add',
templateFile: 'plop-templates/block/block.pug',
};
function generateResourcePath(resourceType) {
const resourcesNamesByType = {
template: '{{lowerCase name}}.pug',
style: '{{lowerCase name}}.css',
};
return `${BLOCKS}/{{lowerCase name}}/${resourcesNamesByType[resourceType]}`;
}
module.exports = (plop) => {
plop.setGenerator('block', {
description: 'Create a new block',
prompts: [{
type: 'input',
name: 'name',
message: 'What is your block name?',
validate: isNotEmpty('name'),
}],
actions: [
assign({}, addStyle, {
path: generateResourcePath('style'),
}),
assign({}, addMarkup, {
path: generateResourcePath('template'),
}),
],
});
};