From 5268b1be0b37c512b23f3dfd40c29f94dd7c61a0 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Fri, 27 Sep 2019 20:59:10 -0400 Subject: [PATCH] pkg mas gulp task --- gulpfile.js | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/gulpfile.js b/gulpfile.js index 61307017b5..f4c277a50f 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -2,10 +2,13 @@ const gulp = require('gulp'); const googleWebFonts = require('gulp-google-webfonts'); const del = require('del'); const fs = require('fs'); +const child = require('child_process'); const paths = { cssDir: './src/css/', node_modules: './node_modules/', + dist: './dist/', + resources: './resources/', }; function clean() { @@ -34,9 +37,65 @@ function fixSweetAlert(cb) { cb(); } +function pkgMas(cb) { + const appPath = paths.dist + 'mas/Bitwarden.app'; + const pkgPath = paths.dist + 'mas/Bitwarden-mas.pkg'; + const safariAppexPath = appPath + '/Contents/PlugIns/safari.appex'; + const safariAppexFrameworkPath = safariAppexPath + '/Contents/Frameworks/'; + const safariEntitlementsPath = paths.resources + 'safari.entitlements'; + + return del([paths.dist + 'Bitwarden*.pkg']) + .then(() => { + const libs = fs.readdirSync(safariAppexFrameworkPath).filter((p) => p.endsWith('.dylib')) + .map((p) => builtAppexFrameworkPath + p); + const allItems = libs.concat([safariAppexPath]); + const promises = []; + allItems.forEach((i) => { + const proc = child.spawn('codesign', [ + '--verbose', + '--force', + '-o', + 'runtime', + '--sign', + '3rd Party Mac Developer Application: 8bit Solutions LLC', + '--entitlements', + safariEntitlementsPath, + i]); + stdOutProc(proc); + promises.push(new Promise((resolve) => proc.on('close', resolve))); + }); + return Promise.all(promises); + }).then(() => { + const libs = fs.readdirSync(safariAppexFrameworkPath).filter((p) => p.endsWith('.dylib')) + .map((p) => builtAppexFrameworkPath + p); + const allItems = libs.concat([safariAppexPath]); + const promises = []; + allItems.forEach((i) => { + const proc = child.spawn('productbuild', [ + '--component', + appPath, + '/Applications', + pkgPath]); + stdOutProc(proc); + promises.push(new Promise((resolve) => proc.on('close', resolve))); + }); + return Promise.all(promises); + }).then(() => { + return cb; + }, () => { + return cb; + }); +} + +function stdOutProc(proc) { + proc.stdout.on('data', (data) => console.log(data.toString())); + proc.stderr.on('data', (data) => console.error(data.toString())); +} + exports.clean = clean; exports.cleanupAotIssue = cleanupAotIssue; exports.webfonts = gulp.series(clean, webfonts); exports['prebuild:renderer'] = gulp.parallel(webfonts, cleanupAotIssue); exports.fixSweetAlert = fixSweetAlert; +exports.pkgMas = pkgMas; exports.postinstall = fixSweetAlert;