1
1
import * as os from "node:os" ;
2
2
import * as fs from "node:fs" ;
3
- import * as path from "node:path" ;
4
3
import { type Configuration as BaseConfiguration , type Protocol } from "electron-builder" ;
5
4
6
5
/**
7
6
* This script has different outputs depending on your os platform.
8
7
*
9
8
* On Windows:
9
+ * Prefixes the nightly version with `0.0.1-nightly.` as it breaks if it is not semver
10
10
* Passes $ED_SIGNTOOL_THUMBPRINT and $ED_SIGNTOOL_SUBJECT_NAME to
11
11
* build.win.signtoolOptions.signingHashAlgorithms and build.win.signtoolOptions.certificateSubjectName respectively if specified.
12
12
*
@@ -16,48 +16,25 @@ import { type Configuration as BaseConfiguration, type Protocol } from "electron
16
16
* Passes $ED_DEBIAN_CHANGELOG to build.deb.fpm if specified
17
17
*/
18
18
19
- /**
20
- * Interface describing relevant fields of the package.json file.
21
- */
19
+ const DEFAULT_APP_ID = "im.riot.app" ;
20
+ const NIGHTLY_APP_ID = "im.riot.nightly" ;
21
+ const NIGHTLY_DEB_NAME = "element-nightly" ;
22
+
23
+ const DEFAULT_PROTOCOL_SCHEME = "io.element.desktop" ;
24
+ const NIGHTLY_PROTOCOL_SCHEME = "io.element.nightly" ;
25
+
22
26
interface Pkg {
23
27
name : string ;
24
28
productName : string ;
25
29
description : string ;
26
30
version : string ;
27
31
}
28
32
29
- /**
30
- * Interface describing the variant configuration format.
31
- */
32
- interface Variant extends Omit < Pkg , "version" > {
33
- "appId" : string ;
34
- "linux.executableName" ?: string ;
35
- "linux.deb.name" ?: string ;
36
- "protocols" : string [ ] ;
37
- }
38
-
39
33
type Writable < T > = NonNullable <
40
34
T extends Function ? T : T extends object ? { - readonly [ K in keyof T ] : Writable < T [ K ] > } : T
41
35
> ;
42
36
43
- // Load the package.json file to get the app metadata
44
37
const pkg : Pkg = JSON . parse ( fs . readFileSync ( "package.json" , "utf8" ) ) ;
45
- // Load the default variant as a base configuration
46
- let variant : Variant = {
47
- ...pkg ,
48
- ...JSON . parse ( fs . readFileSync ( path . join ( "element.io" , "release" , "build.json" ) , "utf8" ) ) ,
49
- } ;
50
-
51
- /**
52
- * If a variant is specified, we will use it to override the build-specific values.
53
- * This allows us to have different builds for different purposes (e.g. stable, nightly).
54
- */
55
- if ( process . env . VARIANT_PATH ) {
56
- variant = {
57
- ...variant ,
58
- ...JSON . parse ( fs . readFileSync ( `${ process . env . VARIANT_PATH } ` , "utf8" ) ) ,
59
- } ;
60
- }
61
38
62
39
interface Configuration extends BaseConfiguration {
63
40
extraMetadata : Partial < Pick < Pkg , "version" > > &
@@ -81,7 +58,7 @@ const config: Omit<Writable<Configuration>, "electronFuses"> & {
81
58
// Make all fuses required to ensure they are all explicitly specified
82
59
electronFuses : Required < Configuration [ "electronFuses" ] > ;
83
60
} = {
84
- appId : variant . appId ,
61
+ appId : DEFAULT_APP_ID ,
85
62
asarUnpack : "**/*.node" ,
86
63
electronFuses : {
87
64
enableCookieEncryption : true ,
@@ -110,8 +87,8 @@ const config: Omit<Writable<Configuration>, "electronFuses"> & {
110
87
name : pkg . name ,
111
88
productName : pkg . productName ,
112
89
description : pkg . description ,
113
- electron_appId : variant . appId ,
114
- electron_protocol : variant . protocols [ 0 ] ,
90
+ electron_appId : DEFAULT_APP_ID ,
91
+ electron_protocol : DEFAULT_PROTOCOL_SCHEME ,
115
92
} ,
116
93
linux : {
117
94
target : [ "tar.gz" , "deb" ] ,
@@ -163,27 +140,14 @@ const config: Omit<Writable<Configuration>, "electronFuses"> & {
163
140
output : "dist" ,
164
141
} ,
165
142
protocols : {
166
- name : variant . productName ,
167
- schemes : variant . protocols ,
143
+ name : "element" ,
144
+ schemes : [ DEFAULT_PROTOCOL_SCHEME , "element" ] ,
168
145
} ,
169
146
nativeRebuilder : "sequential" ,
170
147
nodeGypRebuild : false ,
171
148
npmRebuild : true ,
172
149
} ;
173
150
174
- /**
175
- * Allow specifying the version via env var.
176
- * If unspecified, it will default to the version in package.json.
177
- * @param {string } process.env.VERSION
178
- */
179
- if ( process . env . VERSION ) {
180
- config . extraMetadata . version = process . env . VERSION ;
181
- }
182
-
183
- if ( variant [ "linux.deb.name" ] ) {
184
- config . deb . fpm . push ( "--name" , variant [ "linux.deb.name" ] ) ;
185
- }
186
-
187
151
/**
188
152
* Allow specifying windows signing cert via env vars
189
153
* @param {string } process.env.ED_SIGNTOOL_SUBJECT_NAME
@@ -194,6 +158,33 @@ if (process.env.ED_SIGNTOOL_SUBJECT_NAME && process.env.ED_SIGNTOOL_THUMBPRINT)
194
158
config . win . signtoolOptions ! . certificateSha1 = process . env . ED_SIGNTOOL_THUMBPRINT ;
195
159
}
196
160
161
+ /**
162
+ * Allow specifying nightly version via env var
163
+ * @param {string } process.env.ED_NIGHTLY
164
+ */
165
+ if ( process . env . ED_NIGHTLY ) {
166
+ config . deb . fpm = [ ] ; // Clear the fpm as the breaks deb fields don't apply to nightly
167
+
168
+ config . appId = config . extraMetadata . electron_appId = NIGHTLY_APP_ID ;
169
+ config . extraMetadata . productName += " Nightly" ;
170
+ config . extraMetadata . name += "-nightly" ;
171
+ config . extraMetadata . description += " (nightly unstable build)" ;
172
+ config . linux . executableName += "-nightly" ;
173
+ config . deb . fpm . push ( "--name" , NIGHTLY_DEB_NAME ) ;
174
+ ( config . protocols as Protocol ) . schemes [ 0 ] = config . extraMetadata . electron_protocol = NIGHTLY_PROTOCOL_SCHEME ;
175
+
176
+ let version = process . env . ED_NIGHTLY ;
177
+ if ( os . platform ( ) === "win32" ) {
178
+ // The windows packager relies on parsing this as semver, so we have to make it look like one.
179
+ // This will give our update packages really stupid names, but we probably can't change that either
180
+ // because squirrel windows parses them for the version too. We don't really care: nobody sees them.
181
+ // We just give the installer a static name, so you'll just see this in the 'about' dialog.
182
+ // Turns out if you use 0.0.0 here it makes Squirrel windows crash, so we use 0.0.1.
183
+ version = "0.0.1-nightly." + version ;
184
+ }
185
+ config . extraMetadata . version = version ;
186
+ }
187
+
197
188
if ( os . platform ( ) === "linux" ) {
198
189
// Electron crashes on debian if there's a space in the path.
199
190
// https://github.com/vector-im/element-web/issues/13171
0 commit comments