-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathGulpfile.js
84 lines (74 loc) · 2.42 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
var _ = require("underscore");
var gulp = require("gulp");
var jshint = require("gulp-jshint");
var concat = require("gulp-concat");
var uglify = require("gulp-uglify");
var rename = require("gulp-rename");
var declare = require("gulp-declare");
var insert = require("gulp-insert");
var through = require("through2");
var widgetRoot = process.cwd() + "/lib/widgets/";
gulp.task("lint", function() {
gulp.src(["./lib/**/*.js"])
.pipe(jshint())
.pipe(jshint.reporter());
});
// There is some serious voodoo going on with this one.
//
// The output needs to be wrapped in a self-executing function or we run
// into "unexpected token" errors during `rake assets:precompile`
//
// We also need to include a statement outside of the function or we run
// into "Uncaught object" errors during development.
gulp.task("templates", function(){
function logicalPath(path) {
return path.replace(widgetRoot, "").replace(".jst", "");
}
gulp.src("lib/**/*.jst")
.pipe(through.obj(function (file, enc, cb) {
try {
file.contents = new Buffer(_.template(file.contents.toString()).source);
} catch (err) {
this.emit('error', new gutil.PluginError('gulp-template', err));
}
this.push(file);
cb();
}))
.pipe(declare({
namespace: "Widgets.templates",
processName: logicalPath
}))
.pipe(concat("templates.js"))
.pipe(insert.wrap("(function() {\n", "\n}).call(this);\n"))
.pipe(gulp.dest("./tmp"));
});
gulp.task("concat", function() {
gulp.src(["tmp/index.js", "tmp/templates.js"])
.pipe(concat("widgets.js"))
.pipe(gulp.dest("./dist"));
});
gulp.task("default", function() {
gulp.run("jshint", "test");
});
// Getting useless stack traces when mocha is run through gulp
// gulp.task("test", function() {
// gulp.src("test/**/*.js")
// .pipe(mocha({ reporter: "spec" }));
// });
// Exec output not being captured for some reason
// gulp.task("browserify", function() {
// // gulp.src("").pipe(exec("browserify index.js -s Widgets > ./tmp/index.js"));
// // gulp.src("")
// // .pipe(exec("browserify index.js"))
// // .pipe(gulp.dest("./tmp"));
// });
// gulp.task("browserify", function() {
// gulp.src("index.js")
// .pipe(browserify({
// external: ["underscore", "qs"],
// standalone: "Widgets",
// // exclude: "underscore", // ["underscore", "qs"]
// ignoreMissing: true
// }))
// .pipe(gulp.dest("./tmp"));
// });