forked from BillyBlaze/OctoPrint-TouchUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
116 lines (98 loc) · 3.24 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
var fs = require('fs');
var gulp = require('gulp');
var less = require('gulp-less');
var del = require('del');
var rename = require("gulp-rename");
var uglify = require("gulp-uglify");
var through = require("through2");
var gulpif = require("gulp-if");
var trimlines = require('gulp-trimlines');
var concat = require('gulp-concat');
var stripCssComments = require('gulp-strip-css-comments');
gulp.task('lessc', function () {
return gulp.src('source/less/touchui.less')
.pipe(less({compress: true}))
.pipe(through.obj(function(file, enc, cb) {
var contents = file.contents.toString();
contents = contents.replace(/mixin\:placeholder\;/g, '');
file.contents = Buffer.from(contents);
cb(null, file);
}))
.pipe(gulp.dest('octoprint_touchui/static/css'));
});
gulp.task("less:concat", function() {
return gulp.src('source/less/touchui.less')
.pipe(through.obj(function(file, enc, cb) {
var contents = file.contents.toString();
var regex = /@import \"(.*)\"\;/gm;
while ((m = regex.exec(contents)) !== null) {
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
var replaceString = m[0];
var fileName = m[1];
var importContents = fs.readFileSync(__dirname + '/source/less/' + fileName);
contents = contents.replace(replaceString, importContents);
}
file.contents = Buffer.from(contents);
cb(null, file);
}))
.pipe(stripCssComments())
.pipe(rename("touchui.bundled.less"))
.pipe(trimlines())
.pipe(through.obj(function(file, enc, cb) {
var contents = file.contents.toString();
contents = contents.replace(/\n\s*\n/g, '\n');
file.contents = Buffer.from(contents);
cb(null, file);
}))
.pipe(gulp.dest('octoprint_touchui/static/less/'));
});
gulp.task('clean:hash', function () {
return del([
'octoprint_touchui/static/css/hash.*.touchui',
]);
});
gulp.task('js:concat:libs', function () {
return gulp.src([
'node_modules/keyboard/dist/js/jquery.keyboard.min.js',
'node_modules/jquery-fullscreen-kayahr/jquery.fullscreen-min.js',
'node_modules/iscroll/build/iscroll.js',
'source/vendors/tinycolorpicker/lib/jquery.tinycolorpicker.min.js'
])
.pipe(gulpif("**/iscroll.js", uglify()))
.pipe(concat('touchui.libraries.js'))
.pipe(gulp.dest('octoprint_touchui/static/js/'));
});
gulp.task('js:concat:app', function () {
return gulp.src([
'source/js/constructor.js',
'source/js/**/*.js',
'source/js/**/**/*.js',
'!source/js/bootstrap.js'
])
.pipe(concat('touchui.bundled.js'))
//.pipe(uglify())
.pipe(gulp.dest('octoprint_touchui/static/js/'));
});
gulp.task('js:concat:bootstrap', function () {
return gulp.src([
'source/js/bootstrap.js'
])
.pipe(rename("touchui.bootstrap.js"))
.pipe(uglify())
.pipe(gulp.dest('octoprint_touchui/static/js/'));
});
gulp.task('watch', function () {
gulp.watch(
['source/js/**/*.js', 'source/js/*.js'],
gulp.series('js')
);
gulp.watch(
['source/less/touchui.less', 'source/less/**/*.less'],
gulp.series('less')
);
});
gulp.task('default', gulp.series('lessc', 'clean:hash', 'less:concat', 'js:concat:app', 'js:concat:libs', 'js:concat:bootstrap'));
gulp.task('less', gulp.series('lessc', 'clean:hash', 'less:concat'));
gulp.task('js', gulp.series('js:concat:app', 'js:concat:libs', 'js:concat:bootstrap'));