forked from mbjorkegren/handlebones
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
146 lines (133 loc) · 3.28 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
142
143
144
145
146
var gulp = require("gulp"),
mocha = require("gulp-mocha"),
jshint = require("gulp-jshint"),
uglify = require("gulp-uglify"),
rename = require("gulp-rename"),
clean = require("gulp-clean"),
connect = require("gulp-connect"),
rjs = require("gulp-requirejs"),
async = require("async"),
exec = require("child_process").exec;
gulp.task("mocha", [
"connect",
"dist",
"require:jquery",
"require:zepto"
], function () {
async.series([
"jquery.html",
"zepto.html",
"jquery-bundle.html",
"zepto-bundle.html"
].map(function (page) {
return function (next) {
var cmd = "mocha-phantomjs http://localhost:8080/" + page,
child = exec(cmd, function (error, stdout, stderr) {
if (error) {
throw error;
}
if (stdout) {
process.stdout.write(stdout);
}
if (stderr) {
process.stderr.write(stderr);
}
next();
});
};
}), function () {
process.exit();
});
});
var rjsShim = {
"underscore": {
exports: "_"
},
"backbone": {
deps: ["jquery", "underscore"],
exports: "Backbone"
},
"Handlebars": {
exports: "Handlebars"
},
"jquery": {
exports: "$"
},
"zepto": {
exports: "$"
}
};
var rjsPaths = {
"jquery": "bower_components/jquery/dist/jquery",
"zepto": "bower_components/zepto/zepto",
"underscore": "bower_components/underscore/underscore",
"backbone": "bower_components/backbone/backbone",
"Handlebars": "bower_components/handlebars/handlebars",
};
gulp.task("require:jquery", function () {
return rjs({
baseUrl: "./",
name: "handlebones",
out: "handlebones-jquery-bundle.js",
shim: rjsShim,
paths: rjsPaths,
map: {
"*": {
// Handlebars is used variously by different vendors. Do both here.
"handlebars": "Handlebars"
}
}
// ... more require.js options
}).pipe(gulp.dest("./")); // pipe it to the output DIR
});
gulp.task("require:zepto", function () {
return rjs({
baseUrl: "./",
name: "handlebones",
out: "handlebones-zepto-bundle.js",
shim: rjsShim,
paths: rjsPaths,
map: {
"*": {
"jquery": "zepto",
// Handlebars is used variously by different vendors. Do both here.
"handlebars": "Handlebars"
}
}
// ... more require.js options
}).pipe(gulp.dest("./")); // pipe it to the output DIR
});
gulp.task("connect", connect.server({
root: ["test", "bower_components", __dirname],
livereload: false,
port: 8080
}));
gulp.task("dist", ["move-map"], function () {
return gulp.src("./dist", {
read: false
}).pipe(clean({
force: true
}));
});
gulp.task("compress", function() {
return gulp.src("./handlebones.js")
.pipe(uglify({
outSourceMap: true
}))
.pipe(gulp.dest("./dist"));
});
gulp.task("move-dist", ["compress"], function () {
return gulp.src("./dist/handlebones.js")
.pipe(rename("handlebones.min.js"))
.pipe(gulp.dest("."));
});
gulp.task("move-map", ["move-dist"], function () {
return gulp.src("./dist/handlebones.js.map")
.pipe(gulp.dest("."));
});
gulp.task("lint", function() {
return gulp.src("./handlebones.js")
.pipe(jshint())
.pipe(jshint.reporter("default"));
});
gulp.task("default", ["lint", "mocha", "dist"]);