This repository has been archived by the owner on Dec 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 313
/
gulpfile.js
115 lines (95 loc) · 2.8 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
'use strict';
var
gulp = require('gulp'),
plugins = require('gulp-load-plugins')(),
runSequence = require('run-sequence'),
del = require('del'),
imagemin = require('gulp-imagemin'),
pngquant = require('imagemin-pngquant'),
LineByLine = require('line-by-line'),
fs = require('fs')
;
var htmlMinifierOptions = {
removeComments: true,
collapseWhitespace: true,
collapseBooleanAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
removeOptionalTags: true,
minifyJS: true,
minifyCSS: true
};
gulp.task('useref', function() {
var assets = plugins.useref.assets();
return gulp.src(['public/**/*.html', '!public/quasar-play/**/*.html'])
.pipe(assets)
.pipe(plugins.if('*.css', plugins.cssBase64()))
.pipe(plugins.if('*.css', plugins.minifyCss()))
.pipe(plugins.if('*.js', plugins.uglify()))
.pipe(plugins.rev())
.pipe(assets.restore())
.pipe(plugins.useref())
.pipe(plugins.revReplace({
prefix: '/'
}))
.pipe(plugins.if('*.html', plugins.htmlmin(htmlMinifierOptions)))
.pipe(gulp.dest('public'));
});
gulp.task('images', function() {
return gulp.src('public/images/**/*')
.pipe(plugins.imagemin({
progressive: true,
svgoPlugins: [{removeViewBox: false}],
use: [pngquant()]
}))
.pipe(gulp.dest('public/images'));
});
gulp.task('clean-unused-files', ['useref'], function() {
del.sync(['public/**/*.js', '!public/**/*combined*.js', '!public/quasar-play/**/*']);
del.sync(['public/**/*.css', '!public/**/*combined*.css', '!public/quasar-play/**/*']);
});
gulp.task('copy-assets', function() {
return gulp.src('assets/**/*')
.pipe(gulp.dest('public/'));
});
gulp.task('default', ['useref', 'images', 'clean-unused-files', 'copy-assets']);
var
parsedFiles = 0,
stylusVariables = {}
;
function parseStylusLine(theme) {
return function(line) {
if (line.indexOf(' ?= ') === -1) {
return;
}
var
definition = line.split(' ?= '),
name = definition[0].trim(),
value = definition[1].trim()
;
if (name === '$colors') {
return;
}
if (!stylusVariables[name]) {
stylusVariables[name] = {};
}
stylusVariables[name][theme] = value;
};
}
function finalizeStylusParse() {
parsedFiles++;
if (parsedFiles < 2) {
return;
}
fs.writeFileSync('assets/stylus-variables.json', JSON.stringify(stylusVariables));
}
gulp.task('variables', function() {
var
mat = new LineByLine('/work/quasar-play/node_modules/quasar-framework/dist/quasar.mat.styl'),
ios = new LineByLine('/work/quasar-play/node_modules/quasar-framework/dist/quasar.ios.styl')
;
mat.on('line', parseStylusLine('mat'));
ios.on('line', parseStylusLine('ios'));
mat.on('end', finalizeStylusParse);
ios.on('end', finalizeStylusParse);
});