@@ -5,7 +5,7 @@ import { all, executeFinally } from "./promise"
55import { EventEmitter } from "events"
66import { Promise as BluebirdPromise } from "bluebird"
77import { InfoRetriever } from "./repositoryInfo"
8- import { AppMetadata , DevMetadata } from "./metadata"
8+ import { AppMetadata , DevMetadata , Platform } from "./metadata"
99import { PackagerOptions , PlatformPackager , BuildInfo , ArtifactCreated , use } from "./platformPackager"
1010import MacPackager from "./macPackager"
1111import { WinPackager } from "./winPackager"
@@ -50,7 +50,7 @@ export class Packager implements BuildInfo {
5050 async build ( ) : Promise < any > {
5151 const devPackageFile = this . devPackageFile
5252 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
5454
5555 const metadataList = await BluebirdPromise . map ( Array . from ( new Set ( [ devPackageFile , appPackageFile ] ) ) , readPackageJson )
5656 this . metadata = metadataList [ metadataList . length - 1 ]
@@ -63,7 +63,7 @@ export class Packager implements BuildInfo {
6363 return executeFinally ( this . doBuild ( platforms , cleanupTasks ) , ( ) => all ( cleanupTasks . map ( it => it ( ) ) ) )
6464 }
6565
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 > {
6767 const distTasks : Array < Promise < any > > = [ ]
6868 const outDir = path . resolve ( this . projectDir , use ( this . devMetadata . directories , it => it . output ) || "dist" )
6969
@@ -72,7 +72,7 @@ export class Packager implements BuildInfo {
7272 for ( let arch of normalizeArchs ( platform , this . options . arch ) ) {
7373 await this . installAppDependencies ( arch )
7474 // 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 } ` )
7676 await helper . pack ( outDir , appOutDir , arch )
7777 if ( this . options . dist ) {
7878 distTasks . push ( helper . packageInDistributableFormat ( outDir , appOutDir , arch ) )
@@ -83,32 +83,29 @@ export class Packager implements BuildInfo {
8383 return await BluebirdPromise . all ( distTasks )
8484 }
8585
86- private createHelper ( platform : string , cleanupTasks : Array < ( ) => Promise < any > > ) : PlatformPackager < any > {
86+ private createHelper ( platform : Platform , cleanupTasks : Array < ( ) => Promise < any > > ) : PlatformPackager < any > {
8787 if ( this . options . platformPackagerFactory != null ) {
8888 return this . options . platformPackagerFactory ( this , platform , cleanupTasks )
8989 }
9090
9191 switch ( platform ) {
92- case "darwin" :
93- case "osx" :
92+ case Platform . OSX :
9493 {
9594 const helperClass : typeof MacPackager = require ( "./macPackager" ) . default
9695 return new helperClass ( this , cleanupTasks )
9796 }
9897
99- case "win32" :
100- case "win" :
101- case "windows" :
98+ case Platform . WINDOWS :
10299 {
103100 const helperClass : typeof WinPackager = require ( "./winPackager" ) . WinPackager
104101 return new helperClass ( this , cleanupTasks )
105102 }
106103
107- case "linux" :
104+ case Platform . LINUX :
108105 return new ( require ( "./linuxPackager" ) . LinuxPackager ) ( this )
109106
110107 default :
111- throw new Error ( "Unsupported platform: " + platform )
108+ throw new Error ( "Unknown platform: " + platform )
112109 }
113110 }
114111
@@ -137,7 +134,7 @@ export class Packager implements BuildInfo {
137134 return absoluteAppPath
138135 }
139136
140- private checkMetadata ( appPackageFile : string , devAppPackageFile : string , platforms : Array < string > ) : void {
137+ private checkMetadata ( appPackageFile : string , devAppPackageFile : string , platforms : Array < Platform > ) : void {
141138 const reportError = ( missedFieldName : string ) => {
142139 throw new Error ( "Please specify '" + missedFieldName + "' in the application package.json ('" + appPackageFile + "')" )
143140 }
@@ -163,7 +160,7 @@ export class Packager implements BuildInfo {
163160 if ( author == null ) {
164161 reportError ( "author" )
165162 }
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 ) ) {
167164 throw new Error ( util . format ( errorMessages . authorEmailIsMissed , appPackageFile ) )
168165 }
169166 }
@@ -180,32 +177,32 @@ export class Packager implements BuildInfo {
180177 }
181178}
182179
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 ) {
185182 return [ "x64" ]
186183 }
187184 else {
188185 return arch == null ? [ process . arch ] : ( arch === "all" ? [ "ia32" , "x64" ] : [ arch ] )
189186 }
190187}
191188
192- export function normalizePlatforms ( platforms : Array < string > ) : Array < string > {
189+ export function normalizePlatforms ( platforms : Array < string | Platform > ) : Array < Platform > {
193190 if ( platforms == null || platforms . length === 0 ) {
194- return [ process . platform ]
191+ return [ Platform . fromString ( process . platform ) ]
195192 }
196193 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 ]
199196 }
200- else if ( process . platform === "linux" ) {
197+ else if ( process . platform === Platform . LINUX . nodeName ) {
201198 // OS X code sign works only on OS X
202- return [ "linux" , "win32" ]
199+ return [ Platform . LINUX , Platform . WINDOWS ]
203200 }
204201 else {
205- return [ "win32" ]
202+ return [ Platform . WINDOWS ]
206203 }
207204 }
208205 else {
209- return platforms
206+ return platforms . map ( it => it instanceof Platform ? it : Platform . fromString ( it ) )
210207 }
211208}
0 commit comments