[desktop] define options object for desktopBuilder

This commit is contained in:
nig 2020-04-07 10:32:03 +02:00 committed by ganthern
parent 592b48b783
commit a61c8fe96a
6 changed files with 105 additions and 44 deletions

View file

@ -3,7 +3,17 @@ const babel = Promise.promisifyAll(require("babel-core"))
const fs = Promise.promisifyAll(require("fs-extra")) const fs = Promise.promisifyAll(require("fs-extra"))
const path = require("path") const path = require("path")
function build(dirname, version, targets, updateUrl, nameSuffix, notarize, outDir, unpacked) { function build(opts) {
let {
dirname, // directory this was called from
version, // application version that gets built
targets, // which desktop targets to build and how to package them
updateUrl, // where the client should pull its updates from, if any
nameSuffix, // suffix used to distinguish test-, prod- or snapshot builds on the same machine
notarize, // for the MacOs notarization feature
outDir, // where to copy the finished artifacts
unpacked // output desktop client without packing it into an installer
} = opts
const targetString = Object.keys(targets) const targetString = Object.keys(targets)
.filter(k => typeof targets[k] !== "undefined") .filter(k => typeof targets[k] !== "undefined")
.join(" ") .join(" ")
@ -17,15 +27,16 @@ function build(dirname, version, targets, updateUrl, nameSuffix, notarize, outDi
.map(fn => path.join(dirname, './src/translations', fn)) .map(fn => path.join(dirname, './src/translations', fn))
console.log("Updating electron-builder config...") console.log("Updating electron-builder config...")
const content = require('./electron-package-json-template')( const content = require('./electron-package-json-template')({
nameSuffix, nameSuffix: nameSuffix,
version, version: version,
updateUrl, updateUrl: updateUrl,
path.join(dirname, "/resources/desktop-icons/logo-solo-red.png"), iconPath: path.join(dirname, "/resources/desktop-icons/logo-solo-red.png"),
nameSuffix !== '-snapshot' && updateUrl !== "", // don't sign if it's a test build or if we don't download updates sign: nameSuffix !== '-snapshot' && updateUrl !== "",
notarize, nameSuffix: nameSuffix,
unpacked notarize: notarize,
) unpacked: unpacked
})
let writeConfig = fs.writeFileAsync("./build/dist/package.json", JSON.stringify(content), 'utf-8') let writeConfig = fs.writeFileAsync("./build/dist/package.json", JSON.stringify(content), 'utf-8')
//prepare files //prepare files
@ -53,17 +64,26 @@ function build(dirname, version, targets, updateUrl, nameSuffix, notarize, outDi
.then(() => { .then(() => {
const installerDir = path.join(distDir, 'installers') const installerDir = path.join(distDir, 'installers')
console.log("Move artifacts to", outDir) console.log("Move artifacts to", outDir)
const unpackedFilter = file => file.endsWith("-unpacked") || file === "mac" const outFiles = fs.readdirSync(installerDir)
const packedFilter = file => file.startsWith(content.name) || file.endsWith('.yml') let filesToCopy
// the output of the builder is very inconsistently named and contains
// files that are irrelevant to us. these filters enable us to copy them
// without naming every possible file name explicitly
if (unpacked) {
// when the unpacked option is set, output is a directory for each platform, with
// the mac directory missing the "-unpacked" suffix.
filesToCopy = outFiles.filter(file => file.endsWith("-unpacked") || file === "mac")
} else {
// the installers start with the application name + suffix. the update manifests end in yml.
filesToCopy = outFiles.filter(file => file.startsWith(content.name) || file.endsWith('.yml'))
}
return Promise.all( return Promise.all(
fs.readdirSync(installerDir) filesToCopy.map(file => fs.moveAsync(
.filter(unpacked ? unpackedFilter : packedFilter) path.join(installerDir, file),
.map(file => fs.moveAsync( path.join(outDir, file)
path.join(installerDir, file), )
path.join(outDir, file) )
)
)
) )
}).then(() => Promise.all([ }).then(() => Promise.all([
fs.removeAsync(path.join(distDir, '/installers/')), fs.removeAsync(path.join(distDir, '/installers/')),

View file

@ -6,7 +6,9 @@ const pj = require('../package.json')
* 2. copied to app-desktop/build/dist from dist.js (DesktopBuilder) * 2. copied to app-desktop/build/dist from dist.js (DesktopBuilder)
*/ */
module.exports = function (nameSuffix, version, updateUrl, iconPath, sign, notarize, unpacked) { module.exports = function (opts) {
const {nameSuffix, version, updateUrl, iconPath, sign, notarize, unpacked} = opts
return { return {
"name": "tutanota-desktop" + nameSuffix, "name": "tutanota-desktop" + nameSuffix,
"main": "./src/desktop/DesktopMain.js", "main": "./src/desktop/DesktopMain.js",

60
dist.js
View file

@ -185,34 +185,66 @@ function buildWebapp() {
function buildDesktopClient() { function buildDesktopClient() {
if (options.desktop) { if (options.desktop) {
const desktopBuilder = require('./buildSrc/DesktopBuilder.js') const desktopBuilder = require('./buildSrc/DesktopBuilder.js')
if (options.stage === "release") { const desktopBaseOpts = {
const updateUrl = options.customDesktopRelease dirname: __dirname,
version: version,
targets: options.desktop,
updateUrl: options.customDesktopRelease
? "" ? ""
: "https://mail.tutanota.com/desktop" : "https://mail.tutanota.com/desktop",
const notarize = !!options.customDesktopRelease nameSuffix: "",
notarize: !!options.customDesktopRelease,
outDir: options.outDir,
unpacked: options.unpacked
}
if (options.stage === "release") {
const buildPromise = createHtml(env.create(SystemConfig.distRuntimeConfig(bundles), "https://mail.tutanota.com", version, "Desktop", true), bundles) const buildPromise = createHtml(env.create(SystemConfig.distRuntimeConfig(bundles), "https://mail.tutanota.com", version, "Desktop", true), bundles)
.then(() => desktopBuilder.build(__dirname, version, options.desktop, updateUrl, "", notarize, options.outDir, options.unpacked)) .then(() => desktopBuilder.build(desktopBaseOpts))
if (!options.customDesktopRelease) { // don't build the test version for manual/custom builds if (!options.customDesktopRelease) { // don't build the test version for manual/custom builds
const desktopTestOpts = Object.assign({}, desktopBaseOpts, {
updateUrl: "https://test.tutanota.com",
nameSuffix: "-test",
notarize: true
})
buildPromise.then(() => createHtml(env.create(SystemConfig.distRuntimeConfig(bundles), "https://test.tutanota.com", version, "Desktop", true), bundles)) buildPromise.then(() => createHtml(env.create(SystemConfig.distRuntimeConfig(bundles), "https://test.tutanota.com", version, "Desktop", true), bundles))
.then(() => desktopBuilder.build(__dirname, version, options.desktop, "https://test.tutanota.com/desktop", "-test", /*notarize*/true, options.outDir, options.unpacked)) .then(() => desktopBuilder.build(desktopTestOpts))
} }
return buildPromise return buildPromise
} else if (options.stage === "local") { } else if (options.stage === "local") {
const desktopLocalOpts = Object.assign({}, desktopBaseOpts, {
version: `${new Date().getTime()}.0.0`,
updateUrl: "http://localhost:9000",
nameSuffix: "-snapshot",
notarize: false
})
return createHtml(env.create(SystemConfig.distRuntimeConfig(bundles), "http://localhost:9000", version, "Desktop", true), bundles) return createHtml(env.create(SystemConfig.distRuntimeConfig(bundles), "http://localhost:9000", version, "Desktop", true), bundles)
.then(() => desktopBuilder.build(__dirname, `${new Date().getTime()}.0.0`, .then(() => desktopBuilder.build(desktopLocalOpts))
options.desktop, "http://localhost:9000", "-snapshot", options.outDir, options.unpacked))
} else if (options.stage === "test") { } else if (options.stage === "test") {
const desktopTestOpts = Object.assign({}, desktopBaseOpts, {
version: `${new Date().getTime()}.0.0`,
updateUrl: "https://test.tutanota.com/desktop",
nameSuffix: "-test",
notarize: false
})
return createHtml(env.create(SystemConfig.distRuntimeConfig(bundles), "https://test.tutanota.com", version, "Desktop", true), bundles) return createHtml(env.create(SystemConfig.distRuntimeConfig(bundles), "https://test.tutanota.com", version, "Desktop", true), bundles)
.then(() => desktopBuilder.build(__dirname, `${new Date().getTime()}.0.0`, .then(() => desktopBuilder.build(desktopTestOpts))
options.desktop, "https://test.tutanota.com/desktop", "-test", options.outDir, options.unpacked))
} else if (options.stage === "prod") { } else if (options.stage === "prod") {
const desktopProdOpts = Object.assign({}, desktopBaseOpts, {
version: `${new Date().getTime()}.0.0`,
updateUrl: "http://localhost:9000/desktop",
notarize: false
})
return createHtml(env.create(SystemConfig.distRuntimeConfig(bundles), "https://mail.tutanota.com", version, "Desktop", true), bundles) return createHtml(env.create(SystemConfig.distRuntimeConfig(bundles), "https://mail.tutanota.com", version, "Desktop", true), bundles)
.then(() => desktopBuilder.build(__dirname, `${new Date().getTime()}.0.0`, .then(() => desktopBuilder.build(desktopProdOpts))
options.desktop, "http://localhost:9000/desktop", "", options.outDir, options.unpacked))
} else { // stage = host } else { // stage = host
const desktopHostOpts = Object.assign({}, desktopBaseOpts, {
version: `${new Date().getTime()}.0.0`,
updateUrl: "http://localhost:9000/desktop-snapshot",
nameSuffix: "-snapshot",
notarize: false
})
return createHtml(env.create(SystemConfig.distRuntimeConfig(bundles), options.host, version, "Desktop", true), bundles) return createHtml(env.create(SystemConfig.distRuntimeConfig(bundles), options.host, version, "Desktop", true), bundles)
.then(() => desktopBuilder.build(__dirname, `${new Date().getTime()}.0.0`, .then(() => desktopBuilder.build(desktopHostOpts))
options.desktop, "http://localhost:9000/desktop-snapshot", "-snapshot", options.outDir, options.unpacked))
} }
} }
} }

14
make.js
View file

@ -87,13 +87,13 @@ function startDesktop() {
if (options.desktop) { if (options.desktop) {
console.log("Trying to start desktop client...") console.log("Trying to start desktop client...")
const version = require('./package.json').version const version = require('./package.json').version
const packageJSON = require('./buildSrc/electron-package-json-template.js')( const packageJSON = require('./buildSrc/electron-package-json-template.js')({
"-debug", nameSuffix: "-debug",
version, version: version,
"http://localhost:9000", updateUrl: "http://localhost:9000",
path.join(__dirname, "/resources/desktop-icons/logo-solo-red.png"), iconPath: path.join(__dirname, "/resources/desktop-icons/logo-solo-red.png"),
false sign: false
) })
const content = JSON.stringify(packageJSON) const content = JSON.stringify(packageJSON)
return fs.writeFileAsync("./build/package.json", content, 'utf-8') return fs.writeFileAsync("./build/package.json", content, 'utf-8')
.then(() => { .then(() => {

View file

@ -36,6 +36,8 @@ export class ElectronUpdater {
error: (m: string, ...args: any) => console.error.apply(console, ["autoUpdater error:\n", m].concat(args)), error: (m: string, ...args: any) => console.error.apply(console, ["autoUpdater error:\n", m].concat(args)),
} }
autoUpdater.logger = null autoUpdater.logger = null
// default behaviour is to just dl the update as soon as found, but we want to check the signature
// before doing telling the updater to get the file.
autoUpdater.autoDownload = false autoUpdater.autoDownload = false
autoUpdater.autoInstallOnAppQuit = false autoUpdater.autoInstallOnAppQuit = false
autoUpdater.on('update-available', updateInfo => { autoUpdater.on('update-available', updateInfo => {

View file

@ -7,9 +7,14 @@ o.spec('desktop config migrator test', function () {
o("migrations result in correct default config, client", function () { o("migrations result in correct default config, client", function () {
const migrator = n.subject('../../src/desktop/config/migrations/DesktopConfigMigrator.js').default const migrator = n.subject('../../src/desktop/config/migrations/DesktopConfigMigrator.js').default
const configPath = "../../../../../../buildSrc/electron-package-json-template.js" const configPath = "../../../../../../buildSrc/electron-package-json-template.js"
const oldConfig = require(configPath)( const oldConfig = require(configPath)({
"", "0.0.0", "", "", "", false, false nameSuffix: "",
)["tutao-config"]["defaultDesktopConfig"] version: "0.0.0",
updateUrl: "",
iconPath: "",
sign: false,
notarize: false
})["tutao-config"]["defaultDesktopConfig"]
const requiredResult = { const requiredResult = {
"heartbeatTimeoutInSeconds": 30, "heartbeatTimeoutInSeconds": 30,
"defaultDownloadPath": null, "defaultDownloadPath": null,