-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
253 lines (207 loc) · 6 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
//###[ IMPORTS ]########################################################################################################
import fs from 'node:fs';
import yargs from 'yargs';
import log from 'fancy-log';
import {deleteAsync as del} from 'del';
import gulp from'gulp';
import rename from 'gulp-rename';
import shell from 'gulp-shell';
import sourcemaps from 'gulp-sourcemaps';
import connect from 'gulp-connect';
import * as dartSass from 'sass';
import nodeSass from 'node-sass';
import gulpSass from 'gulp-sass';
import stylus from 'gulp-stylus';
//###[ CONSTANTS ]######################################################################################################
const
// keep DEBUG on false normally, to keep building production assets
DEBUG = false,
PACKAGE_CONFIG = JSON.parse(fs.readFileSync('./package.json', {encoding : 'utf-8'})),
ARGV = yargs(process.argv).argv,
SOURCE_DIR = './source',
DOCS_DIR = './docs',
EXAMPLES_DIR = `${DOCS_DIR}/examples`,
DOCUMENTATION_DIR = `${DOCS_DIR}/documentation`,
NODE_DIR = './node_modules',
LIB_SOURCE_DIR = `${SOURCE_DIR}/lib`,
SCSS_SOURCE_DIR = `${SOURCE_DIR}/scss`,
SCSS_EXAMPLES_DIR = `${EXAMPLES_DIR}/scss`,
SCSS_ENTRY = `${SCSS_EXAMPLES_DIR}/main.scss`,
SCSS_SOURCES = [
`${SCSS_SOURCE_DIR}/**/*.scss`,
`${SCSS_EXAMPLES_DIR}/**/*.scss`,
],
SCSS_INCLUDES = [
SCSS_SOURCE_DIR,
LIB_SOURCE_DIR
],
SCSS_OUT_DIR = `${EXAMPLES_DIR}/css`,
SCSS_LEGACY_SOURCE_DIR = `${SOURCE_DIR}/scss-legacy`,
SCSS_LEGACY_EXAMPLES_DIR = `${EXAMPLES_DIR}/scss-legacy`,
SCSS_LEGACY_ENTRY = `${SCSS_LEGACY_EXAMPLES_DIR}/main.scss`,
SCSS_LEGACY_SOURCES = [
`${SCSS_LEGACY_SOURCE_DIR}/**/*.scss`,
`${SCSS_LEGACY_EXAMPLES_DIR}/**/*.scss`,
],
SCSS_LEGACY_INCLUDES = [
SCSS_LEGACY_SOURCE_DIR,
LIB_SOURCE_DIR
],
SCSS_LEGACY_OUT_DIR = `${EXAMPLES_DIR}/css`,
STYLUS_SOURCE_DIR = `${SOURCE_DIR}/stylus`,
STYLUS_EXAMPLES_DIR = `${EXAMPLES_DIR}/stylus`,
STYLUS_ENTRY = `${STYLUS_EXAMPLES_DIR}/main.styl`,
STYLUS_SOURCES = [
`${STYLUS_SOURCE_DIR}/**/*.styl`,
`${STYLUS_EXAMPLES_DIR}/**/*.styl`,
],
STYLUS_INCLUDES = [
STYLUS_SOURCE_DIR,
LIB_SOURCE_DIR
],
STYLUS_OUT_DIR = `${EXAMPLES_DIR}/css`
;
//###[ FUNCTIONS ]######################################################################################################
function compileNormalize(){
return gulp.src(`${NODE_DIR}/@csstools/normalize.css/normalize.css`)
.pipe(sourcemaps.init())
.pipe(gulpSass(nodeSass)({
outputStyle : 'compressed'
})).on('error', function(err){
log(err);
this.emit('end');
})
.pipe(rename(function(path){
path.basename = 'index';
path.extname = '.css';
}))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(`${LIB_SOURCE_DIR}/normalize`))
;
}
function compileScss(){
return gulp.src(SCSS_ENTRY)
.pipe(sourcemaps.init())
.pipe(gulpSass(dartSass).sync({
outputStyle : 'compressed',
includePaths : SCSS_INCLUDES
})).on('error', function(err){
log(err);
this.emit('end');
})
.pipe(rename(function(path){
path.basename = 'scss';
path.extname = '.css';
}))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(SCSS_OUT_DIR))
;
}
function compileScssLegacy(){
return gulp.src(SCSS_LEGACY_ENTRY)
.pipe(sourcemaps.init())
.pipe(gulpSass(nodeSass)({
outputStyle : 'compressed',
includePaths : SCSS_LEGACY_INCLUDES
})).on('error', function(err){
log(err);
this.emit('end');
})
.pipe(rename(function(path){
path.basename = 'scss-legacy';
path.extname = '.css';
}))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(SCSS_LEGACY_OUT_DIR))
;
}
function compileStylus(){
return gulp.src(STYLUS_ENTRY)
.pipe(sourcemaps.init())
.pipe(stylus({
compress : true,
'include css' : true,
include : STYLUS_INCLUDES,
})).on('error', function(err){
log(err);
this.emit('end');
})
.pipe(rename(function(path){
path.basename = 'stylus';
path.extname = '.css';
}))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(STYLUS_OUT_DIR))
;
}
function serveExamples(done){
connect.server({
https : true,
host : '0.0.0.0',
root : EXAMPLES_DIR,
port : 3000,
livereload : {
port : 3001
},
/*middleware(connect, opt){
return [
serveStatic({
path : DOCS_DIR,
url : '/',
// otherwise connect produces a content encoding error
gzip : false
})
];
}*/
});
done();
}
function reload(source){
return gulp.src(source)
.pipe(connect.reload())
;
}
function clearDocumentation(){
return del(`${DOCUMENTATION_DIR}/**/*`);
}
//###[ TASKS ]##########################################################################################################
gulp.task('watch', function(done){
const watchConfig = {
usePolling : true,
interval : 1000,
binaryInterval : 1000
};
gulp.watch(
[...SCSS_SOURCES, ...SCSS_LEGACY_SOURCES],
watchConfig,
gulp.series(compileScss, compileScssLegacy, function reloadCss(){ return reload(`${EXAMPLES_DIR}/**/*.css`); })
);
gulp.watch(
STYLUS_SOURCES,
watchConfig,
gulp.series(compileStylus, function reloadCss(){ return reload(`${EXAMPLES_DIR}/**/*.css`); })
);
gulp.watch(
`${EXAMPLES_DIR}/index.html`,
watchConfig,
gulp.series(function reloadExamples(){ return reload(`${EXAMPLES_DIR}/index.html`); })
);
gulp.watch(
`${EXAMPLES_DIR}/css/main.css`,
watchConfig,
gulp.series(function reloadExamples(){ return reload(`${EXAMPLES_DIR}/css/main.css`); })
);
done();
});
gulp.task('documentation-scss', shell.task('jsdoc -c jsdoc.config.scss.json --verbose'));
gulp.task('documentation-scss-legacy', shell.task('jsdoc -c jsdoc.config.scss-legacy.json --verbose'));
gulp.task('documentation-stylus', shell.task('jsdoc -c jsdoc.config.stylus.json --verbose'));
gulp.task('documentation', gulp.series(
clearDocumentation,
'documentation-scss',
'documentation-scss-legacy',
'documentation-stylus'
));
gulp.task('build', gulp.series(compileNormalize, compileScss, compileScssLegacy, compileStylus));
gulp.task('examples', gulp.series('build', serveExamples, 'watch'));
gulp.task('default', gulp.series('build'));