@@ -4,17 +4,16 @@ import { PlatformPackager, BuildInfo } from "./platformPackager"
44import { Platform , WinBuildOptions } from "./metadata"
55import * as path from "path"
66import { log , statOrNull } from "./util"
7- import { readFile , deleteFile , stat , rename , copy , emptyDir , writeFile , open , close , read } from "fs-extra-p"
7+ import { readFile , deleteFile , rename , copy , emptyDir , writeFile , open , close , read , move } from "fs-extra-p"
88import { sign } from "signcode-tf"
9+ import ElectronPackagerOptions = ElectronPackager . ElectronPackagerOptions
910
1011//noinspection JSUnusedLocalSymbols
1112const __awaiter = require ( "./awaiter" )
1213
1314export class WinPackager extends PlatformPackager < WinBuildOptions > {
1415 certFilePromise : Promise < string | null >
1516
16- extraNuGetFileSources : Promise < Array < string > > | null
17-
1817 loadingGifStat : Promise < string > | null
1918
2019 readonly iconPath : Promise < string >
@@ -56,32 +55,30 @@ export class WinPackager extends PlatformPackager<WinBuildOptions> {
5655 // we must check icon before pack because electron-packager uses icon and it leads to cryptic error message "spawn wine ENOENT"
5756 await this . iconPath
5857
58+ let appOutDir = this . computeAppOutDir ( outDir , arch )
59+ const packOptions = this . computePackOptions ( outDir , arch )
60+
5961 if ( ! this . options . dist ) {
60- return await super . pack ( outDir , arch , postAsyncTasks )
62+ await this . doPack ( packOptions , outDir , appOutDir , arch , this . customBuildOptions )
63+ return
6164 }
6265
63- const appOutDir = this . computeAppOutDir ( outDir , arch )
66+ const unpackedDir = path . join ( outDir , `win${ arch === "x64" ? "" : `-${ arch } ` } -unpacked` )
67+ const finalAppOut = path . join ( outDir , `win${ arch === "x64" ? "" : `-${ arch } ` } -unpacked` , "lib" , "net45" )
6468 const installerOut = computeDistOut ( outDir , arch )
65- log ( "Removing %s" , installerOut )
69+ log ( "Removing %s and %s " , path . relative ( this . projectDir , installerOut ) , path . relative ( this . projectDir , unpackedDir ) )
6670 await BluebirdPromise . all ( [
67- this . packApp ( this . computePackOptions ( outDir , arch ) , appOutDir ) ,
68- emptyDir ( installerOut )
71+ this . packApp ( packOptions , appOutDir ) ,
72+ emptyDir ( installerOut ) ,
73+ emptyDir ( unpackedDir )
6974 ] )
7075
71- const extraResources = await this . copyExtraResources ( appOutDir , arch , this . customBuildOptions )
72- if ( extraResources . length > 0 ) {
73- this . extraNuGetFileSources = BluebirdPromise . map ( extraResources , file => {
74- return stat ( file )
75- . then ( it => {
76- const relativePath = path . relative ( appOutDir , file )
77- const src = it . isDirectory ( ) ? `${ relativePath } ${ path . sep } **` : relativePath
78- return `<file src="${ src } " target="lib\\net45\\${ relativePath . replace ( / \/ / g, "\\" ) } "/>`
79- } )
80- } )
81- }
76+ await move ( appOutDir , finalAppOut )
77+ appOutDir = finalAppOut
8278
79+ await this . copyExtraResources ( appOutDir , arch , this . customBuildOptions )
8380 if ( this . options . dist ) {
84- postAsyncTasks . push ( this . packageInDistributableFormat ( outDir , appOutDir , arch ) )
81+ postAsyncTasks . push ( this . packageInDistributableFormat ( outDir , appOutDir , arch , packOptions ) )
8582 }
8683 }
8784
@@ -102,7 +99,7 @@ export class WinPackager extends PlatformPackager<WinBuildOptions> {
10299 }
103100 }
104101
105- protected async computeEffectiveDistOptions ( appOutDir : string , installerOutDir : string ) : Promise < any > {
102+ protected async computeEffectiveDistOptions ( appOutDir : string , installerOutDir : string , packOptions : ElectronPackagerOptions ) : Promise < any > {
106103 let iconUrl = this . customBuildOptions . iconUrl || this . devMetadata . build . iconUrl
107104 if ( iconUrl == null ) {
108105 if ( this . info . repositoryInfo != null ) {
@@ -120,6 +117,13 @@ export class WinPackager extends PlatformPackager<WinBuildOptions> {
120117 checkConflictingOptions ( this . customBuildOptions )
121118
122119 const projectUrl = await this . computePackageUrl ( )
120+ const rceditOptions = {
121+ "version-string" : packOptions [ "version-string" ] ,
122+ "file-version" : packOptions [ "build-version" ] ,
123+ "product-version" : packOptions [ "app-version" ] ,
124+ }
125+ rceditOptions [ "version-string" ] ! . LegalCopyright = packOptions [ "app-copyright" ]
126+
123127 const options : any = Object . assign ( {
124128 name : this . metadata . name ,
125129 productName : this . appName ,
@@ -138,13 +142,14 @@ export class WinPackager extends PlatformPackager<WinBuildOptions> {
138142 skipUpdateIcon : true ,
139143 usePackageJson : false ,
140144 noMsi : true ,
141- extraFileSpecs : this . extraNuGetFileSources == null ? null : ( "\n" + ( await this . extraNuGetFileSources ) . join ( "\n" ) ) ,
142145 extraMetadataSpecs : projectUrl == null ? null : `\n <projectUrl>${ projectUrl } </projectUrl>` ,
146+ copyright : packOptions [ "app-copyright" ] ,
143147 sign : {
144148 name : this . appName ,
145149 site : projectUrl ,
146150 overwrite : true ,
147- }
151+ } ,
152+ rcedit : rceditOptions ,
148153 } , this . customBuildOptions )
149154
150155 if ( this . loadingGifStat != null ) {
@@ -154,9 +159,9 @@ export class WinPackager extends PlatformPackager<WinBuildOptions> {
154159 return options
155160 }
156161
157- async packageInDistributableFormat ( outDir : string , appOutDir : string , arch : string ) : Promise < any > {
162+ async packageInDistributableFormat ( outDir : string , appOutDir : string , arch : string , packOptions : ElectronPackagerOptions ) : Promise < any > {
158163 const installerOutDir = computeDistOut ( outDir , arch )
159- await require ( "electron-winstaller-fixed" ) . createWindowsInstaller ( await this . computeEffectiveDistOptions ( appOutDir , installerOutDir ) )
164+ await require ( "electron-winstaller-fixed" ) . createWindowsInstaller ( await this . computeEffectiveDistOptions ( appOutDir , installerOutDir , packOptions ) )
160165
161166 const version = this . metadata . version
162167 const archSuffix = arch === "x64" ? "" : ( "-" + arch )
@@ -170,8 +175,8 @@ export class WinPackager extends PlatformPackager<WinBuildOptions> {
170175 }
171176
172177 const promises : Array < Promise < any > > = [
173- rename ( path . join ( installerOutDir , "Setup.exe" ) , path . join ( installerOutDir , `${ this . appName } Setup- ${ version } ${ archSuffix } .exe` ) )
174- . then ( it => this . dispatchArtifactCreated ( it , `${ this . metadata . name } Setup-${ version } ${ archSuffix } .exe` ) ) ,
178+ rename ( path . join ( installerOutDir , "Setup.exe" ) , path . join ( installerOutDir , `${ this . appName } Setup ${ version } ${ archSuffix } .exe` ) )
179+ . then ( it => this . dispatchArtifactCreated ( it , `${ this . metadata . name } - Setup-${ version } ${ archSuffix } .exe` ) ) ,
175180 ]
176181
177182 if ( archSuffix === "" ) {
@@ -244,7 +249,7 @@ function isIco(buffer: Buffer): boolean {
244249}
245250
246251export function computeDistOut ( outDir : string , arch : string ) : string {
247- return path . join ( outDir , "win" + ( arch === "x64" ? "-x64 " : "" ) )
252+ return path . join ( outDir , "win" + ( arch === "x64" ? "" : "-arch " ) )
248253}
249254
250255function checkConflictingOptions ( options : any ) {
0 commit comments