forked from jbdemonte/gmap3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
111 lines (97 loc) · 3.16 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
var gulp = require("gulp"),
concat = require("gulp-concat"),
clean = require("gulp-clean"),
uglify = require("gulp-uglify"),
rename = require("gulp-rename"),
replace = require("gulp-replace"),
runSequence = require("run-sequence"),
jqc = require("gulp-jquery-closure"),
streamqueue = require('streamqueue'),
mustache = require("gulp-mustache-plus"),
zip = require("gulp-zip"),
md5 = require("MD5"),
path = require("path"),
gulpOptions = require("./gulp-options.js"),
options = gulpOptions.options(),
pjson = require('./package.json');
options.version = pjson.version;
options.date = pjson.date;
gulp.task("clean", function () {
return gulp.src("dist", {read: false}).pipe(clean());
});
gulp.task("cleanTmp", function () {
return gulp.src("tmp", {read: false}).pipe(clean());
});
// build copyright
gulp.task("copyright", function () {
return gulp.src("src/copyright.js")
.pipe(mustache(options, {extension: ".js"}))
.pipe(gulp.dest("./tmp"));
});
// Build tools
gulp.task("tools", function () {
return gulp.src("src/tools.mustache")
.pipe(mustache(options, {extension: ".js", file_prepend: "\n"}, gulpOptions.partials()))
.pipe(gulp.dest("./tmp"));
});
// Build GMAP3 class
gulp.task("gmap3", function () {
return gulp.src("src/gmap3.js")
.pipe(mustache(options, {extension: ".js", file_prepend: "\n"}))
.pipe(gulp.dest("./tmp"));
});
// Build full gmap3 plugin
gulp.task("dist", ["copyright", "tools", "gmap3"], function () {
var stream = streamqueue({ objectMode: true });
stream.queue(gulp.src(["tmp/copyright.js"]));
stream.queue(
gulp.src(["tmp/tools.js", "tmp/gmap3.js", "src/core.js"])
.pipe(concat("gmap3.js"))
.pipe(replace(/(\r\n|\n|\r) *\/\/ *(\r\n|\n|\r)/g, "$1")) // remove the standalone // due to mustache parameters in comments
.pipe(jqc({undefined: "undef"}))
);
return stream.done()
.pipe(concat("gmap3.js"))
.pipe(gulp.dest("dist/"));
});
// Uglify gmap3.js
gulp.task("uglify", function () {
return gulp.src("dist/gmap3.js")
.pipe(uglify({preserveComments: "some"}))
.pipe(rename("gmap3.min.js"))
.pipe(gulp.dest("dist/"));
});
// Append HTML demo and examples into dist
gulp.task("html", function () {
return gulp.src(gulpOptions.assets(), {base: "assets/"})
.pipe(gulp.dest("dist/"));
});
gulp.task("zip", function () {
var filename = "gmap3-" +
options.version +
(options.build_cmd ? "-" + md5(options.build_cmd) : "") +
".zip";
return gulp.src("dist/**/*")
.pipe(zip(filename))
.pipe(gulp.dest("dist/"));
});
// default task
gulp.task("default", function (callback) {
runSequence("clean", "dist", "uglify", "cleanTmp", callback);
});
// build package including demo and examples
gulp.task("package", function (callback) {
runSequence("clean", "dist", "uglify", "html", "zip", "cleanTmp", callback);
});
// extract build_cmd removing task name
options.build_cmd = (function () {
var head = 2,
result = "";
if (process.argv.length > 2) {
if (gulp.hasTask(process.argv[2])) {
head++;
}
result = process.argv.length > head ? "Build options : " + process.argv.slice(head).join(" ") + "\n" : "";
}
return result;
}());