-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathmetadata.ts
executable file
·472 lines (368 loc) · 13 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
import { AsarOptions } from "asar-electron-builder"
import { PlatformPackager } from "./platformPackager"
import { MacOptions, DmgOptions, MasBuildOptions } from "./options/macOptions"
import { PublishConfiguration } from "./options/publishOptions"
import { WinBuildOptions, NsisOptions, SquirrelWindowsOptions } from "./options/winOptions"
export interface Metadata {
readonly repository?: string | RepositoryInfo | null
dependencies?: { [key: string]: string }
}
/*
# 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 (NSIS target only, Squirrel.Windows not supported).
Defaults to `com.electron.${name}`. It is strongly recommended that an explicit ID be set.
*/
readonly appId?: string | null
/*
The human-readable copyright line for the app. Defaults to `Copyright © year author`.
*/
readonly copyright?: 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.
Node modules, that must be unpacked, will be detected automatically, you don't need to explicitly set `asar.unpackDir` - please file issue if this doesn't work.
*/
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.
See [File Patterns](#multiple-glob-patterns).
*/
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](#multiple-glob-patterns).
*/
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
/*
The file associations. See [.build.fileAssociations](#FileAssociation).
*/
readonly fileAssociations?: Array<FileAssociation> | FileAssociation
/*
The URL protocol scheme(s) to associate the app with. See [.build.protocol](#Protocol).
*/
readonly protocols?: Array<Protocol> | Protocol
/*
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](#WinBuildOptions).
*/
readonly win?: WinBuildOptions | null
/**
See [.build.nsis](#NsisOptions).
*/
readonly nsis?: NsisOptions | null
/**
See [.build.squirrelWindows](#SquirrelWindowsOptions).
*/
readonly squirrelWindows?: SquirrelWindowsOptions | null
/*
See [.build.linux](#LinuxBuildOptions).
*/
readonly linux?: LinuxBuildOptions | null
readonly deb?: 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
/*
*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
/*
*two package.json structure only* 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
/*
*two package.json structure only* Whether to omit using [--build-from-source](https://github.com/mapbox/node-pre-gyp#options) flag when installing app native deps. Defaults to `false`.
*/
readonly npmSkipBuildFromSource?: boolean
/*
Whether to execute `node-gyp rebuild` before starting to package the app. Defaults to `false`.
*/
readonly nodeGypRebuild?: boolean
/**
The path to custom Electron build (e.g. `~/electron/out/R`). Only macOS supported, file issue if need for Linux or Windows.
*/
readonly electronDist?: string
readonly icon?: string | null
// deprecated
readonly "app-bundle-id"?: string | null
readonly dereference?: boolean
/*
See [.build.publish](#PublishConfiguration).
*/
readonly publish?: string | Array<string> | null | PublishConfiguration
}
export interface AfterPackContext {
readonly appOutDir: string
// deprecated
readonly options: any
readonly packager: PlatformPackager<any>
}
/*
### `.build.linux`
Linux specific build options.
*/
export interface LinuxBuildOptions extends PlatformSpecificBuildOptions {
/*
The [application category](https://specifications.freedesktop.org/menu-spec/latest/apa.html#main-category-registry).
*/
readonly category?: string | null
/*
The [package category](https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Section). Not applicable for AppImage.
*/
readonly packageCategory?: string | null
/*
As [description](#AppMetadata-description) from application package.json, but allows you to specify different for Linux.
*/
readonly description?: string | null
/*
Target package type: list of `AppImage`, `deb`, `rpm`, `freebsd`, `pacman`, `p5p`, `apk`, `7z`, `zip`, `tar.xz`, `tar.lz`, `tar.gz`, `tar.bz2`, `dir`. Defaults to `AppImage`.
The most effective [xz](https://en.wikipedia.org/wiki/Xz) compression format used by default.
Only `deb` and `AppImage` is tested. Feel free to file issues for `rpm` and other package formats.
*/
readonly target?: Array<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
/**
The [Desktop file](https://developer.gnome.org/integration-guide/stable/desktop-files.html.en) entries.
*/
readonly desktop?: { [key: string]: 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
}
/*
### `.build.fileAssociations`
macOS and NSIS only. Array of option objects.
*/
export interface FileAssociation {
/*
The extension (minus the leading period). e.g. `png`.
*/
readonly ext: string | Array<string>
/*
The name. e.g. `PNG`.
*/
readonly name: string
/*
*windows-only.* The description.
*/
readonly description?: string
/*
The path to icon (`.icns` for MacOS and `.ico` for Windows), relative to `build` (build resources directory). Defaults to `${firstExt}.icns`/`${firstExt}.ico` (if several extensions specified, first is used) or to application icon.
*/
readonly icon?: string
/*
*macOS-only* The app’s role with respect to the type. The value can be `Editor`, `Viewer`, `Shell`, or `None`. Defaults to `Editor`.
*/
readonly role?: string
}
/*
### `.build.protocols`
macOS only.
*/
export interface Protocol {
/*
The name. e.g. `IRC server URL`.
*/
readonly name: string
/*
*macOS-only* The app’s role with respect to the type. The value can be `Editor`, `Viewer`, `Shell`, or `None`. Defaults to `Editor`.
*/
readonly role?: string
/*
The schemes. e.g. `["irc", "ircs"]`.
*/
readonly schemes: Array<string>
}
/*
## `.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
readonly fileAssociations?: Array<FileAssociation> | FileAssociation
readonly publish?: string | Array<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
default:
throw new Error(`Unknown platform: ${name}`)
}
}
}
export enum Arch {
ia32, x64, armv7l
}
export function archFromString(name: string): Arch {
if (name === "x64") {
return Arch.x64
}
if (name === "ia32") {
return Arch.ia32
}
if (name === "armv7l") {
return Arch.armv7l
}
throw new Error(`Unsupported arch ${name}`)
}