-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
95 lines (80 loc) · 2.47 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
// Built for Gulp v4
var
// modules
gulp = require('gulp'),
concat = require('gulp-concat'),
gfi = require("gulp-file-insert"),
path = require('path'),
del = require('del'),
Q = require('q'),
uglify = require('gulp-uglify'),
stripDebug = require('gulp-strip-debug'),
rename = require('gulp-rename'),
babel = require('gulp-babel'),
// development mode
devBuild = (process.env.NODE_ENV !== 'production'),
// folders
folder = {
src: 'src/',
build: 'build/',
tmp: 'temp/'
}
;
// format: replaceString: foldername
var data = {
"/* insert:snippets */": 'snippets',
"/* insert:files */": 'files',
"/* insert:reports */": 'reports',
"/* insert:callbacks */": 'callbacks',
"/* insert:sites */": 'sites',
"/* insert:assets */": 'assets',
"/* insert:directories */": 'directories',
"/* insert:util */": 'util',
};
gulp.task('concat:js', function () {
console.log("concat:js runs");
var promises = [];
for (var type in data){
var defer = Q.defer();
var pipeline = gulp.src(path.join(folder.src, data[type], '/*.js'))
.pipe(concat( data[type]+'.js', {newLine: ',\n'} ))
.pipe(gulp.dest(folder.tmp));
promises.push(defer.promise);
(function(pipeline, defer){
pipeline.on('end', function () {
defer.resolve();
});
})(pipeline, defer);
}
var all = Q.all(promises);
console.log("promises: ", promises);
all.then(function(){console.log('success');}, function(){console.error('error');}, function(data){console.log("progress data: ", data);});
return all;
});
gulp.task('inject:js', function(){
// point to temp files
var replacements = {};
for (var type in data){
replacements[type] = folder.tmp + data[type] + '.js';
}
return gulp.src(folder.src+"ouapi.js")
.pipe(gfi(replacements))
.pipe(gulp.dest(folder.build));
});
gulp.task('remove:tmp', function(){
return del([folder.tmp+'*']);
});
gulp.task('clean:js', function(){
return gulp.src(folder.build + 'ouapi.js')
.pipe(babel())
.pipe(stripDebug())
.pipe(gulp.dest(folder.build))
.pipe(rename('ouapi.min.js'))
.pipe(uglify())
.pipe(gulp.dest(folder.build));
});
gulp.task('default',
gulp.series('concat:js', 'inject:js',
gulp.parallel('remove:tmp', 'clean:js')
)
);