2017-10-29 03:14:14 +01:00
|
|
|
const gulp = require("gulp"),
|
|
|
|
gulpif = require("gulp-if"),
|
2017-11-08 21:17:09 +01:00
|
|
|
filter = require("gulp-filter"),
|
2017-10-29 03:14:14 +01:00
|
|
|
replace = require("gulp-replace"),
|
2017-08-31 21:07:39 +02:00
|
|
|
jeditor = require("gulp-json-editor"),
|
2017-08-31 21:55:39 +02:00
|
|
|
child = require("child_process"),
|
2017-09-07 16:42:25 +02:00
|
|
|
zip = require("gulp-zip"),
|
|
|
|
manifest = require("./src/manifest.json"),
|
2019-01-25 21:05:18 +01:00
|
|
|
del = require("del"),
|
|
|
|
fs = require("fs");
|
2016-09-08 00:51:36 +02:00
|
|
|
|
2017-11-08 03:45:18 +01:00
|
|
|
const paths = {
|
2017-11-16 17:23:53 +01:00
|
|
|
build: "./build/",
|
2017-11-08 03:45:18 +01:00
|
|
|
dist: "./dist/",
|
2017-11-22 20:42:44 +01:00
|
|
|
coverage: "./coverage/",
|
2019-01-25 21:05:18 +01:00
|
|
|
node_modules: "./node_modules/",
|
2017-11-08 03:45:18 +01:00
|
|
|
popupDir: "./src/popup/",
|
2019-08-22 14:51:08 +02:00
|
|
|
cssDir: "./src/popup/css/",
|
|
|
|
safari: "./src/safari/",
|
2017-11-08 03:45:18 +01:00
|
|
|
};
|
2016-09-08 00:51:36 +02:00
|
|
|
|
2018-01-11 23:33:13 +01:00
|
|
|
const filters = {
|
|
|
|
fonts: [
|
|
|
|
"!build/popup/fonts/*",
|
|
|
|
"build/popup/fonts/Open_Sans*.woff",
|
2022-02-02 16:11:09 +01:00
|
|
|
"build/popup/fonts/bwi-font.woff2",
|
|
|
|
"build/popup/fonts/bwi-font.woff",
|
|
|
|
"build/popup/fonts/bwi-font.ttf",
|
2018-01-11 23:33:13 +01:00
|
|
|
],
|
2019-08-21 22:50:15 +02:00
|
|
|
safari: ["!build/safari/**/*"],
|
2018-01-11 23:33:13 +01:00
|
|
|
};
|
2017-11-16 03:39:48 +01:00
|
|
|
|
2017-11-22 22:51:33 +01:00
|
|
|
function buildString() {
|
2017-11-18 19:29:42 +01:00
|
|
|
var build = "";
|
2021-04-01 22:35:42 +02:00
|
|
|
if (process.env.BUILD_NUMBER && process.env.BUILD_NUMBER !== "") {
|
2020-09-28 19:22:07 +02:00
|
|
|
build = `-${process.env.BUILD_NUMBER}`;
|
2017-11-18 04:04:34 +01:00
|
|
|
}
|
2017-11-22 22:51:33 +01:00
|
|
|
return build;
|
|
|
|
}
|
2017-11-18 04:04:34 +01:00
|
|
|
|
2017-11-22 22:51:33 +01:00
|
|
|
function distFileName(browserName, ext) {
|
|
|
|
return `dist-${browserName}${buildString()}.${ext}`;
|
2017-11-18 04:04:34 +01:00
|
|
|
}
|
|
|
|
|
2017-10-29 03:14:14 +01:00
|
|
|
function dist(browserName, manifest) {
|
2017-11-16 17:23:53 +01:00
|
|
|
return gulp
|
|
|
|
.src(paths.build + "**/*")
|
2020-03-05 17:13:55 +01:00
|
|
|
.pipe(filter(["**"].concat(filters.fonts).concat(filters.safari)))
|
2018-04-14 04:29:31 +02:00
|
|
|
.pipe(gulpif("popup/index.html", replace("__BROWSER__", "browser_" + browserName)))
|
2017-10-29 03:14:14 +01:00
|
|
|
.pipe(gulpif("manifest.json", jeditor(manifest)))
|
2017-11-18 04:04:34 +01:00
|
|
|
.pipe(zip(distFileName(browserName, "zip")))
|
2017-11-16 17:23:53 +01:00
|
|
|
.pipe(gulp.dest(paths.dist));
|
2017-10-29 03:14:14 +01:00
|
|
|
}
|
|
|
|
|
2018-11-27 18:36:59 +01:00
|
|
|
function distFirefox() {
|
2017-11-08 21:42:13 +01:00
|
|
|
return dist("firefox", (manifest) => {
|
2018-04-13 22:03:37 +02:00
|
|
|
delete manifest.content_security_policy;
|
2018-05-09 20:52:22 +02:00
|
|
|
removeShortcuts(manifest);
|
2017-10-29 03:14:14 +01:00
|
|
|
return manifest;
|
|
|
|
});
|
2018-11-27 18:36:59 +01:00
|
|
|
}
|
2017-10-29 03:14:14 +01:00
|
|
|
|
2018-11-27 18:36:59 +01:00
|
|
|
function distOpera() {
|
2017-11-08 21:42:13 +01:00
|
|
|
return dist("opera", (manifest) => {
|
2017-11-15 22:40:24 +01:00
|
|
|
delete manifest.applications;
|
2018-04-13 22:03:37 +02:00
|
|
|
delete manifest.content_security_policy;
|
2018-05-09 20:52:22 +02:00
|
|
|
removeShortcuts(manifest);
|
2017-10-29 03:14:14 +01:00
|
|
|
return manifest;
|
|
|
|
});
|
2018-11-27 18:36:59 +01:00
|
|
|
}
|
2017-10-29 03:14:14 +01:00
|
|
|
|
2018-11-27 18:36:59 +01:00
|
|
|
function distChrome() {
|
2017-11-08 21:42:13 +01:00
|
|
|
return dist("chrome", (manifest) => {
|
2020-03-05 17:13:55 +01:00
|
|
|
delete manifest.applications;
|
|
|
|
delete manifest.content_security_policy;
|
|
|
|
delete manifest.sidebar_action;
|
|
|
|
delete manifest.commands._execute_sidebar_action;
|
|
|
|
return manifest;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function distEdge() {
|
|
|
|
return dist("edge", (manifest) => {
|
2017-11-15 22:40:24 +01:00
|
|
|
delete manifest.applications;
|
2018-04-13 22:03:37 +02:00
|
|
|
delete manifest.content_security_policy;
|
2017-11-15 22:40:24 +01:00
|
|
|
delete manifest.sidebar_action;
|
2017-12-04 15:15:28 +01:00
|
|
|
delete manifest.commands._execute_sidebar_action;
|
2017-10-29 03:14:14 +01:00
|
|
|
return manifest;
|
|
|
|
});
|
2018-11-27 18:36:59 +01:00
|
|
|
}
|
2017-10-29 03:14:14 +01:00
|
|
|
|
2018-05-09 20:52:22 +02:00
|
|
|
function removeShortcuts(manifest) {
|
|
|
|
if (manifest.content_scripts && manifest.content_scripts.length > 1) {
|
|
|
|
const shortcutsScript = manifest.content_scripts[1];
|
|
|
|
if (shortcutsScript.js.indexOf("content/shortcuts.js") > -1) {
|
|
|
|
manifest.content_scripts.splice(1, 1);
|
|
|
|
}
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
2018-05-09 20:52:22 +02:00
|
|
|
}
|
|
|
|
|
2019-10-01 23:28:12 +02:00
|
|
|
function distSafariMas(cb) {
|
|
|
|
return distSafariApp(cb, "mas");
|
|
|
|
}
|
|
|
|
|
2019-10-02 15:30:56 +02:00
|
|
|
function distSafariMasDev(cb) {
|
|
|
|
return distSafariApp(cb, "masdev");
|
|
|
|
}
|
|
|
|
|
2019-10-01 23:28:12 +02:00
|
|
|
function distSafariDmg(cb) {
|
|
|
|
return distSafariApp(cb, "dmg");
|
|
|
|
}
|
|
|
|
|
|
|
|
function distSafariApp(cb, subBuildPath) {
|
|
|
|
const buildPath = paths.dist + "Safari/" + subBuildPath + "/";
|
|
|
|
const builtAppexPath = buildPath + "build/Release/safari.appex";
|
|
|
|
const builtAppexFrameworkPath = buildPath + "build/Release/safari.appex/Contents/Frameworks/";
|
|
|
|
const entitlementsPath = paths.safari + "safari/safari.entitlements";
|
2019-10-14 16:47:53 +02:00
|
|
|
var args = [
|
2020-05-14 18:44:35 +02:00
|
|
|
"--verbose",
|
|
|
|
"--force",
|
|
|
|
"-o",
|
|
|
|
"runtime",
|
|
|
|
"--sign",
|
2020-05-14 18:50:59 +02:00
|
|
|
"Developer ID Application: 8bit Solutions LLC",
|
2019-10-14 16:47:53 +02:00
|
|
|
"--entitlements",
|
|
|
|
entitlementsPath,
|
2021-12-21 15:43:35 +01:00
|
|
|
];
|
2019-10-14 16:47:53 +02:00
|
|
|
if (subBuildPath !== "dmg") {
|
2021-12-21 15:43:35 +01:00
|
|
|
args = [
|
|
|
|
"--verbose",
|
|
|
|
"--force",
|
|
|
|
"--sign",
|
2019-10-14 16:47:53 +02:00
|
|
|
subBuildPath === "mas"
|
|
|
|
? "3rd Party Mac Developer Application: 8bit Solutions LLC"
|
2020-05-29 21:58:57 +02:00
|
|
|
: "6B287DD81FF922D86FD836128B0F62F358B38726",
|
2020-05-14 18:44:35 +02:00
|
|
|
"--entitlements",
|
2020-05-14 18:45:22 +02:00
|
|
|
entitlementsPath,
|
2019-10-02 15:30:56 +02:00
|
|
|
];
|
2019-10-14 16:47:53 +02:00
|
|
|
}
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2019-10-01 23:28:12 +02:00
|
|
|
return del([buildPath + "**/*"])
|
|
|
|
.then(() => safariCopyAssets(paths.safari + "**/*", buildPath))
|
|
|
|
.then(() => safariCopyBuild(paths.build + "**/*", buildPath + "safari/app"))
|
|
|
|
.then(() => {
|
|
|
|
const proc = child.spawn("xcodebuild", [
|
|
|
|
"-project",
|
|
|
|
buildPath + "desktop.xcodeproj",
|
|
|
|
"-alltargets",
|
|
|
|
"-configuration",
|
|
|
|
"Release",
|
|
|
|
]);
|
|
|
|
stdOutProc(proc);
|
|
|
|
return new Promise((resolve) => proc.on("close", resolve));
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
const libs = fs
|
|
|
|
.readdirSync(builtAppexFrameworkPath)
|
|
|
|
.filter((p) => p.endsWith(".dylib"))
|
|
|
|
.map((p) => builtAppexFrameworkPath + p);
|
|
|
|
const libPromises = [];
|
|
|
|
libs.forEach((i) => {
|
2019-10-14 16:47:53 +02:00
|
|
|
const proc = child.spawn("codesign", args.concat([i]));
|
2019-10-01 23:28:12 +02:00
|
|
|
stdOutProc(proc);
|
|
|
|
libPromises.push(new Promise((resolve) => proc.on("close", resolve)));
|
|
|
|
});
|
|
|
|
return Promise.all(libPromises);
|
|
|
|
})
|
|
|
|
.then(() => {
|
2019-10-14 16:47:53 +02:00
|
|
|
const proc = child.spawn("codesign", args.concat([builtAppexPath]));
|
2019-10-01 23:28:12 +02:00
|
|
|
stdOutProc(proc);
|
|
|
|
return new Promise((resolve) => proc.on("close", resolve));
|
|
|
|
})
|
|
|
|
.then(
|
|
|
|
() => {
|
|
|
|
return cb;
|
|
|
|
},
|
|
|
|
() => {
|
|
|
|
return cb;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-08-22 16:39:42 +02:00
|
|
|
function safariCopyAssets(source, dest) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
gulp
|
|
|
|
.src(source)
|
|
|
|
.on("error", reject)
|
|
|
|
.pipe(gulpif("safari/Info.plist", replace("0.0.1", manifest.version)))
|
2020-09-28 19:22:07 +02:00
|
|
|
.pipe(
|
|
|
|
gulpif("safari/Info.plist", replace("0.0.2", process.env.BUILD_NUMBER || manifest.version))
|
2021-12-21 15:43:35 +01:00
|
|
|
)
|
2021-02-03 20:36:05 +01:00
|
|
|
.pipe(gulpif("desktop.xcodeproj/project.pbxproj", replace("../../../build", "../safari/app")))
|
2019-08-22 16:39:42 +02:00
|
|
|
.pipe(gulp.dest(dest))
|
|
|
|
.on("end", resolve);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-01-16 15:41:59 +01:00
|
|
|
function safariCopyBuild(source, dest) {
|
2018-01-11 23:33:13 +01:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
gulp
|
|
|
|
.src(source)
|
|
|
|
.on("error", reject)
|
2021-02-03 20:36:05 +01:00
|
|
|
.pipe(filter(["**"].concat(filters.fonts)))
|
|
|
|
.pipe(gulpif("popup/index.html", replace("__BROWSER__", "browser_safari")))
|
2021-02-05 10:00:00 +01:00
|
|
|
.pipe(
|
|
|
|
gulpif(
|
|
|
|
"manifest.json",
|
|
|
|
jeditor((manifest) => {
|
|
|
|
delete manifest.optional_permissions;
|
|
|
|
manifest.permissions.push("nativeMessaging");
|
|
|
|
return manifest;
|
|
|
|
})
|
2021-12-21 15:43:35 +01:00
|
|
|
)
|
|
|
|
)
|
2019-08-02 22:09:59 +02:00
|
|
|
.pipe(gulp.dest(dest))
|
|
|
|
.on("end", resolve);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-08-26 18:13:08 +02:00
|
|
|
function stdOutProc(proc) {
|
|
|
|
proc.stdout.on("data", (data) => console.log(data.toString()));
|
2019-08-26 18:15:52 +02:00
|
|
|
proc.stderr.on("data", (data) => console.error(data.toString()));
|
|
|
|
}
|
2019-08-26 18:13:08 +02:00
|
|
|
|
2018-11-27 18:36:59 +01:00
|
|
|
function ciCoverage(cb) {
|
2018-01-16 15:58:18 +01:00
|
|
|
return gulp
|
|
|
|
.src(paths.coverage + "**/*")
|
|
|
|
.pipe(filter(["**", "!coverage/coverage*.zip"]))
|
|
|
|
.pipe(zip(`coverage${buildString()}.zip`))
|
|
|
|
.pipe(gulp.dest(paths.coverage));
|
2018-11-27 18:36:59 +01:00
|
|
|
}
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2018-11-27 18:36:59 +01:00
|
|
|
exports["dist:firefox"] = distFirefox;
|
|
|
|
exports["dist:chrome"] = distChrome;
|
|
|
|
exports["dist:opera"] = distOpera;
|
|
|
|
exports["dist:edge"] = distEdge;
|
2019-10-22 21:30:23 +02:00
|
|
|
exports["dist:safari"] = gulp.parallel(distSafariMas, distSafariMasDev, distSafariDmg);
|
2020-09-23 18:32:07 +02:00
|
|
|
exports["dist:safari:mas"] = distSafariMas;
|
|
|
|
exports["dist:safari:masdev"] = distSafariMasDev;
|
|
|
|
exports["dist:safari:dmg"] = distSafariDmg;
|
2019-09-04 19:29:31 +02:00
|
|
|
exports.dist = gulp.parallel(distFirefox, distChrome, distOpera, distEdge);
|
2018-11-27 18:36:59 +01:00
|
|
|
exports["ci:coverage"] = ciCoverage;
|
|
|
|
exports.ci = ciCoverage;
|