bitwarden-estensione-browser/gulpfile.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

246 lines
6.8 KiB
JavaScript
Raw Normal View History

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");
2017-11-08 03:45:18 +01:00
const paths = {
build: "./build/",
2017-11-08 03:45:18 +01:00
dist: "./dist/",
2017-11-22 20:42:44 +01:00
coverage: "./coverage/",
node_modules: "./node_modules/",
2017-11-08 03:45:18 +01:00
popupDir: "./src/popup/",
cssDir: "./src/popup/css/",
safari: "./src/safari/",
2017-11-08 03:45:18 +01:00
};
2018-01-11 23:33:13 +01:00
const filters = {
fonts: [
"!build/popup/fonts/*",
"build/popup/fonts/Open_Sans*.woff",
"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 = "";
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
}
function dist(browserName, manifest) {
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)))
.pipe(gulpif("manifest.json", jeditor(manifest)))
2017-11-18 04:04:34 +01:00
.pipe(zip(distFileName(browserName, "zip")))
.pipe(gulp.dest(paths.dist));
}
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;
removeShortcuts(manifest);
return manifest;
});
2018-11-27 18:36:59 +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;
removeShortcuts(manifest);
return manifest;
});
2018-11-27 18:36:59 +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;
delete manifest.commands._execute_sidebar_action;
return manifest;
});
2018-11-27 18:36:59 +01: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
}
}
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";
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",
"--entitlements",
entitlementsPath,
2021-12-21 15:43:35 +01:00
];
if (subBuildPath !== "dmg") {
2021-12-21 15:43:35 +01:00
args = [
"--verbose",
"--force",
"--sign",
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
];
}
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) => {
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(() => {
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;
}
);
}
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
)
.pipe(gulpif("desktop.xcodeproj/project.pbxproj", replace("../../../build", "../safari/app")))
.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)
.pipe(filter(["**"].concat(filters.fonts)))
.pipe(gulpif("popup/index.html", replace("__BROWSER__", "browser_safari")))
.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);
});
}
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()));
}
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;