Skip to content

Commit

Permalink
feat: automatically set channel to version prerelease component
Browse files Browse the repository at this point in the history
BREAKING CHANGE: if app version is `0.12.1-alpha.1`, file `alpha.yml` will be generated instead of `latest.yml`

Close #1182
develar committed Apr 15, 2017
1 parent 2c52ed2 commit 831186f
Showing 22 changed files with 174 additions and 104 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@
"electron-is-dev": "^0.1.2",
"electron-osx-sign": "0.4.4",
"fs-extra-p": "^4.1.0",
"hosted-git-info": "^2.4.1",
"hosted-git-info": "^2.4.2",
"ini": "^1.3.4",
"is-ci": "^1.0.10",
"isbinaryfile": "^3.0.2",
@@ -60,7 +60,7 @@
"tunnel-agent": "^0.6.0",
"update-notifier": "^2.1.0",
"uuid-1345": "^0.99.6",
"yargs": "^7.0.2"
"yargs": "^7.1.0"
},
"devDependencies": {
"@develar/typescript-json-schema": "0.11.0",
4 changes: 2 additions & 2 deletions packages/electron-builder-http/src/publishOptions.ts
Original file line number Diff line number Diff line change
@@ -22,8 +22,6 @@ export interface PublishConfiguration {
* The owner.
*/
readonly owner?: string | null

readonly token?: string | null
}

/**
@@ -172,6 +170,8 @@ export interface BintrayOptions extends PublishConfiguration {
* The Bintray user account. Used in cases where the owner is an organization.
*/
readonly user?: string | null

readonly token?: string | null
}

export interface VersionInfo {
4 changes: 2 additions & 2 deletions packages/electron-builder/package.json
Original file line number Diff line number Diff line change
@@ -58,7 +58,7 @@
"electron-osx-sign": "0.4.4",
"electron-publish": "0.0.0-semantic-release",
"fs-extra-p": "^4.1.0",
"hosted-git-info": "^2.4.1",
"hosted-git-info": "^2.4.2",
"is-ci": "^1.0.10",
"isbinaryfile": "^3.0.2",
"js-yaml": "^3.8.3",
@@ -71,7 +71,7 @@
"semver": "^5.3.0",
"update-notifier": "^2.1.0",
"uuid-1345": "^0.99.6",
"yargs": "^7.0.2"
"yargs": "^7.1.0"
},
"typings": "./out/electron-builder.d.ts",
"publishConfig": {
6 changes: 6 additions & 0 deletions packages/electron-builder/src/metadata.ts
Original file line number Diff line number Diff line change
@@ -201,6 +201,12 @@ export interface Config extends PlatformSpecificBuildOptions {
* Whether to use [electron-compile](http://github.com/electron/electron-compile) to compile app. Defaults to `true` if `electron-compile` in the dependencies. And `false` if in the `devDependencies` or doesn't specified.
*/
readonly electronCompile?: boolean

/**
* Whether to infer update channel from application version prerelease components. e.g. if version `0.12.1-alpha.1`, channel will be set to `alpha`. Otherwise to `latest`.
* @default true
*/
readonly detectUpdateChannel?: boolean

readonly mac?: MacOptions | null
readonly mas?: MasBuildOptions | null
22 changes: 18 additions & 4 deletions packages/electron-builder/src/publish/PublishManager.ts
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@ import { createReadStream, ensureDir, outputJson, 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 * as url from "url"
import { Packager } from "../packager"
import { ArtifactCreated, BuildInfo } from "../packagerApi"
@@ -441,18 +442,31 @@ function expandPublishConfig(options: any, packager: PlatformPackager<any>, arch
async function getResolvedPublishConfig(packager: PlatformPackager<any>, options: PublishConfiguration, arch: Arch | null, errorIfCannot: boolean = true): Promise<PublishConfiguration | null> {
options = Object.assign(Object.create(null), options)
expandPublishConfig(options, packager, arch)


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]
}
}

const provider = options.provider
if (provider === "generic") {
if ((<GenericServerOptions>options).url == null) {
const o = <GenericServerOptions>options
if (o.url == null) {
throw new Error(`Please specify "url" for "generic" update server`)
}

if (channelFromAppVersion != null) {
(<any>o).channel = channelFromAppVersion
}
return options
}

const providerClass = requireProviderClass(options.provider)
if (providerClass != null && providerClass.checkAndResolveOptions != null) {
await providerClass.checkAndResolveOptions(options)
await providerClass.checkAndResolveOptions(options, channelFromAppVersion)
return options
}

@@ -505,7 +519,7 @@ async function getResolvedPublishConfig(packager: PlatformPackager<any>, options
}

if (isGithub) {
if (options.token != null && !(<GithubOptions>options).private) {
if ((<GithubOptions>options).token != null && !(<GithubOptions>options).private) {
warn('"token" specified in the github publish options. It should be used only for [setFeedURL](module:electron-updater/out/AppUpdater.AppUpdater+setFeedURL).')
}
return Object.assign({owner, repo: project}, options)
7 changes: 4 additions & 3 deletions packages/electron-builder/src/targets/nsis.ts
Original file line number Diff line number Diff line change
@@ -397,7 +397,8 @@ export class NsisTarget extends Target {
const command = path.join(nsisPath, process.platform === "darwin" ? "mac" : (process.platform === "win32" ? "Bin" : "linux"), process.platform === "win32" ? "makensis.exe" : "makensis")
const childProcess = doSpawn(command, args, {
// we use NSIS_CONFIG_CONST_DATA_PATH=no to build makensis on Linux, but in any case it doesn't use stubs as MacOS/Windows version, so, we explicitly set NSISDIR
env: Object.assign({}, process.env, {NSISDIR: nsisPath}),
// set LC_CTYPE to avoid crash https://github.com/electron-userland/electron-builder/issues/503 Even "en_DE.UTF-8" leads to error.
env: Object.assign({}, process.env, {NSISDIR: nsisPath, LC_CTYPE: "en_US.UTF-8"}),
cwd: this.nsisTemplatesDir,
}, true)
handleProcess("close", childProcess, command, resolve, error => {
@@ -416,10 +417,10 @@ export class NsisTarget extends Target {

private async computeFinalScript(originalScript: string, isInstaller: boolean) {
const packager = this.packager
let scriptHeader = `!addincludedir "${path.win32.join(__dirname, "..", "..", "templates", "nsis", "include")}"\n`
let scriptHeader = `!addincludedir "${path.join(__dirname, "..", "..", "templates", "nsis", "include")}"\n`

const addCustomMessageFileInclude = async (input: string) => {
return "!include " + await this.writeCustomLangFile(computeCustomMessageTranslations(safeLoad(await readFile(path.join(this.nsisTemplatesDir, input), "utf-8"))).join("\n")) + "\n"
return '!include "' + await this.writeCustomLangFile(computeCustomMessageTranslations(safeLoad(await readFile(path.join(this.nsisTemplatesDir, input), "utf-8"))).join("\n")) + '"\n'
}

const tasks: Array<() => Promise<any>> = [
6 changes: 5 additions & 1 deletion packages/electron-publisher-s3/src/s3Publisher.ts
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ export default class S3Publisher extends Publisher {
debug(`Creating S3 Publisher — bucket: ${info.bucket}`)
}

static async checkAndResolveOptions(options: S3Options) {
static async checkAndResolveOptions(options: S3Options, channelFromAppVersion: string | null) {
const bucket = options.bucket
if (bucket == null) {
throw new Error(`Please specify "bucket" for "s3" update server`)
@@ -27,6 +27,10 @@ export default class S3Publisher extends Publisher {
const s3 = new S3({signatureVersion: "v4"});
(<any>options).region = (await s3.getBucketLocation({Bucket: bucket}).promise()).LocationConstraint
}

if (options.channel == null && channelFromAppVersion != null) {
(<any>options).channel = channelFromAppVersion
}
}

// http://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/s3-example-creating-buckets.html
2 changes: 1 addition & 1 deletion test/fixtures/app-executable-deps/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"build": {
"electronVersion": "1.6.3",
"electronVersion": "1.6.6",
"category": "public.app-category.business"
}
}
2 changes: 1 addition & 1 deletion test/fixtures/test-app-one/package.json
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
"author": "Foo Bar <[email protected]>",
"license": "MIT",
"build": {
"electronVersion": "1.6.3",
"electronVersion": "1.6.6",
"appId": "org.electron-builder.testApp",
"compression": "store",
"npmRebuild": false,
2 changes: 1 addition & 1 deletion test/fixtures/test-app/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"build": {
"electronVersion": "1.6.3",
"electronVersion": "1.6.6",
"appId": "org.electron-builder.testApp",
"compression": "store",
"npmRebuild": false,
24 changes: 22 additions & 2 deletions test/out/__snapshots__/ExtraBuildTest.js.snap
Original file line number Diff line number Diff line change
@@ -32,15 +32,35 @@ Object {
exports[`override targets in the config - only arch 1`] = `
Object {
"win": Array [
Object {
"arch": null,
"file": "beta.yml",
},
Object {
"arch": 0,
"file": "Test App ßW Setup 1.1.0.exe",
"safeArtifactName": "TestApp-Setup-1.1.0.exe",
"file": "Test App ßW Setup 1.0.0-beta.1.exe",
"safeArtifactName": "TestApp-Setup-1.0.0-beta.1.exe",
},
],
}
`;

exports[`override targets in the config - only arch 2`] = `
Object {
"channel": "beta",
"provider": "generic",
"url": "https://develar.s3.amazonaws.com/test",
}
`;

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",
"version": "1.0.0-beta.1",
}
`;

exports[`override targets in the config 1`] = `
Object {
"linux": Array [],
37 changes: 37 additions & 0 deletions test/out/__snapshots__/filesTest.js.snap
Original file line number Diff line number Diff line change
@@ -34,6 +34,43 @@ Object {
}
`;

exports[`extraResources on Linux and Windows 3`] = `
Array [
"lib/net45/blink_image_resources_200_percent.pak",
"lib/net45/content_resources_200_percent.pak",
"lib/net45/content_shell.pak",
"lib/net45/d3dcompiler_47.dll",
"lib/net45/ffmpeg.dll",
"lib/net45/icudtl.dat",
"lib/net45/libEGL.dll",
"lib/net45/libGLESv2.dll",
"lib/net45/LICENSE.electron.txt",
"lib/net45/LICENSES.chromium.html",
"lib/net45/natives_blob.bin",
"lib/net45/node.dll",
"lib/net45/pdf_viewer_resources.pak",
"lib/net45/snapshot_blob.bin",
"lib/net45/Test%20App%20%C3%9FW.exe",
"lib/net45/Test%20App%20%C3%9FW_ExecutionStub.exe",
"lib/net45/ui_resources_200_percent.pak",
"lib/net45/Update.exe",
"lib/net45/views_resources_200_percent.pak",
"lib/net45/xinput1_3.dll",
"lib/net45/locales/en-US.pak",
"lib/net45/resources/app.asar",
"lib/net45/resources/electron.asar",
"lib/net45/resources/platformSpecificR",
"lib/net45/resources/bar/hello.txt",
"lib/net45/resources/bar/x64.txt",
"lib/net45/resources/dir-relative/f.txt",
"lib/net45/resources/foo/nameWithoutDot",
"lib/net45/resources/win/x64.txt",
"TestApp.nuspec",
"[Content_Types].xml",
"_rels/.rels",
]
`;

exports[`extraResources on macOS 1`] = `
Object {
"mac": Array [],
9 changes: 6 additions & 3 deletions test/out/linux/__snapshots__/debTest.js.snap
Original file line number Diff line number Diff line change
@@ -26,6 +26,7 @@ Array [
"/opt/Test App ßW/LICENSE.electron.txt",
"/opt/Test App ßW/LICENSES.chromium.html",
"/opt/Test App ßW/natives_blob.bin",
"/opt/Test App ßW/pdf_viewer_resources.pak",
"/opt/Test App ßW/snapshot_blob.bin",
"/opt/Test App ßW/testapp",
"/opt/Test App ßW/ui_resources_200_percent.pak",
@@ -83,7 +84,7 @@ Object {
"Package": "testapp",
"Priority": "extra",
"Section": "devel",
"Size": "89541",
"Size": "91139",
"Vendor": "Foo Bar <[email protected]>",
}
`;
@@ -127,6 +128,7 @@ Array [
"/opt/Test App ßW/LICENSE.electron.txt",
"/opt/Test App ßW/LICENSES.chromium.html",
"/opt/Test App ßW/natives_blob.bin",
"/opt/Test App ßW/pdf_viewer_resources.pak",
"/opt/Test App ßW/snapshot_blob.bin",
"/opt/Test App ßW/ui_resources_200_percent.pak",
"/opt/Test App ßW/views_resources_200_percent.pak",
@@ -183,7 +185,7 @@ Object {
"Package": "testapp",
"Priority": "extra",
"Section": "devel",
"Size": "123301",
"Size": "124968",
"Vendor": "Foo Bar <[email protected]>",
}
`;
@@ -214,6 +216,7 @@ Array [
"/opt/Test App ßW/LICENSE.electron.txt",
"/opt/Test App ßW/LICENSES.chromium.html",
"/opt/Test App ßW/natives_blob.bin",
"/opt/Test App ßW/pdf_viewer_resources.pak",
"/opt/Test App ßW/snapshot_blob.bin",
"/opt/Test App ßW/testapp",
"/opt/Test App ßW/ui_resources_200_percent.pak",
@@ -271,7 +274,7 @@ Object {
"Package": "testapp",
"Priority": "extra",
"Section": "devel",
"Size": "123301",
"Size": "124968",
"Vendor": "Foo Bar <[email protected]>",
}
`;
2 changes: 1 addition & 1 deletion test/out/mac/__snapshots__/macArchiveTest.js.snap
Original file line number Diff line number Diff line change
@@ -235,6 +235,7 @@ Array [
"Test App ßW.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Resources/natives_blob.bin",
"Test App ßW.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Resources/nb.lproj",
"Test App ßW.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Resources/nl.lproj",
"Test App ßW.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Resources/pdf_viewer_resources.pak",
"Test App ßW.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Resources/pl.lproj",
"Test App ßW.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Resources/pt_BR.lproj",
"Test App ßW.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Resources/pt_PT.lproj",
@@ -433,7 +434,6 @@ Object {
Object {
"_": "#org.electron-builder.testApp.pkg",
"id": "org.electron-builder.testApp",
"installKBytes": "109832",
"onConclusion": "none",
"version": "1.1.0",
},
31 changes: 31 additions & 0 deletions test/out/windows/__snapshots__/squirrelWindowsTest.js.snap
Original file line number Diff line number Diff line change
@@ -24,3 +24,34 @@ Object {
],
}
`;

exports[`Squirrel.Windows 2`] = `
Array [
"lib/net45/blink_image_resources_200_percent.pak",
"lib/net45/content_resources_200_percent.pak",
"lib/net45/content_shell.pak",
"lib/net45/d3dcompiler_47.dll",
"lib/net45/ffmpeg.dll",
"lib/net45/icudtl.dat",
"lib/net45/libEGL.dll",
"lib/net45/libGLESv2.dll",
"lib/net45/LICENSE.electron.txt",
"lib/net45/LICENSES.chromium.html",
"lib/net45/natives_blob.bin",
"lib/net45/node.dll",
"lib/net45/pdf_viewer_resources.pak",
"lib/net45/snapshot_blob.bin",
"lib/net45/Test%20App%20%C3%9FW.exe",
"lib/net45/Test%20App%20%C3%9FW_ExecutionStub.exe",
"lib/net45/ui_resources_200_percent.pak",
"lib/net45/Update.exe",
"lib/net45/views_resources_200_percent.pak",
"lib/net45/xinput1_3.dll",
"lib/net45/locales/en-US.pak",
"lib/net45/resources/app.asar",
"lib/net45/resources/electron.asar",
"TestApp.nuspec",
"[Content_Types].xml",
"_rels/.rels",
]
`;
Loading

0 comments on commit 831186f

Please sign in to comment.