-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathgulpfile.js
315 lines (288 loc) · 11.4 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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
const gulp = require('gulp');
const sass = require('gulp-sass');
sass.compiler = require('node-sass');
const sourcemaps = require('gulp-sourcemaps');
const rename = require('gulp-rename');
const header = require('gulp-header');
const replace = require('gulp-string-replace');
const concatCss = require('gulp-concat-css');
const del = require('del');
path = require('path');
const basepath = './src/assets/styles/';
const fontspath = basepath + 'fonts/';
const infontspath = basepath + 'inlinefonts/';
const temppath = './src/assets/temp/';
const repopath = './src/assets/sb-repo/';
replaceBeforeRegex = /^(.*)\/\*\!Delete\ before\ this\*\//mi;
/*========================
Fonts CSS generate
==========================*/
/* Generate Fonts CSS files */
function fontsCss() {
return (
gulp.src([infontspath + '**/*.scss', '!' + infontspath + 'fonts.scss'])
.pipe(sass({ outputStyle: 'compressed' })).on("error", sass.logError)
.pipe(gulp.dest(repopath + 'fonts'))
);
}
exports.fontsCss = fontsCss;
/* Generate Concated Fonts CSS files */
function fontsConcated() {
return (
gulp.src([infontspath + 'fonts.scss'])
.pipe(sass({ outputStyle: 'compressed' })).on("error", sass.logError)
.pipe(gulp.dest(repopath))
);
}
exports.fontsConcated = fontsConcated;
/*========================
Main CSS file generation
==========================*/
/* Generate Main CSS files from styles folder */
function scssMain() {
return (
gulp.src(basepath + 'styles.scss')
.pipe(sourcemaps.init())
.pipe(sass({ outputStyle: 'compressed' })).on("error", sass.logError)
.pipe(gulp.dest(repopath))
);
}
exports.scssMain = scssMain;
/*========================
Generate Variables file
==========================*/
function scssVariables() {
return (
gulp.src([basepath + '_variables.scss'])
.pipe(rename(function(path) { //since sass() wont compile _partials files we are removing it here
path.basename = path.basename[0] == '_' ? path.basename.substr(1) : path.basename;
}))
.pipe(sass({ outputStyle: 'compressed' }).on('error', sass.logError))
.pipe(rename(function(file) {
const parentFolder = path.dirname(file.dirname);
file.dirname = path.join(parentFolder, ''); //generated file extension
}))
.pipe(gulp.dest(repopath))
);
}
exports.scssVariables = scssVariables;
/*========================
Generate Base file
==========================*/
function scssBase() {
return (
gulp.src([basepath + 'base/base.scss'])
.pipe(header('/*!Delete before this*/'))
.pipe(header('@import \'../mixins/mixins\';\n'))
.pipe(header('@import \'../variables\';\n'))
.pipe(sass({ outputStyle: 'compressed' }).on('error', sass.logError))
.pipe(replace(replaceBeforeRegex, ''))
.pipe(gulp.dest(repopath))
);
}
exports.scssBase = scssBase;
/*========================
Generate Layout file
==========================*/
function scssLayout() {
return (
gulp.src([basepath + 'layout/layout.scss'])
.pipe(header('@import \'../global\';\n'))
.pipe(header('/*!Delete before this*/'))
.pipe(header('@import \'../mixins/mixins\';\n'))
.pipe(header('@import \'../variables\';\n'))
.pipe(sass({ outputStyle: 'compressed' }).on('error', sass.logError))
.pipe(replace(replaceBeforeRegex, ''))
.pipe(gulp.dest(repopath))
);
}
exports.scssLayout = scssLayout;
/*========================
Generate Pages file
==========================*/
// Individual
function scssPages() {
return (
gulp.src([basepath + 'pages/*.scss','!' + basepath + 'pages/pages.scss'])
.pipe(rename(function(path) { //since sass() wont compile _partials files we are removing it here
path.basename = path.basename[0] == '_' ? path.basename.substr(1) : path.basename;
}))
.pipe(header('/*!Delete before this*/'))
.pipe(header('@import \'../mixins/mixins\';\n'))
.pipe(header('@import \'../variables\';\n'))
.pipe(sass({ outputStyle: 'compressed' }).on('error', sass.logError))
.pipe(replace(replaceBeforeRegex, ''))
.pipe(rename(function(file) {
const parentFolder = path.dirname(file.dirname);
file.dirname = path.join(parentFolder, 'pages'); //generated file extension
}))
.pipe(gulp.dest(repopath))
);
}
exports.scssPages = scssPages;
// Concated
function scssPagesConcated() {
return (
gulp.src([basepath + 'pages/pages.scss'])
.pipe(header('/*!Delete before this*/'))
.pipe(header('@import \'../mixins/mixins\';\n'))
.pipe(header('@import \'../variables\';\n'))
.pipe(sass({ outputStyle: 'compressed' }).on('error', sass.logError))
.pipe(replace(replaceBeforeRegex, ''))
.pipe(gulp.dest(repopath))
);
}
exports.scssPagesConcated = scssPagesConcated;
/*========================
Generate vendors file
==========================*/
// Individual
function scssVendors() {
return (
gulp.src([basepath + 'vendors/*.scss','!' + basepath + 'vendors/vendors.scss'])
.pipe(rename(function(path) { //since sass() wont compile _partials files we are removing it here
path.basename = path.basename[0] == '_' ? path.basename.substr(1) : path.basename;
}))
.pipe(header('/*!Delete before this*/'))
.pipe(header('@import \'../mixins/mixins\';\n'))
.pipe(header('@import \'../variables\';\n'))
.pipe(sass({ outputStyle: 'compressed' }).on('error', sass.logError))
.pipe(replace(replaceBeforeRegex, ''))
.pipe(rename(function(file) {
const parentFolder = path.dirname(file.dirname);
file.dirname = path.join(parentFolder, 'vendors'); //generated file extension
}))
.pipe(gulp.dest(repopath))
);
}
exports.scssVendors = scssVendors;
// Concated
function scssVendorsConcated() {
return (
gulp.src([basepath + 'vendors/vendors.scss'])
.pipe(header('/*!Delete before this*/'))
.pipe(header('@import \'../mixins/mixins\';\n'))
.pipe(header('@import \'../variables\';\n'))
.pipe(sass({ outputStyle: 'compressed' }).on('error', sass.logError))
.pipe(replace(replaceBeforeRegex, ''))
.pipe(gulp.dest(repopath))
);
}
exports.scssVendorsConcated = scssVendorsConcated;
/*========================
Generate Common file
==========================*/
function scssCommon() {
return (
gulp.src([repopath + 'base.css', repopath + 'layout.css'])
.pipe(concatCss("common.css"))
.pipe(sass({ outputStyle: 'compressed' }).on('error', sass.logError))
.pipe(gulp.dest(repopath))
);
}
exports.scssCommon = scssCommon;
/*========================
Component CSS Generation
==========================*/
/* Temp Folder - Copy all other files with imports appended at head*/
function appendImport() {
return (
gulp.src([basepath + '**/*.scss', '!' + basepath + '*.scss', '!' + basepath + 'mixins/**/*.scss','!' + basepath + 'fonts/**/*.scss', '!' + basepath + 'inlinefonts/**/*.scss'])
.pipe(header('/*!Delete before this*/'))
.pipe(header('@import \'../mixins/mixins\';\n'))
.pipe(header('@import \'../variables\';\n'))
.pipe(gulp.dest(temppath))
);
}
exports.appendImport = appendImport;
/* Temp Folder - Copy files of level 1*/
function copyStyle() {
return (
gulp.src([basepath + '_variables.scss'])
.pipe(gulp.dest(temppath))
);
}
exports.copyStyle = copyStyle;
/* Temp Folder - Copy mixins folder*/
function copyMixins() {
return (
gulp.src([basepath + 'mixins/**/*'])
.pipe(gulp.dest(temppath + 'mixins'))
);
}
exports.copyMixins = copyMixins;
/* Temp Folder - Copy mixins folder*/
function copyFonts() {
return (
gulp.src([basepath + 'inlinefonts/**/*'])
.pipe(gulp.dest(temppath + 'inlinefonts'))
);
}
exports.copyFonts = copyFonts;
/* Generate Components CSS files from temp folder */
function scssComponents() {
return (
gulp.src([temppath + 'components/*.scss', '!' + temppath + 'components/components.scss'])
.pipe(rename(function(path) { //since sass() wont compile _partials files we are removing it here
path.basename = path.basename[0] == '_' ? path.basename.substr(1) : path.basename;
}))
.pipe(sass({ outputStyle: 'compressed' }).on('error', sass.logError))
.pipe(sourcemaps.write('./'))
.pipe(rename(function(file) {
const parentFolder = path.dirname(file.dirname);
file.dirname = path.join(parentFolder, 'components'); //generated file extension
}))
.pipe(replace(replaceBeforeRegex, ''))
.pipe(gulp.dest(repopath))
);
}
exports.scssComponents = scssComponents;
/* Generate Concated Components CSS files from temp folder */
function scssComponentsConcated() {
return (
gulp.src([basepath + 'components/components.scss'])
.pipe(header('/*!Delete before this*/'))
.pipe(header('@import \'../mixins/mixins\';\n'))
.pipe(header('@import \'../variables\';\n'))
.pipe(sass({ outputStyle: 'compressed' }).on('error', sass.logError))
.pipe(replace(replaceBeforeRegex, ''))
.pipe(gulp.dest(repopath))
);
}
exports.scssComponentsConcated = scssComponentsConcated;
/*========================
Generate Semantic file
==========================*/
function scssSemantic() {
return (
gulp.src([basepath + 'semantic/semantic-merged.scss'])
.pipe(header('/*!Delete before this*/'))
.pipe(header('@import \'../mixins/mixins\';\n'))
.pipe(header('@import \'../variables\';\n'))
.pipe(sass({ outputStyle: 'compressed' }).on('error', sass.logError))
.pipe(replace(replaceBeforeRegex, ''))
.pipe(gulp.dest(repopath))
);
}
exports.scssSemantic = scssSemantic;
/*========================
Cleanup
==========================*/
/* Delete temp and dist folder before regenerate */
const clear = del.bind(null, [repopath,temppath]);
exports.clear = clear;
/*========================
Watcher
==========================*/
/* Sequence of tasks*/
const sequence = gulp.series( clear, appendImport, fontsCss, fontsConcated, copyStyle, scssVariables, copyMixins, scssComponents, scssComponentsConcated, scssSemantic, scssBase, scssLayout, scssCommon, scssPages, scssPagesConcated, scssVendors, scssVendorsConcated, scssMain);
exports.sequence = sequence;
/* Watch file changes */
function watch(){
gulp.watch(basepath + '**/*.scss', sequence);
}
exports.watch = watch;
/* Default task */
//gulp.task('default', ['sequence','watch']);
const defaultTask = gulp.series( sequence, watch);
exports.default = defaultTask;