Skip to content

Commit

Permalink
fix: incorrect nupkg file if created on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed May 14, 2016
1 parent 8d9b952 commit 9a5e18f
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 24 deletions.
2 changes: 1 addition & 1 deletion docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ MAS (Mac Application Store) specific options (in addition to `build.osx`).
| --- | ---
| iconUrl | <a name="WinBuildOptions-iconUrl"></a><p>A URL to an ICO file to use as the application icon (displayed in Control Panel &gt; Programs and Features). Defaults to the Electron icon.</p> <p>Please note — [local icon file url is not accepted](https://github.com/atom/grunt-electron-installer/issues/73), must be https/http.</p> <ul> <li>If you don’t plan to build windows installer, you can omit it.</li> <li>If your project repository is public on GitHub, it will be <code>https://github.com/${u}/${p}/blob/master/build/icon.ico?raw=true</code> by default.</li> </ul>
| loadingGif | <a name="WinBuildOptions-loadingGif"></a><p>The path to a .gif file to display during install. <code>build/install-spinner.gif</code> will be used if exists (it is a recommended way to set) (otherwise [default](https://github.com/electron/windows-installer/blob/master/resources/install-spinner.gif)).</p>
| noMsi | <a name="WinBuildOptions-noMsi"></a>Whether to create an MSI installer. Defaults to `true` (MSI is not created).
| msi | <a name="WinBuildOptions-msi"></a>Whether to create an MSI installer. Defaults to `false` (MSI is not created).
| remoteReleases | <a name="WinBuildOptions-remoteReleases"></a>A URL to your existing updates. If given, these will be downloaded to create delta updates.
| remoteToken | <a name="WinBuildOptions-remoteToken"></a>Authentication token for remote updates

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"deep-assign": "^2.0.0",
"electron-osx-sign-tf": "0.4.0-beta.0",
"electron-packager-tf": "^7.0.2-beta.0",
"electron-winstaller-fixed": "~2.7.1",
"electron-winstaller-fixed": "~2.8.0",
"fs-extra-p": "^1.0.1",
"globby": "^4.0.0",
"hosted-git-info": "^2.1.4",
Expand Down Expand Up @@ -106,8 +106,8 @@
"should": "^8.3.1",
"ts-babel": "^0.8.6",
"tsconfig-glob": "^0.4.3",
"tslint": "^3.10.0-dev.1",
"typescript": "1.9.0-dev.20160511",
"tslint": "3.10.0-dev.1",
"typescript": "1.9.0-dev.20160513",
"whitespace": "^2.0.0"
},
"babel": {
Expand Down
4 changes: 2 additions & 2 deletions src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,9 @@ export interface WinBuildOptions extends PlatformSpecificBuildOptions {
readonly loadingGif?: string | null

/*
Whether to create an MSI installer. Defaults to `true` (MSI is not created).
Whether to create an MSI installer. Defaults to `false` (MSI is not created).
*/
readonly noMsi?: boolean
readonly msi?: boolean

/*
A URL to your existing updates. If given, these will be downloaded to create delta updates.
Expand Down
32 changes: 18 additions & 14 deletions src/winPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { PlatformPackager, BuildInfo } from "./platformPackager"
import { Platform, WinBuildOptions } from "./metadata"
import * as path from "path"
import { log, statOrNull, warn } from "./util"
import { deleteFile, rename, emptyDir, open, close, read, move } from "fs-extra-p"
import { deleteFile, emptyDir, open, close, read, move } from "fs-extra-p"
import { sign } from "signcode-tf"
import ElectronPackagerOptions = ElectronPackager.ElectronPackagerOptions

Expand Down Expand Up @@ -103,7 +103,7 @@ export class WinPackager extends PlatformPackager<WinBuildOptions> {
}
}

protected async computeEffectiveDistOptions(appOutDir: string, installerOutDir: string, packOptions: ElectronPackagerOptions): Promise<any> {
protected async computeEffectiveDistOptions(appOutDir: string, installerOutDir: string, packOptions: ElectronPackagerOptions, setupExeName: string): Promise<any> {
let iconUrl = this.customBuildOptions.iconUrl || this.devMetadata.build.iconUrl
if (iconUrl == null) {
if (this.info.repositoryInfo != null) {
Expand Down Expand Up @@ -132,6 +132,7 @@ export class WinPackager extends PlatformPackager<WinBuildOptions> {
name: this.metadata.name,
productName: this.appName,
exe: this.appName + ".exe",
setupExe: setupExeName,
title: this.appName,
appDirectory: appOutDir,
outputDirectory: installerOutDir,
Expand All @@ -145,7 +146,7 @@ export class WinPackager extends PlatformPackager<WinBuildOptions> {
fixUpPaths: false,
skipUpdateIcon: true,
usePackageJson: false,
noMsi: true,
msi: false,
extraMetadataSpecs: projectUrl == null ? null : `\n <projectUrl>${projectUrl}</projectUrl>`,
copyright: packOptions["app-copyright"],
sign: {
Expand All @@ -166,17 +167,15 @@ export class WinPackager extends PlatformPackager<WinBuildOptions> {
async packageInDistributableFormat(outDir: string, appOutDir: string, arch: string, packOptions: ElectronPackagerOptions): Promise<any> {
const installerOutDir = computeDistOut(outDir, arch)
const winstaller = require("electron-winstaller-fixed")
await winstaller.createWindowsInstaller(await this.computeEffectiveDistOptions(appOutDir, installerOutDir, packOptions))

const version = this.metadata.version
const archSuffix = arch === "x64" ? "" : ("-" + arch)
const nupkgPath = `${this.metadata.name}-${winstaller.convertVersion(version)}-full.nupkg`
const setupExeName = `${this.appName} Setup ${version}${archSuffix}.exe`

this.dispatchArtifactCreated(path.join(installerOutDir, nupkgPath))
this.dispatchArtifactCreated(path.join(installerOutDir, "RELEASES"))
await winstaller.createWindowsInstaller(await this.computeEffectiveDistOptions(appOutDir, installerOutDir, packOptions, setupExeName))

await rename(path.join(installerOutDir, "Setup.exe"), path.join(installerOutDir, `${this.appName} Setup ${version}${archSuffix}.exe`))
.then(it => this.dispatchArtifactCreated(it, `${this.metadata.name}-Setup-${version}${archSuffix}.exe`))
this.dispatchArtifactCreated(path.join(installerOutDir, setupExeName), `${this.metadata.name}-Setup-${version}${archSuffix}.exe`)
this.dispatchArtifactCreated(path.join(installerOutDir, `${this.metadata.name}-${winstaller.convertVersion(version)}-full.nupkg`))
this.dispatchArtifactCreated(path.join(installerOutDir, "RELEASES"))
}
}

Expand Down Expand Up @@ -235,13 +234,18 @@ export function computeDistOut(outDir: string, arch: string): string {

function checkConflictingOptions(options: any) {
for (let name of ["outputDirectory", "appDirectory", "exe", "fixUpPaths", "usePackageJson", "extraFileSpecs", "extraMetadataSpecs", "skipUpdateIcon", "setupExe"]) {
if (name! in options) {
if (name in options) {
throw new Error(`Option ${name} is ignored, do not specify it.`)
}
}

const noMsi = options.noMsi
if (noMsi != null && typeof noMsi !== "boolean") {
throw new Error(`noMsi expected to be boolean value, but string '"${noMsi}"' was specified`)
if ("noMsi" in options) {
warn(`noMsi is deprecated, please specify as "msi": true if you want to create an MSI installer`)
options.msi = !options.noMsi
}

const msi = options.msi
if (msi != null && typeof msi !== "boolean") {
throw new Error(`msi expected to be boolean value, but string '"${msi}"' was specified`)
}
}
8 changes: 4 additions & 4 deletions test/src/winPackagerTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ test.ifDevOrWinCi("win f", () => {
})
})

test.ifNotCiOsx("noMsi as string", t => t.throws(assertPack("test-app-one", platform(Platform.WINDOWS),
test.ifNotCiOsx("msi as string", t => t.throws(assertPack("test-app-one", platform(Platform.WINDOWS),
{
tempDirCreated: it => modifyPackageJson(it, data => {
data.build.win = {
noMsi: "false",
msi: "false",
}
})
}), `noMsi expected to be boolean value, but string '"false"' was specified`)
}), `msi expected to be boolean value, but string '"false"' was specified`)
)

test("detect install-spinner", () => {
Expand Down Expand Up @@ -115,7 +115,7 @@ class CheckingWinPackager extends WinPackager {
// skip pack
const installerOutDir = computeDistOut(outDir, arch)
const packOptions = this.computePackOptions(outDir, arch)
this.effectiveDistOptions = await this.computeEffectiveDistOptions(this.computeAppOutDir(outDir, arch), installerOutDir, packOptions)
this.effectiveDistOptions = await this.computeEffectiveDistOptions(this.computeAppOutDir(outDir, arch), installerOutDir, packOptions, "Foo.exe")
}

async packageInDistributableFormat(outDir: string, appOutDir: string, arch: string, packOptions: ElectronPackagerOptions): Promise<any> {
Expand Down

0 comments on commit 9a5e18f

Please sign in to comment.