-
Notifications
You must be signed in to change notification settings - Fork 453
/
gulpfile.js
190 lines (171 loc) · 6.98 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
var
exec = require('child_process').exec,
fs = require('fs'),
gulp = require("gulp"),
templateCache = require('gulp-angular-templatecache'),
minifyCss = require('gulp-clean-css'),
concat = require('gulp-concat'),
concatCss = require('gulp-concat-css'),
debug = require('gulp-debug'),
eol = require('gulp-eol'),
header = require("gulp-header"),
htmlreplace = require('gulp-html-replace'),
ghtmlSrc = require('gulp-html-src'),
minifyHTML = require('gulp-htmlmin'),
gjscs = require('gulp-jscs'),
jshint = require('gulp-jshint'),
gmanifest = require('gulp-manifest3'),
rename = require('gulp-rename'),
replace = require('gulp-replace'),
sass = require('gulp-sass')(require('sass')),
gutil = require('gulp-util'),
path = require('path'),
streamqueue = require('streamqueue'),
map = require("map-stream"),
terser = require("terser");
var vendorPrefix = "vendor/";
function getFileName(attr, node) {
var file = node.attr(attr);
if (file.indexOf(vendorPrefix) === 0) {
file = path.join("..", "node_modules", file.substr(vendorPrefix.length));
}
return file;
}
function fixup() {
return exec('node fixfa.js', function (err, stdout, stderr) {
if (err) {
console.log(stdout);
console.log(stderr);
}
});
}
function lint() {
return gulp.src('**/*.js')
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('default'))
.pipe(jshint.reporter('fail'));
}
function jscs() {
return gulp.src(['*.js','nodes/*.js','src/*.js','src/*/*.js','src/*/*/*.js'])
.pipe(gjscs())
.pipe(gjscs.reporter("inline"))
}
function icon() {
// gulp.src('src/wheel.png').pipe(gulp.dest('dist/css/'));
gulp.src('src/icon192x192.png').pipe(gulp.dest('dist/'));
gulp.src('src/icon120x120.png').pipe(gulp.dest('dist/'));
return gulp.src('src/icon64x64.png').pipe(gulp.dest('dist/'));
}
function js() {
var scripts = gulp.src('src/index.html')
.pipe(ghtmlSrc({getFileName:getFileName.bind(this, 'src')}));
var templates = gulp.src(['src/**/*.html', '!src/index.html'])
.pipe(minifyHTML({collapseWhitespace:true, conservativeCollapse:true}))
.pipe(templateCache('templates.js', {root:'', module:'ui'}))
.pipe(replace('put(\'/', 'put(\''));
gulp.src('node_modules/tinycolor2/dist/tinycolor-min.js')
.pipe(eol('\n'))
.pipe(gulp.dest('./dist/js'));
gulp.src('src/i18n.js')
.pipe(eol('\n'))
.pipe(gulp.dest('dist/'));
return streamqueue({ objectMode:true }, scripts, templates)
.pipe(map((data, cb) => {
const path = data.path;
const contents = data.contents;
if (/\.min\.js$/.test(path)) {
cb(null, data);
}
else {
(async () => {
try {
const code = await terser.minify(contents.toString('utf8'));
const result = Buffer.from(code.code);
data.contents = result;
cb(null, data);
}
catch (e) {
cb("error: " +e.toString());
}
})();
}
}))
.pipe(concat('app.min.js'))
.pipe(header(fs.readFileSync('license.js')))
.pipe(eol('\n'))
.pipe(gulp.dest('dist/js/'));
}
function css() {
exec('node fixfa.js', function (err, stdout, stderr) {
if (err) {
console.log(stdout);
console.log(stderr);
}
});
return gulp.src('src/index.html')
.pipe(ghtmlSrc({getFileName:getFileName.bind(this, 'href'), presets:'css'}))
.pipe(concatCss('app.min.css',{rebaseUrls:false}))
.pipe(header(fs.readFileSync('license.js')))
.pipe(eol('\n'))
//.pipe(minifyCss())
.pipe(gulp.dest('dist/css/'));
}
function less() {
return gulp.src(['src/*.less'])
.pipe(concat('app.min.less'))
.pipe(header(fs.readFileSync('license.js')))
.pipe(eol('\n'))
.pipe(gulp.dest('./dist/css'));
}
function index() {
return gulp.src('src/index.html')
.pipe(htmlreplace({
'css': 'css/app.min.css',
'js': 'js/app.min.js',
'less': '<link rel="stylesheet/less" href="css/app.min.less" />'
}))
.pipe(minifyHTML({collapseWhitespace:true, conservativeCollapse:true}))
.pipe(eol('\n'))
.pipe(gulp.dest('dist/'));
}
function fonts() {
//return gulp.src('node_modules/font-awesome/fonts/*').pipe(gulp.dest('dist/fonts/'));
gulp.src('node_modules/font-awesome/fonts/fontawesome-webfont.woff').pipe(gulp.dest('dist/fonts/'));
gulp.src('node_modules/material-design-icons-iconfont/dist/fonts/MaterialIcons-Regular.woff').pipe(gulp.dest('dist/fonts/'));
gulp.src('node_modules/weather-icons-lite/fonts/weather-icons-lite.woff').pipe(gulp.dest('dist/fonts/'));
gulp.src('node_modules/font-awesome/fonts/fontawesome-webfont.woff2').pipe(gulp.dest('dist/fonts/'));
gulp.src('node_modules/material-design-icons-iconfont/dist/fonts/MaterialIcons-Regular.woff2').pipe(gulp.dest('dist/fonts/'));
return gulp.src('node_modules/weather-icons-lite/fonts/weather-icons-lite.woff2').pipe(gulp.dest('dist/fonts/'));
}
function gridstack() {
//gulp.src('node_modules/gridstack/dist/gridstack.min.css').pipe(gulp.dest('dist/css/'));
//gulp.src('node_modules/gridstack/dist/gridstack.jQueryUI.min.js').pipe(gulp.dest('dist/js/'));
//gulp.src('node_modules/gridstack/dist/gridstack.min.js').pipe(gulp.dest('dist/js/'));
//gulp.src('node_modules/gridstack/dist/gridstack.min.map').pipe(gulp.dest('dist/js/'));
//gulp.src('node_modules/lodash/lodash.min.js').pipe(gulp.dest('dist/js/'));
return gulp.src('src/gridstack-extra.scss')
.pipe(replace('$gridstack-columns: 11 !default;','$gridstack-columns: 30;'))
.pipe(sass({outputStyle: 'compressed'}))
.pipe(rename({extname: '.min.css'}))
.pipe(gulp.dest('dist/css'))
}
function manifest() {
return gulp.src(['dist/*','dist/css/*','dist/js/*','dist/fonts/*'], { base:'dist/' })
.pipe(gmanifest({
hash: true,
//preferOnline: true,
network: ['*'],
filename: 'dashboard.appcache',
// exclude: 'dashboard.appcache'
exclude: ['dashboard.appcache','index.html']
}))
// Manually add socketio
.pipe(replace('tinycolor-min.js', 'tinycolor-min.js\nsocket.io/socket.io.js'))
// Manually add gridstack items add loading.html (in case it exists)
.pipe(replace('fonts/weather-icons-lite.woff2', 'fonts/weather-icons-lite.woff2\ngs/gridstack.jQueryUI.min.js\ngs/gridstack.min.css\ngs/gridstack.min.js\nloading.html'))
.pipe(eol('\n'))
.pipe(gulp.dest('dist/'));
}
exports.lint = lint;
exports.default = gulp.series(fixup, jscs, icon, js, css, less, index, fonts, gridstack, manifest);
// need to add back in css.