Skip to content

Commit

Permalink
feat(appimage): artifactName support for AppImage
Browse files Browse the repository at this point in the history
Close #775
  • Loading branch information
develar committed Jun 6, 2017
1 parent da1734e commit 0ea43a3
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 33 deletions.
7 changes: 3 additions & 4 deletions docs/Auto Update.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ Simplified auto-update is supported on Windows if you use the default NSIS setup
**NOTICE**:
1. Do not call [setFeedURL](#module_electron-updater/out/AppUpdater.AppUpdater+setFeedURL). electron-builder automatically creates `app-update.yml` file for you on build in the `resources` (this file is internal, you don't need to be aware of it).
2. Bintray provider doesn't support [macOS auto-update](https://github.com/electron-userland/electron-builder/issues/1172) currently.
3. `zip` target for macOS is **required** for Squirrel.Mac, whereas `latest-mac.json` cannot be created, which causes `autoUpdater` error. Default [target](https://github.com/electron-userland/electron-builder/wiki/Options#MacOptions-target) for macOS `dmg`+`zip`, you don't need to explicitly specify target.
2. `zip` target for macOS is **required** for Squirrel.Mac, whereas `latest-mac.json` cannot be created, which causes `autoUpdater` error. Default [target](https://github.com/electron-userland/electron-builder/wiki/Options#MacOptions-target) for macOS `dmg`+`zip`, you don't need to explicitly specify target.

### Examples

Expand All @@ -32,14 +31,14 @@ Simplified auto-update is supported on Windows if you use the default NSIS setup

## File Generated and Uploaded in Addition

`latest.yml` (or `latest-mac.json` for macOS) will be generated and uploaded for all providers except `bintray` (because not required, `bintray` doesn't use `latest.yml`).
`latest.yml` (or `latest-mac.yml` for macOS) will be generated and uploaded for all providers except `bintray` (because not required, `bintray` doesn't use `latest.yml`).
## Private GitHub Update Repo
You can use a private repository for updates with electron-updater by setting the `GH_TOKEN` environment variable (on user machine) and `private` option.
If `GH_TOKEN` is set, electron-updater will use the GitHub API for updates allowing private repositories to work.
Only for [very special](https://github.com/electron-userland/electron-builder/issues/1393#issuecomment-288191885) cases — not intended and not suitable for all users. Doesn't work [on macOs](https://github.com/electron-userland/electron-builder/issues/1370).
Only for [very special](https://github.com/electron-userland/electron-builder/issues/1393#issuecomment-288191885) cases — not intended and not suitable for all users.
**Note:** The GitHub API currently has a rate limit of 5000 requests per user per hour. An update check uses up to 3 requests per check.
Expand Down
2 changes: 0 additions & 2 deletions packages/electron-builder/src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,6 @@ export interface Config extends PlatformSpecificBuildOptions {

/**
* The [artifact file name pattern](https://github.com/electron-userland/electron-builder/wiki/Options#artifact-file-name-pattern). Defaults to `${productName}-${version}.${ext}` (some target can have another defaults, see corresponding options).
*
* Currently supported only for `mas`, `pkg`, `dmg` and `nsis`.
*/
readonly artifactName?: string | null

Expand Down
27 changes: 23 additions & 4 deletions packages/electron-builder/src/platformPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
}

const asarOptions = await this.computeAsarOptions(platformSpecificBuildOptions)
const macroExpander = (it: string) => this.expandMacro(it, arch, {"/*": "{,/**/*}"})
const macroExpander = (it: string) => this.expandMacro(it, arch == null ? null : Arch[arch], {"/*": "{,/**/*}"})
const extraResourceMatchers = this.getExtraFileMatchers(true, appOutDir, macroExpander, platformSpecificBuildOptions)
const extraFileMatchers = this.getExtraFileMatchers(false, appOutDir, macroExpander, platformSpecificBuildOptions)

Expand Down Expand Up @@ -349,12 +349,31 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
if (pattern == null) {
pattern = this.platformSpecificBuildOptions.artifactName || this.config.artifactName || defaultPattern || "${productName}-${version}.${ext}"
}
return this.expandMacro(pattern, arch, {

let archName: string | null = arch == null ? null : Arch[arch]
if (arch === Arch.x64) {
if (ext === "AppImage" || ext === "rpm") {
archName = "x86_64"
}
else if (ext === "deb") {
archName = "amd64"
}
}
else if (arch === Arch.ia32) {
if (ext === "deb" || ext === "AppImage") {
archName = "i386"
}
else if (ext === "pacman" || ext === "rpm") {
archName = "i686"
}
}

return this.expandMacro(pattern, this.platform === Platform.MAC ? null : archName, {
ext: ext
})
}

expandMacro(pattern: string, arch: Arch | n, extra: any = {}): string {
expandMacro(pattern: string, arch: string | n, extra: any = {}): string {
if (arch == null) {
pattern = pattern
.replace("-${arch}", "")
Expand All @@ -374,7 +393,7 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
// see above, we remove macro if no arch
return ""
}
return Arch[arch]
return arch

case "os":
return this.platform.buildConfigurationKey
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-builder/src/publish/PublishManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ function expandPublishConfig(options: any, packager: PlatformPackager<any>, arch
for (const name of Object.keys(options)) {
const value = options[name]
if (typeof value === "string") {
const expanded = packager.expandMacro(value, arch)
const expanded = packager.expandMacro(value, arch == null ? null : Arch[arch])
if (expanded !== value) {
options[name] = expanded
}
Expand Down
18 changes: 2 additions & 16 deletions packages/electron-builder/src/targets/ArchiveTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,11 @@ export class ArchiveTarget extends Target {
async build(appOutDir: string, arch: Arch): Promise<any> {
const packager = this.packager
const isMac = packager.platform === Platform.MAC
const outDir = this.outDir

const format = this.name
log(`Building ${isMac ? "macOS " : ""}${format}`)

// we use app name here - see https://github.com/electron-userland/electron-builder/pull/204
const outFile = (() => {
switch (packager.platform) {
case Platform.MAC:
return path.join(outDir, packager.expandArtifactNamePattern(this.options, format, arch, "${productName}-${version}-${os}.${ext}"))
case Platform.WINDOWS:
return path.join(outDir, packager.generateName(format, arch, false, "win"))
case Platform.LINUX:
return path.join(outDir, packager.generateName(format, arch, true))
default:
throw new Error(`Unknown platform: ${packager.platform}`)
}
})()

// do not specify arch if x64
const outFile = path.join(this.outDir, packager.expandArtifactNamePattern(this.options, format, arch === Arch.x64 ? null : arch, packager.platform === Platform.LINUX ? "${name}-${version}-${arch}.${ext}" : "${productName}-${version}-${arch}-${os}.${ext}"))
if (format.startsWith("tar.")) {
await tar(packager.config.compression, format, outFile, appOutDir, isMac)
}
Expand Down
5 changes: 3 additions & 2 deletions packages/electron-builder/src/targets/appImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ export default class AppImageTarget extends Target {

const packager = this.packager

// avoid spaces in the file name
const resultFile = path.join(this.outDir, packager.generateName("AppImage", arch, true))
// https://github.com/electron-userland/electron-builder/issues/775
const resultFile = path.join(this.outDir, packager.expandArtifactNamePattern(this.options, "AppImage", arch, "${name}-${version}-${arch}.${ext}"))
await unlinkIfExists(resultFile)

const appImagePath = await appImagePathPromise
Expand All @@ -64,6 +64,7 @@ export default class AppImageTarget extends Target {
args.push("-map", this.helper.maxIconPath, "/.DirIcon")

if (arch === Arch.x64) {
// noinspection SpellCheckingInspection
const libDir = await getBin("AppImage-packages", "10.03.17", "https://bintray.com/electron-userland/bin/download_file?file_path=AppImage-packages-10.03.17-x64.7z", "172f9977fe9b24d35091d26ecbfebe2a14d96516a9c903e109e12b2a929042fe")
args.push("-map", libDir, "/usr/lib")
}
Expand Down
4 changes: 2 additions & 2 deletions packages/electron-builder/src/targets/appx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ export default class AppXTarget extends Target {
this.writeManifest(templatePath, preAppx, safeName, arch, publisher)
])

const destination = path.join(this.outDir, packager.generateName("appx", arch, false))
const destination = path.join(this.outDir, packager.expandArtifactNamePattern(this.options, "appx", arch))
const args = ["pack", "/o", "/d", preAppx, "/p", destination]
use(this.options.makeappxArgs, (it: Array<string>) => args.push(...it))
// wine supports only ia32 binary in any case makeappx crashed on wine
// await execWine(path.join(await getSignVendorPath(), "windows-10", process.platform === "win32" ? process.arch : "ia32", "makeappx.exe"), args)
await spawn(path.join(vendorPath, "windows-10", arch === Arch.ia32 ? "ia32" : "x64", "makeappx.exe"), args)

await packager.sign(destination)
packager.dispatchArtifactCreated(destination, this, arch, packager.generateName("appx", arch, true))
packager.dispatchArtifactCreated(destination, this, arch, packager.expandArtifactNamePattern(this.options, "appx", arch, "${name}-${version}-${arch}.${ext}"))
}

private async writeManifest(templatePath: string, preAppx: string, safeName: string, arch: Arch, publisher: string) {
Expand Down
13 changes: 12 additions & 1 deletion packages/electron-builder/src/targets/fpm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,18 @@ export default class FpmTarget extends Target {

log(`Building ${target}`)

const destination = path.join(this.outDir, this.packager.generateName(target, arch, true /* on Linux we use safe name — without space */))
let nameFormat = "${name}-${version}-${arch}.${ext}"
let isUseArchIfX64 = false
if (target === "deb") {
nameFormat = "${name}_${version}_${arch}.${ext}"
isUseArchIfX64 = true
}
else if (target === "rpm") {
nameFormat = "${name}-${version}.${arch}.${ext}"
isUseArchIfX64 = true
}

const destination = path.join(this.outDir, this.packager.expandArtifactNamePattern(this.options, target, arch !== Arch.x64 || isUseArchIfX64 ? arch : null, nameFormat))
await unlinkIfExists(destination)
if (this.packager.info.prepackaged != null) {
await ensureDir(this.outDir)
Expand Down
2 changes: 1 addition & 1 deletion test/out/linux/__snapshots__/fpmTest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Object {
"linux": Array [
Object {
"arch": 1,
"file": "TestApp-1.1.0.rpm",
"file": "TestApp-1.1.0.x86_64.rpm",
},
Object {
"arch": 1,
Expand Down

0 comments on commit 0ea43a3

Please sign in to comment.