Skip to content

Commit

Permalink
feat(electron-updater): full changelog for all versions from current …
Browse files Browse the repository at this point in the history
…to latest
  • Loading branch information
jonkofee authored and develar committed Oct 13, 2017
1 parent 8a31966 commit 67fe9ff
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 9 deletions.
10 changes: 9 additions & 1 deletion docs/auto-update.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ Emitted on progress. Only supported over Windows build, since `Squirrel.Mac` [do
**Extends**: <code>[EventEmitter](https://nodejs.org/api/events.html#events_class_eventemitter)</code>
**Properties**
* <code id="AppUpdater-autoDownload">autoDownload</code> = `true` Boolean - Whether to automatically download an update when it is found.
* <code id="AppUpdater-fullChangelog">fullChangelog</code> = `false` Boolean - Get all release notes, not just the last.
* <code id="AppUpdater-allowPrerelease">allowPrerelease</code> = `false` Boolean - *GitHub provider only.* Whether to allow update to pre-release versions. Defaults to `true` if application version contains prerelease components (e.g. `0.12.1-alpha.1`, here `alpha` is a prerelease component), otherwise `false`.
If `true`, downgrade will be allowed (`allowDowngrade` will be set to `true`).
Expand Down Expand Up @@ -255,7 +256,7 @@ This is different from the normal quit event sequence.
* **<code id="UpdateInfo-sha512">sha512</code>** String
* <code id="UpdateInfo-githubArtifactName">githubArtifactName</code> String
* <code id="UpdateInfo-releaseName">releaseName</code> String - The release name.
* <code id="UpdateInfo-releaseNotes">releaseNotes</code> String - The release notes.
* <code id="UpdateInfo-releaseNotes">releaseNotes</code> String | Array<[ReleaseNoteInfo](#ReleaseNoteInfo)> - The release notes.
* **<code id="UpdateInfo-releaseDate">releaseDate</code>** String - The release date.
* <code id="UpdateInfo-stagingPercentage">stagingPercentage</code> Number - The [staged rollout](auto-update.md#staged-rollouts) percentage, 0-100.
* **<code id="UpdateInfo-version">version</code>** String - The version.
Expand All @@ -266,6 +267,13 @@ This is different from the normal quit event sequence.
**Properties**
* **<code id="VersionInfo-version">version</code>** String - The version.
<a name="ReleaseNoteInfo"></a>
### `ReleaseNoteInfo`
**Kind**: interface of [<code>electron-updater</code>](#module_electron-updater)<br/>
**Properties**
* **<code id="ReleaseNoteInfo-version">version</code>** String - The version.
* **<code id="ReleaseNoteInfo-note">note</code>** String | null - The note.
<a name="UpdateCheckResult"></a>
### `UpdateCheckResult`
**Kind**: interface of [<code>electron-updater</code>](#module_electron-updater)<br/>
Expand Down
2 changes: 1 addition & 1 deletion packages/builder-util-runtime/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export { CancellationToken, CancellationError } from "./CancellationToken"
export { HttpError, HttpExecutor, DownloadOptions, DigestTransform, RequestHeaders, safeGetHeader, configureRequestOptions, configureRequestOptionsFromUrl, safeStringifyJson, parseJson } from "./httpExecutor"
export { BintrayOptions, GenericServerOptions, GithubOptions, PublishConfiguration, S3Options, SpacesOptions, BaseS3Options, getS3LikeProviderBaseUrl, Publish, githubUrl, PublishProvider, AllPublishOptions } from "./publishOptions"
export { UpdateInfo, WindowsUpdateInfo, AppImageUpdateInfo, BlockMapDataHolder, VersionInfo, PackageFileInfo } from "./updateInfo"
export { UpdateInfo, WindowsUpdateInfo, AppImageUpdateInfo, BlockMapDataHolder, VersionInfo, PackageFileInfo, ReleaseNoteInfo } from "./updateInfo"
export { parseDn } from "./rfc2253Parser"
export { UUID } from "./uuid"
export { ProgressCallbackTransform, ProgressInfo } from "./ProgressCallbackTransform"
16 changes: 14 additions & 2 deletions packages/builder-util-runtime/src/updateInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ export interface VersionInfo {
readonly version: string
}

export interface ReleaseNoteInfo {
/**
* The version.
*/
readonly version: string

/**
* The note.
*/
readonly note: string | null
}

export interface BlockMapDataHolder {
size: number
blockMapSize: number
Expand Down Expand Up @@ -35,7 +47,7 @@ export interface UpdateInfo extends VersionInfo {
/**
* The release notes.
*/
readonly releaseNotes?: string | null
releaseNotes?: string | Array<ReleaseNoteInfo> | null

/**
* The release date.
Expand All @@ -60,4 +72,4 @@ export interface WindowsUpdateInfo extends UpdateInfo {
* @private
*/
sha2?: string
}
}
13 changes: 11 additions & 2 deletions packages/electron-updater/src/AppUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,23 @@ export abstract class AppUpdater extends EventEmitter {
*/
allowPrerelease = false

/**
* *GitHub provider only.* Get all release notes, not just the last
* @default false
*/
fullChangelog = false

/**
* Whether to allow version downgrade (when a user from the beta channel wants to go back to the stable channel).
* @default false
*/
allowDowngrade = false

/**
* Current version Electron application
*/
currentVersion: string

/**
* The request headers.
*/
Expand Down Expand Up @@ -90,8 +101,6 @@ export abstract class AppUpdater extends EventEmitter {
protected versionInfo: VersionInfo | null
private fileInfo: FileInfo | null

private currentVersion: string

protected readonly httpExecutor: ElectronHttpExecutor

constructor(options: AllPublishOptions | null | undefined, app?: any) {
Expand Down
26 changes: 23 additions & 3 deletions packages/electron-updater/src/GitHubProvider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { CancellationToken, GithubOptions, githubUrl, HttpError, HttpExecutor, UpdateInfo, WindowsUpdateInfo } from "builder-util-runtime"
import { CancellationToken, GithubOptions, githubUrl, HttpError, HttpExecutor, UpdateInfo, ReleaseNoteInfo, WindowsUpdateInfo } from "builder-util-runtime"
import { safeLoad } from "js-yaml"
import * as path from "path"
import * as semver from "semver"
import { URL } from "url"
import { AppUpdater } from "./AppUpdater"
import { FileInfo, getChannelFilename, getDefaultChannelName, isUseOldMacProvider, newBaseUrl, newUrlFromBase, Provider } from "./main"
Expand Down Expand Up @@ -92,7 +93,26 @@ export class GitHubProvider extends BaseGitHubProvider<UpdateInfo> {
(result as any).releaseName = latestRelease.getElementValue("title")
}
if (result.releaseNotes == null) {
(result as any).releaseNotes = latestRelease.getElementValue("content")
if (this.updater.fullChangelog) {
const currentVersion = this.updater.currentVersion
const allReleases = feed.getElements("entry")
const releaseNotes: Array<ReleaseNoteInfo> = []

for (const release of allReleases) {
const versionRelease = release.element("link").getAttr("href").match(/\/tag\/v?([^\/]+)$/)[1]

if (semver.lt(currentVersion, versionRelease)) {
releaseNotes.push({
version: versionRelease,
note: release.getElementValue("content")
})
}
}

result.releaseNotes = releaseNotes
} else {
(result as any).releaseNotes = latestRelease.getElementValue("content")
}
}
return result
}
Expand Down Expand Up @@ -149,4 +169,4 @@ export class GitHubProvider extends BaseGitHubProvider<UpdateInfo> {

interface GithubReleaseInfo {
readonly tag_name: string
}
}

0 comments on commit 67fe9ff

Please sign in to comment.