2022-02-24 18:14:04 +01:00
|
|
|
const child = require("child_process");
|
|
|
|
const fs = require("fs");
|
|
|
|
|
|
|
|
const del = require("del");
|
|
|
|
const gulp = require("gulp");
|
|
|
|
const filter = require("gulp-filter");
|
|
|
|
const gulpif = require("gulp-if");
|
|
|
|
const jeditor = require("gulp-json-editor");
|
|
|
|
const replace = require("gulp-replace");
|
|
|
|
const zip = require("gulp-zip");
|
|
|
|
|
|
|
|
const manifest = require("./src/manifest.json");
|
2016-09-08 00:51:36 +02:00
|
|
|
|
2017-11-08 03:45:18 +01:00
|
|
|
const paths = {
|
2021-12-21 15:43:35 +01:00
|
|
|
build: "./build/",
|
|
|
|
dist: "./dist/",
|
|
|
|
coverage: "./coverage/",
|
|
|
|
node_modules: "./node_modules/",
|
|
|
|
popupDir: "./src/popup/",
|
|
|
|
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 = {
|
2021-12-21 15:43:35 +01:00
|
|
|
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",
|
2021-12-21 15:43:35 +01: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() {
|
2021-12-21 15:43:35 +01:00
|
|
|
var build = "";
|
2022-08-18 18:07:02 +02:00
|
|
|
if (process.env.MANIFEST_VERSION) {
|
|
|
|
build = `-mv${process.env.MANIFEST_VERSION}`;
|
|
|
|
}
|
2021-12-21 15:43:35 +01:00
|
|
|
if (process.env.BUILD_NUMBER && process.env.BUILD_NUMBER !== "") {
|
|
|
|
build = `-${process.env.BUILD_NUMBER}`;
|
|
|
|
}
|
|
|
|
return build;
|
2017-11-22 22:51:33 +01:00
|
|
|
}
|
2017-11-18 04:04:34 +01:00
|
|
|
|
2017-11-22 22:51:33 +01:00
|
|
|
function distFileName(browserName, ext) {
|
2021-12-21 15:43:35 +01:00
|
|
|
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) {
|
2021-12-21 15:43:35 +01:00
|
|
|
return gulp
|
|
|
|
.src(paths.build + "**/*")
|
|
|
|
.pipe(filter(["**"].concat(filters.fonts).concat(filters.safari)))
|
|
|
|
.pipe(gulpif("popup/index.html", replace("__BROWSER__", "browser_" + browserName)))
|
|
|
|
.pipe(gulpif("manifest.json", jeditor(manifest)))
|
|
|
|
.pipe(zip(distFileName(browserName, "zip")))
|
|
|
|
.pipe(gulp.dest(paths.dist));
|
2017-10-29 03:14:14 +01:00
|
|
|
}
|
|
|
|
|
2018-11-27 18:36:59 +01:00
|
|
|
function distFirefox() {
|
2021-12-21 15:43:35 +01:00
|
|
|
return dist("firefox", (manifest) => {
|
2022-08-26 15:54:06 +02:00
|
|
|
delete manifest.storage;
|
2021-12-21 15:43:35 +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() {
|
2021-12-21 15:43:35 +01:00
|
|
|
return dist("opera", (manifest) => {
|
|
|
|
delete manifest.applications;
|
|
|
|
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() {
|
2021-12-21 15:43:35 +01:00
|
|
|
return dist("chrome", (manifest) => {
|
|
|
|
delete manifest.applications;
|
|
|
|
delete manifest.sidebar_action;
|
|
|
|
delete manifest.commands._execute_sidebar_action;
|
|
|
|
return manifest;
|
|
|
|
});
|
2020-03-05 17:13:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function distEdge() {
|
2021-12-21 15:43:35 +01:00
|
|
|
return dist("edge", (manifest) => {
|
|
|
|
delete manifest.applications;
|
|
|
|
delete manifest.sidebar_action;
|
|
|
|
delete manifest.commands._execute_sidebar_action;
|
|
|
|
return manifest;
|
|
|
|
});
|
2018-11-27 18:36:59 +01:00
|
|
|
}
|
2017-10-29 03:14:14 +01:00
|
|
|
|
2019-10-01 23:28:12 +02:00
|
|
|
function distSafariMas(cb) {
|
2021-12-21 15:43:35 +01:00
|
|
|
return distSafariApp(cb, "mas");
|
2019-10-01 23:28:12 +02:00
|
|
|
}
|
|
|
|
|
2019-10-02 15:30:56 +02:00
|
|
|
function distSafariMasDev(cb) {
|
2021-12-21 15:43:35 +01:00
|
|
|
return distSafariApp(cb, "masdev");
|
2019-10-02 15:30:56 +02:00
|
|
|
}
|
|
|
|
|
2019-10-01 23:28:12 +02:00
|
|
|
function distSafariDmg(cb) {
|
2021-12-21 15:43:35 +01:00
|
|
|
return distSafariApp(cb, "dmg");
|
2019-10-01 23:28:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function distSafariApp(cb, subBuildPath) {
|
2021-12-21 15:43:35 +01:00
|
|
|
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";
|
|
|
|
var args = [
|
|
|
|
"--verbose",
|
|
|
|
"--force",
|
|
|
|
"-o",
|
|
|
|
"runtime",
|
|
|
|
"--sign",
|
|
|
|
"Developer ID Application: 8bit Solutions LLC",
|
|
|
|
"--entitlements",
|
|
|
|
entitlementsPath,
|
|
|
|
];
|
|
|
|
if (subBuildPath !== "dmg") {
|
|
|
|
args = [
|
|
|
|
"--verbose",
|
|
|
|
"--force",
|
|
|
|
"--sign",
|
|
|
|
subBuildPath === "mas"
|
2022-04-07 22:12:41 +02:00
|
|
|
? "3rd Party Mac Developer Application: 8bit Solutions LLC"
|
|
|
|
: "6B287DD81FF922D86FD836128B0F62F358B38726",
|
2021-12-21 15:43:35 +01:00
|
|
|
"--entitlements",
|
|
|
|
entitlementsPath,
|
2019-10-02 15:30:56 +02:00
|
|
|
];
|
2021-12-21 15:43:35 +01: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) => {
|
|
|
|
const proc = child.spawn("codesign", args.concat([i]));
|
|
|
|
stdOutProc(proc);
|
|
|
|
libPromises.push(new Promise((resolve) => proc.on("close", resolve)));
|
|
|
|
});
|
|
|
|
return Promise.all(libPromises);
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
const proc = child.spawn("codesign", args.concat([builtAppexPath]));
|
|
|
|
stdOutProc(proc);
|
|
|
|
return new Promise((resolve) => proc.on("close", resolve));
|
|
|
|
})
|
|
|
|
.then(
|
|
|
|
() => {
|
|
|
|
return cb;
|
|
|
|
},
|
|
|
|
() => {
|
|
|
|
return cb;
|
|
|
|
}
|
|
|
|
);
|
2019-10-01 23:28:12 +02:00
|
|
|
}
|
|
|
|
|
2019-08-22 16:39:42 +02:00
|
|
|
function safariCopyAssets(source, dest) {
|
2021-12-21 15:43:35 +01:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
gulp
|
|
|
|
.src(source)
|
|
|
|
.on("error", reject)
|
|
|
|
.pipe(gulpif("safari/Info.plist", replace("0.0.1", manifest.version)))
|
|
|
|
.pipe(
|
|
|
|
gulpif("safari/Info.plist", replace("0.0.2", process.env.BUILD_NUMBER || manifest.version))
|
|
|
|
)
|
|
|
|
.pipe(gulpif("desktop.xcodeproj/project.pbxproj", replace("../../../build", "../safari/app")))
|
|
|
|
.pipe(gulp.dest(dest))
|
|
|
|
.on("end", resolve);
|
|
|
|
});
|
2019-08-22 16:39:42 +02:00
|
|
|
}
|
|
|
|
|
2018-01-16 15:41:59 +01:00
|
|
|
function safariCopyBuild(source, dest) {
|
2021-12-21 15:43:35 +01:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
gulp
|
|
|
|
.src(source)
|
|
|
|
.on("error", reject)
|
|
|
|
.pipe(filter(["**"].concat(filters.fonts)))
|
|
|
|
.pipe(gulpif("popup/index.html", replace("__BROWSER__", "browser_safari")))
|
|
|
|
.pipe(
|
|
|
|
gulpif(
|
|
|
|
"manifest.json",
|
|
|
|
jeditor((manifest) => {
|
2022-09-08 14:48:45 +02:00
|
|
|
delete manifest.sidebar_action;
|
|
|
|
delete manifest.commands._execute_sidebar_action;
|
2021-12-21 15:43:35 +01:00
|
|
|
delete manifest.optional_permissions;
|
|
|
|
manifest.permissions.push("nativeMessaging");
|
|
|
|
return manifest;
|
|
|
|
})
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.pipe(gulp.dest(dest))
|
|
|
|
.on("end", resolve);
|
|
|
|
});
|
2019-08-02 22:09:59 +02:00
|
|
|
}
|
|
|
|
|
2019-08-26 18:13:08 +02:00
|
|
|
function stdOutProc(proc) {
|
2021-12-21 15:43:35 +01:00
|
|
|
proc.stdout.on("data", (data) => console.log(data.toString()));
|
|
|
|
proc.stderr.on("data", (data) => console.error(data.toString()));
|
2019-08-26 18:15:52 +02:00
|
|
|
}
|
2019-08-26 18:13:08 +02:00
|
|
|
|
2018-11-27 18:36:59 +01:00
|
|
|
function ciCoverage(cb) {
|
2021-12-21 15:43:35 +01:00
|
|
|
return gulp
|
|
|
|
.src(paths.coverage + "**/*")
|
|
|
|
.pipe(filter(["**", "!coverage/coverage*.zip"]))
|
|
|
|
.pipe(zip(`coverage${buildString()}.zip`))
|
|
|
|
.pipe(gulp.dest(paths.coverage));
|
|
|
|
}
|
|
|
|
|
|
|
|
exports["dist:firefox"] = distFirefox;
|
|
|
|
exports["dist:chrome"] = distChrome;
|
|
|
|
exports["dist:opera"] = distOpera;
|
|
|
|
exports["dist:edge"] = distEdge;
|
|
|
|
exports["dist:safari"] = gulp.parallel(distSafariMas, distSafariMasDev, distSafariDmg);
|
|
|
|
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);
|
2021-12-21 15:43:35 +01:00
|
|
|
exports["ci:coverage"] = ciCoverage;
|
2018-11-27 18:36:59 +01:00
|
|
|
exports.ci = ciCoverage;
|