forked from michael-benin-CN/gifshot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
98 lines (87 loc) · 2.92 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
/*
Build File
*/
// Dependencies
const gulp = require('gulp');
const runSequence = require('run-sequence');
const babel = require('rollup-plugin-babel');
const rollup = require('rollup');
const iife = require("gulp-iife");
const uglify = require('gulp-uglify');
const insert = require('gulp-insert');
const rename = require('gulp-rename');
const mocha = require('gulp-mocha');
const fs = require('fs');
// Helpers
const licenseText = '/*' + fs.readFileSync('./LICENSE.txt', 'utf8') + '\n*/\n';
// const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
gulp.task('build', function (cb) {
rollup.rollup({
entry: 'src/modules/index.js',
plugins: [
babel({
plugins: [
'external-helpers'
],
presets: [
[
'es2015',
{
'modules': false
}
]
]
})
]
}).then(function (bundle) {
bundle.write({
dest: 'src/gifshot.js',
format: 'es'
});
cb();
}).catch(console.error); // log errors;
});
// Wrap IIFE
gulp.task('iife', function () {
return gulp.src('src/gifshot.js')
.pipe(iife({
params: ['window', 'document', 'navigator', 'undefined'],
args: ['typeof window !== "undefined" ? window : {}', 'typeof document !== "undefined" ? document : { createElement: function() {} }', 'typeof window !== "undefined" ? window.navigator : {}']
}))
.pipe(gulp.dest('src'));
});
// Task that runs the Mocha unit tests and Instanbul test coverage
gulp.task('test', function (cb) {
gulp.src('tests/tests.js')
.pipe(mocha({
reporter: 'nyan'
}))
.on('end', cb);
});
// Copies src/gifshot.js to dist/gifshot.js
gulp.task('copy', function () {
return gulp.src('src/gifshot.js')
.pipe(insert.prepend(licenseText))
.pipe(gulp.dest('dist'))
.pipe(gulp.dest('demo/js/dependencies/'));
});
// Uglify.js task that minifies dist/gifshot.js and adds gifshot.min.js to the build folder
gulp.task('minify', function () {
return gulp.src('dist/gifshot.js')
.pipe(uglify())
.pipe(rename('gifshot.min.js'))
.pipe(insert.prepend(licenseText))
.pipe(gulp.dest('dist'))
.pipe(gulp.dest('demo/js/dependencies/'));
});
// The default build task (called when you run `gulp`)
gulp.task('default', function () {
runSequence('build', 'iife', 'test', 'copy', 'minify');
});
// The watch task that runs the default task on any gifshot module file changes
gulp.task('watch', function () {
const watcher = gulp.watch('src/modules/**/*.js', ['default']);
watcher.on('change', function (event) {
console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
});
});