tutanota/buildSrc/DesktopBuilder.js

85 lines
3.5 KiB
JavaScript
Raw Normal View History

2018-09-24 11:56:41 +02:00
const Promise = require('bluebird')
const fs = Promise.promisifyAll(require("fs-extra"))
const path = require("path")
2018-10-02 16:02:55 +02:00
function build(dirname, version, targets, targetUrl) {
2018-10-02 16:19:03 +02:00
const targetString = Object.keys(targets)
.filter(k => typeof targets[k] !== "undefined")
.join(" ")
console.log("Building desktop client for v" + version + " (" + targetString + ")...")
2018-10-02 16:02:55 +02:00
const updateSubdir = '/desktop'
const updateUrl = targetUrl + updateSubdir
2018-09-24 11:56:41 +02:00
const electronSourcesDir = path.join(dirname, '/app-desktop/dist/')
const resourcesDir = path.join(electronSourcesDir, "/resources/")
console.log("Updating config...")
const builderPackageJSON = Object.assign(require(path.join(dirname, '/app-desktop/', '/package.json')), {
version: version
})
builderPackageJSON.build.publish.url = updateUrl
builderPackageJSON.build.icon = path.join(dirname, "/resources/desktop-icons/desktop-icon.png")
//prepare files
2018-10-01 09:28:08 +02:00
return Promise.resolve()
.then(() => {
console.log("Cleaning up...")
return fs.removeAsync(electronSourcesDir)
})
.then(() => {
//copy webapp files to app-desktop folder
console.log("Copying files...")
return Promise.all([
fs.copyAsync(path.join(dirname, '/build/dist/'), resourcesDir),
fs.copyAsync(path.join(dirname, '/app-desktop/', '/main.js'), path.join(electronSourcesDir, "main.js")),
fs.copyAsync(path.join(dirname, '/app-desktop/', '/src/'), path.join(electronSourcesDir, "/src/"))
])
})
.then(() => {
//remove app & browser stuff
return Promise.all([
fs.unlink(resourcesDir + "app.html", (e) => {}),
fs.unlink(resourcesDir + "app.js", (e) => {}),
fs.unlink(resourcesDir + "index.js", (e) => {}),
fs.unlink(resourcesDir + "index.html", (e) => {})
])
})
.then(() => {
return fs.writeFile(path.join(electronSourcesDir, "/package.json"),
JSON.stringify(builderPackageJSON),
'utf8',
(e) => {
if (e) {
console.log("couldn't write package.json: ", e);
}
})
})
.then(() => {
console.log("Starting installer build...")
//package for linux, win, mac
const builder = require("electron-builder")
return builder.build({
_: ['build'],
2018-10-02 16:02:55 +02:00
win: targets.win,
mac: targets.mac,
linux: targets.linux,
2018-10-01 09:28:08 +02:00
p: 'always',
project: electronSourcesDir
})
})
.then(() => {
2018-10-02 16:02:55 +02:00
console.log("Move output to /build/dist" + updateSubdir + "/...")
return Promise.all(
fs.readdirSync(path.join(electronSourcesDir, 'installers'))
.filter((file => file.startsWith(builderPackageJSON.name) || file.endsWith('.yml')))
.map(file => fs.copyAsync(
path.join(electronSourcesDir, '/installers/', file),
2018-10-02 16:02:55 +02:00
path.join(dirname, '/build/dist', updateSubdir, file)
)
)
).then(() => fs.removeAsync(path.join(electronSourcesDir)))
})
2018-09-24 11:56:41 +02:00
}
module.exports = {
2018-10-01 09:28:08 +02:00
build
2018-09-24 11:56:41 +02:00
}