Skip to content

Commit

Permalink
WIP(nsis): NSIS web installer electron-userland#1207
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Feb 9, 2017
1 parent 2eb1298 commit 84bb4d8
Show file tree
Hide file tree
Showing 13 changed files with 322 additions and 135 deletions.
18 changes: 9 additions & 9 deletions docs/Auto Update.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,18 @@ Emitted when checking if an update has started.

#### Event: `update-available`

* `info` [UpdateInfo](#updateinfo) for generic and github providers. [VersionInfo](#versioninfo) for Bintray provider.
* `info` [UpdateInfo](#updateinfo) (for generic and github providers) | [VersionInfo](#versioninfo) (for Bintray provider)

Emitted when there is an available update. The update is downloaded automatically if `autoDownload` is `true`.

#### Event: `update-not-available`

Emitted when there is no available update.

* `info` [UpdateInfo](#updateinfo) for generic and github providers. [VersionInfo](#versioninfo) for Bintray provider.
* `info` [UpdateInfo](#updateinfo) (for generic and github providers) | [VersionInfo](#versioninfo) (for Bintray provider)

#### Event: `download-progress`
* `progressObj` - it's object with properties:
* `progress` ProgressInfo
* `bytesPerSecond`
* `percent`
* `total`
Expand All @@ -90,7 +90,7 @@ Emitted on progress. Only supported over Windows build, since `Squirrel.Mac` [do

#### Event: `update-downloaded`

* `info` [UpdateInfo](#updateinfo) for generic and github providers. [VersionInfo](#versioninfo) for Bintray provider.
* `info` [UpdateInfo](#updateinfo) for generic and github providers. [VersionInfo](#versioninfo) for Bintray provider.

Emitted when an update has been downloaded.

Expand All @@ -100,7 +100,7 @@ The `autoUpdater` object has the following methods:

#### `autoUpdater.setFeedURL(options)`

* `options` GenericServerOptions | BintrayOptions | GithubOptions | string — if you want to override configuration in the `app-update.yml`.
* `options` GenericServerOptions | S3Options | BintrayOptions | GithubOptions | string — if you want to override configuration in the `app-update.yml`.

Sets the `options`. If value is `string`, `GenericServerOptions` will be set with value as `url`.

Expand All @@ -118,13 +118,13 @@ This is different from the normal quit event sequence.

### VersionInfo

* `version` The version.
* `version` string — The version.

### UpdateInfo

Extends [VersionInfo](#versioninfo).

* `releaseDate` The release date.
* `releaseName?` The release name.
* `releaseNotes?` The release notes.
* `releaseDate` string — The release date.
* `releaseName` string (optional) — The release name.
* `releaseNotes` string (optional) — The release notes.

3 changes: 2 additions & 1 deletion docs/Publishing Artifacts.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ Amazon S3 — `https` must be used, so, if you use direct Amazon S3 endpoints, f

| Name | Description
| --- | ---
| bucket | <a name="S3Options-bucket"></a>The bucket name.
| **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`.
Expand Down
4 changes: 2 additions & 2 deletions packages/electron-builder-http/src/httpExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createWriteStream } from "fs-extra-p"
import { RequestOptions } from "http"
import { parse as parseUrl } from "url"
import _debug from "debug"
import { ProgressCallbackTransform } from "./ProgressCallbackTransform"
import { ProgressCallbackTransform, ProgressInfo } from "./ProgressCallbackTransform"
import { safeLoad } from "js-yaml"
import { EventEmitter } from "events"
import { Socket } from "net"
Expand All @@ -30,7 +30,7 @@ export interface DownloadOptions {

readonly cancellationToken: CancellationToken

onProgress?(progress: any): void
onProgress?(progress: ProgressInfo): void
}

export class HttpExecutorHolder {
Expand Down
15 changes: 14 additions & 1 deletion packages/electron-builder-http/src/publishOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ export interface S3Options extends PublishConfiguration {
/*
The bucket name.
*/
bucket?: string
bucket: string

/*
The directory path. Defaults to `/`.
*/
path?: string | null

/**
The channel. Defaults to `latest`.
Expand All @@ -73,6 +78,14 @@ export interface S3Options extends PublishConfiguration {
secret?: string | null
}

export function s3Url(options: S3Options) {
let url = `https://s3.amazonaws.com/${options.bucket}`
if (options.path != null) {
url += `/${options.path}`
}
return url
}

export interface VersionInfo {
readonly version: string
}
Expand Down
9 changes: 9 additions & 0 deletions packages/electron-builder/src/options/winOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,15 @@ export interface NsisOptions {
readonly artifactName?: string | null
}

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).
*/
readonly appPackageUrl?: string | null
}

/*
### `squirrelWindows`
Expand Down
27 changes: 19 additions & 8 deletions packages/electron-builder/src/publish/PublishManager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import BluebirdPromise from "bluebird-lst-c"
import { createHash } from "crypto"
import { Arch, Platform } from "electron-builder-core"
import { GenericServerOptions, GithubOptions, PublishConfiguration, S3Options, UpdateInfo, VersionInfo } from "electron-builder-http/out/publishOptions"
import { GenericServerOptions, GithubOptions, PublishConfiguration, S3Options, UpdateInfo, VersionInfo, s3Url } from "electron-builder-http/out/publishOptions"
import { asArray, debug, isEmptyOrSpaces } from "electron-builder-util"
import { log } from "electron-builder-util/out/log"
import { throwError } from "electron-builder-util/out/promise"
Expand Down Expand Up @@ -172,7 +172,7 @@ export class PublishManager implements PublishContext {
}
}

async function getPublishConfigsForUpdateInfo(packager: PlatformPackager<any>, publishConfigs: Array<PublishConfiguration> | null): Promise<Array<PublishConfiguration> | null> {
export async function getPublishConfigsForUpdateInfo(packager: PlatformPackager<any>, publishConfigs: Array<PublishConfiguration> | null): Promise<Array<PublishConfiguration> | null> {
if (publishConfigs === null) {
return null
}
Expand Down Expand Up @@ -281,19 +281,30 @@ export function createPublisher(context: PublishContext, version: string, publis
return null
}

function computeDownloadUrl(publishConfig: PublishConfiguration, fileName: string, version: string, macros: Macros) {
export function computeDownloadUrl(publishConfig: PublishConfiguration, fileName: string | null, version: string, macros: Macros) {
if (publishConfig.provider === "generic") {
const baseUrl = url.parse(expandPattern((<GenericServerOptions>publishConfig).url, macros))
const baseUrlString = expandPattern((<GenericServerOptions>publishConfig).url, macros)
if (fileName == null) {
return baseUrlString
}

const baseUrl = url.parse(baseUrlString)
return url.format(Object.assign({}, baseUrl, {pathname: path.posix.resolve(baseUrl.pathname || "/", encodeURI(fileName))}))
}
else if (publishConfig.provider === "s3") {
const bucket = (<S3Options>publishConfig).bucket
return `https://s3.amazonaws.com/${bucket}/${fileName}`

let baseUrl
if (publishConfig.provider === "s3") {
baseUrl = s3Url((<S3Options>publishConfig))
}
else {
const gh = <GithubOptions>publishConfig
return `https://github.com${`/${gh.owner}/${gh.repo}/releases`}/download/v${version}/${encodeURI(fileName)}`
baseUrl = `https://github.com${`/${gh.owner}/${gh.repo}/releases`}/download/v${version}`
}

if (fileName == null) {
return baseUrl
}
return `${baseUrl}/${encodeURI(fileName)}`
}

function expandPattern(pattern: string, macros: Macros): string {
Expand Down
Loading

0 comments on commit 84bb4d8

Please sign in to comment.