-
Notifications
You must be signed in to change notification settings - Fork 20
/
forge.config.ts
134 lines (126 loc) · 4.04 KB
/
forge.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// When ts-node runs this file it doesn't seem to use our tsconfig.json project
// settings, so we need to reference custom package definitions manually.
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
/// <reference path="./src/custom-package-definitions.d.ts" />
import fs from 'fs';
import path from 'path';
import { MakerDeb } from '@electron-forge/maker-deb';
import { MakerDMG } from '@electron-forge/maker-dmg';
import { MakerSquirrel } from '@electron-forge/maker-squirrel';
import { MakerZIP } from '@electron-forge/maker-zip';
import { AutoUnpackNativesPlugin } from '@electron-forge/plugin-auto-unpack-natives';
import { WebpackPlugin } from '@electron-forge/plugin-webpack';
import ForgeExternalsPlugin from '@timfish/forge-externals-plugin';
import ejs from 'ejs';
import { isErrnoException } from './src/lib/is-errno-exception';
import mainConfig, { mainBaseConfig } from './webpack.main.config';
import { rendererConfig } from './webpack.renderer.config';
import type { ForgeConfig } from '@electron-forge/shared-types';
const config: ForgeConfig = {
packagerConfig: {
asar: true,
extraResource: [ './wp-files', './assets', './bin' ],
executableName: process.platform === 'linux' ? 'studio' : undefined,
icon: './assets/studio-app-icon',
osxSign: {},
},
rebuildConfig: {},
makers: [
new MakerZIP( {}, [ 'darwin' ] ),
new MakerDeb( {
options: {
genericName: 'Studio by WordPress.com',
categories: [ 'Utility' ],
name: 'studio',
},
} ),
new MakerSquirrel(
{
loadingGif: './installers/loading.gif',
setupIcon: './assets/studio-app-icon.ico',
// This icon is shown in Control Panel -> Programs and Features
// Windows Explorer caches the icon agressively; use the cache busting param when necessary.
iconUrl: 'https://s0.wp.com/i/studio-app/studio-app-icon.ico?v=3',
setupExe: 'studio-setup.exe',
certificateFile: 'certificate.pfx',
certificatePassword: process.env.WINDOWS_CODE_SIGNING_CERT_PASSWORD,
},
[ 'win32' ]
),
...( process.env.SKIP_DMG
? []
: [
new MakerDMG(
{
icon: 'assets/studio-app-icon.icns',
background: 'assets/dmg-background.png',
contents: [
{
x: 533,
y: 122,
type: 'file',
path: `${ process.cwd() }/out/Studio-darwin-${
process.env.FILE_ARCHITECTURE || 'arm64'
}/Studio.app`,
},
{ x: 533, y: 354, type: 'link', path: '/Applications' },
],
additionalDMGOptions: {
window: {
size: {
width: 710,
height: 502,
},
},
},
},
[ 'darwin' ]
),
] ),
],
plugins: [
new AutoUnpackNativesPlugin( {} ),
new WebpackPlugin( {
mainConfig,
renderer: {
config: rendererConfig,
entryPoints: [
{
html: './dist/index.html',
js: './src/renderer.ts',
name: 'main_window',
preload: {
js: './src/preload.ts',
},
},
],
},
// By default the dev server uses the same port as calypso.localhost
port: 3456,
} ),
// This plugin bundles the externals defined in the Webpack config file.
new ForgeExternalsPlugin( { externals: Object.keys( mainBaseConfig.externals ?? {} ) } ),
],
hooks: {
generateAssets: async () => {
console.log( 'Building the HTML entry file ...' );
const REACT_DEV_TOOLS =
process.env.REACT_DEV_TOOLS === 'true' || process.env.REACT_DEV_TOOLS === '1';
const ejsTemplate = fs.readFileSync( './src/index.ejs', 'utf8' );
const data = { REACT_DEV_TOOLS };
const renderedHtml = ejs.render( ejsTemplate, data );
fs.mkdirSync( './dist', { recursive: true } );
fs.writeFileSync( './dist/index.html', renderedHtml );
},
prePackage: async () => {
console.log( "Ensuring latest WordPress zip isn't included in production build ..." );
const zipPath = path.join( __dirname, 'wp-files', 'latest.zip' );
try {
fs.unlinkSync( zipPath );
} catch ( err ) {
if ( isErrnoException( err ) && err.code !== 'ENOENT' ) throw err;
}
},
},
};
export default config;