/
metadata.ts
executable file
·540 lines (421 loc) · 17 KB
/
metadata.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
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
import { ElectronPackagerOptions } from "electron-packager-tf"
import { AsarOptions } from "asar"
export interface Metadata {
readonly repository?: string | RepositoryInfo | null
}
/*
# Application `package.json`
*/
export interface AppMetadata extends Metadata {
readonly version: string
/*
The application name.
*/
readonly name: string
/*
As [name](#AppMetadata-name), but allows you to specify a product name for your executable which contains spaces and other special characters
not allowed in the [name property](https://docs.npmjs.com/files/package.json#name}).
*/
readonly productName?: string | null
/*
The application description.
*/
readonly description: string
readonly main?: string | null
readonly author: AuthorMetadata
/*
The url to the project [homepage](https://docs.npmjs.com/files/package.json#homepage) (NuGet Package `projectUrl` (optional) or Linux Package URL (required)).
If not specified and your project repository is public on GitHub, it will be `https://github.com/${user}/${project}` by default.
*/
readonly homepage?: string | null
/*
*linux-only.* The [license](https://docs.npmjs.com/files/package.json#license) name.
*/
readonly license?: string | null
}
/*
# Development `package.json`
*/
export interface DevMetadata extends Metadata {
/*
See [.build](#BuildMetadata).
*/
readonly build: BuildMetadata
// deprecated
readonly homepage?: string | null
// deprecated
readonly license?: string | null
/*
See [.directories](#MetadataDirectories)
*/
readonly directories?: MetadataDirectories | null
}
export interface RepositoryInfo {
readonly url: string
}
export interface AuthorMetadata {
readonly name: string
readonly email: string
}
export type CompressionLevel = "store" | "normal" | "maximum"
/*
## `.build`
*/
export interface BuildMetadata {
/*
The application id. Used as
[CFBundleIdentifier](https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html#//apple_ref/doc/uid/20001431-102070) for MacOS and as
[Application User Model ID](https://msdn.microsoft.com/en-us/library/windows/desktop/dd378459(v=vs.85).aspx) for Windows.
For windows only NSIS target supports it. Squirrel.Windows is not fixed yet.
Defaults to `com.electron.${name}`. It is strongly recommended that an explicit ID be set.
*/
readonly appId?: string | null
// deprecated
readonly "app-bundle-id"?: string | null
/*
*MacOS-only.* The application category type, as shown in the Finder via *View -> Arrange by Application Category* when viewing the Applications directory.
For example, `app-category-type=public.app-category.developer-tools` will set the application category to *Developer Tools*.
Valid values are listed in [Apple's documentation](https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/LaunchServicesKeys.html#//apple_ref/doc/uid/TP40009250-SW8).
*/
readonly "app-category-type"?: string | null
/*
Whether to package the application's source code into an archive, using [Electron's archive format](https://github.com/electron/asar). Defaults to `true`.
Reasons why you may want to disable this feature are described in [an application packaging tutorial in Electron's documentation](http://electron.atom.io/docs/latest/tutorial/application-packaging/#limitations-on-node-api/).
Or you can pass object of any asar options.
*/
readonly asar?: AsarOptions | boolean | null
// deprecated
readonly iconUrl?: string | null
/*
See [AppMetadata.productName](#AppMetadata-productName).
*/
readonly productName?: string | null
/**
A [glob patterns](https://www.npmjs.com/package/glob#glob-primer) relative to the [app directory](#MetadataDirectories-app), which specifies which files to include when copying files to create the package. Defaults to `\*\*\/\*` (i.e. [hidden files are ignored by default](https://www.npmjs.com/package/glob#dots)).
Development dependencies are never copied in any case. You don't need to ignore it explicitly.
[Multiple patterns](#multiple-glob-patterns) are supported. You can use `${os}` (expanded to mac, linux or win according to current platform) and `${arch}` in the pattern.
If directory matched, all contents are copied. So, you can just specify `foo` to copy `foo` directory.
Remember that default pattern `\*\*\/\*` is not added to your custom, so, you have to add it explicitly — e.g. `["\*\*\/\*", "!ignoreMe${/\*}"]`.
May be specified in the platform options (e.g. in the `build.mac`).
*/
readonly files?: Array<string> | string | null
/**
A [glob patterns](https://www.npmjs.com/package/glob#glob-primer) relative to the project directory, when specified, copy the file or directory with matching names directly into the app's resources directory (`Contents/Resources` for MacOS, `resources` for Linux/Windows).
Glob rules the same as for [files](#BuildMetadata-files).
*/
readonly extraResources?: Array<string> | string | null
/**
The same as [extraResources](#BuildMetadata-extraResources) but copy into the app's content directory (`Contents` for MacOS, root directory for Linux/Windows).
*/
readonly extraFiles?: Array<string> | string | null
/*
See [.build.mac](#MacOptions).
*/
readonly mac?: MacOptions | null
/*
See [.build.dmg](#DmgOptions).
*/
readonly dmg?: DmgOptions | null
// deprecated
readonly osx?: MacOptions | null
/*
See [.build.mas](#MasBuildOptions).
*/
readonly mas?: MasBuildOptions | null
/**
See [.build.win](#LinuxBuildOptions).
*/
readonly win?: WinBuildOptions | null
/**
See [.build.nsis](#NsisOptions).
*/
readonly nsis?: NsisOptions | null
/*
See [.build.linux](#LinuxBuildOptions).
*/
readonly linux?: LinuxBuildOptions | null
/*
The compression level, one of `store`, `normal`, `maximum` (default: `normal`). If you want to rapidly test build, `store` can reduce build time significantly.
*/
readonly compression?: CompressionLevel | null
readonly "build-version"?: string | null
/*
*programmatic API only* The function to be run after pack (but before pack into distributable format and sign). Promise must be returned.
*/
readonly afterPack?: (context: AfterPackContext) => Promise<any> | null
// /*
// Whether to [prune](https://docs.npmjs.com/cli/prune) dependencies (`npm prune --production`) before starting to package the app.
// Defaults to `false`.
// */
// readonly npmPrune?: boolean
// deprecated
// readonly prune?: boolean
/*
Whether to [rebuild](https://docs.npmjs.com/cli/rebuild) native dependencies (`npm rebuild`) before starting to package the app. Defaults to `true`.
*/
readonly npmRebuild?: boolean
readonly icon?: string | null
}
export interface AfterPackContext {
readonly appOutDir: string
readonly options: ElectronPackagerOptions
}
/*
### `.build.mac`
MacOS specific build options.
*/
export interface MacOptions extends PlatformSpecificBuildOptions {
/*
Target package type: list of `default`, `dmg`, `mas`, `7z`, `zip`, `tar.xz`, `tar.lz`, `tar.gz`, `tar.bz2`. Defaults to `default` (dmg and zip for Squirrel.Mac).
*/
readonly target?: Array<string> | null
/*
The name of certificate to use when signing. Consider using environment variables [CSC_LINK or CSC_NAME](https://github.com/electron-userland/electron-builder/wiki/Code-Signing).
MAS installer identity is specified in the [.build.mas](#MasBuildOptions-identity).
*/
readonly identity?: string | null
/*
The path to application icon. Defaults to `build/icon.icns` (consider using this convention instead of complicating your configuration).
*/
readonly icon?: string | null
/*
The path to entitlements file for signing the app. `build/entitlements.osx.plist` will be used if exists (it is a recommended way to set).
MAS entitlements is specified in the [.build.mas](#MasBuildOptions-entitlements).
*/
readonly entitlements?: string | null
/*
The path to child entitlements which inherit the security settings for signing frameworks and bundles of a distribution. `build/entitlements.osx.inherit.plist` will be used if exists (it is a recommended way to set).
Otherwise [default](https://github.com/electron-userland/electron-osx-sign/blob/master/default.entitlements.darwin.inherit.plist).
This option only applies when signing with `entitlements` provided.
*/
readonly entitlementsInherit?: string | null
}
/*
### `.build.dmg`
MacOS DMG specific options.
See all [appdmg options](https://www.npmjs.com/package/appdmg#json-specification).
*/
export interface DmgOptions {
/*
The path to DMG icon, which will be shown when mounted. Defaults to `build/icon.icns`.
*/
readonly icon?: string | null
/*
The path to background (default: `build/background.png` if exists). The resolution of this file determines the resolution of the installer window.
If background is not specified, use `window.size`, see [specification](https://github.com/LinusU/node-appdmg#json-specification).
*/
readonly background?: string | null
}
/*
### `.build.mas`
MAS (Mac Application Store) specific options (in addition to `build.mac`).
*/
export interface MasBuildOptions extends MacOptions {
/*
The path to entitlements file for signing the app. `build/entitlements.mas.plist` will be used if exists (it is a recommended way to set).
Otherwise [default](https://github.com/electron-userland/electron-osx-sign/blob/master/default.entitlements.mas.plist).
*/
readonly entitlements?: string | null
/*
The path to child entitlements which inherit the security settings for signing frameworks and bundles of a distribution. `build/entitlements.mas.inherit.plist` will be used if exists (it is a recommended way to set).
Otherwise [default](https://github.com/electron-userland/electron-osx-sign/blob/master/default.entitlements.mas.inherit.plist).
*/
readonly entitlementsInherit?: string | null
}
/*
### `.build.win`
Windows specific build options.
*/
export interface WinBuildOptions extends PlatformSpecificBuildOptions {
readonly certificateFile?: string
readonly certificatePassword?: string
/*
Target package type: list of `squirrel`, `nsis`, `7z`, `zip`, `tar.xz`, `tar.lz`, `tar.gz`, `tar.bz2`. Defaults to `squirrel`.
*/
readonly target?: Array<string> | null
/*
*Squirrel.Windows-only.* A URL to an ICO file to use as the application icon (displayed in Control Panel > Programs and Features). Defaults to the Electron icon.
Please note — [local icon file url is not accepted](https://github.com/atom/grunt-electron-installer/issues/73), must be https/http.
* If you don't plan to build windows installer, you can omit it.
* If your project repository is public on GitHub, it will be `https://github.com/${u}/${p}/blob/master/build/icon.ico?raw=true` by default.
*/
readonly iconUrl?: string | null
/*
*Squirrel.Windows-only.* The path to a .gif file to display during install. `build/install-spinner.gif` will be used if exists (it is a recommended way to set)
(otherwise [default](https://github.com/electron/windows-installer/blob/master/resources/install-spinner.gif)).
*/
readonly loadingGif?: string | null
/*
*Squirrel.Windows-only.* Whether to create an MSI installer. Defaults to `false` (MSI is not created).
*/
readonly msi?: boolean
/*
*Squirrel.Windows-only.* A URL to your existing updates. If given, these will be downloaded to create delta updates.
*/
readonly remoteReleases?: string | null
/*
*Squirrel.Windows-only.* Authentication token for remote updates
*/
readonly remoteToken?: string | null
/*
Array of signing algorithms used. Defaults to `['sha1', 'sha256']`
*/
readonly signingHashAlgorithms?: Array<string> | null
readonly signcodePath?: string | null
/*
The path to application icon. Defaults to `build/icon.ico` (consider using this convention instead of complicating your configuration).
*/
readonly icon?: string | null
}
/*
### `.build.nsis`
NSIS target support in progress — not polished and not fully tested and checked.
See [NSIS target notes](https://github.com/electron-userland/electron-builder/wiki/NSIS).
*/
export interface NsisOptions {
/*
Mark "all users" (per-machine) as default. Not recommended. Defaults to `false`.
*/
readonly perMachine?: boolean | null
/*
Allow requesting for elevation. If false, user will have to restart installer with elevated permissions. Defaults to `true`.
*/
readonly allowElevation?: boolean | null
readonly guid?: string | null
/*
One-click installation. Defaults to `true`.
*/
readonly oneClick?: boolean | null
/*
*boring installer only.* `MUI_HEADERIMAGE`, relative to the project directory. Defaults to `build/installerHeader.bmp`
*/
readonly installerHeader?: string | null
/*
*one-click installer only.* The path to header icon (above the progress bar), relative to the project directory. Defaults to `build/headerIcon.ico` or application icon.
*/
readonly headerIcon?: string | null
}
/*
### `.build.linux`
Linux specific build options.
*/
export interface LinuxBuildOptions extends PlatformSpecificBuildOptions {
/*
As [description](#AppMetadata-description) from application package.json, but allows you to specify different for Linux.
*/
readonly description?: string | null
/*
*deb-only.* The [short description](https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Description).
*/
readonly synopsis?: string | null
/*
The maintainer. Defaults to [author](#AppMetadata-author).
*/
readonly maintainer?: string | null
/*
The vendor. Defaults to [author](#AppMetadata-author).
*/
readonly vendor?: string | null
// should be not documented, only to experiment
readonly fpm?: Array<string> | null
//.desktop file template
readonly desktop?: string | null
readonly afterInstall?: string | null
readonly afterRemove?: string | null
/*
*deb-only.* The compression type, one of `gz`, `bzip2`, `xz`. Defaults to `xz`.
*/
readonly compression?: string | null
/*
Package dependencies. Defaults to `["libappindicator1", "libnotify-bin"]`.
*/
readonly depends?: string[] | null
/*
Target package type: list of `deb`, `rpm`, `freebsd`, `pacman`, `p5p`, `apk`, `7z`, `zip`, `tar.xz`, `tar.lz`, `tar.gz`, `tar.bz2`. Defaults to `deb`.
The most effective [xz](https://en.wikipedia.org/wiki/Xz) compression format used by default.
Only `deb` is tested. Feel free to file issues for `rpm` and other package formats.
*/
readonly target?: Array<string> | null
}
/*
## `.directories`
*/
export interface MetadataDirectories {
/*
The path to build resources, defaults to `build`.
*/
readonly buildResources?: string | null
/*
The output directory, defaults to `dist`.
*/
readonly output?: string | null
/*
The application directory (containing the application package.json), defaults to `app`, `www` or working directory.
*/
readonly app?: string | null
}
export interface PlatformSpecificBuildOptions {
readonly files?: Array<string> | null
readonly extraFiles?: Array<string> | null
readonly extraResources?: Array<string> | null
readonly asar?: AsarOptions | boolean
readonly target?: Array<string> | null
readonly icon?: string | null
}
export class Platform {
static MAC = new Platform("mac", "mac", "darwin")
static LINUX = new Platform("linux", "linux", "linux")
static WINDOWS = new Platform("windows", "win", "win32")
// deprecated
//noinspection JSUnusedGlobalSymbols
static OSX = Platform.MAC
constructor(public name: string, public buildConfigurationKey: string, public nodeName: string) {
}
toString() {
return this.name
}
toJSON() {
return this.name
}
createTarget(type?: string | Array<string> | null, ...archs: Array<Arch>): Map<Platform, Map<Arch, Array<string>>> {
const archToType = new Map()
if (this === Platform.MAC) {
archs = [Arch.x64]
}
for (let arch of (archs == null || archs.length === 0 ? [archFromString(process.arch)] : archs)) {
archToType.set(arch, type == null ? [] : (Array.isArray(type) ? type : [type]))
}
return new Map([[this, archToType]])
}
static current(): Platform {
return Platform.fromString(process.platform)
}
static fromString(name: string): Platform {
name = name.toLowerCase()
switch (name) {
case Platform.MAC.nodeName:
case Platform.MAC.name:
case "osx":
return Platform.MAC
case Platform.WINDOWS.nodeName:
case Platform.WINDOWS.name:
case Platform.WINDOWS.buildConfigurationKey:
return Platform.WINDOWS
case Platform.LINUX.nodeName:
return Platform.LINUX
}
throw new Error(`Unknown platform: ${name}`)
}
}
export enum Arch {
ia32, x64
}
export function archFromString(name: string): Arch {
if (name === "x64") {
return Arch.x64
}
if (name === "ia32") {
return Arch.ia32
}
throw new Error(`Unsupported arch ${name}`)
}