forked from electron-userland/electron-builder
/
publishOptions.ts
385 lines (327 loc) · 10 KB
/
publishOptions.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
import { OutgoingHttpHeaders } from "http"
export type PublishProvider = "github" | "bintray" | "s3" | "spaces" | "generic" | "custom" | "snapStore" | "keygen"
// typescript-json-schema generates only PublishConfiguration if it is specified in the list, so, it is not added here
export type AllPublishOptions = string | GithubOptions | S3Options | SpacesOptions | GenericServerOptions | BintrayOptions | CustomPublishOptions | KeygenOptions | SnapStoreOptions
export interface PublishConfiguration {
/**
* The provider.
*/
readonly provider: PublishProvider
/**
* @private
* win-only
*/
publisherName?: Array<string> | null
/**
* @private
* win-only
*/
readonly updaterCacheDirName?: string | null
/**
* Whether to publish auto update info files.
*
* Auto update relies only on the first provider in the list (you can specify several publishers).
* Thus, probably, there`s no need to upload the metadata files for the other configured providers. But by default will be uploaded.
*
* @default true
*/
readonly publishAutoUpdate?: boolean
/**
* Any custom request headers
*/
readonly requestHeaders?: OutgoingHttpHeaders
}
// https://github.com/electron-userland/electron-builder/issues/3261
export interface CustomPublishOptions extends PublishConfiguration {
/**
* The provider. Must be `custom`.
*/
readonly provider: "custom"
/**
* The Provider to provide UpdateInfo regarding available updates. Required
* to use custom providers with electron-updater.
*/
updateProvider?: new (options: CustomPublishOptions, updater: any, runtimeOptions: any) => any
[index: string]: any
}
/**
* [GitHub](https://help.github.com/articles/about-releases/) options.
*
* GitHub [personal access token](https://help.github.com/articles/creating-an-access-token-for-command-line-use/) is required. You can generate by going to [https://github.com/settings/tokens/new](https://github.com/settings/tokens/new). The access token should have the repo scope/permission.
* Define `GH_TOKEN` environment variable.
*/
export interface GithubOptions extends PublishConfiguration {
/**
* The provider. Must be `github`.
*/
readonly provider: "github"
/**
* The repository name. [Detected automatically](#github-repository-and-bintray-package).
*/
readonly repo?: string | null
/**
* The owner.
*/
readonly owner?: string | null
/**
* Whether to use `v`-prefixed tag name.
* @default true
*/
readonly vPrefixedTagName?: boolean
/**
* The host (including the port if need).
* @default github.com
*/
readonly host?: string | null
/**
* The protocol. GitHub Publisher supports only `https`.
* @default https
*/
readonly protocol?: "https" | "http" | null
/**
* The access token to support auto-update from private github repositories. Never specify it in the configuration files. Only for [setFeedURL](/auto-update#appupdatersetfeedurloptions).
*/
readonly token?: string | null
/**
* Whether to use private github auto-update provider if `GH_TOKEN` environment variable is defined. See [Private GitHub Update Repo](/auto-update#private-github-update-repo).
*/
readonly private?: boolean | null
/**
* The type of release. By default `draft` release will be created.
*
* Also you can set release type using environment variable. If `EP_DRAFT`is set to `true` — `draft`, if `EP_PRE_RELEASE`is set to `true` — `prerelease`.
* @default draft
*/
releaseType?: "draft" | "prerelease" | "release" | null
}
/** @private */
export function githubUrl(options: GithubOptions, defaultHost = "github.com") {
return `${options.protocol || "https"}://${options.host || defaultHost}`
}
/**
* Generic (any HTTP(S) server) options.
* In all publish options [File Macros](/file-patterns#file-macros) are supported.
*/
export interface GenericServerOptions extends PublishConfiguration {
/**
* The provider. Must be `generic`.
*/
readonly provider: "generic"
/**
* The base url. e.g. `https://bucket_name.s3.amazonaws.com`.
*/
readonly url: string
/**
* The channel.
* @default latest
*/
readonly channel?: string | null
/**
* Whether to use multiple range requests for differential update. Defaults to `true` if `url` doesn't contain `s3.amazonaws.com`.
*/
readonly useMultipleRangeRequest?: boolean
}
/**
* Keygen options.
* https://keygen.sh/
* Define `KEYGEN_TOKEN` environment variable.
*/
export interface KeygenOptions extends PublishConfiguration {
/**
* The provider. Must be `keygen`.
*/
readonly provider: "keygen"
/**
* Keygen account's UUID
*/
readonly account: string
/**
* Keygen product's UUID
*/
readonly product: string
/**
* The channel.
* @default stable
*/
readonly channel?: "stable" | "rc" | "beta" | "alpha" | "dev" | null
/**
* The target Platform. Is set programmatically explicitly during publishing.
*/
readonly platform?: string | null
}
/**
* [Snap Store](https://snapcraft.io/) options.
*/
export interface SnapStoreOptions extends PublishConfiguration {
/**
* The provider. Must be `snapStore`.
*/
readonly provider: "snapStore"
/**
* snapcraft repo name
*/
readonly repo: string
/**
* The list of channels the snap would be released.
* @default ["edge"]
*/
readonly channels?: string | Array<string> | null
}
export interface BaseS3Options extends PublishConfiguration {
/**
* The update channel.
* @default latest
*/
channel?: string | null
/**
* The directory path.
* @default /
*/
readonly path?: string | null
/**
* The ACL. Set to `null` to not [add](https://github.com/electron-userland/electron-builder/issues/1822).
*
* @default public-read
*/
readonly acl?: "private" | "public-read" | null
}
export interface S3Options extends BaseS3Options {
/**
* The provider. Must be `s3`.
*/
readonly provider: "s3"
/**
* The bucket name.
*/
readonly bucket: string
/**
* The region. Is determined and set automatically when publishing.
*/
region?: string | null
/**
* The ACL. Set to `null` to not [add](https://github.com/electron-userland/electron-builder/issues/1822).
*
* Please see [required permissions for the S3 provider](https://github.com/electron-userland/electron-builder/issues/1618#issuecomment-314679128).
*
* @default public-read
*/
readonly acl?: "private" | "public-read" | null
/**
* The type of storage to use for the object.
* @default STANDARD
*/
readonly storageClass?: "STANDARD" | "REDUCED_REDUNDANCY" | "STANDARD_IA" | null
/**
* Server-side encryption algorithm to use for the object.
*/
readonly encryption?: "AES256" | "aws:kms" | null
/**
* The endpoint URI to send requests to. The default endpoint is built from the configured region.
* The endpoint should be a string like `https://{service}.{region}.amazonaws.com`.
*/
readonly endpoint?: string | null
}
/**
* [DigitalOcean Spaces](https://www.digitalocean.com/community/tutorials/an-introduction-to-digitalocean-spaces) options.
* Access key is required, define `DO_KEY_ID` and `DO_SECRET_KEY` environment variables.
*/
export interface SpacesOptions extends BaseS3Options {
/**
* The provider. Must be `spaces`.
*/
readonly provider: "spaces"
/**
* The space name.
*/
readonly name: string
/**
* The region (e.g. `nyc3`).
*/
readonly region: string
}
export function getS3LikeProviderBaseUrl(configuration: PublishConfiguration) {
const provider = configuration.provider
if (provider === "s3") {
return s3Url(configuration as S3Options)
}
if (provider === "spaces") {
return spacesUrl(configuration as SpacesOptions)
}
throw new Error(`Not supported provider: ${provider}`)
}
function s3Url(options: S3Options) {
let url: string
if (options.endpoint != null) {
url = `${options.endpoint}/${options.bucket}`
} else if (options.bucket.includes(".")) {
if (options.region == null) {
throw new Error(`Bucket name "${options.bucket}" includes a dot, but S3 region is missing`)
}
// special case, see http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingBucket.html#access-bucket-intro
if (options.region === "us-east-1") {
url = `https://s3.amazonaws.com/${options.bucket}`
} else {
url = `https://s3-${options.region}.amazonaws.com/${options.bucket}`
}
} else if (options.region === "cn-north-1") {
url = `https://${options.bucket}.s3.${options.region}.amazonaws.com.cn`
} else {
url = `https://${options.bucket}.s3.amazonaws.com`
}
return appendPath(url, options.path)
}
function appendPath(url: string, p: string | null | undefined): string {
if (p != null && p.length > 0) {
if (!p.startsWith("/")) {
url += "/"
}
url += p
}
return url
}
function spacesUrl(options: SpacesOptions) {
if (options.name == null) {
throw new Error(`name is missing`)
}
if (options.region == null) {
throw new Error(`region is missing`)
}
return appendPath(`https://${options.name}.${options.region}.digitaloceanspaces.com`, options.path)
}
/**
* [Bintray](https://bintray.com/) options. Requires an API key. An API key can be obtained from the user [profile](https://bintray.com/profile/edit) page ("Edit Your Profile" -> API Key).
* Define `BT_TOKEN` environment variable.
*/
export interface BintrayOptions extends PublishConfiguration {
/**
* The provider. Must be `bintray`.
*/
readonly provider: "bintray"
/**
* The Bintray package name.
*/
readonly package?: string | null
/**
* The Bintray repository name.
* @default generic
*/
readonly repo?: string | null
/**
* The owner.
*/
readonly owner?: string | null
/**
* The Bintray component (Debian only).
*/
readonly component?: string | null
/**
* The Bintray distribution (Debian only).
* @default stable
*/
readonly distribution?: string | null
/**
* The Bintray user account. Used in cases where the owner is an organization.
*/
readonly user?: string | null
readonly token?: string | null
}