-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
97 lines (85 loc) · 2.33 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
var gulp = require('gulp');
var concat = require('gulp-concat');
var sourcemaps = require('gulp-sourcemaps');
var header = require('gulp-header');
var rename = require('gulp-rename');
var order = require("gulp-order");
var fs = require('fs');
var compile = false;
var theHeader = `/*
Timeplate
A modern animation timeline built for performance and simplify
some complex usage for animator needs.
https://github.com/ScarletsFiction/Timeplate
*/\n`;
var dateMinify = {};
// var dateMinify = {mapFile:function(path){return path.replace('js.map', Date.now()+'.js.map')}};
gulp.task('js-es6', function(){
removeOldMap('dist/');
// Set the order
var temp = gulp.src('src/**/*.js')
.pipe(sourcemaps.init())
.pipe(order([
'a_init.js',
'Timeplate.js',
'**/*.js',
'z_end.js'
]))
.pipe(concat('timeplate.js'));
if(compile)
temp = temp.pipe(gulp.dest('dist'))
.pipe(header(theHeader))
.pipe(rename({extname:'.min.js'}))
.pipe(babel({
babelrc: false,
plugins: [
["@babel/plugin-proposal-class-properties", {loose: true}]
],
presets: [
[
"@babel/preset-env", {
targets: {
ie: "11"
},
modules: false,
loose: false
}
]
]
}))
.pipe(uglify());
temp = temp.pipe(sourcemaps.write('.', dateMinify))
.pipe(gulp.dest('dist'))
.on('end', function(){
// notifier.notify({
// title: 'Gulp Compilation',
// message: 'JavaScript was finished!'
// });
});
return temp;
});
gulp.task('default', function(done){
require('./tests/server.js');done();
return gulp.watch(['src/**/*.js'], gulp.series('js-es6'));
});
var compile, uglify, babel;
gulp.task('enableCompile', function(done){
uglify = require('gulp-uglify-es').default;
babel = require("gulp-babel");
compile = true;
done();
});
gulp.task('compile', gulp.series(['enableCompile', 'js-es6']));
function swallowError(error){
console.log(error.message)
this.emit('end')
}
function removeOldMap(path){
fs.readdir(path, function(err, files){
for (var i = 0, len = files.length; i < len; i++) {
if(files[i].match(/.*\.(js|css)\.map/) !== null){
try{fs.unlinkSync(path+files[i]);}catch(e){}
}
}
});
}