|
| 1 | +/* |
| 2 | + * Wire |
| 3 | + * Copyright (C) 2019 Wire Swiss GmbH |
| 4 | + * |
| 5 | + * This program is free software: you can redistribute it and/or modify |
| 6 | + * it under the terms of the GNU General Public License as published by |
| 7 | + * the Free Software Foundation, either version 3 of the License, or |
| 8 | + * (at your option) any later version. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + * GNU General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License |
| 16 | + * along with this program. If not, see http://www.gnu.org/licenses/. |
| 17 | + * |
| 18 | + */ |
| 19 | + |
| 20 | +import {LogFactory} from '@wireapp/commons'; |
| 21 | +import commander from 'commander'; |
| 22 | +import path from 'path'; |
| 23 | + |
| 24 | +import {logEntries} from '../bin-utils'; |
| 25 | +import {buildLinuxConfig, buildLinuxWrapper} from './lib/build-linux'; |
| 26 | +import {buildMacOSConfig, buildMacOSWrapper} from './lib/build-macos'; |
| 27 | +import {buildWindowsConfig, buildWindowsWrapper} from './lib/build-windows'; |
| 28 | +import {buildWindowsInstaller, buildWindowsInstallerConfig} from './lib/build-windows-installer'; |
| 29 | + |
| 30 | +const toolName = path.basename(__filename).replace('.ts', ''); |
| 31 | +const logger = LogFactory.getLogger(toolName, {namespace: '@wireapp/build-tools', forceEnable: true}); |
| 32 | +const appSource = path.join(__dirname, '../../'); |
| 33 | + |
| 34 | +commander |
| 35 | + .name(toolName) |
| 36 | + .description( |
| 37 | + 'Build the Wire wrapper for your platform.\n\nValid values for platform are: "windows", "windows-installer", "macos", "linux".', |
| 38 | + ) |
| 39 | + .option('-e, --env-file <path>', 'Specify the env file path', path.join(appSource, '.env.defaults')) |
| 40 | + .option('-m, --manual-sign', `Manually sign and package the app (i.e. don't use electron-packager, macOS only)`) |
| 41 | + .option('-p, --package-json <path>', 'Specify the package.json path', path.join(appSource, 'package.json')) |
| 42 | + .option('-w, --wire-json <path>', 'Specify the wire.json path', path.join(appSource, 'electron/wire.json')) |
| 43 | + .arguments('<platform>') |
| 44 | + .parse(process.argv); |
| 45 | + |
| 46 | +const platform = (commander.args[0] || '').toLowerCase(); |
| 47 | + |
| 48 | +new Promise(() => { |
| 49 | + switch (platform) { |
| 50 | + case 'win': |
| 51 | + case 'windows': { |
| 52 | + const {packagerConfig} = buildWindowsConfig(commander.wireJson, commander.envFile); |
| 53 | + |
| 54 | + logEntries(packagerConfig, 'packagerConfig', toolName); |
| 55 | + |
| 56 | + return buildWindowsWrapper(packagerConfig, commander.packageJson, commander.wireJson, commander.envFile); |
| 57 | + } |
| 58 | + |
| 59 | + case 'windows-installer': { |
| 60 | + const {wInstallerOptions} = buildWindowsInstallerConfig(commander.wireJson, commander.envFile); |
| 61 | + |
| 62 | + logEntries(wInstallerOptions, 'wInstallerOptions', toolName); |
| 63 | + |
| 64 | + return buildWindowsInstaller(commander.wireJson, commander.envFile, wInstallerOptions); |
| 65 | + } |
| 66 | + |
| 67 | + case 'mac': |
| 68 | + case 'macos': { |
| 69 | + const {macOSConfig, packagerConfig} = buildMacOSConfig( |
| 70 | + commander.wireJson, |
| 71 | + commander.envFile, |
| 72 | + commander.manualSign, |
| 73 | + ); |
| 74 | + |
| 75 | + logEntries(packagerConfig, 'builderConfig', toolName); |
| 76 | + |
| 77 | + return buildMacOSWrapper( |
| 78 | + packagerConfig, |
| 79 | + macOSConfig, |
| 80 | + commander.packageJson, |
| 81 | + commander.wireJson, |
| 82 | + commander.manualSign, |
| 83 | + ); |
| 84 | + } |
| 85 | + |
| 86 | + case 'linux': { |
| 87 | + const {linuxConfig, builderConfig} = buildLinuxConfig(commander.wireJson, commander.envFile); |
| 88 | + |
| 89 | + logEntries(builderConfig, 'builderConfig', toolName); |
| 90 | + |
| 91 | + return buildLinuxWrapper( |
| 92 | + builderConfig, |
| 93 | + linuxConfig, |
| 94 | + commander.packageJson, |
| 95 | + commander.wireJson, |
| 96 | + commander.envFile, |
| 97 | + ); |
| 98 | + } |
| 99 | + |
| 100 | + default: { |
| 101 | + logger.error(`Invalid or no platform specified.`); |
| 102 | + return commander.help(); |
| 103 | + } |
| 104 | + } |
| 105 | +}).catch(error => { |
| 106 | + logger.error(error); |
| 107 | + process.exit(1); |
| 108 | +}); |
0 commit comments