Skip to content

Commit

Permalink
feat(windows): Portable Build
Browse files Browse the repository at this point in the history
Close #1157
  • Loading branch information
develar committed Feb 24, 2017
1 parent 09f7fde commit 6292855
Show file tree
Hide file tree
Showing 23 changed files with 303 additions and 197 deletions.
1 change: 1 addition & 0 deletions .idea/dictionaries/develar.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ A complete solution to package and build a ready for distribution Electron app f
* All platforms: `7z`, `zip`, `tar.xz`, `tar.lz`, `tar.gz`, `tar.bz2`, `dir` (unpacked directory).
* [macOS](https://github.com/electron-userland/electron-builder/wiki/Options#MacOptions-target): `dmg`, `pkg`, `mas`.
* [Linux](https://github.com/electron-userland/electron-builder/wiki/Options#LinuxBuildOptions-target): [AppImage](http://appimage.org), [snap](http://snapcraft.io), debian package (`deb`), `rpm`, `freebsd`, `pacman`, `p5p`, `apk`.
* [Windows](https://github.com/electron-userland/electron-builder/wiki/Options#WinBuildOptions-target): NSIS, Web installer, AppX (Windows Store), Squirrel.Windows.
* [Windows](https://github.com/electron-userland/electron-builder/wiki/Options#WinBuildOptions-target): `nsis` (Installer), `nsis-web` (Web installer), `portable` (portable app without installation), AppX (Windows Store), Squirrel.Windows.
* [Two package.json structure](https://github.com/electron-userland/electron-builder/wiki/Two-package.json-Structure) is supported, but you are not forced to use it even if you have native production dependencies.
* [Publishing artifacts](https://github.com/electron-userland/electron-builder/wiki/Publishing-Artifacts) to GitHub Releases, Amazon S3 and Bintray.
* Pack in a distributable format [already packaged app](#pack-only-in-a-distributable-format).
Expand Down
2 changes: 1 addition & 1 deletion docs/NSIS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Two options are available — [include](https://github.com/electron-userland/ele
Keep in mind — if you customize NSIS script, you should always state about it in the issue reports. And don't expect that your issue will be resolved.

1. Add file `build/installer.nsh`.
2. Define wanted macro to customise: `customHeader`, `preInit`, `customInit`, `customUnInit`, `customInstall`, `customUnInstall`. Example:
2. Define wanted macro to customise: `customHeader`, `preInit`, `customInit`, `customUnInit`, `customInstall`, `customUnInstall`, `customRemoveFiles`. Example:
```nsis
!macro customHeader
!system "echo '' > ${BUILD_RESOURCES_DIR}/customHeader"
Expand Down
2 changes: 1 addition & 1 deletion docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ To use Squirrel.Windows please install `electron-builder-squirrel-windows` depen
### `win` Windows Specific Options
| Name | Description
| --- | ---
| target | <a name="WinBuildOptions-target"></a><p>Target package type: list of <code>nsis</code>, <code>nsis-web</code> (Web installer), <code>appx</code>, <code>squirrel</code>, <code>7z</code>, <code>zip</code>, <code>tar.xz</code>, <code>tar.lz</code>, <code>tar.gz</code>, <code>tar.bz2</code>, <code>dir</code>. Defaults to <code>nsis</code>.</p> <p>AppX package can be built only on Windows 10.</p> <p>To use Squirrel.Windows please install <code>electron-builder-squirrel-windows</code> dependency.</p>
| target | <a name="WinBuildOptions-target"></a><p>Target package type: list of <code>nsis</code>, <code>nsis-web</code> (Web installer), <code>portable</code> (portable app without installation), <code>appx</code>, <code>squirrel</code>, <code>7z</code>, <code>zip</code>, <code>tar.xz</code>, <code>tar.lz</code>, <code>tar.gz</code>, <code>tar.bz2</code>, <code>dir</code>. Defaults to <code>nsis</code>.</p> <p>AppX package can be built only on Windows 10.</p> <p>To use Squirrel.Windows please install <code>electron-builder-squirrel-windows</code> dependency.</p>
| signingHashAlgorithms | <a name="WinBuildOptions-signingHashAlgorithms"></a><p>Array of signing algorithms used. Defaults to <code>['sha1', 'sha256']</code></p> <p>For AppX <code>sha256</code> is always used.</p>
| 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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"chromium-pickle-js": "^0.2.0",
"cuint": "^0.2.2",
"debug": "^2.6.1",
"electron-download-tf": "3.2.0",
"electron-download-tf": "4.0.0",
"electron-macos-sign": "~1.6.0",
"fs-extra-p": "^4.0.2",
"hosted-git-info": "^2.2.0",
Expand Down Expand Up @@ -78,7 +78,7 @@
"decompress-zip": "^0.3.0",
"depcheck": "^0.6.7",
"docdash": "https://github.com/develar/docdash.git",
"electron-download-tf": "3.2.0",
"electron-download-tf": "4.0.0",
"jest-cli": "^19.0.2",
"jest-environment-node-debug": "^2.0.0",
"jest-junit-reporter": "^1.0.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/electron-builder-http/src/CancellationToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import BluebirdPromise from "bluebird-lst"
import { EventEmitter } from "events"

export class CancellationToken extends EventEmitter {
private parentCancelHandler: any | null = null
private parentCancelHandler: (() => any) | null = null

private _cancelled: boolean
get cancelled(): boolean {
Expand Down Expand Up @@ -42,7 +42,7 @@ export class CancellationToken extends EventEmitter {
}
}

createPromise<R>(callback: (resolve: (thenableOrResult?: R) => void, reject: (error?: any) => void, onCancel: (callback: () => void) => void) => void): Promise<R> {
createPromise<R>(callback: (resolve: (thenableOrResult?: R) => void, reject: (error?: Error) => void, onCancel: (callback: () => void) => void) => void): Promise<R> {
if (this.cancelled) {
return BluebirdPromise.reject(new CancellationError())
}
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"electron-builder-http": "0.0.0-semantic-release",
"electron-builder-util": "0.0.0-semantic-release",
"electron-publish": "0.0.0-semantic-release",
"electron-download-tf": "3.2.0",
"electron-download-tf": "4.0.0",
"electron-macos-sign": "~1.6.0",
"fs-extra-p": "^4.0.2",
"hosted-git-info": "^2.2.0",
Expand Down
14 changes: 7 additions & 7 deletions packages/electron-builder/src/cli/create-self-signed-cert.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import yargs from "yargs"
import { printErrorAndExit } from "electron-builder-util/out/promise"
import { exec, spawn } from "electron-builder-util"
import { getSignVendorPath } from "../windowsCodeSign"
import * as path from "path"
import sanitizeFileName from "sanitize-filename"
import { unlinkIfExists } from "electron-builder-util/out/fs"
import { log } from "electron-builder-util/out/log"
import { printErrorAndExit } from "electron-builder-util/out/promise"
import { TmpDir } from "electron-builder-util/out/tmp"
import { unlinkIfExists } from "electron-builder-util/out/fs"
import * as path from "path"
import sanitizeFileName from "sanitize-filename"
import yargs from "yargs"
import { getSignVendorPath } from "../windowsCodeSign"

async function main() {
const args: any = yargs
Expand Down Expand Up @@ -34,7 +34,7 @@ async function main() {
const certLocation = "Cert:\\LocalMachine\\TrustedPeople"
log(`${pfx} will be imported into ${certLocation} Operation will be succeed only if runned from root. Otherwise import file manually.`)
await spawn("powershell.exe", ["Import-PfxCertificate", "-FilePath", `"${pfx}"`, "-CertStoreLocation", ""])
tmpDir.cleanup()
await tmpDir.cleanup()
}

main()
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-builder/src/options/winOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { PlatformSpecificBuildOptions } from "../metadata"
*/
export interface WinBuildOptions extends PlatformSpecificBuildOptions {
/**
Target package type: list of `nsis`, `nsis-web` (Web installer), `appx`, `squirrel`, `7z`, `zip`, `tar.xz`, `tar.lz`, `tar.gz`, `tar.bz2`, `dir`. Defaults to `nsis`.
Target package type: list of `nsis`, `nsis-web` (Web installer), `portable` (portable app without installation), `appx`, `squirrel`, `7z`, `zip`, `tar.xz`, `tar.lz`, `tar.gz`, `tar.bz2`, `dir`. Defaults to `nsis`.
AppX package can be built only on Windows 10.
Expand Down
49 changes: 49 additions & 0 deletions packages/electron-builder/src/targets/WebInstaller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { Platform } from "electron-builder-core"
import { NsisWebOptions } from "../options/winOptions"
import { computeDownloadUrl, getPublishConfigs, getPublishConfigsForUpdateInfo } from "../publish/PublishManager"
import { WinPackager } from "../winPackager"
import NsisTarget from "./nsis"

export default class WebInstallerTarget extends NsisTarget {
constructor(packager: WinPackager, outDir: string, targetName: string) {
super(packager, outDir, targetName)
}

protected get isWebInstaller(): boolean {
return true
}

protected async configureDefines(oneClick: boolean, defines: any) {
//noinspection ES6MissingAwait
const promise = (<any>NsisTarget.prototype).configureDefines.call(this, oneClick, defines)
await promise

const packager = this.packager
const options = this.options

let appPackageUrl = (<NsisWebOptions>options).appPackageUrl
if (appPackageUrl == null) {
const publishConfigs = await getPublishConfigsForUpdateInfo(packager, await getPublishConfigs(packager, this.options, false))
if (publishConfigs == null || publishConfigs.length === 0) {
throw new Error("Cannot compute app package download URL")
}

appPackageUrl = computeDownloadUrl(publishConfigs[0], null, packager.appInfo.version, {
os: Platform.WINDOWS.buildConfigurationKey,
arch: ""
})

defines.APP_PACKAGE_URL_IS_INCOMLETE = null
}

defines.APP_PACKAGE_URL = appPackageUrl
}

protected get installerFilenamePattern(): string {
return "${productName} Web Setup ${version}.${ext}"
}

protected generateGitHubInstallerName(): string {
return `${this.packager.appInfo.name}-WebSetup-${this.packager.appInfo.version}.exe`
}
}
Loading

0 comments on commit 6292855

Please sign in to comment.