Skip to content

Commit

Permalink
feat: bintray publisher configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Oct 8, 2016
1 parent 96d9206 commit 1a9caa8
Show file tree
Hide file tree
Showing 18 changed files with 190 additions and 87 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ A complete solution to package and build a ready for distribution Electron app f
* [Auto Update](#auto-update) ready application packaging.
* [Build version management](https://github.com/electron-userland/electron-builder/wiki/Options#build-version-management).
* Numerous target formats:
* All platforms: `7z`, `zip`, `tar.xz`, `tar.lz`, `tar.gz`, `tar.bz2`.
* All platforms: `7z`, `zip`, `tar.xz`, `tar.lz`, `tar.gz`, `tar.bz2`, `dir` (unpacked directory).
* [MacOS](https://github.com/electron-userland/electron-builder/wiki/Options#MacOptions-target): `dmg`, `mas`.
* [Linux](https://github.com/electron-userland/electron-builder/wiki/Options#LinuxBuildOptions-target): `AppImage`, `deb`, `rpm`, `freebsd`, `pacman`, `p5p`, `apk`.
* [Windows](https://github.com/electron-userland/electron-builder/wiki/Options#WinBuildOptions-target): NSIS, Squirrel.Windows.
Expand Down
38 changes: 34 additions & 4 deletions docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ Don't customize paths to background and icon, — just follow conventions.
* [.build.mas](#MasBuildOptions)
* [.build.nsis](#NsisOptions)
* [.build.protocols](#Protocol)
* [.build.publish](#PublishConfiguration)
* [.build.publish Bintray](#BintrayOptions)
* [.build.publish GitHub](#GithubOptions)
* [.build.squirrelWindows](#SquirrelWindowsOptions)
* [.build.win](#WinBuildOptions)
* [.directories](#MetadataDirectories)
Expand Down Expand Up @@ -82,6 +85,7 @@ Don't customize paths to background and icon, — just follow conventions.
| npmSkipBuildFromSource | <a name="BuildMetadata-npmSkipBuildFromSource"></a>*two package.json structure only* Whether to omit using [--build-from-source](https://github.com/mapbox/node-pre-gyp#options) flag when installing app native deps. Defaults to `false`.
| nodeGypRebuild | <a name="BuildMetadata-nodeGypRebuild"></a>Whether to execute `node-gyp rebuild` before starting to package the app. Defaults to `false`.
| electronDist | <a name="BuildMetadata-electronDist"></a>The path to custom Electron build (e.g. `~/electron/out/R`). Only macOS supported, file issue if need for Linux or Windows.
| publish | <a name="BuildMetadata-publish"></a>See [.build.publish](#publish).

<a name="DmgOptions"></a>
### `.build.dmg`
Expand Down Expand Up @@ -114,7 +118,7 @@ The DMG windows position and size.
<a name="FileAssociation"></a>
### `.build.fileAssociations`

NSIS and MacOS only.
macOS and NSIS only. Array of option objects.

| Name | Description
| --- | ---
Expand All @@ -134,7 +138,7 @@ Linux specific build options.
| category | <a name="LinuxBuildOptions-category"></a>The [application category](https://specifications.freedesktop.org/menu-spec/latest/apa.html#main-category-registry).
| packageCategory | <a name="LinuxBuildOptions-packageCategory"></a>The [package category](https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Section). Not applicable for AppImage.
| description | <a name="LinuxBuildOptions-description"></a>As [description](#AppMetadata-description) from application package.json, but allows you to specify different for Linux.
| target | <a name="LinuxBuildOptions-target"></a><p>Target package type: list of <code>AppImage</code>, <code>deb</code>, <code>rpm</code>, <code>freebsd</code>, <code>pacman</code>, <code>p5p</code>, <code>apk</code>, <code>7z</code>, <code>zip</code>, <code>tar.xz</code>, <code>tar.lz</code>, <code>tar.gz</code>, <code>tar.bz2</code>. Defaults to <code>AppImage</code>.</p> <p>The most effective [xz](https://en.wikipedia.org/wiki/Xz) compression format used by default.</p> <p>Only <code>deb</code> and <code>AppImage</code> is tested. Feel free to file issues for <code>rpm</code> and other package formats.</p>
| target | <a name="LinuxBuildOptions-target"></a><p>Target package type: list of <code>AppImage</code>, <code>deb</code>, <code>rpm</code>, <code>freebsd</code>, <code>pacman</code>, <code>p5p</code>, <code>apk</code>, <code>7z</code>, <code>zip</code>, <code>tar.xz</code>, <code>tar.lz</code>, <code>tar.gz</code>, <code>tar.bz2</code>, <code>dir</code>. Defaults to <code>AppImage</code>.</p> <p>The most effective [xz](https://en.wikipedia.org/wiki/Xz) compression format used by default.</p> <p>Only <code>deb</code> and <code>AppImage</code> is tested. Feel free to file issues for <code>rpm</code> and other package formats.</p>
| synopsis | <a name="LinuxBuildOptions-synopsis"></a>*deb-only.* The [short description](https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Description).
| maintainer | <a name="LinuxBuildOptions-maintainer"></a>The maintainer. Defaults to [author](#AppMetadata-author).
| vendor | <a name="LinuxBuildOptions-vendor"></a>The vendor. Defaults to [author](#AppMetadata-author).
Expand All @@ -150,7 +154,7 @@ MacOS specific build options.
| Name | Description
| --- | ---
| category | <a name="MacOptions-category"></a><p>The application category type, as shown in the Finder via *View -&gt; Arrange by Application Category* when viewing the Applications directory.</p> <p>For example, <code>&quot;category&quot;: &quot;public.app-category.developer-tools&quot;</code> will set the application category to *Developer Tools*.</p> <p>Valid values are listed in [Apple’s documentation](https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/LaunchServicesKeys.html#//apple_ref/doc/uid/TP40009250-SW8).</p>
| target | <a name="MacOptions-target"></a>Target package type: list of `default`, `dmg`, `mas`, `7z`, `zip`, `tar.xz`, `tar.lz`, `tar.gz`, `tar.bz2`. Defaults to `default` (dmg and zip for Squirrel.Mac).
| target | <a name="MacOptions-target"></a>Target package type: list of `default`, `dmg`, `mas`, `7z`, `zip`, `tar.xz`, `tar.lz`, `tar.gz`, `tar.bz2`, `dir`. Defaults to `default` (dmg and zip for Squirrel.Mac).
| identity | <a name="MacOptions-identity"></a><p>The name of certificate to use when signing. Consider using environment variables [CSC_LINK or CSC_NAME](https://github.com/electron-userland/electron-builder/wiki/Code-Signing). MAS installer identity is specified in the [.build.mas](#MasBuildOptions-identity).</p>
| icon | <a name="MacOptions-icon"></a>The path to application icon. Defaults to `build/icon.icns` (consider using this convention instead of complicating your configuration).
| entitlements | <a name="MacOptions-entitlements"></a><p>The path to entitlements file for signing the app. <code>build/entitlements.mac.plist</code> will be used if exists (it is a recommended way to set). MAS entitlements is specified in the [.build.mas](#MasBuildOptions-entitlements).</p>
Expand Down Expand Up @@ -198,6 +202,32 @@ macOS only.
| role | <a name="Protocol-role"></a>*macOS-only* The app’s role with respect to the type. The value can be `Editor`, `Viewer`, `Shell`, or `None`. Defaults to `Editor`.
| **schemes** | <a name="Protocol-schemes"></a>The schemes. e.g. `["irc", "ircs"]`.

<a name="PublishConfiguration"></a>
### `.build.publish`

Please see [Publishing Artifacts](https://github.com/electron-userland/electron-builder/wiki/Publishing-Artifacts).

Array of option objects.

| Name | Description
| --- | ---
| **provider** | <a name="PublishConfiguration-provider"></a>The provider, one of `github`, `bintray`.
| owner | <a name="PublishConfiguration-owner"></a>The owner.

<a name="BintrayOptions"></a>
### `.build.publish` Bintray
| Name | Description
| --- | ---
| package | <a name="BintrayOptions-package"></a>The Bintray package name.
| repo | <a name="BintrayOptions-repo"></a>The Bintray repository name. Defaults to `generic`.

<a name="GithubOptions"></a>
### `.build.publish` GitHub
| Name | Description
| --- | ---
| repo | <a name="GithubOptions-repo"></a>The repository name. [Detected automatically](https://github.com/electron-userland/electron-builder/wiki/Publishing-Artifacts#github-repository).
| vPrefixedTagName | <a name="GithubOptions-vPrefixedTagName"></a>Whether to use `v`-prefixed tag name. Defaults to `true`.

<a name="SquirrelWindowsOptions"></a>
### `.build.squirrelWindows`
| Name | Description
Expand All @@ -216,7 +246,7 @@ Windows specific build options.

| Name | Description
| --- | ---
| target | <a name="WinBuildOptions-target"></a>Target package type: list of `nsis`, `squirrel`, `7z`, `zip`, `tar.xz`, `tar.lz`, `tar.gz`, `tar.bz2`. Defaults to `squirrel`.
| target | <a name="WinBuildOptions-target"></a>Target package type: list of `nsis`, `squirrel`, `7z`, `zip`, `tar.xz`, `tar.lz`, `tar.gz`, `tar.bz2`, `dir`. Defaults to `squirrel`.
| signingHashAlgorithms | <a name="WinBuildOptions-signingHashAlgorithms"></a>Array of signing algorithms used. Defaults to `['sha1', 'sha256']`
| icon | <a name="WinBuildOptions-icon"></a>The path to application icon. Defaults to `build/icon.ico` (consider using this convention instead of complicating your configuration).
| legalTrademarks | <a name="WinBuildOptions-legalTrademarks"></a>The trademarks and registered trademarks.
Expand Down
20 changes: 15 additions & 5 deletions docs/Publishing Artifacts.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Travis and AppVeyor support publishing artifacts. But it requires additional configuration. For each CI (since AppVeyor can build only Windows and Travis only MacOS / Linux).
Travis and AppVeyor support publishing artifacts. But it requires additional configuration. For each CI (since AppVeyor can build only Windows and Travis only macOS / Linux).

`electron-builder` allows you to just add `GH_TOKEN` environment variable and that's all.

Currently, only GitHub Releases is supported.
Currently, [GitHub Releases](https://help.github.com/articles/about-releases/) and [Bintray](https://bintray.com) are supported.

`--publish` option values:
CLI `--publish` option values:

| Value | Description
| -------------- | -----------
Expand Down Expand Up @@ -38,9 +38,19 @@ But please consider using automatic rules instead of explicitly specifying `publ
```
and if you run `npm run release`, a release will be drafted (if doesn't already exist) and artifacts published.

# GitHub Repository
# GitHub Repository and Bintray Package

No option to specify GitHub repository, detected automatically using:
Detected automatically using:
* [repository](https://docs.npmjs.com/files/package.json#repository) in the application or development `package.json`,
* if not set, env `TRAVIS_REPO_SLUG` or `APPVEYOR_ACCOUNT_NAME`/`APPVEYOR_PROJECT_NAME` or `CIRCLE_PROJECT_USERNAME`/`CIRCLE_PROJECT_REPONAME`,
* if no env, from `.git/config` origin url.

# Publish Options

[build.publish](https://github.com/electron-userland/electron-builder/wiki/Options#PublishConfiguration) can be specified in [build](https://github.com/electron-userland/electron-builder/wiki/Options#build) or any platform- or target- specific options.

```json
"win": {
"publish": ["github", "bintray"]
}
```
7 changes: 4 additions & 3 deletions nsis-auto-updater/src/BintrayProvider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Provider, VersionInfo, FileInfo } from "./api"
import { BintrayClient, BintrayOptions } from "../../src/publish/bintray"
import { BintrayClient } from "../../src/publish/bintray"
import { HttpError } from "../../src/publish/restApiRequest"
import { BintrayOptions } from "../../src/options/publishOptions"

//noinspection JSUnusedLocalSymbols
const __awaiter = require("../../src/util/awaiter")
Expand All @@ -9,7 +10,7 @@ export class BintrayProvider implements Provider {
private client: BintrayClient

constructor(configuration: BintrayOptions) {
this.client = new BintrayClient(configuration.user, configuration.package, configuration.repo)
this.client = new BintrayClient(configuration.owner!, configuration.package!, configuration.repo)
}

async getLatestVersion(): Promise<VersionInfo> {
Expand All @@ -35,7 +36,7 @@ export class BintrayProvider implements Provider {
if (file.name.endsWith(suffix) && file.name.includes("Setup")) {
return {
name: file.name,
url: `https://dl.bintray.com/${this.client.user}/${this.client.repo}/${file.name}`,
url: `https://dl.bintray.com/${this.client.owner}/${this.client.repo}/${file.name}`,
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions nsis-auto-updater/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { NsisUpdater } from "./nsis-updater"

if (process.platform === "win32") {
module.exports = require("electron").autoUpdater
}
else {
const updater: NsisUpdater = new (require("./nsis-updater").NsisUpdater)()

module.exports = updater
}
29 changes: 21 additions & 8 deletions nsis-auto-updater/src/nsis-updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { EventEmitter } from "events"
import { spawn } from "child_process"
import * as path from "path"
import { tmpdir } from "os"
import { BintrayOptions } from "../../src/publish/bintray"
import semver = require("semver")
import { download } from "../../src/util/httpRequest"
import { Provider, UpdateCheckResult } from "./api"
import { BintrayProvider } from "./BintrayProvider"
import { Promise as BluebirdPromise } from "bluebird"
import { BintrayOptions, PublishConfiguration, GithubOptions } from "../../src/options/publishOptions"

//noinspection JSUnusedLocalSymbols
const __awaiter = require("../../src/util/awaiter")
Expand All @@ -22,24 +22,37 @@ export class NsisUpdater extends EventEmitter {

private readonly app: any

constructor(public updateUrl?: string) {
constructor(options?: PublishConfiguration | BintrayOptions | GithubOptions) {
super()

this.app = (<any>global).__test_app || require("electron").app

if (options != null) {
this.setFeedURL(options)
}
}

getFeedURL(): string | null | undefined {
return this.updateUrl
return JSON.stringify(this.client, null, 2)
}

setFeedURL(value: string | BintrayOptions) {
this.updateUrl = value.toString()

this.client = new BintrayProvider(<BintrayOptions>value)
setFeedURL(value: string | PublishConfiguration | BintrayOptions | GithubOptions) {
if (typeof value === "string") {
throw new Error("Please pass PublishConfiguration object")
}
else {
const provider = (<PublishConfiguration>value).provider
if (provider === "bintray") {
this.client = new BintrayProvider(<BintrayOptions>value)
}
else {
throw new Error(`Unsupported provider: ${provider}`)
}
}
}

checkForUpdates(): Promise<UpdateCheckResult> {
if (this.updateUrl == null) {
if (this.client == null) {
const message = "Update URL is not set"
this.emitError(message)
return BluebirdPromise.reject(new Error(message))
Expand Down
2 changes: 2 additions & 0 deletions nsis-auto-updater/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
"../node_modules/fs-extra-p/bluebird.d.ts",
"../src/util/httpRequest.ts",
"../src/publish/restApiRequest.ts",
"../src/publish/restApiRequest.ts",
"../src/publish/bintray.ts",
"../src/options/publishOptions.ts",
"../src/util/awaiter.ts"
],
"include": [
Expand Down
47 changes: 22 additions & 25 deletions src/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import { Platform, Arch, archFromString } from "./metadata"
import { getRepositoryInfo } from "./repositoryInfo"
import { DIR_TARGET } from "./targets/targetFactory"
import { BintrayPublisher } from "./publish/BintrayPublisher"
import { BintrayOptions } from "./publish/bintray"
import { PublishConfiguration, GithubPublishConfiguration } from "./options/publishOptions"
import { PublishConfiguration, GithubOptions, BintrayOptions } from "./options/publishOptions"

//noinspection JSUnusedLocalSymbols
const __awaiter = require("./util/awaiter")
Expand Down Expand Up @@ -300,7 +299,7 @@ function publishManager(packager: Packager, publishTasks: Array<BluebirdPromise<
})
}

export async function createPublisher(packager: Packager, options: PublishOptions, publishConfig: PublishConfiguration | GithubPublishConfiguration, isPublishOptionGuessed: boolean = false): Promise<Publisher | null> {
export async function createPublisher(packager: Packager, options: PublishOptions, publishConfig: PublishConfiguration | GithubOptions | BintrayOptions, isPublishOptionGuessed: boolean = false): Promise<Publisher | null> {
async function getInfo() {
const info = await getRepositoryInfo(packager.metadata, packager.devMetadata)
if (info != null) {
Expand All @@ -312,37 +311,35 @@ export async function createPublisher(packager: Packager, options: PublishOption
}

warn("Cannot detect repository by .git/config")
throw new Error(`Please specify 'repository' in the dev package.json ('${packager.devPackageFile}')`)
throw new Error(`Please specify "repository" in the dev package.json ('${packager.devPackageFile}').\nPlease see https://github.com/electron-userland/electron-builder/wiki/Publishing-Artifacts`)
}

if (publishConfig.provider === "github") {
const config = <GithubPublishConfiguration>publishConfig
let user = config.owner
let repo = config.repo
if (!user || !repo) {
const info = await getInfo()
if (info == null) {
return null
}
let owner = publishConfig.owner
let project = publishConfig.provider === "github" ? (<GithubOptions>publishConfig).repo : (<BintrayOptions>publishConfig).package
if (!owner || !project) {
const info = await getInfo()
if (info == null) {
return null
}

user = info.user
repo = info.project
if (!owner) {
owner = info.user
}
if (!project) {
project = info.project
}
}

if (publishConfig.provider === "github") {
const config = <GithubOptions>publishConfig
const version = packager.metadata.version!
log(`Creating Github Publisher — user: ${user}, project: ${repo}, version: ${version}`)
return new GitHubPublisher(user, repo, version, options, isPublishOptionGuessed, config)
log(`Creating Github Publisher — owner: ${owner}, project: ${project}, version: ${version}`)
return new GitHubPublisher(owner, project, version, options, isPublishOptionGuessed, config)
}
if (publishConfig.provider === "bintray") {
const info = await getInfo()
if (info == null) {
return null
}

const version = packager.metadata.version!
//noinspection ReservedWordAsName
const bintrayInfo: BintrayOptions = {user: info.user, package: info.project, repo: "generic"}
log(`Creating Bintray Publisher — user: ${bintrayInfo.user}, package: ${bintrayInfo.package}, repository: ${bintrayInfo.repo}, version: ${version}`)
const bintrayInfo: BintrayOptions = Object.assign({}, publishConfig, {owner: owner, package: project, repo: "generic"})
log(`Creating Bintray Publisher — user: ${bintrayInfo.owner}, package: ${bintrayInfo.package}, repository: ${bintrayInfo.repo}, version: ${version}`)
return new BintrayPublisher(bintrayInfo, version, options)
}
return null
Expand Down
7 changes: 5 additions & 2 deletions src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ export interface BuildMetadata {

readonly dereference?: boolean

/*
See [.build.publish](#PublishConfiguration).
*/
readonly publish?: string | Array<string> | null | PublishConfiguration
}

Expand Down Expand Up @@ -257,7 +260,7 @@ export interface LinuxBuildOptions extends PlatformSpecificBuildOptions {
readonly description?: string | null

/*
Target package type: list of `AppImage`, `deb`, `rpm`, `freebsd`, `pacman`, `p5p`, `apk`, `7z`, `zip`, `tar.xz`, `tar.lz`, `tar.gz`, `tar.bz2`. Defaults to `AppImage`.
Target package type: list of `AppImage`, `deb`, `rpm`, `freebsd`, `pacman`, `p5p`, `apk`, `7z`, `zip`, `tar.xz`, `tar.lz`, `tar.gz`, `tar.bz2`, `dir`. Defaults to `AppImage`.
The most effective [xz](https://en.wikipedia.org/wiki/Xz) compression format used by default.
Expand Down Expand Up @@ -305,7 +308,7 @@ export interface LinuxBuildOptions extends PlatformSpecificBuildOptions {
/*
### `.build.fileAssociations`
NSIS and MacOS only.
macOS and NSIS only. Array of option objects.
*/
export interface FileAssociation {
/*
Expand Down
2 changes: 1 addition & 1 deletion src/options/macOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface MacOptions extends PlatformSpecificBuildOptions {
readonly category?: string | null

/*
Target package type: list of `default`, `dmg`, `mas`, `7z`, `zip`, `tar.xz`, `tar.lz`, `tar.gz`, `tar.bz2`. Defaults to `default` (dmg and zip for Squirrel.Mac).
Target package type: list of `default`, `dmg`, `mas`, `7z`, `zip`, `tar.xz`, `tar.lz`, `tar.gz`, `tar.bz2`, `dir`. Defaults to `default` (dmg and zip for Squirrel.Mac).
*/
readonly target?: Array<string> | null

Expand Down
Loading

0 comments on commit 1a9caa8

Please sign in to comment.