forked from PopcornTimeCommunity/desktop
-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
320 lines (293 loc) · 9.33 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
var gulp = require("gulp");
var NwBuilder = require("nw-builder");
var os = require("os");
var del = require("del");
var zip = require("gulp-zip");
var unzip = require("gulp-unzip");
var gzip = require("gulp-gzip");
var tar = require("gulp-tar");
var download = require("gulp-download");
var package = require("./package.json");
var merge2 = require("merge2");
//Write function to detect current platform
function detectCurrentPlatform() {
if (os.platform() === "win32") {
return "win32";
} else if (os.platform() === "linux") {
return "linux64";
} else if (os.platform() === "darwin") {
return "mac64";
}
}
//Commandline
var argv = require("yargs")
.alias("p", "platforms")
.options({
nwversion: {
alias: "nwv",
describe: "Set nw.js version",
},
nwdownloadurl: {
alias: "nwurl",
describe: "Provide an alt download URL",
},
})
.help().argv;
//Set Default nw.js version
var nwVersion = "0.44.1";
var buildDownloadUrl = "https://dl.nwjs.io/";
nwVersion = argv.nwv ? argv.nwv : nwVersion;
buildDownloadUrl = argv.nwurl ? argv.nwurl : buildDownloadUrl;
var buildplatforms = argv.p ? argv.p.split(",") : [detectCurrentPlatform()];
//Example URL FFMPEG Location:
//https://github.com/iteufel/nwjs-ffmpeg-prebuilt/releases/download/0.31.4/0.31.4-osx-x64.zip
var ffmpegDownloadurl =
"https://github.com/iteufel/nwjs-ffmpeg-prebuilt/releases/download/" +
nwVersion;
//Platform specific overrides if needed
if (buildplatforms.indexOf("linuxarm") >= 0) {
nwVersion = "0.31.2";
}
if (buildplatforms.indexOf("linuxarm") >= 0) {
buildDownloadUrl =
"https://github.com/LeonardLaszlo/nw.js-armv7-binaries/releases/download/v0.27.6/nwjs-sdk-v0.27.6-linux-arm-chrome-branding.tar.gz";
}
var nw = new NwBuilder({
files: [
"./src/**",
"./node_modules/**",
"./package.json",
"./install",
"LICENSE.txt",
"CHANGELOG.md",
"README.md",
],
version: nwVersion,
zip: false,
downloadUrl: buildDownloadUrl,
platforms: buildplatforms,
});
gulp.task("run", function run() {
nw.options.files = "./**";
return nw.run().catch(function (error) {
console.error(error);
});
});
var buildTask = function () {
return nw.build().catch(function (error) {
console.error(error);
});
};
var cleanTask = function () {
var item = 0;
buildplatforms.forEach((item) => {
del("build/Popcorn-Time-CE/" + item + "/");
});
return del("build/Popcorn-Time-CE/" + item + "/");
};
var ffmpegcacheTask = function () {
var cacheDir = "./cache/" + nwVersion + "-sdk";
var downloadArray = merge2();
var item = 0;
buildplatforms.forEach((item) => {
switch (item) {
case "linux64":
//Copy updated FFMPEG into the cache directory before building
downloadArray.add(
download(ffmpegDownloadurl + "/" + nwVersion + "-linux-x64.zip")
.pipe(unzip())
.pipe(gulp.dest(cacheDir + "/" + item + "/lib")),
);
break;
case "linux32":
//Copy updated FFMPEG into the cache directory before building
downloadArray.add(
download(ffmpegDownloadurl + "/" + nwVersion + "-linux-ia32.zip")
.pipe(unzip())
.pipe(gulp.dest(cacheDir + "/" + item + "/lib")),
);
break;
case "win32":
//Copy updated FFMPEG into the cache directory before building
downloadArray.add(
download(ffmpegDownloadurl + "/" + nwVersion + "-win-ia32.zip")
.pipe(unzip())
.pipe(gulp.dest(cacheDir + "/" + item)),
);
break;
case "win64":
//Copy updated FFMPEG into the cache directory before building
downloadArray.add(
download(ffmpegDownloadurl + "/" + nwVersion + "-win-x64.zip")
.pipe(unzip())
.pipe(gulp.dest(cacheDir + "/" + item)),
);
break;
case "osx64":
var fs = require("fs");
var osxCachedir =
"./cache/" + nwVersion + "-sdk/osx64/nwjs.app/Contents/Versions/";
var files = fs.readdirSync(osxCachedir);
if (files.length > 0) {
osxCachedir =
"./cache/" +
nwVersion +
"-sdk/osx64/nwjs.app/Contents/Versions/" +
files[0];
}
downloadArray.add(
download(ffmpegDownloadurl + "/" + nwVersion + "-osx-x64.zip")
.pipe(unzip())
.pipe(gulp.dest(osxCachedir)),
);
break;
}
});
return downloadArray;
};
var ffmpegbuildTask = function () {
var downloadArray = merge2();
var item = 0;
buildplatforms.forEach((item) => {
switch (item) {
case "linux64":
//Copy updated FFMPEG into the cache directory before building
downloadArray.add(
download(ffmpegDownloadurl + "/" + nwVersion + "-linux-x64.zip")
.pipe(unzip())
.pipe(gulp.dest("./pre/" + item))
.pipe(gulp.dest("./build/Popcorn-Time-CE/" + item + "/lib")),
);
break;
case "linux32":
//Copy updated FFMPEG into the cache directory before building
downloadArray.add(
download(ffmpegDownloadurl + "/" + nwVersion + "-linux-ia32.zip")
.pipe(unzip())
.pipe(gulp.dest("./pre/" + item))
.pipe(gulp.dest("./build/Popcorn-Time-CE/" + item + "/lib")),
);
break;
case "win32":
//Copy updated FFMPEG into the cache directory before building
downloadArray.add(
download(ffmpegDownloadurl + "/" + nwVersion + "-win-ia32.zip")
.pipe(unzip())
.pipe(gulp.dest("./pre/" + item))
.pipe(gulp.dest("./build/Popcorn-Time-CE/" + item)),
);
break;
case "win64":
//Copy updated FFMPEG into the cache directory before building
downloadArray.add(
download(ffmpegDownloadurl + "/" + nwVersion + "-win-x64.zip")
.pipe(unzip())
.pipe(gulp.dest("./pre/" + item))
.pipe(gulp.dest("./build/Popcorn-Time-CE/" + item)),
);
break;
case "osx64":
var fs = require("fs");
var osxBuilddir =
"./build/Popcorn-Time-CE/" +
item +
"/" +
"Popcorn-Time-CE.app/Contents/Versions/";
var files = fs.readdirSync(osxBuilddir);
if (files.length > 0) {
//osxCachedir = './cache/' + nwVersion + '-sdk/osx64/nwjs.app/Contents/Versions/' + files[0];
osxBuilddir =
"./build/Popcorn-Time-CE/" +
item +
"/" +
"Popcorn-Time-CE.app/Contents/Versions/" +
files[0];
}
//Copy updated FFMPEG into the cache directory before building
//https://github.com/iteufel/nwjs-ffmpeg-prebuilt/releases/download/0.31.4/0.31.4-osx-x64.zip
downloadArray.add(
download(ffmpegDownloadurl + "/" + nwVersion + "-osx-x64.zip")
.pipe(unzip())
.pipe(gulp.dest("./pre/" + item))
.pipe(gulp.dest(osxBuilddir)),
);
break;
}
});
return downloadArray;
};
var zipTask = function () {
var zipArray = merge2();
buildplatforms.forEach((item) => {
switch (item) {
case "linux64":
zipArray.add(
gulp
.src("./build/Popcorn-Time-CE/linux64/**")
.pipe(tar("popcorn-time-ce_linux64_" + package.version + ".tar"))
.pipe(gzip())
.pipe(gulp.dest("./dist"))
.on("end", function () {
console.log("Build Zip Complete: " + item);
}),
);
break;
case "linux32":
zipArray.add(
gulp
.src("./build/Popcorn-Time-CE/linux32/**")
.pipe(tar("popcorn-time-ce_linux32_" + package.version + ".tar"))
.pipe(gzip())
.pipe(gulp.dest("./dist"))
.on("end", function () {
console.log("Build Zip Complete: " + item);
}),
);
break;
case "win32":
zipArray.add(
gulp
.src("./build/Popcorn-Time-CE/win32/**")
.pipe(zip("popcorn-time-ce_win32_" + package.version + ".zip"))
.pipe(gulp.dest("./dist"))
.on("end", function () {
console.log("Build Zip Complete: " + item);
}),
);
break;
case "win64":
zipArray.add(
gulp
.src("./build/Popcorn-Time-CE/win64/**")
.pipe(zip("popcorn-time-ce_win64_" + package.version + ".zip"))
.pipe(gulp.dest("./dist"))
.on("end", function () {
console.log("Build Zip Complete: " + item);
}),
);
break;
case "osx64":
zipArray.add(
gulp
.src("./build/Popcorn-Time-CE/osx64/**")
.pipe(zip("popcorn-time-ce_osx64_" + package.version + ".zip"))
//.pipe(gzip())
.pipe(gulp.dest("./dist"))
.on("end", function () {
console.log("Build Zip Complete: " + item);
}),
);
break;
}
});
return zipArray;
};
gulp.task("build", gulp.series(cleanTask, buildTask));
gulp.task("clean", cleanTask);
gulp.task("ffmpegbuild", ffmpegbuildTask);
gulp.task("ffmpegcache", ffmpegcacheTask);
gulp.task("zip", gulp.series(ffmpegbuildTask, zipTask));
gulp.task("default", function defaultTask() {
// place code for your default task here
console.log(nwVersion);
});