-
Notifications
You must be signed in to change notification settings - Fork 384
/
gulpfile.js
176 lines (127 loc) · 3.78 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
"use strict";
var meta = require("./package.json");
var path = require("path");
var gulp = require("gulp");
var uglify = require("gulp-uglify");
var rename = require("gulp-rename");
var concat = require("gulp-concat");
var clean = require("gulp-clean");
var minifyCSS = require("gulp-minify-css");
var replace = require("gulp-replace");
var shell = require("gulp-shell");
var API_JS_BUILD_ROOT = path.join("build", "api", meta.version);
// Cleaning.
gulp.task("clean", function() {
return gulp.src([
"build"
], {
"read": false
})
.pipe(clean());
});
// Building.
gulp.task("api-js", function() {
return gulp.src([
"src/lib/flowplayer/flowplayer.js",
"src/lib/domready/domready.js",
"src/api/html5media.js"
])
.pipe(concat("html5media.js"))
.pipe(gulp.dest(API_JS_BUILD_ROOT))
.pipe(uglify())
.pipe(rename("html5media.min.js"))
.pipe(gulp.dest(API_JS_BUILD_ROOT));
});
gulp.task("api-swf", function() {
return gulp.src([
"src/lib/flowplayer/flowplayer.swf",
"src/lib/flowplayer/flowplayer.controls.swf",
"src/lib/flowplayer.audio/flowplayer.audio.swf",
"src/lib/swfobject/expressInstall.swf"
])
.pipe(gulp.dest(API_JS_BUILD_ROOT));
});
gulp.task("api-license", function() {
return gulp.src([
"LICENSE",
])
.pipe(gulp.dest(API_JS_BUILD_ROOT));
});
gulp.task("api", ["api-js", "api-swf", "api-license"]);
gulp.task("media-css", function() {
return gulp.src([
"src/media/styles.css"
])
.pipe(gulp.dest("build/media"))
.pipe(minifyCSS({
compatibility: "ie8"
}))
.pipe(rename("styles.min.css"))
.pipe(gulp.dest("build/media"));
});
gulp.task("media-static", function() {
return gulp.src([
"src/media/*",
"!src/media/*.css",
])
.pipe(gulp.dest("build/media"));
});
gulp.task("media", ["media-static", "media-css"]);
function injectHtml(stream) {
return stream
// Fix api paths.
.pipe(replace(/\.\.\/api\//g, "//api.html5media.info/" + meta.version + "/"))
// Fix media paths.
.pipe(replace(/\.\.\/media\//g, "//media.html5media.info/"))
// Use minified js.
.pipe(replace(/html5media\.js/g, "html5media.min.js"))
// Use minified css.
.pipe(replace(/styles\.css/g, "styles.min.css"));
}
gulp.task("www-html", ["api"], function() {
return injectHtml(gulp.src([
"src/www/*.html"
]))
.pipe(gulp.dest("build/www"));
});
gulp.task("www", ["www-html"]);
gulp.task("common-misc", function() {
return gulp.src([
"src/common/*.txt",
"src/common/*.xml"
])
.pipe(gulp.dest("build/api"))
.pipe(gulp.dest("build/media"))
.pipe(gulp.dest("build/www"));
});
gulp.task("common-html", ["api"], function() {
return injectHtml(gulp.src([
"src/common/*.html"
]))
.pipe(gulp.dest("build/api"))
.pipe(gulp.dest("build/media"))
.pipe(gulp.dest("build/www"));
});
gulp.task("common", ["common-misc", "common-html"]);
gulp.task("build", ["api", "media", "www", "common"]);
// Distributing.
gulp.task("dist", ["build"], function() {
return gulp.src([
"build/**",
])
.pipe(gulp.dest("dist/"));
});
// Publishing.
var publishViaRsync = function(src, dest) {
return "rsync -rh --progress --delete " + src + " " + process.env.HTML5MEDIA_HOST + ":" + dest;
};
gulp.task("publish-www", ["dist"], shell.task([
publishViaRsync("dist/www/*", process.env.HTML5MEDIA_PATH_WWW),
]));
gulp.task("publish-media", ["dist"], shell.task([
publishViaRsync("dist/media/*", process.env.HTML5MEDIA_PATH_MEDIA),
]));
gulp.task("publish-api", ["dist"], shell.task([
publishViaRsync("dist/api/*", process.env.HTML5MEDIA_PATH_API),
]));
gulp.task("publish", ["publish-www", "publish-media", "publish-api"]);