Skip to content

Commit

Permalink
feat: ${os} and ${arch} in publish.url
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Feb 1, 2017
1 parent e5d58e2 commit ec3b2f3
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 63 deletions.
22 changes: 11 additions & 11 deletions docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ Don't customize paths to background and icon, — just follow conventions.
* [protocols URL Protocol Schemes](#Protocol)
* [squirrelWindows](#SquirrelWindowsOptions)
* [win Windows Specific Options](#WinBuildOptions)
* [dmg.window DMG Windows Position and Size](#DmgWindow)
* [snap [Snap](http://snapcraft.io) Specific Options](#SnapOptions)
* [appImage [AppImage](http://appimage.org) Specific Options](#AppImageOptions)
* [dmg.window DMG Windows Position and Size](#DmgWindow)
* [Fields in the package.json](#Metadata)

<a name="Config"></a>
Expand Down Expand Up @@ -219,15 +219,6 @@ To use Squirrel.Windows please install `electron-builder-squirrel-windows` depen
| rfc3161TimeStampServer | <a name="WinBuildOptions-rfc3161TimeStampServer"></a>The URL of the RFC 3161 time stamp server. Defaults to `http://timestamp.comodoca.com/rfc3161`.
| timeStampServer | <a name="WinBuildOptions-timeStampServer"></a>The URL of the time stamp server. Defaults to `http://timestamp.verisign.com/scripts/timstamp.dll`.

<a name="DmgWindow"></a>
### `dmg.window` DMG Windows Position and Size
| Name | Description
| --- | ---
| x | <a name="DmgWindow-x"></a>The X position relative to left of the screen. Defaults to 400.
| y | <a name="DmgWindow-y"></a>The Y position relative to top of the screen. Defaults to 100.
| width | <a name="DmgWindow-width"></a>* The width. Defaults to background image width or 540.
| height | <a name="DmgWindow-height"></a>* The height. Defaults to background image height or 380.

<a name="SnapOptions"></a>
### `snap` [Snap](http://snapcraft.io) Specific Options
| Name | Description
Expand All @@ -245,6 +236,15 @@ To use Squirrel.Windows please install `electron-builder-squirrel-windows` depen
| --- | ---
| includeRequiredLib | <a name="AppImageOptions-includeRequiredLib"></a>Whether to include required system libraries (`gconf2`, `libappindicator1`). Defaults to `false`.

<a name="DmgWindow"></a>
### `dmg.window` DMG Windows Position and Size
| Name | Description
| --- | ---
| x | <a name="DmgWindow-x"></a>The X position relative to left of the screen. Defaults to 400.
| y | <a name="DmgWindow-y"></a>The Y position relative to top of the screen. Defaults to 100.
| width | <a name="DmgWindow-width"></a>* The width. Defaults to background image width or 540.
| height | <a name="DmgWindow-height"></a>* The height. Defaults to background image height or 380.

<a name="Metadata"></a>
## Fields in the package.json

Expand Down Expand Up @@ -274,7 +274,7 @@ Some standard fields should be defined in the `package.json`.

Development dependencies are never copied in any case. You don't need to ignore it explicitly.

[Multiple patterns](#multiple-glob-patterns) are supported. You can use `${os}` (expanded to mac, linux or win according to current platform) and `${arch}` in the pattern.
[Multiple patterns](#multiple-glob-patterns) are supported. You can use `${os}` (expanded to `mac`, `linux` or `win` according to current platform) and `${arch}` in the pattern.
If directory matched, all contents are copied. So, you can just specify `foo` to copy `foo` directory.

Remember that default pattern `**/*` **is not added to your custom** if some of your patterns is not ignore (i.e. not starts with `!`).
Expand Down
2 changes: 1 addition & 1 deletion docs/Publishing Artifacts.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Amazon S3 — `https` must be used, so, if you use direct Amazon S3 endpoints, f
### `publish` Generic (any https server)
| Name | Description
| --- | ---
| **url** | <a name="GenericServerOptions-url"></a>The base url. e.g. `https://s3.amazonaws.com/bucket_name`
| **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 current platform) and `${arch}` macros.
| channel | <a name="GenericServerOptions-channel"></a>The channel. Defaults to `latest`.

<a name="GithubOptions"></a>
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-builder-http/src/publishOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface PublishConfiguration {
*/
export interface GenericServerOptions extends PublishConfiguration {
/*
The base url. e.g. `https://s3.amazonaws.com/bucket_name`
The base url. e.g. `https://s3.amazonaws.com/bucket_name`. You can use `${os}` (expanded to `mac`, `linux` or `win` according to current platform) and `${arch}` macros.
*/
url: string

Expand Down
18 changes: 7 additions & 11 deletions packages/electron-builder/src/fileMatcher.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
import * as path from "path"
import { createFilter, hasMagic } from "./util/filter"
import { Minimatch } from "minimatch"
import { asArray } from "electron-builder-util"
import BluebirdPromise from "bluebird-lst-c"
import { statOrNull, copyDir, copyFile, Filter } from "electron-builder-util/out/fs"
import { asArray } from "electron-builder-util"
import { copyDir, copyFile, Filter, statOrNull } from "electron-builder-util/out/fs"
import { warn } from "electron-builder-util/out/log"
import { mkdirs } from "fs-extra-p"

export interface FileMatchOptions {
arch: string,
os: string
}
import { Minimatch } from "minimatch"
import * as path from "path"
import { Macros } from "./metadata"
import { createFilter, hasMagic } from "./util/filter"

export class FileMatcher {
readonly from: string
readonly to: string

readonly patterns: Array<string>

constructor(from: string, to: string, private options: FileMatchOptions, patterns?: Array<string> | string | n) {
constructor(from: string, to: string, private options: Macros, patterns?: Array<string> | string | n) {
this.from = this.expandPattern(from)
this.to = this.expandPattern(to)
this.patterns = asArray(patterns).map(it => path.posix.normalize(it))
Expand Down
14 changes: 10 additions & 4 deletions packages/electron-builder/src/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { PlatformPackager } from "./platformPackager"
import { MacOptions, DmgOptions, MasBuildOptions } from "./options/macOptions"
import { Arch, Platform } from "electron-builder-core"
import { Publish } from "electron-builder-http/out/publishOptions"
import { WinBuildOptions, NsisOptions, SquirrelWindowsOptions, AppXOptions } from "./options/winOptions"
import { LinuxBuildOptions, SnapOptions } from "./options/linuxOptions"
import { Platform } from "electron-builder-core"
import { DmgOptions, MacOptions, MasBuildOptions } from "./options/macOptions"
import { AppXOptions, NsisOptions, SquirrelWindowsOptions, WinBuildOptions } from "./options/winOptions"
import { PlatformPackager } from "./platformPackager"

export interface AsarOptions {
dot?: boolean
Expand Down Expand Up @@ -222,6 +222,7 @@ export interface AfterPackContext {
readonly appOutDir: string
readonly packager: PlatformPackager<any>
readonly electronPlatformName: string
readonly arch: Arch
}

export interface BeforeBuildContext {
Expand Down Expand Up @@ -332,4 +333,9 @@ export interface PlatformSpecificBuildOptions {
readonly publish?: Publish

readonly forceCodeSigning?: boolean
}

export interface Macros {
os: string
arch: string
}
27 changes: 14 additions & 13 deletions packages/electron-builder/src/platformPackager.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { PlatformSpecificBuildOptions, FileAssociation, Config, AsarOptions, FilePattern } from "./metadata"
import BluebirdPromise from "bluebird-lst-c"
import * as path from "path"
import { Arch, getArchSuffix, Platform, Target } from "electron-builder-core"
import { asArray, debug, isEmptyOrSpaces, use } from "electron-builder-util"
import { deepAssign } from "electron-builder-util/out/deepAssign"
import { copyDir, statOrNull, unlinkIfExists } from "electron-builder-util/out/fs"
import { log, warn } from "electron-builder-util/out/log"
import { readdir, remove, rename } from "fs-extra-p"
import { use, isEmptyOrSpaces, asArray, debug } from "electron-builder-util"
import { Minimatch } from "minimatch"
import { checkFileInArchive, createAsarArchive } from "./asarUtil"
import { warn, log } from "electron-builder-util/out/log"
import * as path from "path"
import { AppInfo } from "./appInfo"
import { checkFileInArchive, createAsarArchive } from "./asarUtil"
import { copyFiles, deprecatedUserIgnoreFilter, FileMatcher } from "./fileMatcher"
import { AsarOptions, Config, FileAssociation, FilePattern, Macros, PlatformSpecificBuildOptions } from "./metadata"
import { unpackElectron } from "./packager/dirPackager"
import { FileMatchOptions, FileMatcher, deprecatedUserIgnoreFilter, copyFiles } from "./fileMatcher"
import { deepAssign } from "electron-builder-util/out/deepAssign"
import { statOrNull, unlinkIfExists, copyDir } from "electron-builder-util/out/fs"
import { Arch, Target, getArchSuffix, Platform } from "electron-builder-core"
import { BuildInfo, PackagerOptions } from "./packagerApi"
import { readInstalled } from "./readInstalled"
import { PackagerOptions, BuildInfo } from "./packagerApi"

export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions> {
readonly packagerOptions: PackagerOptions
Expand Down Expand Up @@ -104,7 +104,7 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
.then(() => BluebirdPromise.each(targets, it => it.isAsyncSupported ? null : it.build(appOutDir, arch))))
}

private getExtraFileMatchers(isResources: boolean, appOutDir: string, fileMatchOptions: FileMatchOptions, customBuildOptions: DC): Array<FileMatcher> | null {
private getExtraFileMatchers(isResources: boolean, appOutDir: string, fileMatchOptions: Macros, customBuildOptions: DC): Array<FileMatcher> | null {
const base = isResources ? this.getResourcesDir(appOutDir) : (this.platform === Platform.MAC ? path.join(appOutDir, `${this.appInfo.productFilename}.app`, "Contents") : appOutDir)
return this.getFileMatchers(isResources ? "extraResources" : "extraFiles", this.projectDir, base, true, fileMatchOptions, customBuildOptions)
}
Expand All @@ -115,7 +115,7 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
}

const asarOptions = await this.computeAsarOptions(platformSpecificBuildOptions)
const fileMatchOptions: FileMatchOptions = {
const fileMatchOptions: Macros = {
arch: Arch[arch],
os: this.platform.buildConfigurationKey
}
Expand Down Expand Up @@ -220,6 +220,7 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
appOutDir: appOutDir,
packager: this,
electronPlatformName: platformName,
arch: arch,
})
await this.sanityCheckPackage(appOutDir, asarOptions != null)
}
Expand Down Expand Up @@ -272,7 +273,7 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
return deepAssign({}, result, defaultOptions)
}

private getFileMatchers(name: "files" | "extraFiles" | "extraResources" | "asarUnpack", defaultSrc: string, defaultDest: string, allowAdvancedMatching: boolean, fileMatchOptions: FileMatchOptions, customBuildOptions: DC): Array<FileMatcher> | null {
private getFileMatchers(name: "files" | "extraFiles" | "extraResources" | "asarUnpack", defaultSrc: string, defaultDest: string, allowAdvancedMatching: boolean, fileMatchOptions: Macros, customBuildOptions: DC): Array<FileMatcher> | null {
const globalPatterns: Array<string | FilePattern> | string | n | FilePattern = (<any>this.config)[name]
const platformSpecificPatterns: Array<string | FilePattern> | string | n = (<any>customBuildOptions)[name]

Expand Down
49 changes: 30 additions & 19 deletions packages/electron-builder/src/publish/PublishManager.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { Packager } from "../packager"
import { PlatformPackager } from "../platformPackager"
import { debug, isEmptyOrSpaces, asArray} from "electron-builder-util"
import { Publisher, PublishOptions, getResolvedPublishConfig, getCiTag } from "./publisher"
import BluebirdPromise from "bluebird-lst-c"
import { GitHubPublisher } from "./gitHubPublisher"
import { PublishConfiguration, GithubOptions, BintrayOptions, GenericServerOptions, VersionInfo, UpdateInfo } from "electron-builder-http/out/publishOptions"
import { createHash } from "crypto"
import { Platform, Arch } from "electron-builder-core"
import { BintrayOptions, GenericServerOptions, GithubOptions, PublishConfiguration, UpdateInfo, VersionInfo } from "electron-builder-http/out/publishOptions"
import { asArray, debug, isEmptyOrSpaces } from "electron-builder-util"
import { log } from "electron-builder-util/out/log"
import { BintrayPublisher } from "./BintrayPublisher"
import { BuildInfo, ArtifactCreated } from "../packagerApi"
import { Platform } from "electron-builder-core"
import { safeDump } from "js-yaml"
import { writeFile, outputJson, createReadStream } from "fs-extra-p"
import * as path from "path"
import { ArchiveTarget } from "../targets/ArchiveTarget"
import { throwError } from "electron-builder-util/out/promise"
import { createReadStream, outputJson, writeFile } from "fs-extra-p"
import isCi from "is-ci"
import { safeDump } from "js-yaml"
import * as path from "path"
import * as url from "url"
import { PlatformSpecificBuildOptions } from "../metadata"
import { createHash } from "crypto"
import { Macros, PlatformSpecificBuildOptions } from "../metadata"
import { Packager } from "../packager"
import { ArtifactCreated, BuildInfo } from "../packagerApi"
import { PlatformPackager } from "../platformPackager"
import { ArchiveTarget } from "../targets/ArchiveTarget"
import { BintrayPublisher } from "./BintrayPublisher"
import { GitHubPublisher } from "./gitHubPublisher"
import { getCiTag, getResolvedPublishConfig, Publisher, PublishOptions } from "./publisher"

export class PublishManager {
private readonly nameToPublisher = new Map<string, Publisher | null>()
Expand Down Expand Up @@ -68,7 +68,11 @@ export class PublishManager {
return
}

await writeFile(path.join(packager.getResourcesDir(event.appOutDir), "app-update.yml"), safeDump(publishConfigs[0]))
let publishConfig = publishConfigs[0]
if ((<GenericServerOptions>publishConfig).url != null) {
publishConfig = Object.assign({}, publishConfig, {url: expandPattern((<GenericServerOptions>publishConfig).url, {os: packager.platform.buildConfigurationKey, arch: Arch[Arch.x64]})})
}
await writeFile(path.join(packager.getResourcesDir(event.appOutDir), "app-update.yml"), safeDump(publishConfig))
})

packager.artifactCreated(event => this.addTask(this.artifactCreated(event)))
Expand Down Expand Up @@ -191,7 +195,7 @@ async function writeUpdateInfo(event: ArtifactCreated, _publishConfigs: Array<Pu
const updateInfoFile = isGitHub ? path.join(outDir, "github", `${channel}-mac.json`) : path.join(outDir, `${channel}-mac.json`)
await (<any>outputJson)(updateInfoFile, <VersionInfo>{
version: version,
url: computeDownloadUrl(publishConfig, packager.generateName2("zip", "mac", isGitHub), version)
url: computeDownloadUrl(publishConfig, packager.generateName2("zip", "mac", isGitHub), version, {os: Platform.MAC.buildConfigurationKey, arch: Arch[Arch.x64]})
}, {spaces: 2})

packager.info.dispatchArtifactCreated({
Expand Down Expand Up @@ -261,9 +265,9 @@ function isAuthTokenSet() {
return !isEmptyOrSpaces(process.env.GH_TOKEN) || !isEmptyOrSpaces(process.env.BT_TOKEN)
}

function computeDownloadUrl(publishConfig: PublishConfiguration, fileName: string, version: string) {
function computeDownloadUrl(publishConfig: PublishConfiguration, fileName: string, version: string, macros: Macros) {
if (publishConfig.provider === "generic") {
const baseUrl = url.parse((<GenericServerOptions>publishConfig).url)
const baseUrl = url.parse(expandPattern((<GenericServerOptions>publishConfig).url, macros))
return url.format(Object.assign({}, baseUrl, {pathname: path.posix.resolve(baseUrl.pathname || "/", encodeURI(fileName))}))
}
else {
Expand All @@ -272,6 +276,13 @@ function computeDownloadUrl(publishConfig: PublishConfiguration, fileName: strin
}
}

function expandPattern(pattern: string, macros: Macros): string {
return pattern
.replace(/\$\{os}/g, macros.os)
.replace(/\$\{arch}/g, macros.arch)
}


export function getPublishConfigs(packager: PlatformPackager<any>, targetSpecificOptions: PlatformSpecificBuildOptions | null | undefined, errorIfCannot: boolean): Promise<Array<PublishConfiguration>> | null {
let publishers

Expand Down
2 changes: 1 addition & 1 deletion test/out/mac/__snapshots__/macPackagerTest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Array [

exports[`test one-package 3`] = `
Object {
"url": "https://develar.s3.amazonaws.com/test/Test%20App%20%C3%9FW-1.1.0-mac.zip",
"url": "https://develar.s3.amazonaws.com/test/mac/x64/Test%20App%20%C3%9FW-1.1.0-mac.zip",
"version": "1.1.0",
}
`;
Expand Down
2 changes: 1 addition & 1 deletion test/src/mac/macPackagerTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test.ifMac("one-package", app({
config: {
publish: {
provider: "generic",
url: "https://develar.s3.amazonaws.com/test",
url: "https://develar.s3.amazonaws.com/test/${os}/${arch}",
},
mac: {
fileAssociations: [
Expand Down
2 changes: 1 addition & 1 deletion test/src/windows/nsisTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ test.ifDevOrLinuxCi("perMachine, no run after finish", app({
},
publish: {
provider: "generic",
url: "https://develar.s3.amazonaws.com/test",
url: "https://develar.s3.amazonaws.com/test/${os}/${arch}",
},
},
}, {
Expand Down

0 comments on commit ec3b2f3

Please sign in to comment.