-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgulpfile.js
140 lines (122 loc) · 3.36 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
const gulp = require('gulp');
const concat = require('gulp-concat');
const sourcemaps = require('gulp-sourcemaps');
const header = require('gulp-header');
const rename = require('gulp-rename');
const fs = require('fs');
// const notifier = require('node-notifier'); // For other OS
const notifier = new require('node-notifier/notifiers/balloon')(); // For Windows
let terser, babel;
gulp.task('enableCompile', function(done){
terser = require('gulp-terser');
babel = require("gulp-babel");
removeOldMap('dist/');
done && done();
});
const dateMinify = {};
// var dateMinify = {mapFile:function(path){return path.replace('js.map', Date.now()+'.js.map')}};
const theHeader = `/*
ScarletsFrame (MIT Licensed)
https://github.com/ScarletsFiction/ScarletsFrame
*/\n`;
const theOrderES5 = [
'src/sf-polyfill.js',
'src/sf-a_init.js',
'src/sf-loader.js',
'src/sf-dom.js',
'src/sf-space.js',
'src/sf-model.js',
'src/sf-component.js',
'src/sf-model/*.js',
'src/**/*.js',
'!src/sf-hot-reload.js',
'src/sf-z_end.js',
];
const theOrderES6 = theOrderES5.slice(1);
const devTest = theOrderES6.slice(0);
devTest.splice(-2, 1); // Remove '!src/sf-hot-reload.js'
gulp.task('watch-js', function(){
removeOldMap('dist/');
// Set the order
return gulp.src(devTest)
.pipe(sourcemaps.init())
.pipe(concat('scarletsframe.js'))
.pipe(sourcemaps.write('.', dateMinify))
.pipe(gulp.dest('dist'))
.on('end', function(){
notifier.notify({
title: 'Gulp Compilation',
message: 'JavaScript was finished!',
timeout: 4, time: 4,
});
});
});
gulp.task('js-es5', ()=>
gulp.src(theOrderES5)
.pipe(sourcemaps.init())
.pipe(concat('scarletsframe.js'))
.pipe(gulp.dest('dist'))
.pipe(babel({
babelrc: false,
presets: [
[
"@babel/preset-env", {
targets: {
ie: "11"
},
modules: false,
loose: false,
shippedProposals: true
}
]
]
}))
.pipe(terser())
.pipe(header(theHeader))
.pipe(rename({extname:'.min.js'}))
.pipe(sourcemaps.write('.', dateMinify))
.pipe(gulp.dest('dist'))
);
gulp.task('js-es6', ()=>
gulp.src(theOrderES6)
.pipe(sourcemaps.init())
.pipe(concat('scarletsframe.es6.js'))
.pipe(terser())
.pipe(header(theHeader))
.pipe(sourcemaps.write('.', dateMinify))
.pipe(gulp.dest('dist'))
);
gulp.task('js-hot', ()=>
gulp.src(devTest)
.pipe(sourcemaps.init())
.pipe(concat('scarletsframe.hot.js'))
.pipe(terser())
.pipe(header(theHeader))
.pipe(sourcemaps.write('.', dateMinify))
.pipe(gulp.dest('dist'))
);
gulp.task('default', function(){
require('./tests/server.js');
gulp.watch(['src/**/*.js'], gulp.series('watch-js'));
});
function ie11(){
require('./tests/server.js');
gulp.task('enableCompile')();
gulp.watch(['src/**/*.js'], gulp.series('js-es5'));
}
gulp.task('ie11', ie11);
gulp.task('compile', gulp.parallel(['enableCompile', 'js-es6', 'js-es5', 'js-hot']));
function swallowError(error){
console.log(error.message)
this.emit('end')
}
function removeOldMap(path){
fs.readdir(path, function(err, files){
if(err) return;
for (let i = 0, len = files.length; i < len; i++) {
if(files[i].match(/.*\.(js|css)\.map/) !== null){
try{fs.unlinkSync(path+files[i]);}catch(e){}
}
}
});
}