Skip to content

Commit

Permalink
feat(nsis): NSIS Web Installer
Browse files Browse the repository at this point in the history
Close #1207
  • Loading branch information
develar committed Feb 10, 2017
1 parent 22746bd commit 7041b5d
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 39 deletions.
10 changes: 9 additions & 1 deletion docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Most of the options accept `null` — for example, to explicitly set that DMG ic
* [mac macOS Specific Options](#MacOptions)
* [mas MAS (Mac Application Store) Specific Options](#MasBuildOptions)
* [nsis](#NsisOptions)
* [nsis Web Installer Specific Options](#NsisWebOptions)
* [pkg macOS Product Archive Options](#PkgOptions)
* [protocols URL Protocol Schemes](#Protocol)
* [squirrelWindows](#SquirrelWindowsOptions)
Expand Down Expand Up @@ -191,6 +192,13 @@ See [NSIS target notes](https://github.com/electron-userland/electron-builder/wi
| menuCategory | <a name="NsisOptions-menuCategory"></a>Whether to create submenu for start menu shortcut and program files directory. Defaults to `false`. If `true`, company name will be used. Or string value.
| artifactName | <a name="NsisOptions-artifactName"></a>The [artifact file name pattern](https://github.com/electron-userland/electron-builder/wiki/Options#artifact-file-name-pattern). Defaults to `${productName} Setup ${version}.${ext}`.

<a name="NsisWebOptions"></a>
### `nsis` Web Installer Specific Options
| Name | Description
| --- | ---
| appPackageUrl | <a name="NsisWebOptions-appPackageUrl"></a><p>The application package download URL. Optional — by default computed using publish configuration.</p> <p>URL like <code>https://example.com/download/latest</code> allows web installer to be version independent (installer will download latest application package).</p> <p>Custom <code>X-Arch</code> http header is set to <code>32</code> or <code>64</code>.</p>
| artifactName | <a name="NsisWebOptions-artifactName"></a>The [artifact file name pattern](https://github.com/electron-userland/electron-builder/wiki/Options#artifact-file-name-pattern). Defaults to `${productName} Web Setup ${version}.${ext}`.

<a name="PkgOptions"></a>
### `pkg` macOS Product Archive Options
| Name | Description
Expand All @@ -214,7 +222,7 @@ Please note — on macOS [you need to register an `open-url` event handler](http
<a name="SquirrelWindowsOptions"></a>
### `squirrelWindows`

To use Squirrel.Windows please install `electron-builder-squirrel-windows` dependency.
To use Squirrel.Windows please install `electron-builder-squirrel-windows` dependency. Squirrel.Windows target is maintained, but deprecated. Please use `nsis` instead.

| Name | Description
| --- | ---
Expand Down
34 changes: 17 additions & 17 deletions docs/Publishing Artifacts.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ But please consider using automatic rules instead of explicitly specifying `publ

<!-- do not edit. start of generated block -->
* [publish](#PublishConfiguration)
* [publish Amazon S3](#S3Options)
* [publish Bintray](#BintrayOptions)
* [publish Generic (any https server)](#GenericServerOptions)
* [publish Generic (any HTTP(S) server)](#GenericServerOptions)
* [publish GitHub](#GithubOptions)
* [publish S3](#S3Options)

<a name="PublishConfiguration"></a>
### `publish`
Expand All @@ -89,6 +89,19 @@ Amazon S3 — `https` must be used, so, if you use direct Amazon S3 endpoints, f
| **provider** | <a name="PublishConfiguration-provider"></a>The provider, one of `github`, `s3`, `bintray`, `generic`.
| owner | <a name="PublishConfiguration-owner"></a>The owner.

<a name="S3Options"></a>
### `publish` Amazon S3

[Getting your credentials](http://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/getting-your-credentials.html).

| Name | Description
| --- | ---
| **bucket** | <a name="S3Options-bucket"></a>The bucket name.
| path | <a name="S3Options-path"></a>The directory path. Defaults to `/`.
| channel | <a name="S3Options-channel"></a>The channel. Defaults to `latest`.
| acl | <a name="S3Options-acl"></a>The ACL. Defaults to `public-read`.
| storageClass | <a name="S3Options-storageClass"></a>The type of storage to use for the object. One of `STANDARD`, `REDUCED_REDUNDANCY`, `STANDARD_IA`. Defaults to `STANDARD`.

<a name="BintrayOptions"></a>
### `publish` Bintray
| Name | Description
Expand All @@ -98,10 +111,10 @@ Amazon S3 — `https` must be used, so, if you use direct Amazon S3 endpoints, f
| user | <a name="BintrayOptions-user"></a>The Bintray user account. Used in cases where the owner is an organization.

<a name="GenericServerOptions"></a>
### `publish` Generic (any https server)
### `publish` Generic (any HTTP(S) server)
| Name | Description
| --- | ---
| **url** | <a name="GenericServerOptions-url"></a>The base url. e.g. `https://s3.amazonaws.com/bucket_name`. You can use `${os}` (expanded to `mac`, `linux` or `win` according to target platform) and `${arch}` macros.
| **url** | <a name="GenericServerOptions-url"></a>The base url. e.g. `https://bucket_name.s3.amazonaws.com`. You can use `${os}` (expanded to `mac`, `linux` or `win` according to target platform) and `${arch}` macros.
| channel | <a name="GenericServerOptions-channel"></a>The channel. Defaults to `latest`.

<a name="GithubOptions"></a>
Expand All @@ -113,17 +126,4 @@ Amazon S3 — `https` must be used, so, if you use direct Amazon S3 endpoints, f
| host | <a name="GithubOptions-host"></a>The host (including the port if need). Defaults to `github.com`.
| protocol | <a name="GithubOptions-protocol"></a><p>The protocol, one of <code>https</code> or <code>http</code>. Defaults to <code>https</code>.</p> <p>GitHub Publisher supports only <code>https</code>.</p>

<a name="S3Options"></a>
### `publish` S3

[Getting your credentials](http://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/getting-your-credentials.html).

| Name | Description
| --- | ---
| **bucket** | <a name="S3Options-bucket"></a>The bucket name.
| path | <a name="S3Options-path"></a>The directory path. Defaults to `/`.
| channel | <a name="S3Options-channel"></a>The channel. Defaults to `latest`.
| acl | <a name="S3Options-acl"></a>The ACL. Defaults to `public-read`.
| storageClass | <a name="S3Options-storageClass"></a>The type of storage to use for the object. One of `STANDARD`, `REDUCED_REDUNDANCY`, `STANDARD_IA`. Defaults to `STANDARD`.

<!-- end of generated block -->
8 changes: 4 additions & 4 deletions packages/electron-builder-http/src/publishOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ export interface PublishConfiguration {
}

/*
### `publish` Generic (any https server)
### `publish` Generic (any HTTP(S) server)
*/
export interface GenericServerOptions extends PublishConfiguration {
/*
The base url. e.g. `https://s3.amazonaws.com/bucket_name`. You can use `${os}` (expanded to `mac`, `linux` or `win` according to target platform) and `${arch}` macros.
The base url. e.g. `https://bucket_name.s3.amazonaws.com`. You can use `${os}` (expanded to `mac`, `linux` or `win` according to target platform) and `${arch}` macros.
*/
url: string

Expand All @@ -45,7 +45,7 @@ export interface GenericServerOptions extends PublishConfiguration {
}

/*
### `publish` S3
### `publish` Amazon S3
[Getting your credentials](http://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/getting-your-credentials.html).
*/
Expand Down Expand Up @@ -79,7 +79,7 @@ export interface S3Options extends PublishConfiguration {
}

export function s3Url(options: S3Options) {
let url = `https://s3.amazonaws.com/${options.bucket}`
let url = `https://${options.bucket}.s3.amazonaws.com`
if (options.path != null) {
url += `/${options.path}`
}
Expand Down
12 changes: 11 additions & 1 deletion packages/electron-builder/src/options/winOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,29 @@ export interface NsisOptions {
readonly artifactName?: string | null
}

/*
### `nsis` Web Installer Specific Options
*/
export interface NsisWebOptions extends NsisOptions {
/*
The application package download URL. Optional — by default computed using publish configuration.
URL like `https://example.com/download/latest` allows web installer to be version independent (installer will download latest application package).
Custom `X-Arch` http header is set to `32` or `64`.
*/
readonly appPackageUrl?: string | null

/*
The [artifact file name pattern](https://github.com/electron-userland/electron-builder/wiki/Options#artifact-file-name-pattern). Defaults to `${productName} Web Setup ${version}.${ext}`.
*/
readonly artifactName?: string | null
}

/*
### `squirrelWindows`
To use Squirrel.Windows please install `electron-builder-squirrel-windows` dependency.
To use Squirrel.Windows please install `electron-builder-squirrel-windows` dependency. Squirrel.Windows target is maintained, but deprecated. Please use `nsis` instead.
*/
export interface SquirrelWindowsOptions extends WinBuildOptions {
/*
Expand Down
8 changes: 4 additions & 4 deletions packages/electron-builder/src/targets/nsis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default class NsisTarget extends Target {
const appInfo = packager.appInfo
const version = appInfo.version
const options = this.options
const installerFilename = packager.expandArtifactNamePattern(options, "exe", null, "${productName} Setup ${version}.${ext}")
const installerFilename = packager.expandArtifactNamePattern(options, "exe", null, "${productName} " + (this.isWebInstaller ? "Web " : "") + "Setup ${version}.${ext}")
const iconPath = await packager.getResource(options.installerIcon, "installerIcon.ico") || await packager.getIconPath()
const oneClick = options.oneClick !== false

Expand Down Expand Up @@ -134,9 +134,9 @@ export default class NsisTarget extends Target {
throw new Error("Cannot compute app package download URL")
}

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

defines.APP_PACKAGE_URL_IS_INCOMLETE = null
Expand Down Expand Up @@ -172,7 +172,7 @@ export default class NsisTarget extends Target {
await subTask(`Executing makensis — installer`, this.executeMakensis(defines, commands, true, await this.computeScript(defines, commands, installerPath)))
await packager.sign(installerPath)

packager.dispatchArtifactCreated(installerPath, this, `${packager.appInfo.name}-Setup-${version}.exe`)
packager.dispatchArtifactCreated(installerPath, this, `${packager.appInfo.name}-${this.isWebInstaller ? "Web-" : ""}Setup-${version}.exe`)
}

private get isWebInstaller(): boolean {
Expand Down
27 changes: 19 additions & 8 deletions packages/electron-builder/templates/nsis/installSection.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -147,30 +147,41 @@ SetOutPath $INSTDIR
File /r "${APP_BUILD_DIR}/*.*"
!else
!ifdef APP_PACKAGE_URL
StrCpy $0 "${APP_PACKAGE_URL}"
Var /GLOBAL packageUrl
Var /GLOBAL packageArch

StrCpy $packageUrl "${APP_PACKAGE_URL}"
StrCpy $packageArch "${APP_PACKAGE_URL}"

!ifdef APP_PACKAGE_URL_IS_INCOMLETE
!ifdef APP_64_NAME
!ifdef APP_32_NAME
${if} ${RunningX64}
StrCpy $0 "$0/${APP_64_NAME}"
StrCpy $packageUrl "$packageUrl/${APP_64_NAME}"
${else}
StrCpy $0 "$0/${APP_32_NAME}"
StrCpy $packageUrl "$packageUrl/${APP_32_NAME}"
${endif}
!else
StrCpy $0 "$0/${APP_64_NAME}"
StrCpy $packageUrl "$packageUrl/${APP_64_NAME}"
!endif
!else
StrCpy $0 "$0/${APP_32_NAME}"
StrCpy $packageUrl "$packageUrl/${APP_32_NAME}"
!endif
!endif

${if} ${RunningX64}
StrCpy $packageArch "64"
${else}
StrCpy $packageArch "32"
${endif}

download:
inetc::get /RESUME "$0" "$PLUGINSDIR\package.7z"
pop $0
inetc::get /header "X-Arch: $packageArch" /RESUME "" "$packageUrl" "$PLUGINSDIR\package.7z" /END
Pop $0
${if} $0 == "Cancelled"
quit
${elseif} $0 != "OK"
messagebox MB_RETRYCANCEL|MB_ICONEXCLAMATION "Unable to download application package (status: $0).$\r$\n$\r$\nPlease check you Internet connection and retry." IDRETRY download
Messagebox MB_RETRYCANCEL|MB_ICONEXCLAMATION "Unable to download application package from $packageUrl (status: $0).$\r$\n$\r$\nPlease check you Internet connection and retry." IDRETRY download
quit
${endif}

Expand Down
4 changes: 2 additions & 2 deletions test/out/windows/__snapshots__/nsisTest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ Object {

exports[`test web installer 1`] = `
Array [
"Test App ßW Setup 1.1.0.exe",
"Test App ßW Web Setup 1.1.0.exe",
"TestApp-1.1.0-x64.nsis.7z",
]
`;

exports[`test web installer 2`] = `
Array [
"TestApp-Setup-1.1.0.exe",
"TestApp-Web-Setup-1.1.0.exe",
]
`;
4 changes: 2 additions & 2 deletions test/src/helpers/runTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ async function runTests() {
args.push(...baseForLinuxTests)
}
else if (circleNodeIndex === 2) {
args.push("snapTest", "nsisUpdaterTest", "linuxArchiveTest")
args.push("snapTest", "nsisUpdaterTest")
}
else {
args.push("windows.*")
args.push("windows.*", "linuxArchiveTest")
}
console.log(`Test files for node ${circleNodeIndex}: ${args.join(", ")}`)
}
Expand Down
1 change: 1 addition & 0 deletions test/src/windows/nsisTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ test.ifDevOrLinuxCi("file associations only perMachine", appThrows(/Please set p
test.ifNotCiMac("web installer", app({
targets: Platform.WINDOWS.createTarget(["nsis-web"], Arch.x64),
config: {
compression: process.env.COMPRESSION || "store",
publish: {
provider: "s3",
bucket: "develar",
Expand Down

0 comments on commit 7041b5d

Please sign in to comment.