-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
gulpfile.js
106 lines (97 loc) · 2.73 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
var gulp = require('gulp'),
replace = require('gulp-replace'),
rename = require('gulp-rename'),
del = require('del'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
clean = require('gulp-clean-css'),
autoprefix = require('gulp-autoprefixer'),
jshint = require('gulp-jshint'),
fs = require('fs');
function processScripts (dir, out, name) {
return gulp.src(dir)
.pipe(concat(name))
.pipe(uglify().on('error', function(e){
console.log(e);
}))
.pipe(gulp.dest(out));
}
function processStyles (dir, out, name) {
return gulp.src(dir)
.pipe(concat(name))
.pipe(clean())
.pipe(autoprefix())
.pipe(gulp.dest(out));
}
// linting
function lint () {
return gulp.src('./src/js/*.js')
.pipe(jshint())
.pipe(jshint.reporter('default', { beep : true }));
}
// clean
function rimraf () {
return del([
'./src/wrap/min.js',
'./dist/**/*'
]);
}
// build functions
function buildScripts () {
var jsFiles = [
'vendor/detect.js',
'fast.js',
'options.js',
'get.js',
'audio.js',
'track.js',
'group.js',
'list.js',
'extensions.js',
'controlpanel.js',
'preload.js',
'state.js',
'setup.js',
'userland.js',
'macros.js'
].map( function (file) {
return './src/js/' + file;
});
return processScripts(jsFiles, './src/wrap', 'min.js');
}
function buildStyles () {
var cssFiles = [
'overlay.css',
'panel.css',
'slider.css'
].map( function (file) {
return './src/css/' + file;
});
return processStyles(cssFiles, './src/wrap', 'min.css');
}
// add js wrapper
function wrapJS () {
return gulp.src('./src/wrap/wrapper.js')
.pipe(replace('{{version}}', require('./package.json').version))
.pipe(replace('{{code}}', fs.readFileSync('./src/wrap/min.js', 'utf8')))
.pipe(rename('harlowe-audio.min.js'))
.pipe(gulp.dest('./dist'));
}
// add CSS wrapper
function wrapCSS () {
return gulp.src('./src/wrap/wrapper.css')
.pipe(replace('{{version}}', require('./package.json').version))
.pipe(replace('{{code}}', fs.readFileSync('./src/wrap/min.css', 'utf8')))
.pipe(rename('harlowe-audio.min.css'))
.pipe(gulp.dest('./dist'));
}
// tasks
gulp.task('clean', rimraf);
gulp.task('scripts', buildScripts);
gulp.task('styles', buildStyles);
gulp.task('wrapJS', wrapJS);
gulp.task('wrapCSS', wrapCSS);
gulp.task('files', gulp.parallel('scripts', 'styles'));
gulp.task('wrap', gulp.parallel('wrapJS', 'wrapCSS'));
gulp.task('build', gulp.series('clean', 'files', 'wrap'));
gulp.task('lint', lint);