-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathgulpfile.js
155 lines (142 loc) · 3.67 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
147
148
149
150
151
152
153
154
155
var gulp = require("gulp"),
path = require("path"),
dateformat = require("dateformat"),
sync = require("gulp-sync")(gulp),
concat = require("gulp-concat"),
rename = require("gulp-rename"),
header = require("gulp-header"),
sass = require("gulp-sass"),
base64 = require("gulp-base64"),
templatecache = require("gulp-angular-templatecache"),
usemin = require("gulp-usemin"),
uglify = require("gulp-uglify"),
minifyCss = require("gulp-minify-css"),
minifyHtml = require("gulp-minify-html"),
replace = require("gulp-replace"),
connect = require("gulp-connect"),
karma = require("gulp-karma");
var pkg = require("./package.json"),
banner = [
"/* " + pkg.name + " v" + pkg.version + " " + dateformat(new Date(), "yyyy-mm-dd"),
" * " + pkg.homepage,
" * License: " + pkg.license,
" */\n\n"
].join("\n"),
paths = {
"index.html": ["index.html"],
"index.src.html": ["index.src.html"],
"tmpl": ["directives/*.html", "index/*.html"],
"js": ["!**/*.tmp.js", "!**/*.test.js",
"config/*.js", "directives/*.js", "index/*.js", "services/*.js"],
"css": ["index/*.css"],
"sass": ["index/*.scss"],
"test": ["!**/*.tmp.js", "!config/ga.js",
"lib/angular/angular.js",
"lib/angular-mocks/angular-mocks.js",
"lib/angular-ui-bootstrap-bower/ui-bootstrap-tpls.js",
"lib/angular-animate/angular-animate.js",
"lib/angular-local-storage/angular-local-storage.js",
"lib/angular-translate/angular-translate.js",
"lib/xterm.js/src/xterm.js",
"config/*.js", "directives/*.js", "index/*.js", "services/*.js"]
};
gulp.task("build", sync.sync([
["sass", "js", "tmpl", "bower.json"],
["css"],
["index.src.html"],
["index.html"]
]));
gulp.task("default", ["build", "watch", "connect"]);
gulp.task("sass", function(done) {
gulp.src(paths.sass)
.pipe(sass())
.pipe(base64({
baseDir: "./",
maxImageSize: 16 * 1024,
debug: true
}))
.pipe(gulp.dest("index/"))
.pipe(rename({ extname: ".css" }))
.pipe(connect.reload())
.on("end", done);
});
gulp.task("css", function(done) {
gulp.src(paths.css)
.pipe(connect.reload())
.on("end", done);
});
gulp.task("js", function(done) {
gulp.src(paths.js)
.pipe(connect.reload())
.on("end", done);
});
gulp.task("tmpl", function(done) {
gulp.src(paths.tmpl)
.pipe(templatecache("angular-template.tmp.js", {
module: "KDockerWeb",
base: function(file) {
return path.relative(".", file.path);
}
}))
.pipe(gulp.dest("./index/"))
.pipe(connect.reload())
.on("end", done);
});
gulp.task("index.src.html", function(done) {
gulp.src(["index.src.html"])
.pipe(rename({ basename: "index" }))
.pipe(gulp.dest("./"))
.pipe(connect.reload())
.on("end", done);
});
gulp.task("index.html", function(done) {
gulp.src(["index.html"])
.pipe(usemin({
css: [
minifyCss(),
header(banner)
],
js: [
replace(/\.version = \"0\";/, ".version = \"" + pkg.version + "\""),
uglify(),
header(banner)
],
html: [
minifyHtml({ empty: true })
],
enableHtmlComment: true
}))
.pipe(gulp.dest("./"))
.pipe(connect.reload())
.on("end", done);
});
gulp.task("bower.json", function(done) {
gulp.src(["bower.json"])
.pipe(replace(/"version": "[^"]*"/, "\"version\": \"" + pkg.version + "\""))
.pipe(gulp.dest("./"))
.on("end", done);
});
gulp.task("watch", ["build"], function() {
for (var i in paths) {
gulp.watch(paths[i], [i]);
}
});
gulp.task("connect", ["build"], function() {
connect.server({
root: "./",
port: 9000,
livereload: true
});
});
gulp.task("test", function(done) {
gulp.src(paths.test)
.pipe(karma({
configFile: "karma.config.js",
action: "run"
}))
.on("error", function(err) {
console.log(err);
this.emit("end");
})
.on("end", done);
});