Skip to content

Commit

Permalink
fix: Windows installer metadata is incorrect #278
Browse files Browse the repository at this point in the history
Closes #278
  • Loading branch information
develar committed Apr 1, 2016
1 parent de216b1 commit b151ffc
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 22 deletions.
9 changes: 4 additions & 5 deletions docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ In the development `package.json` custom `build` field can be specified to custo
```json
"build": {
"osx": {
"title": "computed name from the app package.js, you can overwrite",
"icon": "build/icon.icns",
"icon-size": 80,
"background": "build/background.png",
Expand All @@ -22,16 +21,13 @@ In the development `package.json` custom `build` field can be specified to custo
"path": "computed path to artifact, do not specify it - will be overwritten"
}
]
},
"win": "see https://github.com/electronjs/windows-installer#usage"
}
}
```

As you can see, you need to customize OS X options only if you want to provide custom `x, y`.
Don't customize paths to background and icon, — just follow conventions (if you don't want to use `build` as directory of resources — please create issue to ask ability to customize it).

See [OS X options](https://www.npmjs.com/package/appdmg#json-specification) and [Windows options](https://github.com/electronjs/windows-installer#usage).

Here documented only `electron-builder` specific options:

<!-- do not edit. start of generated block -->
Expand All @@ -45,6 +41,7 @@ Here documented only `electron-builder` specific options:
# Development `package.json`
| Name | Description
| --- | ---
| <a class="anchor" id="user-content-DevMetadata-homepage" href="#DevMetadata-homepage" aria-hidden="true"></a>homepage | The url to the project homepage (NuGet Package `projectUrl` or Linux Package URL).
| <a class="anchor" id="user-content-DevMetadata-build" href="#DevMetadata-build" aria-hidden="true"></a>build | See [BuildMetadata](#BuildMetadata).
<a class="anchor" id="user-content-BuildMetadata" href="#BuildMetadata" aria-hidden="true"></a>
## `.build`
Expand All @@ -53,5 +50,7 @@ Here documented only `electron-builder` specific options:
| <a class="anchor" id="user-content-BuildMetadata-iconUrl" href="#BuildMetadata-iconUrl" aria-hidden="true"></a>iconUrl | <p>*windows-only.* A URL to an ICO file to use as the application icon (displayed in Control Panel &gt; Programs and Features). Defaults to the Atom 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://raw.githubusercontent.com/${info.user}/${info.project}/master/build/icon.ico</code> by default.</li> </ul>
| <a class="anchor" id="user-content-BuildMetadata-productName" href="#BuildMetadata-productName" aria-hidden="true"></a>productName | See [AppMetadata.productName](#AppMetadata-productName).
| <a class="anchor" id="user-content-BuildMetadata-extraResources" href="#BuildMetadata-extraResources" aria-hidden="true"></a>extraResources | <p>A [glob expression](https://www.npmjs.com/package/glob#glob-primer), when specified, copy the file or directory with matching names directly into the app’s directory (<code>Contents/Resources</code> for OS X).</p> <p>You can use <code>${os}</code> (expanded to osx, linux or win according to current platform) and <code>${arch}</code> in the pattern.</p> <p>If directory matched, all contents are copied. So, you can just specify <code>foo</code> to copy <code>&lt;project_dir&gt;/foo</code> directory.</p> <p>May be specified in the platform options (i.e. in the <code>build.osx</code>).</p>
| <a class="anchor" id="user-content-BuildMetadata-osx" href="#BuildMetadata-osx" aria-hidden="true"></a>osx | See [OS X options](https://www.npmjs.com/package/appdmg#json-specification)
| <a class="anchor" id="user-content-BuildMetadata-win" href="#BuildMetadata-win" aria-hidden="true"></a>win | See [windows-installer options](https://github.com/electronjs/windows-installer#usage)

<!-- end of generated block -->
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"bluebird": "^3.3.4",
"command-line-args": "^2.1.6",
"electron-packager": "^6.0.0",
"electron-winstaller-fixed": "^2.0.6-beta.4",
"electron-winstaller-fixed": "^2.0.6-beta.5",
"fs-extra": "^0.26.7",
"fs-extra-p": "^0.2.0",
"globby": "^4.0.0",
Expand Down
21 changes: 17 additions & 4 deletions src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ export interface AppMetadata extends Metadata {
# Development `package.json`
*/
export interface DevMetadata extends Metadata {
/**
The url to the project homepage (NuGet Package `projectUrl` or Linux Package URL).
*/
readonly homepage?: string

/**
See [BuildMetadata](#BuildMetadata).
*/
Expand Down Expand Up @@ -71,10 +76,6 @@ export interface BuildMetadata {
*/
readonly productName?: string

readonly osx?: appdmg.Specification
readonly win?: any,
readonly linux?: any

/**
A [glob expression](https://www.npmjs.com/package/glob#glob-primer), when specified, copy the file or directory with matching names directly into the app's directory (`Contents/Resources` for OS X).
Expand All @@ -85,6 +86,18 @@ export interface BuildMetadata {
May be specified in the platform options (i.e. in the `build.osx`).
*/
readonly extraResources?: Array<string>

/**
See [OS X options](https://www.npmjs.com/package/appdmg#json-specification)
*/
readonly osx?: appdmg.Specification

/**
See [windows-installer options](https://github.com/electronjs/windows-installer#usage)
*/
readonly win?: any,

readonly linux?: any
}

export interface PlatformSpecificBuildOptions {
Expand Down
4 changes: 3 additions & 1 deletion src/winPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export default class WinPackager extends PlatformPackager<WinBuildOptions> {
const version = this.metadata.version
const installerOutDir = WinPackager.computeDistOut(outDir, arch)
const archSuffix = arch === "x64" ? "" : ("-" + arch)
const projectUrl = this.devMetadata.homepage

const options = Object.assign({
name: this.metadata.name,
Expand All @@ -133,7 +134,8 @@ export default class WinPackager extends PlatformPackager<WinBuildOptions> {
fixUpPaths: false,
usePackageJson: false,
noMsi: true,
extraFileSpecs: this.extraNuGetFileSources == null ? null : ("\n" + (await this.extraNuGetFileSources).join("\n"))
extraFileSpecs: this.extraNuGetFileSources == null ? null : ("\n" + (await this.extraNuGetFileSources).join("\n")),
extraMetadataSpecs: projectUrl == null ? null : `\n<projectUrl>${projectUrl}</projectUrl>`,
}, this.customBuildOptions)

await require("electron-winstaller-fixed").createWindowsInstaller(options)
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/test-app-one/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
"private": true,
"name": "TestApp",
"version": "1.0.0",
"homepage": "http://foo.example.com",
"description": "Test Application",
"scripts": {
"start": "electron ."
},
"author": "Foo Bar <foo@example.com>",
"devDependencies": {
"electron-prebuilt": "^0.37.2"
"electron-prebuilt": "^0.37.3"
},
"build": {
"app-bundle-id": "your.id",
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/test-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"start": "electron ."
},
"devDependencies": {
"electron-prebuilt": "^0.37.2"
"electron-prebuilt": "^0.37.3"
},
"build": {
"app-bundle-id": "your.id",
Expand Down
2 changes: 1 addition & 1 deletion test/src/BuildTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ test("version from electron-prebuilt dependency", () => assertPack("test-app-one
tempDirCreated: projectDir => {
return BluebirdPromise.all([
outputJson(path.join(projectDir, "node_modules", "electron-prebuilt", "package.json"), {
version: "0.37.2"
version: "0.37.3"
}),
modifyPackageJson(projectDir, data => {
data.devDependencies = {}
Expand Down
34 changes: 27 additions & 7 deletions test/src/helpers/packTester.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { copy, emptyDir, remove, writeJson, readJson } from "fs-extra-p"
import { copy, emptyDir, remove, writeJson, readJson, readFile } from "fs-extra-p"
import * as assertThat from "should/as-function"
import * as path from "path"
import { parse as parsePlist } from "plist"
Expand Down Expand Up @@ -186,12 +186,11 @@ async function checkWindowsResult(packager: Packager, packagerOptions: PackagerO
assertThat(artifacts.map(it => it.artifactName).filter(it => it != null)).deepEqual([`TestAppSetup-1.0.0${archSuffix}.exe`])
}

const files = pathSorter((await new BluebirdPromise<Array<string>>((resolve, reject) => {
const unZipper = new DecompressZip(path.join(path.dirname(artifacts[0].file), `TestApp-1.0.0${archSuffix}-full.nupkg`))
unZipper.on("list", resolve)
unZipper.on('error', reject)
unZipper.list()
})).map(it => it.replace(/\\/g, "/")).filter(it => (!it.startsWith("lib/net45/locales/") || it === "lib/net45/locales/en-US.pak") && !it.endsWith(".psmdcp")))
const packageFile = path.join(path.dirname(artifacts[0].file), `TestApp-1.0.0${archSuffix}-full.nupkg`)
const unZipper = new DecompressZip(packageFile)
const fileDescriptors = await unZipper.getFiles()

const files = pathSorter(fileDescriptors.map(it => it.path.replace(/\\/g, "/")).filter(it => (!it.startsWith("lib/net45/locales/") || it === "lib/net45/locales/en-US.pak") && !it.endsWith(".psmdcp")))

// console.log(JSON.stringify(files, null, 2))
const expectedContents = checkOptions == null || checkOptions.expectedContents == null ? expectedWinContents : checkOptions.expectedContents
Expand All @@ -203,6 +202,27 @@ async function checkWindowsResult(packager: Packager, packagerOptions: PackagerO
return it
}
}))

if (checkOptions == null || checkOptions.expectedContents == null) {
await unZipper.extractFile(fileDescriptors.filter(it => it.path === "TestApp.nuspec")[0], {
path: path.dirname(packageFile),
})
assertThat((await readFile(path.join(path.dirname(packageFile), "TestApp.nuspec"), "utf8")).replace(/\r\n/g, "\n")).equal(`<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>TestApp</id>
<version>1.0.0</version>
<title>My App</title>
<authors>Foo Bar</authors>
<owners>Foo Bar</owners>
<projectUrl>http://foo.example.com</projectUrl>
<iconUrl>https://raw.githubusercontent.com/szwacz/electron-boilerplate/master/resources/windows/icon.ico</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Test Application</description>
<copyright>Copyright © ${new Date().getFullYear()} Foo Bar</copyright>
</metadata>
</package>`)
}
}

async function getContents(path: string, productName: string) {
Expand Down
2 changes: 1 addition & 1 deletion test/src/helpers/runTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const rootDir = path.join(__dirname, "..", "..", "..")
const testPackageDir = path.join(require("os").tmpdir(), "electron_builder_published")
const testNodeModules = path.join(testPackageDir, "node_modules")

const electronVersion = "0.37.2"
const electronVersion = "0.37.3"

BluebirdPromise.all([
deleteOldElectronVersion(),
Expand Down
10 changes: 10 additions & 0 deletions test/typings/decompress-zip.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
declare module "decompress-zip" {
import { EventEmitter } from "events"

interface FileDescriptor {
path: string
}

export = class DecompressZip extends EventEmitter {
constructor(filename: string)

list(): void

getFiles(): Promise<Array<FileDescriptor>>

extract(options: {path: string, filter?: (file: string) => boolean}): void

extractFile(file: FileDescriptor, options: {path: string, filter?: (file: string) => boolean}): Promise<void>
}
}

0 comments on commit b151ffc

Please sign in to comment.