Skip to content

Commit 0ea43a3

Browse files
committed
feat(appimage): artifactName support for AppImage
Close #775
1 parent da1734e commit 0ea43a3

File tree

9 files changed

+47
-33
lines changed

9 files changed

+47
-33
lines changed

docs/Auto Update.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ Simplified auto-update is supported on Windows if you use the default NSIS setup
2121
**NOTICE**:
2222
2323
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).
24-
2. Bintray provider doesn't support [macOS auto-update](https://github.com/electron-userland/electron-builder/issues/1172) currently.
25-
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.
24+
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.
2625

2726
### Examples
2827

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

3332
## File Generated and Uploaded in Addition
3433

35-
`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`).
34+
`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`).
3635
3736
## Private GitHub Update Repo
3837
3938
You can use a private repository for updates with electron-updater by setting the `GH_TOKEN` environment variable (on user machine) and `private` option.
4039
If `GH_TOKEN` is set, electron-updater will use the GitHub API for updates allowing private repositories to work.
4140
42-
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).
41+
Only for [very special](https://github.com/electron-userland/electron-builder/issues/1393#issuecomment-288191885) cases — not intended and not suitable for all users.
4342
4443
**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.
4544

packages/electron-builder/src/metadata.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,6 @@ export interface Config extends PlatformSpecificBuildOptions {
186186

187187
/**
188188
* 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).
189-
*
190-
* Currently supported only for `mas`, `pkg`, `dmg` and `nsis`.
191189
*/
192190
readonly artifactName?: string | null
193191

packages/electron-builder/src/platformPackager.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
131131
}
132132

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

@@ -349,12 +349,31 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
349349
if (pattern == null) {
350350
pattern = this.platformSpecificBuildOptions.artifactName || this.config.artifactName || defaultPattern || "${productName}-${version}.${ext}"
351351
}
352-
return this.expandMacro(pattern, arch, {
352+
353+
let archName: string | null = arch == null ? null : Arch[arch]
354+
if (arch === Arch.x64) {
355+
if (ext === "AppImage" || ext === "rpm") {
356+
archName = "x86_64"
357+
}
358+
else if (ext === "deb") {
359+
archName = "amd64"
360+
}
361+
}
362+
else if (arch === Arch.ia32) {
363+
if (ext === "deb" || ext === "AppImage") {
364+
archName = "i386"
365+
}
366+
else if (ext === "pacman" || ext === "rpm") {
367+
archName = "i686"
368+
}
369+
}
370+
371+
return this.expandMacro(pattern, this.platform === Platform.MAC ? null : archName, {
353372
ext: ext
354373
})
355374
}
356375

357-
expandMacro(pattern: string, arch: Arch | n, extra: any = {}): string {
376+
expandMacro(pattern: string, arch: string | n, extra: any = {}): string {
358377
if (arch == null) {
359378
pattern = pattern
360379
.replace("-${arch}", "")
@@ -374,7 +393,7 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
374393
// see above, we remove macro if no arch
375394
return ""
376395
}
377-
return Arch[arch]
396+
return arch
378397

379398
case "os":
380399
return this.platform.buildConfigurationKey

packages/electron-builder/src/publish/PublishManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ function expandPublishConfig(options: any, packager: PlatformPackager<any>, arch
437437
for (const name of Object.keys(options)) {
438438
const value = options[name]
439439
if (typeof value === "string") {
440-
const expanded = packager.expandMacro(value, arch)
440+
const expanded = packager.expandMacro(value, arch == null ? null : Arch[arch])
441441
if (expanded !== value) {
442442
options[name] = expanded
443443
}

packages/electron-builder/src/targets/ArchiveTarget.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,11 @@ export class ArchiveTarget extends Target {
1414
async build(appOutDir: string, arch: Arch): Promise<any> {
1515
const packager = this.packager
1616
const isMac = packager.platform === Platform.MAC
17-
const outDir = this.outDir
18-
1917
const format = this.name
2018
log(`Building ${isMac ? "macOS " : ""}${format}`)
2119

22-
// we use app name here - see https://github.com/electron-userland/electron-builder/pull/204
23-
const outFile = (() => {
24-
switch (packager.platform) {
25-
case Platform.MAC:
26-
return path.join(outDir, packager.expandArtifactNamePattern(this.options, format, arch, "${productName}-${version}-${os}.${ext}"))
27-
case Platform.WINDOWS:
28-
return path.join(outDir, packager.generateName(format, arch, false, "win"))
29-
case Platform.LINUX:
30-
return path.join(outDir, packager.generateName(format, arch, true))
31-
default:
32-
throw new Error(`Unknown platform: ${packager.platform}`)
33-
}
34-
})()
35-
20+
// do not specify arch if x64
21+
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}"))
3622
if (format.startsWith("tar.")) {
3723
await tar(packager.config.compression, format, outFile, appOutDir, isMac)
3824
}

packages/electron-builder/src/targets/appImage.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ export default class AppImageTarget extends Target {
3737

3838
const packager = this.packager
3939

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

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

6666
if (arch === Arch.x64) {
67+
// noinspection SpellCheckingInspection
6768
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")
6869
args.push("-map", libDir, "/usr/lib")
6970
}

packages/electron-builder/src/targets/appx.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ export default class AppXTarget extends Target {
6363
this.writeManifest(templatePath, preAppx, safeName, arch, publisher)
6464
])
6565

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

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

7777
private async writeManifest(templatePath: string, preAppx: string, safeName: string, arch: Arch, publisher: string) {

packages/electron-builder/src/targets/fpm.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,18 @@ export default class FpmTarget extends Target {
6767

6868
log(`Building ${target}`)
6969

70-
const destination = path.join(this.outDir, this.packager.generateName(target, arch, true /* on Linux we use safe name — without space */))
70+
let nameFormat = "${name}-${version}-${arch}.${ext}"
71+
let isUseArchIfX64 = false
72+
if (target === "deb") {
73+
nameFormat = "${name}_${version}_${arch}.${ext}"
74+
isUseArchIfX64 = true
75+
}
76+
else if (target === "rpm") {
77+
nameFormat = "${name}-${version}.${arch}.${ext}"
78+
isUseArchIfX64 = true
79+
}
80+
81+
const destination = path.join(this.outDir, this.packager.expandArtifactNamePattern(this.options, target, arch !== Arch.x64 || isUseArchIfX64 ? arch : null, nameFormat))
7182
await unlinkIfExists(destination)
7283
if (this.packager.info.prepackaged != null) {
7384
await ensureDir(this.outDir)

test/out/linux/__snapshots__/fpmTest.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Object {
55
"linux": Array [
66
Object {
77
"arch": 1,
8-
"file": "TestApp-1.1.0.rpm",
8+
"file": "TestApp-1.1.0.x86_64.rpm",
99
},
1010
Object {
1111
"arch": 1,

0 commit comments

Comments
 (0)