-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathgulpfile.js
104 lines (78 loc) · 3.26 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
(function main() {
var gulp = require('gulp'),
jshint = require('gulp-jshint'),
uglify = require('gulp-uglify'),
rename = require('gulp-rename'),
concat = require('gulp-concat'),
babel = require('gulp-babel'),
fs = require('fs'),
yaml = require('js-yaml'),
browserify = require('browserify'),
babelify = require('babelify');
var cfg = yaml.safeLoad(fs.readFileSync('maple.yml', 'utf8')),
entryFile = cfg.gulp.entry,
allFiles = cfg.gulp.all,
prodPath = cfg.gulp.directories.dist + '/' + cfg.gulp.names.default.prod,
devPath = cfg.gulp.directories.dist + '/' + cfg.gulp.names.default.dev;
/**
* @method compile
* @param {String} destPath
* @param {String} [entryPath=entryFile]
* @return Object
*/
var compile = function(destPath, entryPath) {
return browserify({ debug: true })
.transform(babelify)
.require(entryPath || entryFile, { entry: true })
.bundle()
.on('error', function (model) { console.error(['Error:', model.message].join(' ')); })
.pipe(fs.createWriteStream(destPath));
};
gulp.task('bundler', ['compile', 'babel'], function() {
return gulp.src([].concat(cfg.gulp.polyfills.bower, [prodPath]))
.pipe(concat('all.js'))
.pipe(rename(cfg.gulp.names.bundle.dev))
.pipe(gulp.dest(cfg.gulp.directories.dist))
.pipe(uglify())
.pipe(rename(cfg.gulp.names.bundle.prod))
.pipe(gulp.dest(cfg.gulp.directories.dist));
});
gulp.task('minify', ['compile'], function() {
return gulp.src(devPath)
.pipe(rename(prodPath))
.pipe(uglify())
.pipe(gulp.dest(cfg.gulp.directories.dist));
});
gulp.task('compile', function() {
return compile(devPath);
});
gulp.task('minify', ['compile'], function() {
return gulp.src(devPath)
.pipe(uglify())
.pipe(rename(cfg.gulp.names.default.prod))
.pipe(rename(cfg.gulp.names.default.prod))
.pipe(gulp.dest(cfg.gulp.directories.dist));
});
gulp.task('vendorify', ['compile'], function() {
return gulp.src(devPath)
.pipe(rename(cfg.gulp.names.default.dev))
.pipe(gulp.dest(cfg.gulp.directories.vendor + '/maple'));
});
gulp.task('lint', function() {
return gulp.src(allFiles)
.pipe(jshint())
.pipe(jshint.reporter('default', {
verbose: true
}));
});
gulp.task('babel', function() {
return gulp.src(cfg.gulp.polyfills.npm + '/*.js', { base: './node_modules' })
.pipe(gulp.dest(cfg.gulp.directories.vendor));
});
gulp.task('test', ['lint']);
gulp.task('build', ['compile', 'babel', 'vendorify', 'minify', 'bundler']);
gulp.task('default', ['test', 'build']);
gulp.task('watch', function watch() {
gulp.watch(cfg.gulp.all, ['compile', 'vendorify']);
});
})();