Skip to content

Commit

Permalink
fix: electron-builder not generating "latest.yml" file
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Jan 5, 2017
1 parent fdc3eba commit b46105e
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .idea/rc-producer.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ language: c
cache:
directories:
- node_modules
- packages/electron-builder/node_modules
- packages/electron-builder-util/node_modules
- $HOME/.electron
- /tmp/jest-electron-builder-tests

Expand Down
2 changes: 1 addition & 1 deletion packages/electron-auto-updater/src/GitHubProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class GitHubProvider implements Provider<VersionInfo> {
async getUpdateFile(versionInfo: UpdateInfo): Promise<FileInfo> {
const basePath = this.getBasePath()
// space is not supported on GitHub
const name = path.posix.basename(versionInfo.path).replace(/ /g, "-")
const name = versionInfo.githubArtifactName || path.posix.basename(versionInfo.path).replace(/ /g, "-")
return {
name: name,
url: `https://github.com${basePath}/download/v${versionInfo.version}/${name}`,
Expand Down
1 change: 1 addition & 0 deletions packages/electron-builder-http/src/publishOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export interface VersionInfo {

export interface UpdateInfo extends VersionInfo {
readonly path: string
readonly githubArtifactName?: string | null
readonly sha2: string
}

Expand Down
8 changes: 1 addition & 7 deletions packages/electron-builder/src/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,7 @@ function publishManager(packager: Packager, publishTasks: Array<BluebirdPromise<
if (it == null) {
return null
}

if (event.file == null) {
return publishTasks.push(<BluebirdPromise<any>>it.uploadData(event.data!, event.artifactName!))
}
else {
return publishTasks.push(<BluebirdPromise<any>>it.upload(event.file!, event.artifactName))
}
return publishTasks.push(<BluebirdPromise<any>>it.upload(event.file, event.artifactName))
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/electron-builder/src/platformPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -541,8 +541,7 @@ export interface RepositoryInfo {
export interface ArtifactCreated {
readonly packager: PlatformPackager<any>

readonly file?: string
readonly data?: Buffer
readonly file: string

readonly artifactName?: string

Expand Down Expand Up @@ -586,6 +585,7 @@ export function getPublishConfigs(packager: PlatformPackager<any>, platformSpeci

if (publishers == null) {
publishers = packager.config.publish
// triple equals - if explicitly set to null
if (publishers === null) {
return null
}
Expand Down
74 changes: 43 additions & 31 deletions packages/electron-builder/src/targets/nsis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { safeDump } from "js-yaml"
import { createHash } from "crypto"
import { Target, Arch } from "electron-builder-core"
import sanitizeFileName from "sanitize-filename"
import { unlinkIfExists } from "../../../electron-builder-util/src/fs"

const NSIS_VERSION = "3.0.4"
//noinspection SpellCheckingInspection
Expand Down Expand Up @@ -42,14 +43,25 @@ export default class NsisTarget extends Target {
}
}

private computePublishConfigs(): Promise<Array<PublishConfiguration> | null> {
const publishConfigs = getPublishConfigs(this.packager, this.options)
if (publishConfigs != null && publishConfigs.length > 0) {
return BluebirdPromise.map(publishConfigs, it => getResolvedPublishConfig(this.packager.info, it, true))
private async computePublishConfigs(): Promise<Array<PublishConfiguration> | null> {
let publishConfigs = getPublishConfigs(this.packager, this.options)
if (publishConfigs == null) {
return null
}
else {
return BluebirdPromise.resolve(null)

if (publishConfigs.length === 0) {
// https://github.com/electron-userland/electron-builder/issues/925#issuecomment-261732378
// default publish config is github, file should be generated regardless of publish state (user can test installer locally or manage the release process manually)
const repositoryInfo = await this.packager.getRepositoryInfo()
if (repositoryInfo != null && repositoryInfo.type === "github") {
publishConfigs = [{provider: "github"}]
}
else {
return null
}
}

return await BluebirdPromise.map(publishConfigs, it => <Promise<PublishConfiguration>>getResolvedPublishConfig(this.packager.info, it, true))
}

build(appOutDir: string, arch: Arch) {
Expand Down Expand Up @@ -226,36 +238,36 @@ export default class NsisTarget extends Target {
const publishConfigs = await this.publishConfigs
const githubArtifactName = `${appInfo.name}-Setup-${version}.exe`
if (publishConfigs != null) {
let sha2: string | null = null
for (const publishConfig of publishConfigs) {
if (publishConfig.provider === "generic" || publishConfig.provider === "github") {
if (sha2 == null) {
sha2 = await sha256(installerPath)
}
if (!(publishConfig.provider === "generic" || publishConfig.provider === "github")) {
continue
}

const channel = (<GenericServerOptions>publishConfig).channel || "latest"
if (publishConfig.provider === "generic") {
await writeFile(path.join(this.outDir, `${channel}.yml`), safeDump(<UpdateInfo>{
version: version,
path: installerFilename,
sha2: sha2,
}))
}
else {
packager.info.eventEmitter.emit("artifactCreated", <ArtifactCreated>{
data: new Buffer(safeDump(<UpdateInfo>{
version: version,
path: githubArtifactName,
sha2: sha2,
})),
artifactName: `${channel}.yml`,
packager: packager,
publishConfig: publishConfig,
})
}
const sha2 = await sha256(installerPath)
const channel = (<GenericServerOptions>publishConfig).channel || "latest"
const updateInfoFile = path.join(this.outDir, `${channel}.yml`)
await writeFile(updateInfoFile, safeDump(<UpdateInfo>{
version: version,
githubArtifactName: githubArtifactName,
path: installerFilename,
sha2: sha2,
}))

const githubPublishConfig = publishConfigs.find(it => it.provider === "github")
if (githubPublishConfig != null) {
packager.info.eventEmitter.emit("artifactCreated", <ArtifactCreated>{
file: updateInfoFile,
packager: packager,
publishConfig: githubPublishConfig,
})
}

break
}
}
else {
await unlinkIfExists(path.join(this.outDir, `latest.yml`))
}

packager.dispatchArtifactCreated(installerPath, githubArtifactName)
}
Expand Down
10 changes: 9 additions & 1 deletion packages/electron-builder/src/winPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,18 @@ export class WinPackager extends PlatformPackager<WinBuildOptions> {
switch (name) {
case "nsis":
return require("./targets/nsis").default

case "squirrel":
return require("electron-builder-squirrel-windows").default
try {
return require("electron-builder-squirrel-windows").default
}
catch (e) {
throw new Error(`Since electron-builder 11, module electron-builder-squirrel-windows must be installed in addition to build Squirrel.Windows: ${e.stack || e}`)
}

case "appx":
return require("./targets/appx").default

default:
return null
}
Expand Down

0 comments on commit b46105e

Please sign in to comment.