This repository has been archived by the owner on Feb 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
205 lines (148 loc) · 6.09 KB
/
gulpfile.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
199
200
201
202
203
204
/**
* @Filename: gulpfile.js
* @Description: config gulp builder
*/
// ----------------------------------------------------------------------------- DEPENDENCIES
const gulp = require('gulp');
const prompt = require('gulp-prompt');
const template = require('gulp-template');
const rename = require('gulp-rename');
const changeCase = require('change-case');
const gutil = require("gulp-util");
// ----------------------------------------------------------------------------- PATHS
/**
* project Paths
*/
const root = './';
path = {
// skeletons folder
skeletons: root + 'config/skeletons/',
// Path to components
components: root + 'src/project/components/',
// Path to pages
pages: root + 'src/project/pages/',
// Path to config
env: root + 'config/env/',
};
// ----------------------------------------------------------------------------- SCAFF TASK
let DOMTsTemplate = path.skeletons + 'dom/tsTemplate';
let DOMLessTemplate = path.skeletons + 'dom/scssTemplate';
let DOMTWIGTemplate = path.skeletons + 'dom/twigTemplate';
let wpPageTemplate = path.skeletons + 'dom/wpPageTemplate';
// let DOMPHPTemplate = path.skeletons + 'dom/phpTemplate';
gulp.task('scaff', () => {
gulp.src(DOMTsTemplate)
.pipe(prompt.prompt([
// question 2 : type page / component
{
type: 'list',
name: 'type',
message: 'Type of scaffolding ?',
choices: ['Component', 'Page']
},
// question 3 : name
{
type: 'input',
name: 'name',
message: 'What\'s your component name (camelCase) ?'
}
], function (res) {
// change case of name
let formatName = changeCase.camelCase(res.name); // debut lowerCase
let wpPageFormatName = changeCase.paramCase(res.name); // ma-page.php
// ----------------------------------------------------------------- DOM (2 files)
// ---- JS template
gulp.src(DOMTsTemplate)
// config
.pipe(template({name: formatName}))
// rename file with response name
.pipe(rename(formatName + '.ts'))
// define Dest
.pipe(gulp.dest((res.type === 'Component' ? path.components : path.pages) + formatName));
// ---- LESS template
gulp.src(DOMLessTemplate)
// config
.pipe(template({name: formatName}))
// rename file with response name
.pipe(rename(formatName + '.scss'))
// define Dest
.pipe(gulp.dest((res.type === 'Component' ? path.components : path.pages) + formatName));
// ---- TWIG View template
gulp.src(DOMTWIGTemplate)
// config
.pipe(template({name: formatName}))
// rename file with response name
.pipe(rename(formatName + '.twig'))
// define Dest
.pipe(gulp.dest((res.type === 'Component' ? path.components : path.pages) + formatName));
/**
* Seulement si c'est une page :
* Créer un template de page type "WP" à la racine du projet
* dans lequel on inclu le composant page
*/
// if (res.type === 'Page')
// {
// // ---- PHP page template
// gulp.src(wpPageTemplate)
// // config
// .pipe(template({name: formatName}))
// // rename file with response name
// .pipe(rename(wpPageFormatName + '.php'))
// // define Dest
// .pipe(gulp.dest( root ));
// }
// ----------------------------------------------------------------- END - console message
gutil.log(
gutil.colors.yellow('Your ' + (res.type === 'Component' ? 'component' : 'pages')),
gutil.colors.cyan(formatName),
gutil.colors.yellow('has just been built in'),
gutil.colors.cyan(res.type === 'Component' ? 'src/project/components/' : 'src/project/pages/'),
gutil.colors.yellow('folder :)')
);
}));
});
// ----------------------------------------------------------------------------- ENV
/**
* Define Env Scaffolder
* @type {string}
*/
let envTemplate = path.skeletons + 'config/env';
let envPropertiesTemplate = path.skeletons + 'config/properties';
gulp.task('env', () => {
gulp.src(envTemplate)
.pipe(prompt.prompt([
// question 1 : name
{
type: 'input',
name: 'name',
message: 'What\'s your name ? (ex: john)'
}
], function (res) {
// change case of name
let formatName = changeCase.camelCase(res.name);
// ----------------------------------------------------------------- ENV SCAFFOLDER
// env file
gulp.src(envTemplate)
// config
.pipe(template({name: formatName}))
// rename file with response name
.pipe(rename('env.js'))
// define Dest
.pipe(gulp.dest(path.env));
// properties file
gulp.src(envPropertiesTemplate)
// config
.pipe(template({name: formatName}))
// rename file with response name
.pipe(rename(formatName + '.properties.js'))
// define Dest
.pipe(gulp.dest(path.env));
// ----------------------------------------------------------------- END - console message
gutil.log(
gutil.colors.yellow('Env is now define with the name'),
gutil.colors.cyan(formatName + ' !'),
gutil.colors.yellow('Change your locale Paths variable in'),
gutil.colors.cyan('config/env/' + formatName + '.properties.js'),
);
}));
});