Skip to content
Permalink
Browse files

feat(electron-publisher): Allow pass configuration to custom electron…

…-publisher provider

Close #3261
  • Loading branch information...
develar committed Nov 1, 2018
1 parent e101832 commit 6570e4b0d2f6d33648a4b25c69467cb4327248ec
@@ -118,7 +118,7 @@
"ts-babel": "6.1.0",
"ts-jsdoc": "^3.0.1",
"tslint": "^5.11.0",
"typescript": "^3.1.4",
"typescript": "^3.1.5",
"whitespace": "^2.1.0",
"worker-farm": "^1.6.0"
},
@@ -191,7 +191,7 @@ export class PublishManager implements PublishContext {
const providerCacheKey = safeStringifyJson(publishConfig)
let publisher = this.nameToPublisher.get(providerCacheKey)
if (publisher == null) {
publisher = createPublisher(this, appInfo.version, publishConfig, this.publishOptions)
publisher = createPublisher(this, appInfo.version, publishConfig, this.publishOptions, this.packager)
this.nameToPublisher.set(providerCacheKey, publisher)
log.info({publisher: publisher!!.toString()}, "publishing")
}
@@ -259,7 +259,7 @@ export async function getPublishConfigsForUpdateInfo(packager: PlatformPackager<
return publishConfigs
}

export function createPublisher(context: PublishContext, version: string, publishConfig: PublishConfiguration, options: PublishOptions): Publisher | null {
export function createPublisher(context: PublishContext, version: string, publishConfig: PublishConfiguration, options: PublishOptions, packager: Packager): Publisher | null {
if (debug.enabled) {
debug(`Create publisher: ${safeStringifyJson(publishConfig)}`)
}
@@ -276,12 +276,12 @@ export function createPublisher(context: PublishContext, version: string, publis
return null

default:
const clazz = requireProviderClass(provider)
const clazz = requireProviderClass(provider, packager)
return clazz == null ? null : new clazz(context, publishConfig)
}
}

function requireProviderClass(provider: string): any | null {
function requireProviderClass(provider: string, packager: Packager): any | null {
switch (provider) {
case "github":
return GitHubPublisher
@@ -299,7 +299,19 @@ function requireProviderClass(provider: string): any | null {
return SpacesPublisher

default:
return require(`electron-publisher-${provider}`).default
const name = `electron-publisher-${provider}`
let module: any = null
try {
module = require(path.join(packager.buildResourcesDir, name + ".js"))
}
catch (ignored) {
console.log(ignored)
}

if (module == null) {
module = require(name)
}
return module.default || module
}
}

@@ -429,7 +441,7 @@ async function getResolvedPublishConfig(platformPackager: PlatformPackager<any>
return options
}

const providerClass = requireProviderClass(options.provider)
const providerClass = requireProviderClass(options.provider, packager)
if (providerClass != null && providerClass.checkAndResolveOptions != null) {
await providerClass.checkAndResolveOptions(options, channelFromAppVersion, errorIfCannot)
return options
@@ -1,7 +1,7 @@
export type PublishProvider = "github" | "bintray" | "s3" | "spaces" | "generic"
export type PublishProvider = "github" | "bintray" | "s3" | "spaces" | "generic" | "custom"

// typescript-json-schema generates only PublishConfiguration if it is specified in the list, so, it is not added here
export type AllPublishOptions = string | GithubOptions | S3Options | SpacesOptions | GenericServerOptions | BintrayOptions
export type AllPublishOptions = string | GithubOptions | S3Options | SpacesOptions | GenericServerOptions | BintrayOptions | CustomPublishOptions
// https://github.com/YousefED/typescript-json-schema/issues/80
export type Publish = AllPublishOptions | Array<AllPublishOptions> | null

@@ -27,6 +27,11 @@ export interface PublishConfiguration {
readonly publishAutoUpdate?: boolean
}

// https://github.com/electron-userland/electron-builder/issues/3261
export interface CustomPublishOptions extends PublishConfiguration {
[index: string]: any
}

/**
* [GitHub](https://help.github.com/articles/about-releases/) options.
*
@@ -1,5 +1,16 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`custom provider 1`] = `
Object {
"linux": Array [
Object {
"arch": "x64",
"file": "TestApp-1.1.0.zip",
},
],
}
`;

exports[`dotted s3 bucket 1`] = `
Object {
"linux": Array [
@@ -111,7 +111,7 @@ testAndIgnoreApiRate("GitHub upload", async () => {

if (process.env.AWS_ACCESS_KEY_ID != null && process.env.AWS_SECRET_ACCESS_KEY != null) {
test("S3 upload", async () => {
const publisher = createPublisher(publishContext, "0.0.1", {provider: "s3", bucket: "electron-builder-test"} as S3Options, {})!!
const publisher = createPublisher(publishContext, "0.0.1", {provider: "s3", bucket: "electron-builder-test"} as S3Options, {}, {} as any)!!
await publisher.upload({file: iconPath, arch: Arch.x64})
// test overwrite
await publisher.upload({file: iconPath, arch: Arch.x64})
@@ -125,7 +125,7 @@ if (process.env.DO_KEY_ID != null && process.env.DO_SECRET_KEY != null) {
name: "electron-builder-test",
region: "nyc3",
}
const publisher = createPublisher(publishContext, "0.0.1", configuration, {})!!
const publisher = createPublisher(publishContext, "0.0.1", configuration, {}, {} as any)!!
await publisher.upload({file: iconPath, arch: Arch.x64})
// test overwrite
await publisher.upload({file: iconPath, arch: Arch.x64})
@@ -1,4 +1,5 @@
import { createTargets, Platform } from "electron-builder"
import { outputFile } from "fs-extra-p"
import * as path from "path"
import { assertThat } from "./helpers/fileAssert"
import { app, checkDirContents } from "./helpers/packTester"
@@ -106,4 +107,23 @@ test.ifAll.ifNotWindows("dotted s3 bucket", app({
},
}, {
publish: "never"
}))

// https://github.com/electron-userland/electron-builder/issues/3261
test.ifAll.ifNotWindows("custom provider", app({
targets: createTargets([Platform.LINUX], "zip"),
config: {
publish: {
provider: "custom",
boo: "foo",
},
},
}, {
publish: "never",
projectDirCreated: projectDir => outputFile(path.join(projectDir, "build/electron-publisher-custom.js"), `class Publisher {
async upload(task) {
}
}
module.exports = Publisher`)
}))
@@ -6356,10 +6356,10 @@ type-check@~0.3.2:
dependencies:
prelude-ls "~1.1.2"

typescript@^3.1.4:
version "3.1.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.1.4.tgz#c74ef7b3c2da65beff548b903022cb8c3cd997ed"
integrity sha512-JZHJtA6ZL15+Q3Dqkbh8iCUmvxD3iJ7ujXS+fVkKnwIVAdHc5BJTDNM0aTrnr2luKulFjU7W+SRhDZvi66Ru7Q==
typescript@^3.1.5:
version "3.1.5"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.1.5.tgz#93d8b6864375325a91177372cb370ae0ae3a0703"
integrity sha512-muYNWV9j5+3mXoKD6oPONKuGUmYiFX14gfo9lWm9ZXRHOqVDQiB4q1CzFPbF4QLV2E9TZXH6oK55oQ94rn3PpA==

typescript@~2.6.2:
version "2.6.2"

0 comments on commit 6570e4b

Please sign in to comment.
You can’t perform that action at this time.