2018-09-24 11:56:41 +02:00
|
|
|
const Promise = require('bluebird')
|
|
|
|
|
const fs = Promise.promisifyAll(require("fs-extra"))
|
|
|
|
|
const path = require("path")
|
|
|
|
|
|
2018-09-24 15:29:24 +02:00
|
|
|
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/")
|
|
|
|
|
|
2018-09-24 15:29:24 +02:00
|
|
|
//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),
|
2018-09-25 16:59:26 +02:00
|
|
|
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(() => {
|
2018-09-25 16:59:26 +02:00
|
|
|
//remove app & browser stuff
|
2018-09-24 11:56:41 +02:00
|
|
|
return Promise.all([
|
2018-09-25 16:59:26 +02:00
|
|
|
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...")
|
2018-09-24 15:29:24 +02:00
|
|
|
//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")
|
2018-09-24 15:29:24 +02:00
|
|
|
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
|
|
|
})
|
2018-09-24 15:29:24 +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
|
|
|
})
|
2018-09-26 17:22:05 +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
|
|
|
|
|
}
|