-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
executable file
·106 lines (92 loc) · 2.81 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
'use strict';
var babelify = require('babelify');
var babelRegister = require('babel-register');
var browserify = require('browserify');
var buffer = require('vinyl-buffer');
var childProcess = require('child_process');
var del = require('del');
var gulp = require('gulp');
var gulpif = require('gulp-if');
var mocha = require('gulp-mocha');
var rename = require('gulp-rename');
var source = require('vinyl-source-stream');
var uglify = require('gulp-uglify');
var config = {
environment: 'production',
development: {
lint: true,
minify: false,
sourcemaps: true
},
production: {
lint: false,
minify: true,
sourcemaps: false
},
scripts: {
destDirectory: './dist',
destFileName: 'oculo.js',
source: './src/scripts/oculo.js'
},
tests: {
source: './tests/*.js'
},
vendor: {
dest: ['./dist/TweenMax.min.js', './dist/Draggable.min.js'],
source: ['./node_modules/gsap/src/minified/TweenMax.min.js', './node_modules/gsap/src/minified/utils/Draggable.min.js']
}
};
var docs = {
destDirectory: './docs'
};
if (config.environment === 'production') {
process.env.NODE_ENV = config.environment;
}
// set up default task
gulp.task('default', ['build']);
gulp.task('build', ['compile:scripts'], function () {
return;
});
gulp.task('clean:docs', function () {
return del(docs.destDirectory);
});
gulp.task('clean:scripts', function () {
return del(config.scripts.destDirectory);
});
gulp.task('copy:vendor', ['clean:scripts'], function () {
return gulp.src(config.vendor.source)
.pipe(gulp.dest(config.scripts.destDirectory));
});
gulp.task('compile:scripts', ['clean:scripts', 'copy:vendor'], function () {
return browserify(config.scripts.source, {
debug: config[config.environment].sourcemaps,
standalone: 'Oculo',
transform: babelify
})
.bundle()
.on('error', function (error) {
console.log('Error: ' + error.message);
})
.pipe(source(config.scripts.destFileName))
// Minify
.pipe(buffer())
.pipe(gulpif(config[config.environment].minify, uglify()))
.pipe(gulpif(config[config.environment].minify, rename({suffix: '.min'})))
.pipe(gulp.dest(config.scripts.destDirectory));
});
gulp.task('generate:docs', ['clean:docs'], function () {
childProcess.exec('./node_modules/jsdoc/jsdoc.js -c jsdocconfig.json');
});
gulp.task('test:scripts', function () {
return gulp.src(config.tests.source)
.pipe(mocha({
compilers: {
js: babelRegister
},
reporter: 'nyan'
})
// HACK: process hangs when GSAP is imported in a test
.once('end', function () {
process.exit();
}));
});