thedesk/app/build.js

166 lines
5.6 KiB
JavaScript
Raw Normal View History

const builder = require('electron-builder')
const path = require('path')
const fs = require('fs')
const basefile = __dirname + '/'
const package = fs.readFileSync(basefile + 'package.json')
const data = JSON.parse(package)
const version = data.version
const codename = data.codename
const ver = `${version} (${codename})`
const construct = require('./view/make/make.js')
const { platform, arch } = process
2019-05-26 21:42:52 +10:00
const Platform = builder.Platform
const Arch = builder.Arch
const config = {
productName: 'TheDesk',
appId: 'top.thedesk',
asarUnpack: ['node_modules/itunes-nowplaying-mac', 'main/script'],
afterSign: 'build/notarize.js',
2019-05-26 21:42:52 +10:00
directories: {
output: '../build',
2019-05-26 21:42:52 +10:00
},
win: {
icon: 'build/thedesk.ico',
2021-04-13 15:33:15 +10:00
target: ['nsis', 'appx', 'portable']
2019-05-26 21:42:52 +10:00
},
appx: {
identityName: '53491Cutls.TheDesk',
applicationId: 'Cutls.TheDesk',
publisherDisplayName: 'Cutls',
publisher: 'CN=629757F5-A5EE-474F-9562-B304A89A9FD1',
languages: ['JA-JP', 'EN-US'],
2019-05-26 21:42:52 +10:00
},
nsis: {
oneClick: false,
allowToChangeInstallationDirectory: true,
artifactName: 'TheDesk-setup.${ext}',
2019-05-26 21:42:52 +10:00
},
linux: {
icon: 'build/icons',
target: ['zip', 'appImage', 'snap', 'deb'],
category: 'Network',
2019-05-26 21:42:52 +10:00
},
mac: {
hardenedRuntime: true,
gatekeeperAssess: false,
entitlements: 'build/entitlements.mac.plist',
entitlementsInherit: 'build/entitlements.mac.plist',
2019-05-26 21:42:52 +10:00
},
dmg: {
sign: false,
2019-05-26 21:42:52 +10:00
},
}
async function build(os, arch, config) {
let targets = new Map()
let archToType = new Map()
archToType.set(arch, [])
targets.set(os, archToType)
await builder.build({
targets: targets,
config: config,
})
2019-05-26 21:42:52 +10:00
}
async function cmd() {
if (isTrue('onlyStore') || isTrue('withStore')) {
console.log('start building for application stores')
construct(ver, basefile, false, true)
if (platform == 'win32') {
if ((isTrue('withIa32') && arch == 'x64') || arch == 'ia32') {
await build(Platform.WINDOWS, Arch.ia32, config)
fs.renameSync(
`../build/TheDesk ${version}.exe`,
2021-04-13 14:48:59 +10:00
'../build/TheDesk-ia32-store.exe'
)
fs.renameSync(
`../build/TheDesk-setup.exe`,
2021-04-13 14:48:59 +10:00
'../build/TheDesk-setup-ia32-store.exe'
)
}
if (arch == 'x64') {
await build(Platform.WINDOWS, Arch.x64, config)
fs.renameSync(
`../build/TheDesk ${version}.exe`,
2021-04-13 14:48:59 +10:00
'../build/TheDesk-store.exe'
)
fs.renameSync(
`../build/TheDesk-setup.exe`,
'../build/TheDesk-setup-ia32-store.exe'
)
}
} else if (platform == 'linux') {
2021-04-13 14:48:59 +10:00
if (arch == 'ia32') {
await build(Platform.LINUX, Arch.ia32, config)
}
2021-04-13 14:48:59 +10:00
if ((isTrue('withIa32') && arch == 'x64') ) {
console.log('snapcraft does not curretly support builing i386 on amd64')
}
if (arch == 'x64') {
await build(Platform.LINUX, Arch.x64, config)
if (!isTrue('onlyStore')) {
fs.renameSync(
`../build/thedesk_${version}_amd64.snap`,
`../build/thedesk_${version}_amd64-store.snap`
)
}
}
} else if (platform == 'darwin') {
console.log('Mac App Store should be use electron-packager')
} else {
return false
2019-05-26 21:42:52 +10:00
}
}
if (!isTrue('onlyStore')) {
console.log('start building for normal usage')
construct(ver, basefile, false, false)
if (platform == 'win32') {
if ((isTrue('withIa32') && arch == 'x64') || arch == 'ia32') {
await build(Platform.WINDOWS, Arch.ia32, config)
fs.renameSync(
`../build/TheDesk ${version}.exe`,
'../build/TheDesk-ia32.exe'
)
fs.renameSync(
`../build/TheDesk-setup.exe`,
'../build/TheDesk-setup-ia32.exe'
)
}
if (arch == 'x64') {
await build(Platform.WINDOWS, Arch.x64, config)
fs.renameSync(
`../build/TheDesk ${version}.exe`,
'../build/TheDesk.exe'
)
}
} else if (platform == 'linux') {
if ((isTrue('withIa32') && arch == 'x64') || arch == 'ia32') {
await build(Platform.LINUX, Arch.ia32, config)
}
if (arch == 'x64') {
await build(Platform.LINUX, Arch.x64, config)
fs.renameSync(
`../build/thedesk_${version}_amd64.snap`,
`../build/thedesk_${version}_amd64-normal.snap`
)
if (isTrue('onlyStore') || isTrue('withStore')) {
fs.renameSync(
`../build/thedesk_${version}_amd64-store.snap`,
`../build/thedesk_${version}_amd64.snap`
)
}
}
} else if (platform == 'darwin') {
await build(Platform.MAC, Arch.x64, config)
} else {
return false
}
}
}
function isTrue(long, short) {
const { argv } = process
if (argv.includes(`--${long}`)) return true
if (short && argv.includes(`-${short}`)) return true
return false
}
cmd()