Skip to content

Commit

Permalink
feat: option to use appId to identify package instead of name #773
Browse files Browse the repository at this point in the history
Change unique identifier to appId instead of name for Squirrel.Windows
builds. This alligns the behavior of packaging a Squirrel.Windows app with
packaging a Squirrel.Mac app (as mac app uses appId for uniqueness).
This makes creating separate builds for one app (i.e. one for test and
one for production) more intuitive.

Closes #753
  • Loading branch information
symbyte authored and develar committed Sep 23, 2016
1 parent 44ad719 commit 6f3d365
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 53 deletions.
20 changes: 14 additions & 6 deletions docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Don't customize paths to background and icon, — just follow conventions.
* [.build.mas](#MasBuildOptions)
* [.build.nsis](#NsisOptions)
* [.build.protocols](#Protocol)
* [.build.squirrelWindows](#SquirrelWindowsOptions)
* [.build.win](#WinBuildOptions)
* [.directories](#MetadataDirectories)

Expand Down Expand Up @@ -74,6 +75,7 @@ Don't customize paths to background and icon, — just follow conventions.
| mas | <a name="BuildMetadata-mas"></a>See [.build.mas](#MasBuildOptions).
| win | <a name="BuildMetadata-win"></a>See [.build.win](#WinBuildOptions).
| nsis | <a name="BuildMetadata-nsis"></a>See [.build.nsis](#NsisOptions).
| squirrelWindows | <a name="BuildMetadata-squirrelWindows"></a>See [.build.squirrelWindows](#SquirrelWindowsOptions).
| linux | <a name="BuildMetadata-linux"></a>See [.build.linux](#LinuxBuildOptions).
| compression | <a name="BuildMetadata-compression"></a>The compression level, one of `store`, `normal`, `maximum` (default: `normal`). If you want to rapidly test build, `store` can reduce build time significantly.
| afterPack | <a name="BuildMetadata-afterPack"></a>*programmatic API only* The function to be run after pack (but before pack into distributable format and sign). Promise must be returned.
Expand Down Expand Up @@ -180,19 +182,25 @@ macOS only.
| role | <a name="Protocol-role"></a>*macOS-only* The app’s role with respect to the type. The value can be `Editor`, `Viewer`, `Shell`, or `None`. Defaults to `Editor`.
| **schemes** | <a name="Protocol-schemes"></a>The schemes. e.g. `["irc", "ircs"]`.

<a name="SquirrelWindowsOptions"></a>
### `.build.squirrelWindows`
| Name | Description
| --- | ---
| iconUrl | <a name="SquirrelWindowsOptions-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="SquirrelWindowsOptions-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>
| msi | <a name="SquirrelWindowsOptions-msi"></a>*Squirrel.Windows-only.* Whether to create an MSI installer. Defaults to `false` (MSI is not created).
| remoteReleases | <a name="SquirrelWindowsOptions-remoteReleases"></a>*Squirrel.Windows-only.* A URL to your existing updates. Or `true` to automatically set to your GitHub repository. If given, these will be downloaded to create delta updates.
| remoteToken | <a name="SquirrelWindowsOptions-remoteToken"></a>*Squirrel.Windows-only.* Authentication token for remote updates
| useAppIdAsId | <a name="SquirrelWindowsOptions-useAppIdAsId"></a>Use `appId` to identify package instead of `name`.

<a name="WinBuildOptions"></a>
### `.build.win`

Windows specific build options.

| Name | Description
| --- | ---
| target | <a name="WinBuildOptions-target"></a>Target package type: list of `squirrel`, `nsis`, `7z`, `zip`, `tar.xz`, `tar.lz`, `tar.gz`, `tar.bz2`. Defaults to `squirrel`.
| iconUrl | <a name="WinBuildOptions-iconUrl"></a><p>*Squirrel.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 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>*Squirrel.Windows-only.* 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>
| msi | <a name="WinBuildOptions-msi"></a>*Squirrel.Windows-only.* Whether to create an MSI installer. Defaults to `false` (MSI is not created).
| remoteReleases | <a name="WinBuildOptions-remoteReleases"></a>*Squirrel.Windows-only.* A URL to your existing updates. Or `true` to automatically set to your GitHub repository. If given, these will be downloaded to create delta updates.
| remoteToken | <a name="WinBuildOptions-remoteToken"></a>*Squirrel.Windows-only.* Authentication token for remote updates
| target | <a name="WinBuildOptions-target"></a>Target package type: list of `nsis`, `squirrel`, `7z`, `zip`, `tar.xz`, `tar.lz`, `tar.gz`, `tar.bz2`. Defaults to `squirrel`.
| signingHashAlgorithms | <a name="WinBuildOptions-signingHashAlgorithms"></a>Array of signing algorithms used. Defaults to `['sha1', 'sha256']`
| icon | <a name="WinBuildOptions-icon"></a>The path to application icon. Defaults to `build/icon.ico` (consider using this convention instead of complicating your configuration).
| legalTrademarks | <a name="WinBuildOptions-legalTrademarks"></a>The trademarks and registered trademarks.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
"pre-git": "^3.10.0",
"ts-babel": "^1.0.12",
"tslint": "^3.15.1",
"typescript": "^2.0.2",
"typescript": "^2.0.3",
"whitespace": "^2.1.0"
},
"babel": {
Expand Down
7 changes: 6 additions & 1 deletion src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AsarOptions } from "asar-electron-builder"
import { PlatformPackager } from "./platformPackager"
import { MacOptions, DmgOptions, MasBuildOptions } from "./options/macOptions"
import { PublishConfiguration } from "./options/publishOptions"
import { WinBuildOptions, NsisOptions } from "./options/winOptions"
import { WinBuildOptions, NsisOptions, SquirrelWindowsOptions } from "./options/winOptions"

export interface Metadata {
readonly repository?: string | RepositoryInfo | null
Expand Down Expand Up @@ -174,6 +174,11 @@ export interface BuildMetadata {
*/
readonly nsis?: NsisOptions | null

/**
See [.build.squirrelWindows](#SquirrelWindowsOptions).
*/
readonly squirrelWindows?: SquirrelWindowsOptions | null

/*
See [.build.linux](#LinuxBuildOptions).
*/
Expand Down
84 changes: 47 additions & 37 deletions src/options/winOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,10 @@ import { PlatformSpecificBuildOptions } from "../metadata"
*/
export interface WinBuildOptions extends PlatformSpecificBuildOptions {
/*
Target package type: list of `squirrel`, `nsis`, `7z`, `zip`, `tar.xz`, `tar.lz`, `tar.gz`, `tar.bz2`. Defaults to `squirrel`.
Target package type: list of `nsis`, `squirrel`, `7z`, `zip`, `tar.xz`, `tar.lz`, `tar.gz`, `tar.bz2`. Defaults to `squirrel`.
*/
readonly target?: Array<string> | null

/*
*Squirrel.Windows-only.* A URL to an ICO file to use as the application icon (displayed in Control Panel > Programs and Features). Defaults to the Electron icon.
Please note — [local icon file url is not accepted](https://github.com/atom/grunt-electron-installer/issues/73), must be https/http.
* If you don't plan to build windows installer, you can omit it.
* If your project repository is public on GitHub, it will be `https://github.com/${u}/${p}/blob/master/build/icon.ico?raw=true` by default.
*/
readonly iconUrl?: string | null

/*
*Squirrel.Windows-only.* The path to a .gif file to display during install. `build/install-spinner.gif` 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)).
*/
readonly loadingGif?: string | null

/*
*Squirrel.Windows-only.* Whether to create an MSI installer. Defaults to `false` (MSI is not created).
*/
readonly msi?: boolean

/*
*Squirrel.Windows-only.* A URL to your existing updates. Or `true` to automatically set to your GitHub repository. If given, these will be downloaded to create delta updates.
*/
readonly remoteReleases?: string | boolean | null

/*
*Squirrel.Windows-only.* Authentication token for remote updates
*/
readonly remoteToken?: string | null

/*
Array of signing algorithms used. Defaults to `['sha1', 'sha256']`
*/
Expand Down Expand Up @@ -80,7 +49,7 @@ export interface NsisOptions {
/*
One-click installation. Defaults to `true`.
*/
readonly oneClick?: boolean | null
readonly oneClick?: boolean

/*
Defaults to `false`.
Expand All @@ -89,17 +58,17 @@ export interface NsisOptions {
If `oneClick` is `false`: no install mode installer page (choice per-machine or per-user), always install per-machine.
*/
readonly perMachine?: boolean | null
readonly perMachine?: boolean

/*
*boring installer only.* Allow requesting for elevation. If false, user will have to restart installer with elevated permissions. Defaults to `true`.
*/
readonly allowElevation?: boolean | null
readonly allowElevation?: boolean

/*
*one-click installer only.* Run application after finish. Defaults to `true`.
*/
readonly runAfterFinish?: boolean | null
readonly runAfterFinish?: boolean

/*
See [GUID vs Application Name](https://github.com/electron-userland/electron-builder/wiki/NSIS#guid-vs-application-name).
Expand Down Expand Up @@ -138,5 +107,46 @@ export interface NsisOptions {
If `warningsAsErrors` is `false`: NSIS will allow warnings.
*/
readonly warningsAsErrors?: boolean | null
readonly warningsAsErrors?: boolean
}

/*
### `.build.squirrelWindows`
*/
export interface SquirrelWindowsOptions extends WinBuildOptions {
/*
A URL to an ICO file to use as the application icon (displayed in Control Panel > Programs and Features). Defaults to the Electron icon.
Please note — [local icon file url is not accepted](https://github.com/atom/grunt-electron-installer/issues/73), must be https/http.
* If you don't plan to build windows installer, you can omit it.
* If your project repository is public on GitHub, it will be `https://github.com/${u}/${p}/blob/master/build/icon.ico?raw=true` by default.
*/
readonly iconUrl?: string | null

/*
The path to a .gif file to display during install. `build/install-spinner.gif` 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)).
*/
readonly loadingGif?: string | null

/*
*Squirrel.Windows-only.* Whether to create an MSI installer. Defaults to `false` (MSI is not created).
*/
readonly msi?: boolean

/*
*Squirrel.Windows-only.* A URL to your existing updates. Or `true` to automatically set to your GitHub repository. If given, these will be downloaded to create delta updates.
*/
readonly remoteReleases?: string | boolean | null

/*
*Squirrel.Windows-only.* Authentication token for remote updates
*/
readonly remoteToken?: string | null

/*
Use `appId` to identify package instead of `name`.
*/
readonly useAppIdAsId?: boolean
}
5 changes: 3 additions & 2 deletions src/targets/squirrelPack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface SquirrelOptions {
remoteToken?: string
loadingGif?: string
productName?: string
appId?: string
name: string
packageCompressionLevel?: number
version: string
Expand Down Expand Up @@ -121,7 +122,7 @@ async function pack(options: SquirrelOptions, directory: string, updateFile: str
const nuspecContent = `<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>${options.name}</id>
<id>${options.appId}</id>
<version>${version}</version>
<title>${options.productName}</title>
<authors>${author}</authors>
Expand Down Expand Up @@ -165,7 +166,7 @@ async function pack(options: SquirrelOptions, directory: string, updateFile: str
xmlns="http://schemas.openxmlformats.org/package/2006/metadata/core-properties">
<dc:creator>${author}</dc:creator>
<dc:description>${options.description}</dc:description>
<dc:identifier>${options.name}</dc:identifier>
<dc:identifier>${options.appId}</dc:identifier>
<version>${version}</version>
<keywords/>
<dc:title>${options.productName}</dc:title>
Expand Down
10 changes: 7 additions & 3 deletions src/targets/squirrelWindows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { warn, log } from "../util/log"
import { getRepositoryInfo } from "../repositoryInfo"
import { getBinFromBintray } from "../util/binDownload"
import { buildInstaller, convertVersion, SquirrelOptions } from "./squirrelPack"
import { SquirrelWindowsOptions } from "../options/winOptions"

//noinspection JSUnusedLocalSymbols
const __awaiter = require("../util/awaiter")
Expand All @@ -15,6 +16,8 @@ const SW_VERSION = "1.4.4"
const SW_SHA2 = "98e1d81c80d7afc1bcfb37f3b224dc4f761088506b9c28ccd72d1cf8752853ba"

export default class SquirrelWindowsTarget extends Target {
private readonly options: SquirrelWindowsOptions = Object.assign({}, this.packager.platformSpecificBuildOptions, this.packager.devMetadata.build.squirrelWindows)

constructor(private packager: WinPackager) {
super("squirrel")
}
Expand Down Expand Up @@ -48,7 +51,7 @@ export default class SquirrelWindowsTarget extends Target {

async computeEffectiveDistOptions(): Promise<SquirrelOptions> {
const packager = this.packager
let iconUrl = packager.platformSpecificBuildOptions.iconUrl || packager.devMetadata.build.iconUrl
let iconUrl = this.options.iconUrl || packager.devMetadata.build.iconUrl
if (iconUrl == null) {
const info = await getRepositoryInfo(packager.appInfo.metadata, packager.devMetadata)
if (info != null) {
Expand All @@ -60,13 +63,14 @@ export default class SquirrelWindowsTarget extends Target {
}
}

checkConflictingOptions(packager.platformSpecificBuildOptions)
checkConflictingOptions(this.options)

const appInfo = packager.appInfo
const projectUrl = await appInfo.computePackageUrl()
const options: any = Object.assign({
name: appInfo.name,
productName: appInfo.productName,
appId: this.options.useAppIdAsId ? appInfo.id : appInfo.name,
version: appInfo.version,
description: appInfo.description,
authors: appInfo.companyName,
Expand All @@ -75,7 +79,7 @@ export default class SquirrelWindowsTarget extends Target {
copyright: appInfo.copyright,
packageCompressionLevel: packager.devMetadata.build.compression === "store" ? 0 : 9,
vendorPath: await getBinFromBintray("Squirrel.Windows", SW_VERSION, SW_SHA2)
}, packager.platformSpecificBuildOptions)
}, this.options)

if (options.remoteToken == null) {
options.remoteToken = packager.info.options.githubToken
Expand Down
5 changes: 3 additions & 2 deletions test/src/helpers/packTester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { spawnNpmProduction } from "out/util/util"
import { TEST_DIR } from "./config"
import { deepAssign } from "out/util/deepAssign"
import { AssertContext } from "ava-tf"
import { SquirrelWindowsOptions } from "out/options/winOptions"

//noinspection JSUnusedLocalSymbols
const __awaiter = require("out/util/awaiter")
Expand Down Expand Up @@ -307,7 +308,7 @@ async function checkWindowsResult(packager: Packager, checkOptions: AssertPackOp
squirrel = true
expectedFileNames.push("RELEASES", `${appInfo.productFilename} Setup ${appInfo.version}${archSuffix}.exe`, `${appInfo.name}-${convertVersion(appInfo.version)}-full.nupkg`)

if (buildOptions != null && buildOptions.remoteReleases != null) {
if (buildOptions != null && (<SquirrelWindowsOptions>buildOptions).remoteReleases != null) {
expectedFileNames.push(`${appInfo.name}-${convertVersion(appInfo.version)}-delta.nupkg`)
}

Expand Down Expand Up @@ -431,4 +432,4 @@ export function currentPlatform(dist: boolean = true): PackagerOptions {
return {
targets: Platform.fromString(process.platform).createTarget(dist ? null : DIR_TARGET),
}
}
}
9 changes: 8 additions & 1 deletion test/src/winPackagerTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test.skip("delta and msi", app({
targets: Platform.WINDOWS.createTarget(null, Arch.ia32),
devMetadata: {
build: {
win: {
squirrelWindows: {
remoteReleases: "https://github.com/develar/__test-app-releases",
msi: true,
},
Expand All @@ -35,6 +35,13 @@ test.ifDevOrWinCi("beta version", app({
}
}))

test.ifDevOrWinCi("beta version", app({
targets: Platform.WINDOWS.createTarget(["squirrel", "nsis"]),
devMetadata: <any>{
version: "3.0.0-beta.2",
}
}))

test.ifNotCiOsx("msi as string", t => t.throws(assertPack("test-app-one", platform(Platform.WINDOWS),
{
projectDirCreated: it => modifyPackageJson(it, data => {
Expand Down

0 comments on commit 6f3d365

Please sign in to comment.