Skip to content

Commit

Permalink
feat: add channel to file macros
Browse files Browse the repository at this point in the history
Close #1701
  • Loading branch information
develar committed Jun 24, 2017
1 parent af2f559 commit 6aa3809
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 10 deletions.
1 change: 1 addition & 0 deletions docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ You can use macros in the file patterns, artifact file name patterns and publish
* `${name}` – `package.json` `name`.
* `${productName}` — [Sanitized](https://www.npmjs.com/package/sanitize-filename) product name.
* `${version}`
* `${channel}` — detected prerelease component from version (e.g. `beta`).
* `${env.ENV_NAME}` — any environment variable.
* Any property of [AppInfo](https://github.com/electron-userland/electron-builder/wiki/electron-builder#AppInfo) (e.g. `buildVersion`, `buildNumber`).

Expand Down
10 changes: 9 additions & 1 deletion packages/electron-builder/src/appInfo.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isEmptyOrSpaces, smarten, warn } from "electron-builder-util"
import sanitizeFileName from "sanitize-filename"
import { SemVer } from "semver"
import { prerelease, SemVer } from "semver"
import { BuildInfo } from "./packagerApi"

export class AppInfo {
Expand Down Expand Up @@ -32,6 +32,14 @@ export class AppInfo {
this.productFilename = sanitizeFileName(this.productName)
}

get channel(): string | null {
const prereleaseInfo = prerelease(this.version)
if (prereleaseInfo != null && prereleaseInfo.length > 0) {
return prereleaseInfo[0]
}
return null
}

get versionInWeirdWindowsForm(): string {
const parsedVersion = new SemVer(this.version)
return `${parsedVersion.major}.${parsedVersion.minor}.${parsedVersion.patch}.${this.buildNumber || "0"}`
Expand Down
6 changes: 1 addition & 5 deletions packages/electron-builder/src/publish/PublishManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { ensureDir, outputJson, readFile, writeFile } from "fs-extra-p"
import isCi from "is-ci"
import { safeDump } from "js-yaml"
import * as path from "path"
import { prerelease } from "semver"
import { WriteStream as TtyWriteStream } from "tty"
import * as url from "url"
import { Arch, Platform, Target } from "../core"
Expand Down Expand Up @@ -466,10 +465,7 @@ async function getResolvedPublishConfig(packager: PlatformPackager<any>, options

let channelFromAppVersion: string | null = null
if ((<any>options).channel == null && packager.config.detectUpdateChannel !== false) {
const prereleaseInfo = prerelease(packager.appInfo.version)
if (prereleaseInfo != null && prereleaseInfo.length > 0) {
channelFromAppVersion = prereleaseInfo[0]
}
channelFromAppVersion = packager.appInfo.channel
}

const provider = options.provider
Expand Down
3 changes: 1 addition & 2 deletions packages/electron-updater/src/MacUpdater.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import BluebirdPromise from "bluebird-lst"
import { CancellationToken, configureRequestOptions, DigestTransform, ProgressCallbackTransform, safeGetHeader } from "electron-builder-http"
import { CancellationToken, configureRequestOptions, DigestTransform, ProgressCallbackTransform, RequestHeaders, safeGetHeader } from "electron-builder-http"
import { PublishConfiguration } from "electron-builder-http/out/publishOptions"
import { VersionInfo } from "electron-builder-http/out/updateInfo"
import { createServer, IncomingMessage, ServerResponse } from "http"
import { parse as parseUrl } from "url"
import { AppUpdater } from "./AppUpdater"
import { DOWNLOAD_PROGRESS, FileInfo, UPDATE_DOWNLOADED } from "./main"
import AutoUpdater = Electron.AutoUpdater
import { RequestHeaders } from "../../electron-builder-http/src/httpExecutor"

export class MacUpdater extends AppUpdater {
private readonly nativeUpdater: AutoUpdater = require("electron").autoUpdater
Expand Down
4 changes: 2 additions & 2 deletions test/out/__snapshots__/ExtraBuildTest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Object {
},
Object {
"arch": 0,
"file": "Test App ßW Setup 1.0.0-beta.1.exe",
"file": "beta-TestApp.exe",
"safeArtifactName": "TestApp-Setup-1.0.0-beta.1.exe",
},
],
Expand All @@ -69,7 +69,7 @@ Object {
exports[`override targets in the config - only arch 3`] = `
Object {
"githubArtifactName": "TestApp-Setup-1.0.0-beta.1.exe",
"path": "Test App ßW Setup 1.0.0-beta.1.exe",
"path": "beta-TestApp.exe",
"version": "1.0.0-beta.1",
}
`;
Expand Down
1 change: 1 addition & 0 deletions test/src/ExtraBuildTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ test.ifAll.ifDevOrWinCi("override targets in the config - only arch", app({
},
// https://github.com/electron-userland/electron-builder/issues/1348
win: {
artifactName: "${channel}-${name}.exe",
target: [
"nsis",
],
Expand Down

0 comments on commit 6aa3809

Please sign in to comment.