-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgulpfile.js
More file actions
163 lines (141 loc) · 4.65 KB
/
Copy pathgulpfile.js
File metadata and controls
163 lines (141 loc) · 4.65 KB
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// Load plugins and declare variables
"use strict";
var gulp = require("gulp"),
del = require("del"),
bower = require("bower"),
browserify = require("browserify"),
source = require("vinyl-source-stream"),
buffer = require("vinyl-buffer"),
es = require("event-stream"),
qunit = require("node-qunit-phantomjs"),
styledown = require("gulp-styledown"),
gutil = require("gulp-util"),
sourcemaps = require("gulp-sourcemaps"),
plumber = require("gulp-plumber"),
notify = require("gulp-notify"),
bump = require("gulp-bump"),
git = require("gulp-git"),
gitmodified = require("gulp-gitmodified"),
eslint = require("gulp-eslint"),
uglify = require("gulp-uglify"),
rename = require("gulp-rename"),
sass = require("gulp-sass"),
bulkimport = require("gulp-sass-bulk-import"),
combinemq = require("gulp-combine-mq"),
autoprefixer = require("gulp-autoprefixer"),
minify = require("gulp-minify-css"),
onerror = notify.onError("Error: <%= error.message %>");
// Make browserify bundle
function bundle(files, opts) {
var streams = [],
bundler = function(file) {
opts.entries = "./" + file;
return browserify(opts).bundle()
.on("error", function(error) {
onerror(error);
// End the stream to prevent gulp from crashing
this.end();
})
.pipe(source(file.split(/[\\/]/).pop()));
};
opts = opts || {};
if (files && files instanceof Array) {
for (var i = 0, l = files.length; i < l; i++) {
if (typeof files[i] === "string") {
streams.push(bundler(files[i]));
}
}
} else if (typeof files === "string") {
streams.push(bundler(files));
}
return es.merge.apply(null, streams).pipe(buffer());
}
// Install and copy third-party libraries
gulp.task("bower", function() {
return bower.commands.install([], { save: true }, {})
.on("error", onerror);
});
// Bump version and do a new release
gulp.task("bump", [ "test" ], function() {
return gulp.src([ "package.json", "bower.json" ])
.pipe(plumber({ errorHandler: onerror }))
.pipe(bump())
.pipe(gulp.dest("."));
});
gulp.task("release", [ "bump" ], function() {
var version = require("./package.json").version,
message = "Release " + version;
return gulp.src([ "package.json", "bower.json" ])
.pipe(plumber({ errorHandler: onerror }))
.pipe(git.add())
.pipe(git.commit(message))
.on("end", function() {
git.tag("v" + version, message, function() {
git.push("origin", "master", { args: "--tags" }, function() {});
});
});
});
// Lint JavaScript files
gulp.task("lint", function() {
return gulp.src([ "src/js/**/*.js", "test/**/*.js" ])
.pipe(plumber({ errorHandler: onerror }))
.pipe(gitmodified("modified"))
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failOnError());
});
// Combine and minify scripts
gulp.task("bundle", function() {
return bundle("test/test.js", { debug: true })
.pipe(plumber({ errorHandler: onerror }))
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(gutil.env.production ? uglify() : gutil.noop())
.pipe(rename({ suffix: ".min" }))
.pipe(sourcemaps.write("."))
.pipe(gulp.dest("dist/scripts"));
});
gulp.task("scripts", [ "bower", "bundle" ]);
// Generate styles
gulp.task("styles", function() {
return gulp.src("test/**/*.scss")
.pipe(plumber({ errorHandler: onerror }))
.pipe(sourcemaps.init())
.pipe(bulkimport())
.pipe(sass())
.pipe(combinemq())
.pipe(autoprefixer())
.pipe(gutil.env.production ? minify() : gutil.noop())
.pipe(rename({ suffix: ".min" }))
.pipe(sourcemaps.write("."))
.pipe(gulp.dest("dist/styles"));
});
// Generate living styleguide
gulp.task("styleguide", [ "styles" ], function() {
return gulp.src("src/scss/**/*.scss")
.pipe(styledown({
config: "styledown.md",
filename: "index.html"
}))
.pipe(gulp.dest("dist/styleguide"));
});
// Clean up generated files
gulp.task("clean", function() {
return del([ "dist" ]);
});
// Build scripts and styles
gulp.task("build", [ "scripts", "styles" ]);
// Run unit tests with phantom.js
gulp.task("test", [ "build" ], function() {
return qunit("./test/index.html", {
verbose: true,
timeout: 10
});
});
gulp.task("watch", function() {
gulp.watch([ "src/js/**/*.js", "test/**/*.js" ], [ "scripts" ]);
gulp.watch([ "src/scss/**/*.scss", "test/**/*.scss" ], [ "styles" ]);
});
// Default Task
gulp.task("default", [ "lint", "clean" ], function() {
gulp.start("build");
});