tutanota/buildSrc/DesktopBuilder.js

74 lines
3 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")
function packageDesktop(dirname, version) {
console.log("Building desktop client for v" + version + "...")
2018-09-24 11:56:41 +02:00
const electronSourcesDir = path.join(dirname, '/app-desktop/dist/')
const resourcesDir = path.join(electronSourcesDir, "/resources/")
//prepare files
2018-09-24 11:56:41 +02:00
return fs.removeAsync(electronSourcesDir)
.then(() => {
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/"))
2018-09-24 11:56:41 +02:00
])
})
.then(() => {
//remove app & browser stuff
2018-09-24 11:56:41 +02:00
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) => {})
2018-09-24 11:56:41 +02:00
])
})
.then(() => {
2018-09-24 16:56:59 +02:00
console.log("Creating config...")
//create package.json for electron-builder
const builderPackageJSON = Object.assign(require(path.join(dirname, '/app-desktop/', '/package.json')), {
version: version
})
2018-09-24 16:56:59 +02:00
builderPackageJSON.build.icon = path.join(dirname, "/resources/desktop-icons/desktop-icon.png")
return fs.writeFile(path.join(electronSourcesDir, "/package.json"),
JSON.stringify(builderPackageJSON),
'utf8',
(e) => {
if (e) {
console.log("couldn't write package.json: ", e);
}
2018-09-24 11:56:41 +02:00
})
})
.then(() => {
//package for linux, win, mac
const builder = require("electron-builder")
return builder.build({
_: ['build'],
win: [],
mac: [],
linux: [],
p: 'always',
project: electronSourcesDir
})
2018-09-24 11:56:41 +02:00
})
.then(() => {
//copy installers to
return fs.move(path.join(dirname, '/app-desktop/dist/installers'), path.join(dirname, '/app-desktop/installers/'))
})
.then(() => {
return Promise.all([
fs.remove(path.join(dirname, '/app-desktop/dist/'), (e) => {}),
fs.remove(path.join(dirname, '/app-desktop/installers/', '/.icon-icns/'), (e) => {}),
fs.remove(path.join(dirname, '/app-desktop/installers/', '/.icon-ico/'), (e) => {}),
fs.remove(path.join(dirname, '/app-desktop/installers/', '/.icon-set/'), (e) => {}),
fs.remove(path.join(dirname, '/app-desktop/installers/', '/linux-unpacked/'), (e) => {}),
fs.remove(path.join(dirname, '/app-desktop/installers/', '/win-unpacked/'), (e) => {}),
])
})
2018-09-24 11:56:41 +02:00
}
module.exports = {
packageDesktop
}