-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.js
141 lines (125 loc) · 3.44 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
var gulp = require("gulp");
var sourcemaps = require("gulp-sourcemaps");
var browserify = require("browserify");
var source = require("vinyl-source-stream");
var buffer = require("vinyl-buffer");
var stringify = require("stringify");
var ngAnnotate = require("gulp-ng-annotate");
var config = require("./package.json");
var writeJSON = require("jsonfile").writeFileSync;
var bump = require('gulp-bump');
var uglify = require('gulp-uglify');
var watchify = require('watchify');
var gutil = require('gulp-util');
var spawn = require('child_process').spawn;
var gulpif = require('gulp-if');
var ghPages = require('gulp-gh-pages');
gulp.task("default", ["package"], function() {});
var fullBundle = browserify({
entries: ["src/index.js"],
cache: {},
packageCache: {},
debug: true,
transform: stringify(),
standalone: "endev",
ignoreTransform: ["browserify-shim"]
});
var bundle = browserify({
entries: ["src/index.js"],
cache: {},
packageCache: {},
debug: true,
transform: stringify(),
standalone: "endev",
});
var p = null
var spawnChildren = function(){
if(p) p.kill();
return p = spawn('gulp',['watch'], {stdio: 'inherit'});
}
gulp.task("watch",function(){
var watchifyBundle = watchify(fullBundle);
var bundle = function(file){
if(file) {
file.map(function (fileName) {
gutil.log('File updated', gutil.colors.yellow(fileName));
});
}
return watchifyBundle.bundle()
.on('error', gutil.log.bind(gutil, 'Browserify Error'))
.pipe(source("endev.full.js"))
.pipe(buffer())
.pipe(sourcemaps.init({
loadMaps: true
}))
.pipe(ngAnnotate())
.pipe(sourcemaps.write("./"))
.pipe(gulp.dest("./dist"))
.on('end', gutil.log.bind(gutil,'Done!'));
}
watchifyBundle.on('update',bundle);
gulp.watch('gulpfile.js',spawnChildren)
return bundle();
})
var build = function(full, minify) {
var name = "endev" + (full ? '.full' : '') + (minify ? '.min' : '') + ".js";
var b = full ? fullBundle : bundle;
return b.bundle()
.pipe(source(name))
.pipe(buffer())
.pipe(sourcemaps.init({
loadMaps: true
}))
.pipe(ngAnnotate())
.pipe(gulpif(minify,uglify()))
.pipe(sourcemaps.write("./"))
.pipe(gulp.dest("./dist"));
}
gulp.task("full", function() {
return build(true);
});
gulp.task("small", function() {
return build(false);
});
gulp.task("build",['full','small','uglifyFull','uglifySmall']);
gulp.task("uglifyFull", function() {
return build(true,true);
});
gulp.task("uglifySmall", function() {
return build(true,true);
});
gulp.task("package", ["build"], function() {
var filename, i, json, len, ref, results;
json = {
name: config.name,
version: config.version,
author: config.author,
license: config.license,
description: config.description,
main: "endev.full.js",
moduleType: ["globals", "node", "amd", "es6", "yui"],
repository: config.repository,
bugs: config.bugs
};
ref = ["package", "bower"];
results = [];
for (i = 0, len = ref.length; i < len; i++) {
filename = ref[i];
results.push(writeJSON("dist/" + filename + ".json", json, {
spaces: 2
}));
}
return results;
});
gulp.task("bump", function(){
gulp.src(['./package.json','./bower.json'])
.pipe(bump())
.pipe(gulp.dest('./'));
});
gulp.task('deploy', ['build'], function() {
return gulp.src('./dist/**/*')
.pipe(ghPages({
remove: false,
cacheDir: "../gh-pages",
}));
});