@@ -5,7 +5,7 @@ import { all, executeFinally } from "./promise"
5
5
import { EventEmitter } from "events"
6
6
import { Promise as BluebirdPromise } from "bluebird"
7
7
import { InfoRetriever } from "./repositoryInfo"
8
- import { AppMetadata , DevMetadata } from "./metadata"
8
+ import { AppMetadata , DevMetadata , Platform } from "./metadata"
9
9
import { PackagerOptions , PlatformPackager , BuildInfo , ArtifactCreated , use } from "./platformPackager"
10
10
import MacPackager from "./macPackager"
11
11
import { WinPackager } from "./winPackager"
@@ -50,7 +50,7 @@ export class Packager implements BuildInfo {
50
50
async build ( ) : Promise < any > {
51
51
const devPackageFile = this . devPackageFile
52
52
const appPackageFile = this . projectDir === this . appDir ? devPackageFile : path . join ( this . appDir , "package.json" )
53
- const platforms = normalizePlatforms ( this . options . platform )
53
+ const platforms = this . options . platform
54
54
55
55
const metadataList = await BluebirdPromise . map ( Array . from ( new Set ( [ devPackageFile , appPackageFile ] ) ) , readPackageJson )
56
56
this . metadata = metadataList [ metadataList . length - 1 ]
@@ -63,7 +63,7 @@ export class Packager implements BuildInfo {
63
63
return executeFinally ( this . doBuild ( platforms , cleanupTasks ) , ( ) => all ( cleanupTasks . map ( it => it ( ) ) ) )
64
64
}
65
65
66
- private async doBuild ( platforms : Array < string > , cleanupTasks : Array < ( ) => Promise < any > > ) : Promise < any > {
66
+ private async doBuild ( platforms : Array < Platform > , cleanupTasks : Array < ( ) => Promise < any > > ) : Promise < any > {
67
67
const distTasks : Array < Promise < any > > = [ ]
68
68
const outDir = path . resolve ( this . projectDir , use ( this . devMetadata . directories , it => it . output ) || "dist" )
69
69
@@ -72,7 +72,7 @@ export class Packager implements BuildInfo {
72
72
for ( let arch of normalizeArchs ( platform , this . options . arch ) ) {
73
73
await this . installAppDependencies ( arch )
74
74
// electron-packager uses productName in the directory name
75
- const appOutDir = path . join ( outDir , helper . appName + "-" + platform + "-" + arch )
75
+ const appOutDir = path . join ( outDir , ` ${ helper . appName } - ${ platform . nodeName } - ${ arch } ` )
76
76
await helper . pack ( outDir , appOutDir , arch )
77
77
if ( this . options . dist ) {
78
78
distTasks . push ( helper . packageInDistributableFormat ( outDir , appOutDir , arch ) )
@@ -83,32 +83,29 @@ export class Packager implements BuildInfo {
83
83
return await BluebirdPromise . all ( distTasks )
84
84
}
85
85
86
- private createHelper ( platform : string , cleanupTasks : Array < ( ) => Promise < any > > ) : PlatformPackager < any > {
86
+ private createHelper ( platform : Platform , cleanupTasks : Array < ( ) => Promise < any > > ) : PlatformPackager < any > {
87
87
if ( this . options . platformPackagerFactory != null ) {
88
88
return this . options . platformPackagerFactory ( this , platform , cleanupTasks )
89
89
}
90
90
91
91
switch ( platform ) {
92
- case "darwin" :
93
- case "osx" :
92
+ case Platform . OSX :
94
93
{
95
94
const helperClass : typeof MacPackager = require ( "./macPackager" ) . default
96
95
return new helperClass ( this , cleanupTasks )
97
96
}
98
97
99
- case "win32" :
100
- case "win" :
101
- case "windows" :
98
+ case Platform . WINDOWS :
102
99
{
103
100
const helperClass : typeof WinPackager = require ( "./winPackager" ) . WinPackager
104
101
return new helperClass ( this , cleanupTasks )
105
102
}
106
103
107
- case "linux" :
104
+ case Platform . LINUX :
108
105
return new ( require ( "./linuxPackager" ) . LinuxPackager ) ( this )
109
106
110
107
default :
111
- throw new Error ( "Unsupported platform: " + platform )
108
+ throw new Error ( "Unknown platform: " + platform )
112
109
}
113
110
}
114
111
@@ -137,7 +134,7 @@ export class Packager implements BuildInfo {
137
134
return absoluteAppPath
138
135
}
139
136
140
- private checkMetadata ( appPackageFile : string , devAppPackageFile : string , platforms : Array < string > ) : void {
137
+ private checkMetadata ( appPackageFile : string , devAppPackageFile : string , platforms : Array < Platform > ) : void {
141
138
const reportError = ( missedFieldName : string ) => {
142
139
throw new Error ( "Please specify '" + missedFieldName + "' in the application package.json ('" + appPackageFile + "')" )
143
140
}
@@ -163,7 +160,7 @@ export class Packager implements BuildInfo {
163
160
if ( author == null ) {
164
161
reportError ( "author" )
165
162
}
166
- else if ( this . options . dist && author . email == null && platforms . includes ( "linux" ) ) {
163
+ else if ( this . options . dist && author . email == null && platforms . includes ( Platform . LINUX ) ) {
167
164
throw new Error ( util . format ( errorMessages . authorEmailIsMissed , appPackageFile ) )
168
165
}
169
166
}
@@ -180,32 +177,32 @@ export class Packager implements BuildInfo {
180
177
}
181
178
}
182
179
183
- export function normalizeArchs ( platform : string , arch ?: string ) {
184
- if ( platform === "darwin" ) {
180
+ export function normalizeArchs ( platform : Platform , arch ?: string ) {
181
+ if ( platform === Platform . OSX ) {
185
182
return [ "x64" ]
186
183
}
187
184
else {
188
185
return arch == null ? [ process . arch ] : ( arch === "all" ? [ "ia32" , "x64" ] : [ arch ] )
189
186
}
190
187
}
191
188
192
- export function normalizePlatforms ( platforms : Array < string > ) : Array < string > {
189
+ export function normalizePlatforms ( platforms : Array < string | Platform > ) : Array < Platform > {
193
190
if ( platforms == null || platforms . length === 0 ) {
194
- return [ process . platform ]
191
+ return [ Platform . fromString ( process . platform ) ]
195
192
}
196
193
else if ( platforms [ 0 ] === "all" ) {
197
- if ( process . platform === "darwin" ) {
198
- return [ "darwin" , "linux" , "win32" ]
194
+ if ( process . platform === Platform . OSX . nodeName ) {
195
+ return [ Platform . OSX , Platform . LINUX , Platform . WINDOWS ]
199
196
}
200
- else if ( process . platform === "linux" ) {
197
+ else if ( process . platform === Platform . LINUX . nodeName ) {
201
198
// OS X code sign works only on OS X
202
- return [ "linux" , "win32" ]
199
+ return [ Platform . LINUX , Platform . WINDOWS ]
203
200
}
204
201
else {
205
- return [ "win32" ]
202
+ return [ Platform . WINDOWS ]
206
203
}
207
204
}
208
205
else {
209
- return platforms
206
+ return platforms . map ( it => it instanceof Platform ? it : Platform . fromString ( it ) )
210
207
}
211
208
}
0 commit comments