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
177
178
179
180
|
// **********************************************************************
//
// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************
var browserSync = require("browser-sync");
var concat = require('gulp-concat');
var del = require("del");
var extreplace = require("gulp-ext-replace");
var gzip = require('gulp-gzip');
var newer = require('gulp-newer');
var path = require('path');
var paths = require('vinyl-paths');
var uglify = require("gulp-uglify");
var util = require('./util');
module.exports = function(gulp) {
var subprojects =
{
test: [
"Ice/acm", "Ice/ami", "Ice/binding", "Ice/defaultValue", "Ice/enums", "Ice/exceptions",
"Ice/exceptionsBidir", "Ice/facets", "Ice/facetsBidir", "Ice/hold", "Ice/inheritance",
"Ice/inheritanceBidir", "Ice/location", "Ice/objects", "Ice/operations", "Ice/operationsBidir",
"Ice/optional", "Ice/optionalBidir", "Ice/promise", "Ice/properties", "Ice/proxy", "Ice/retry",
"Ice/slicing/exceptions", "Ice/slicing/objects", "Ice/timeout", "Ice/number", "Glacier2/router"],
demo: ["Ice/hello", "Ice/throughput", "Ice/minimal", "Ice/latency", "Ice/bidir", "Glacier2/chat",
"ChatDemo"]
};
var minDemos =
{
"Ice/minimal":
{
srcs: [
"lib/Ice.min.js",
"demo/Ice/minimal/Hello.js",
"demo/Ice/minimal/browser/Client.js"],
dest: "demo/Ice/minimal/browser/"
},
"ChatDemo":
{
srcs: [
"lib/Ice.min.js",
"lib/Glacier2.min.js",
"demo/ChatDemo/Chat.js",
"demo/ChatDemo/ChatSession.js",
"demo/ChatDemo/Client.js"],
dest: "demo/ChatDemo"
}
};
function testHtmlTask(name) { return "test_" + name.replace("/", "_") + ":html"; }
function testHtmlCleanTask(name) { return "test_" + name.replace("/", "_") + ":html:clean"; }
subprojects.test.forEach(
function(name)
{
gulp.task(testHtmlTask(name), [],
function()
{
return gulp.src("test/Common/index.html")
.pipe(newer(path.join("test", name, "index.html")))
.pipe(gulp.dest(path.join("test", name)));
});
gulp.task(testHtmlCleanTask(name), [],
function()
{
del(path.join("test", name, "index.html"));
});
});
gulp.task("html", subprojects.test.map(testHtmlTask));
gulp.task("html:watch", ["html"],
function()
{
gulp.watch(["test/Common/index.html"], ["html"]);
});
gulp.task("html:clean", subprojects.test.map(testHtmlCleanTask));
Object.keys(subprojects).forEach(
function(group)
{
function groupTask(name) { return group + "_" + name.replace("/", "_"); }
function groupGenerateTask(name) { return groupTask(name); }
function groupWatchTask(name) { return groupTask(name) + ":watch"; }
function groupCleanTask(name) { return groupTask(name) + ":clean"; }
subprojects[group].forEach(
function(name)
{
gulp.task(groupGenerateTask(name), (util.useBinDist ? [] : ["dist"]),
function()
{
return gulp.src(path.join(group, name, "*.ice"))
.pipe(util.slice2js(
{
args: ["-I" + path.join(group, name)],
dest: path.join(group, name)
}))
.pipe(gulp.dest(path.join(group, name)));
});
gulp.task(groupWatchTask(name),
(group == "test" ? [groupGenerateTask(name), "html"] : [groupGenerateTask(name)]),
function()
{
gulp.watch([path.join(group, name, "*.ice")], [groupGenerateTask(name)]);
gulp.watch([path.join(group, name, "*.js"),
path.join(group, name, "browser", "*.js"),
path.join(group, name, "*.html")], function(e){
browserSync.reload(e.path);
});
});
gulp.task(groupCleanTask(name), [],
function()
{
return gulp.src(path.join(group, name, "*.ice"))
.pipe(extreplace(".js"))
.pipe(paths(del));
});
});
gulp.task(group, subprojects[group].map(groupGenerateTask).concat(
group == "test" ? ["common:slice", "common:js", "common:css"].concat(subprojects.test.map(testHtmlTask)) :
["common:slice", "common:js", "common:css", "demo_Ice_minimal:min", "demo_ChatDemo:min"]));
gulp.task(group + ":watch", subprojects[group].map(groupWatchTask).concat(
group == "test" ? ["common:slice:watch", "common:css:watch", "common:js:watch", "html:watch"] :
["common:css:watch", "common:js:watch"].concat(Object.keys(minDemos).map(minDemoWatchTaskName))));
gulp.task(group + ":clean", subprojects[group].map(groupCleanTask).concat(
group == "test" ? subprojects.test.map(testHtmlCleanTask).concat(["common:slice:clean"]) :
["demo_Ice_minimal:min:clean", "demo_ChatDemo:min:clean"]));
});
function demoTaskName(name) { return "demo_" + name.replace("/", "_"); }
function minDemoTaskName(name) { return demoTaskName(name) + ":min"; }
function minDemoWatchTaskName(name) { return minDemoTaskName(name) + ":watch"; }
function minDemoCleanTaskName(name) { return minDemoTaskName(name) + ":clean"; }
Object.keys(minDemos).forEach(
function(name)
{
var demo = minDemos[name];
gulp.task(minDemoTaskName(name), [demoTaskName(name)],
function()
{
return gulp.src(demo.srcs)
.pipe(newer(path.join(demo.dest, "Client.min.js")))
.pipe(concat("Client.min.js"))
.pipe(uglify())
.pipe(gulp.dest(demo.dest))
.pipe(gzip())
.pipe(gulp.dest(demo.dest));
});
gulp.task(minDemoWatchTaskName(name), [minDemoTaskName(name)],
function()
{
gulp.watch(demo.srcs, [minDemoTaskName(name)]);
});
gulp.task(minDemoCleanTaskName(name), [],
function()
{
del([path.join(demo.dest, "Client.min.js"),
path.join(demo.dest, "Client.min.js.gz")]);
});
});
};
|