Skip to content

Commit f9dbf27

Browse files
committed
Add gulp file with multiple tasks
- help: receive a list of available tasks - clean: delete `release` folder - build-min: minify and copy module to release folder - copy-module: simple copy of source module to release folder - build: a combination of `build-min` and `copy-module` tasks
1 parent a59fe11 commit f9dbf27

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

Diff for: gulpfile.js

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
var gulp = require("gulp"),
2+
del = require("del"),
3+
plugins = require("gulp-load-plugins")();
4+
5+
var paths = require("./gulp.config.json");
6+
7+
var log = plugins.util.log,
8+
colors = plugins.util.colors;
9+
10+
gulp.task("help", plugins.taskListing);
11+
12+
gulp.task("clean", function (callback) {
13+
log("Cleaning: " + colors.blue(paths.release));
14+
15+
del(paths.release, callback);
16+
});
17+
18+
gulp.task("build-min", function () {
19+
log("Minifying and copying angular module to release folder: " + colors.blue(paths.release));
20+
21+
return gulp
22+
.src(paths.source)
23+
.pipe(plugins.ngAnnotate())
24+
.pipe(plugins.bytediff.start())
25+
.pipe(plugins.uglify())
26+
.pipe(plugins.bytediff.stop(bytediffFormatter))
27+
.pipe(plugins.rename({ extname: ".min.js" }))
28+
.pipe(gulp.dest(paths.release));
29+
});
30+
31+
gulp.task("copy-module", function () {
32+
log("Copying angular module to release folder: " + colors.blue(paths.release));
33+
34+
return gulp
35+
.src(paths.source)
36+
.pipe(plugins.ngAnnotate())
37+
.pipe(plugins.rename({ extname: ".js" }))
38+
.pipe(gulp.dest(paths.release));
39+
});
40+
41+
gulp.task("build", [ "build-min", "copy-module" ], function () {});
42+
43+
/////////////////////////////////////////////////////////////////////////////////////////////
44+
45+
function bytediffFormatter(data) {
46+
var difference = (data.savings > 0) ? " smaller." : " larger.";
47+
48+
return data.fileName
49+
+ " went from "
50+
+ colors.yellow((data.startSize / 1000).toFixed(2) + " kB")
51+
+ " to "
52+
+ colors.yellow((data.endSize / 1000).toFixed(2) + " kB")
53+
+ " and is "
54+
+ colors.yellow(formatPercent(1 - data.percent, 2) + "%")
55+
+ difference;
56+
}
57+
58+
function formatPercent(num, precision) {
59+
return (num * 100).toFixed(precision);
60+
}

0 commit comments

Comments
 (0)