|
| 1 | +const convertToWindowsStore = require('electron-windows-store'); |
| 2 | +const ebuilder = require('electron-builder'); |
| 3 | +const path = require('path'); |
| 4 | +const fs = require('fs-extra'); |
| 5 | + |
| 6 | +/** |
| 7 | + * A script that performs Windows build and signing then it converts |
| 8 | + * the build into APPX package that can be ditributed in Windows store. |
| 9 | + * |
| 10 | + * The build script assumes the following variables are set: |
| 11 | + * - CSC_NAME |
| 12 | + * - CSC_LINK |
| 13 | + * - WIN_CSC_LINK |
| 14 | + * - CSC_KEY_PASSWORD |
| 15 | + * - WIN_CSC_KEY_PASSWORD |
| 16 | + */ |
| 17 | +class WindowsStoreBuild { |
| 18 | + async getConverterOpts() { |
| 19 | + const version = await this.getVersion(); |
| 20 | + return { |
| 21 | + inputDirectory: path.join(__dirname, '..', 'dist', 'win-unpacked'), |
| 22 | + outputDirectory: path.join(__dirname, '..', 'dist', 'win-store'), |
| 23 | + packageVersion: version, |
| 24 | + packageName: 'AdvancedRestClient', |
| 25 | + packageDisplayName: 'Advanced REST Client', |
| 26 | + packageDescription: 'The Advanced REST Client desktop application.', |
| 27 | + assets: path.join(__dirname, '..', 'build', 'appx'), |
| 28 | + deploy: false, |
| 29 | + publisher: 'CN=D213CA20-88CE-42AC-A9F2-C5D41BF04550', |
| 30 | + publisherDisplayName: 'Pawel Psztyc', |
| 31 | + identityName: '48695PawelPsztyc.advanced-rest-client', |
| 32 | + }; |
| 33 | + } |
| 34 | + |
| 35 | + async getVersion() { |
| 36 | + const file = path.join(__dirname, '..', 'package.json'); |
| 37 | + const pkg = await fs.readJson(file); |
| 38 | + return `${pkg.version}.0`; |
| 39 | + } |
| 40 | + |
| 41 | + async getWinConfig() { |
| 42 | + const file = path.join(__dirname, '..', 'package.json'); |
| 43 | + const pkg = await fs.readJson(file); |
| 44 | + return pkg.build; |
| 45 | + } |
| 46 | + |
| 47 | + async buildWindows() { |
| 48 | + const config = await this.getWinConfig(); |
| 49 | + const Platform = ebuilder.Platform; |
| 50 | + const opts = { |
| 51 | + targets: Platform.WINDOWS.createTarget('nsis'), |
| 52 | + config, |
| 53 | + }; |
| 54 | + return await ebuilder.build(opts); |
| 55 | + } |
| 56 | + |
| 57 | + async convert() { |
| 58 | + const options = await this.getConverterOpts(); |
| 59 | + await convertToWindowsStore(options); |
| 60 | + } |
| 61 | + |
| 62 | + async build() { |
| 63 | + await this.buildWindows(); |
| 64 | + await this.convert(); |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +new WindowsStoreBuild().build(); |
0 commit comments