@@ -4,17 +4,16 @@ import { PlatformPackager, BuildInfo } from "./platformPackager"
4
4
import { Platform , WinBuildOptions } from "./metadata"
5
5
import * as path from "path"
6
6
import { 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"
8
8
import { sign } from "signcode-tf"
9
+ import ElectronPackagerOptions = ElectronPackager . ElectronPackagerOptions
9
10
10
11
//noinspection JSUnusedLocalSymbols
11
12
const __awaiter = require ( "./awaiter" )
12
13
13
14
export class WinPackager extends PlatformPackager < WinBuildOptions > {
14
15
certFilePromise : Promise < string | null >
15
16
16
- extraNuGetFileSources : Promise < Array < string > > | null
17
-
18
17
loadingGifStat : Promise < string > | null
19
18
20
19
readonly iconPath : Promise < string >
@@ -56,32 +55,30 @@ export class WinPackager extends PlatformPackager<WinBuildOptions> {
56
55
// we must check icon before pack because electron-packager uses icon and it leads to cryptic error message "spawn wine ENOENT"
57
56
await this . iconPath
58
57
58
+ let appOutDir = this . computeAppOutDir ( outDir , arch )
59
+ const packOptions = this . computePackOptions ( outDir , arch )
60
+
59
61
if ( ! this . options . dist ) {
60
- return await super . pack ( outDir , arch , postAsyncTasks )
62
+ await this . doPack ( packOptions , outDir , appOutDir , arch , this . customBuildOptions )
63
+ return
61
64
}
62
65
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" )
64
68
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 ) )
66
70
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 )
69
74
] )
70
75
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
82
78
79
+ await this . copyExtraResources ( appOutDir , arch , this . customBuildOptions )
83
80
if ( this . options . dist ) {
84
- postAsyncTasks . push ( this . packageInDistributableFormat ( outDir , appOutDir , arch ) )
81
+ postAsyncTasks . push ( this . packageInDistributableFormat ( outDir , appOutDir , arch , packOptions ) )
85
82
}
86
83
}
87
84
@@ -102,7 +99,7 @@ export class WinPackager extends PlatformPackager<WinBuildOptions> {
102
99
}
103
100
}
104
101
105
- protected async computeEffectiveDistOptions ( appOutDir : string , installerOutDir : string ) : Promise < any > {
102
+ protected async computeEffectiveDistOptions ( appOutDir : string , installerOutDir : string , packOptions : ElectronPackagerOptions ) : Promise < any > {
106
103
let iconUrl = this . customBuildOptions . iconUrl || this . devMetadata . build . iconUrl
107
104
if ( iconUrl == null ) {
108
105
if ( this . info . repositoryInfo != null ) {
@@ -120,6 +117,13 @@ export class WinPackager extends PlatformPackager<WinBuildOptions> {
120
117
checkConflictingOptions ( this . customBuildOptions )
121
118
122
119
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
+
123
127
const options : any = Object . assign ( {
124
128
name : this . metadata . name ,
125
129
productName : this . appName ,
@@ -138,13 +142,14 @@ export class WinPackager extends PlatformPackager<WinBuildOptions> {
138
142
skipUpdateIcon : true ,
139
143
usePackageJson : false ,
140
144
noMsi : true ,
141
- extraFileSpecs : this . extraNuGetFileSources == null ? null : ( "\n" + ( await this . extraNuGetFileSources ) . join ( "\n" ) ) ,
142
145
extraMetadataSpecs : projectUrl == null ? null : `\n <projectUrl>${ projectUrl } </projectUrl>` ,
146
+ copyright : packOptions [ "app-copyright" ] ,
143
147
sign : {
144
148
name : this . appName ,
145
149
site : projectUrl ,
146
150
overwrite : true ,
147
- }
151
+ } ,
152
+ rcedit : rceditOptions ,
148
153
} , this . customBuildOptions )
149
154
150
155
if ( this . loadingGifStat != null ) {
@@ -154,9 +159,9 @@ export class WinPackager extends PlatformPackager<WinBuildOptions> {
154
159
return options
155
160
}
156
161
157
- async packageInDistributableFormat ( outDir : string , appOutDir : string , arch : string ) : Promise < any > {
162
+ async packageInDistributableFormat ( outDir : string , appOutDir : string , arch : string , packOptions : ElectronPackagerOptions ) : Promise < any > {
158
163
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 ) )
160
165
161
166
const version = this . metadata . version
162
167
const archSuffix = arch === "x64" ? "" : ( "-" + arch )
@@ -170,8 +175,8 @@ export class WinPackager extends PlatformPackager<WinBuildOptions> {
170
175
}
171
176
172
177
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` ) ) ,
175
180
]
176
181
177
182
if ( archSuffix === "" ) {
@@ -244,7 +249,7 @@ function isIco(buffer: Buffer): boolean {
244
249
}
245
250
246
251
export 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 " ) )
248
253
}
249
254
250
255
function checkConflictingOptions ( options : any ) {
0 commit comments