-
Notifications
You must be signed in to change notification settings - Fork 527
/
gulpfile.babel.js
80 lines (72 loc) · 2.07 KB
/
gulpfile.babel.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
var gulp = require('gulp');
var fs = require('fs');
var babelify = require('babelify');
var browserify = require('browserify');
var buffer = require('vinyl-buffer');
var source = require('vinyl-source-stream');
var sourcemaps = require('gulp-sourcemaps');
var uglify = require('gulp-uglify');
var clean = require('gulp-clean');
const excludeDirectories = ['node_modules', 'statics', '.git', '.idea', 'common'];
function processOnEachFolder(callback, directory = __dirname) {
fs.readdir(directory, function (err, files) {
for(let file of files) {
if(excludeDirectories.indexOf(file) === -1) {
let path = directory + '/' + file;
fs.stat(path, function (err, stats) {
if(stats.isDirectory()) {
callback(path);
}
});
}
}
});
}
gulp.task('clean', function () {
var callback = function (path) {
gulp.src(path, {read: false})
.pipe(clean());
};
processOnEachFolder(function (path) {
fs.stat(path + '/1', function (err, stats) {
if(stats && stats.isDirectory) {
processOnEachFolder(function (path) {
callback(path + '/dist');
}, path);
} else {
callback(path + '/dist');
}
});
});
});
gulp.task('default', ['clean'], function () {
function bundle(src, dest) {
var bundler = browserify({
entries: src,
debug: true
});
bundler.transform(babelify);
bundler.bundle()
.on('error', function (err) { console.error(err); })
.pipe(source('main.js'))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(uglify()) // Use any gulp plugins you want now
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(dest));
}
function callback(path) {
bundle( path + '/scripts/main.js', path + '/dist/scripts');
}
processOnEachFolder(function (path) {
fs.stat(path + '/1', function (err, stats) {
if(stats && stats.isDirectory) {
processOnEachFolder(function (path) {
callback(path);
}, path);
} else {
callback(path);
}
});
});
});