Skip to content

Commit

Permalink
feat(electron-publisher): Allow pass configuration to custom electron…
Browse files Browse the repository at this point in the history
…-publisher provider

Close electron-userland#3261
  • Loading branch information
develar committed Nov 1, 2018
1 parent ce1de01 commit c6a2a4f
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
24 changes: 18 additions & 6 deletions packages/app-builder-lib/src/publish/PublishManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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)}`)
}
Expand All @@ -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
Expand All @@ -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
}
}

Expand Down Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions packages/builder-util-runtime/src/publishOptions.ts
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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.
*
Expand Down
11 changes: 11 additions & 0 deletions test/out/__snapshots__/PublishManagerTest.js.snap
Original file line number Diff line number Diff line change
@@ -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 [
Expand Down
4 changes: 2 additions & 2 deletions test/src/ArtifactPublisherTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand All @@ -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})
Expand Down
20 changes: 20 additions & 0 deletions test/src/PublishManagerTest.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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`)
}))
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit c6a2a4f

Please sign in to comment.