-
Notifications
You must be signed in to change notification settings - Fork 13
/
gulpfile.js
105 lines (90 loc) · 2.49 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
// Build automation
// Require sudo npm install -g gulp
// For dev, initiate watch by executing either `gulp` or `gulp watch`
var gulp = require('gulp'),
browserify = require('browserify'),
source = require('vinyl-source-stream'),
buffer = require('vinyl-buffer'),
gutil = require('gulp-util'),
uglify = require('gulp-uglify'),
shell = require('gulp-shell'),
rename = require('gulp-rename');
_ = require('underscore');
listFiles = require('file-lister');
var babelify = require('babelify');
var path = {
originalJs: ['./js/framework','./js/plugins'],
dependencies: ['./js/plugin-dependencies'],
scripts: ['./js/plugins/**/*.*']
};
// Build All
gulp.task('build', ['browserify', 'publishDependencies']);
gulp.task('publishDependencies', function() {
var publish = function(srcArray)
{
_.each(srcArray, function(sourceFile)
{
gulp.src(sourceFile).pipe(gulp.dest('./build/'));
});
};
listFiles(path.dependencies, function(error, files) {
if (error) {
console.log(error);
} else {
var filteredList = files.filter(_.bind(checkFileExtension,this,".js"));
publish(filteredList);
}
});
});
gulp.task('browserify', function() {
var bundleThis = function(srcArray)
{
_.each(srcArray, function(sourceFile)
{
var b = browserify({
entries: sourceFile,
debug: false,
transform: [babelify]
});
b.bundle()
.pipe(source(getFileNameFromPath(sourceFile)))
.pipe(buffer())
.pipe(gulp.dest('./build/'))
.pipe(uglify())
.pipe(rename({
extname: '.min.js'
}))
.pipe(gulp.dest('./build/'))
});
};
listFiles(path.originalJs, function(error, files) {
if (error) {
console.log(error);
} else {
var filteredList = files.filter(_.bind(checkFileExtension,this,".js"));
bundleThis(filteredList);
}
});
});
var checkFileExtension = function(extension, fileName)
{
if (!fileName || fileName.length < extension.length)
{
return false;
}
return (fileName.lastIndexOf(extension) == fileName.length - extension.length);
}
var getFileNameFromPath = function(path)
{
var start = path.lastIndexOf('/') + 1;
return path.substring(start);
}
// Run tests
gulp.task('test', shell.task(['npm test']));
// Initiate a watch
gulp.task('watch', function()
{
gulp.watch(path.scripts, ['browserify']);
});
// The default task (called when you run `gulp` from cli)
gulp.task('default', ['build']);