-
Notifications
You must be signed in to change notification settings - Fork 0
/
plopfile.js
110 lines (106 loc) · 2.65 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
module.exports = function(plop) {
// Partials
plop.setGenerator('partial', {
description: 'Generate a twig partial',
prompts: [
{
type: 'input',
name: 'filename',
message: 'Partial file name',
default: 'partial',
},
],
actions: [
{
type: 'add',
path: './app/_partials/_{{ dashCase filename }}.twig',
},
{
type: 'add',
path: './app/styles/_partials/_{{ dashCase filename }}.scss',
template: '.{{ dashCase filename}} {}',
},
{
type: 'append',
path: './app/styles/_partials.scss',
template: '@import "_partials/_{{ dashCase filename }}";\n',
},
],
});
// Component
plop.setGenerator('component', {
description: 'Generate a component',
prompts: [
{
type: 'input',
name: 'filename',
message: 'Component file name',
default: 'partial',
},
],
actions: [
{
type: 'add',
path: './app/_partials/components/_{{ dashCase filename }}.twig',
},
{
type: 'add',
path: './app/styles/_components/_{{ dashCase filename }}.scss',
template: '.{{ dashCase filename}} {}',
},
{
type: 'append',
path: './app/styles/_components.scss',
template: '@import "_components/_{{ dashCase filename }}";\n',
},
],
});
// Page
plop.setGenerator('page', {
description: 'Generate a HTML page',
prompts: [
{
type: 'input',
name: 'filename',
message: 'Page file name',
default: 'index',
},
],
actions: [
{
type: 'add',
path: './app/{{ lowerCase filename }}.html',
template:
'{% extends "_layouts/base.twig" %}\n' +
'{% block title %}page-{{ dashCase filename}}{% endblock %}\n' +
'{% block body_class %}{{ lowerCase filename }}{% endblock %}\n' +
'\n' +
'{% block content %}\n' +
' Blank\n' +
'{% endblock %}\n',
},
{
type: 'add',
path: './app/styles/_pages/_page-{{ dashCase filename }}.scss',
template: '.page-{{ dashCase filename}} {}',
},
{
type: 'append',
path: './app/styles/_pages.scss',
template: '@import "_pages/_page-{{ dashCase filename }}";\n',
},
],
});
// Helpers
plop.setHelper('relativePath', function(path) {
let relativePath = '';
const parts = path.split(/\//g);
if (path === '.' || !parts.length) {
return './';
}
parts.forEach(() => {
relativePath += '../';
});
return relativePath;
});
};