Skip to content

Commit

Permalink
refactor: prepare to support AppImage electron-userland#504
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Jul 1, 2016
1 parent 01abc3a commit 11e6d0f
Show file tree
Hide file tree
Showing 22 changed files with 359 additions and 192 deletions.
6 changes: 6 additions & 0 deletions .idea/dictionaries/develar.xml

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

3 changes: 2 additions & 1 deletion .idea/electron-builder.iml

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

1 change: 1 addition & 0 deletions .idea/jsLibraryMappings.xml

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

15 changes: 15 additions & 0 deletions .idea/libraries/ts.xml

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

4 changes: 4 additions & 0 deletions .idea/runConfigurations/winPackagerTest.xml

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

4 changes: 2 additions & 2 deletions docker/base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ RUN apt-get update -y && \
curl -L http://tukaani.org/xz/xz-$XZ_VERSION.tar.xz | tar -xJ && cd xz-$XZ_VERSION && ./configure && make && make install && cd .. && rm -rf xz-$XZ_VERSION && ldconfig && \
mkdir -p /tmp/7z && curl -L http://downloads.sourceforge.net/project/p7zip/p7zip/15.14.1/p7zip_15.14.1_src_all.tar.bz2 | tar -xj -C /tmp/7z --strip-components 1 && cd /tmp/7z && cp makefile.linux_amd64_asm makefile.machine && make && make install && rm -rf /tmp/7z && \
mkdir -p /tmp/s && cd /tmp/s && \
curl -L https://sourceforge.net/code-snapshots/git/o/os/osslsigncode/osslsigncode.git/osslsigncode-osslsigncode-e72a1937d1a13e87074e4584f012f13e03fc1d64.zip > a.zip && \
7za x a.zip && cd osslsigncode-osslsigncode-e72a1937d1a13e87074e4584f012f13e03fc1d64 && ./autogen.sh && ./configure && make && make install && rm -rf /tmp/s
curl -L https://dl.bintray.com/develar/bin/osslsigncode-src.7z > a.7z && \
7za x -oosslsigncode a.7z && cd osslsigncode && ./autogen.sh && ./configure && make && make install && rm -rf /tmp/s

# nodejs keys
RUN set -ex \
Expand Down
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"electron-osx-sign-tf": "0.6.0",
"electron-packager-tf": "~7.5.1",
"electron-winstaller-fixed": "~2.11.5",
"fs-extra-p": "^1.0.3",
"fs-extra-p": "^1.0.5",
"hosted-git-info": "^2.1.5",
"image-size": "^0.5.0",
"lodash.template": "^4.2.5",
Expand All @@ -81,9 +81,10 @@
"progress-stream": "^1.2.0",
"read-package-json": "^2.0.4",
"sanitize-filename": "^1.6.0",
"semver": "^5.1.1",
"semver": "^5.2.0",
"signcode-tf": "~0.7.3",
"source-map-support": "^0.4.0",
"source-map-support": "^0.4.1",
"typescript": "^2.0.0-dev.20160630",
"update-notifier": "^1.0.2",
"uuid-1345": "^0.99.6",
"yargs": "^4.7.1"
Expand Down Expand Up @@ -118,10 +119,10 @@
"pre-git": "^3.10.0",
"semantic-release": "^6.3.0",
"should": "^9.0.2",
"ts-babel": "^1.0.2",
"ts-babel": "^1.0.3",
"tsconfig-glob": "^0.4.3",
"tslint": "3.12.0-dev.1",
"typescript": "1.9.0-dev.20160620-1.0",
"typescript": "2.0.0-dev.20160620-1.0",
"whitespace": "^2.0.0"
},
"babel": {
Expand Down
5 changes: 2 additions & 3 deletions src/codeSign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export async function createKeychain(keychainName: string, cscLink: string, cscK
["set-keychain-settings", "-t", "3600", "-u", keychainName]
], it => exec("security", it))
])
.then(() => importCerts(keychainName, certPaths, <Array<string>>[cscKeyPassword, cscIKeyPassword].filter(it => it != null))),
.then<CodeSigningInfo>(() => importCerts(keychainName, certPaths, <Array<string>>[cscKeyPassword, cscIKeyPassword].filter(it => it != null))),
errorOccurred => {
const tasks = certPaths.map(it => deleteFile(it, true))
if (errorOccurred) {
Expand Down Expand Up @@ -163,7 +163,7 @@ export async function findIdentity(namePrefix: CertType, qualifier?: string): Pr
if (findIdentityRawResult == null) {
// https://github.com/electron-userland/electron-builder/issues/481
// https://github.com/electron-userland/electron-builder/issues/535
findIdentityRawResult = BluebirdPromise.all([
findIdentityRawResult = BluebirdPromise.all<Array<string>>([
exec("security", ["find-identity", "-v"])
.then(it => it.trim().split("\n").filter(it => {
for (let prefix of appleCertificatePrefixes) {
Expand All @@ -177,7 +177,6 @@ export async function findIdentity(namePrefix: CertType, qualifier?: string): Pr
.then(it => it.trim().split(("\n"))),
])
.then(it => {
//noinspection SpellCheckingInspection
const array = it[0].concat(it[1])
.filter(it => !it.includes("(Missing required extension)") && !it.includes("valid identities found") && !it.includes("iPhone ") && !it.includes("com.apple.idms.appleid.prd."))
// remove 1)
Expand Down
36 changes: 22 additions & 14 deletions src/linuxPackager.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import * as path from "path"
import { Promise as BluebirdPromise } from "bluebird"
import { PlatformPackager, BuildInfo, Target } from "./platformPackager"
import { PlatformPackager, BuildInfo, Target, TargetEx } from "./platformPackager"
import { Platform, LinuxBuildOptions, Arch } from "./metadata"
import { FpmTarget } from "./targets/fpm"
import FpmTarget from "./targets/fpm"
import { createCommonTarget, DEFAULT_TARGET } from "./targets/targetFactory"
import { LinuxTargetHelper } from "./targets/LinuxTargetHelper"
import AppImageTarget from "./targets/appImage"

//noinspection JSUnusedLocalSymbols
const __awaiter = require("./util/awaiter")

export const installPrefix = "/opt"

export class LinuxPackager extends PlatformPackager<LinuxBuildOptions> {
constructor(info: BuildInfo) {
super(info)
Expand All @@ -26,17 +26,28 @@ export class LinuxPackager extends PlatformPackager<LinuxBuildOptions> {
}
}

createTargets(targets: Array<string>, mapper: (name: string, factory: () => Target) => void, cleanupTasks: Array<() => Promise<any>>): void {
createTargets(targets: Array<string>, mapper: (name: string, factory: (outDir: string) => Target) => void, cleanupTasks: Array<() => Promise<any>>): void {
for (let name of targets) {
if (name === "dir") {
continue
}

if (name === DEFAULT_TARGET || name === "deb") {
mapper("deb", () => new FpmTarget("deb", this, cleanupTasks))
let helper: LinuxTargetHelper | null
const getHelper = () => {
if (helper == null) {
helper = new LinuxTargetHelper(this, cleanupTasks)
}
return helper
}

if (name === "appimage") {
const targetClass: typeof AppImageTarget = require("./targets/appImage").default
mapper(name, outDir => new targetClass(this, getHelper(), outDir))
}
else if (name === "rpm" || name === "sh" || name === "freebsd" || name === "pacman" || name === "apk" || name === "p5p") {
mapper(name, () => new FpmTarget(name, this, cleanupTasks))
else if (name === DEFAULT_TARGET || name === "deb" || name === "rpm" || name === "sh" || name === "freebsd" || name === "pacman" || name === "apk" || name === "p5p") {
const targetClass: typeof FpmTarget = require("./targets/fpm").default
const target = name === DEFAULT_TARGET ? "deb" : name
mapper(target, outDir => new targetClass(target, this, getHelper(), outDir))
}
else {
mapper(name, () => createCommonTarget(name))
Expand All @@ -58,11 +69,8 @@ export class LinuxPackager extends PlatformPackager<LinuxBuildOptions> {
protected async packageInDistributableFormat(outDir: string, appOutDir: string, arch: Arch, targets: Array<Target>): Promise<any> {
// todo fix fpm - if run in parallel, get strange tar errors
for (let t of targets) {
if (t instanceof FpmTarget) {
const target = t.name
const destination = path.join(outDir, this.generateName(target, arch, true /* on Linux we use safe name — without space */))
await t.build(destination, target, appOutDir, arch)
this.dispatchArtifactCreated(destination)
if (t instanceof TargetEx) {
await t.build(appOutDir, arch)
}
}

Expand Down
41 changes: 22 additions & 19 deletions src/platformPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import EventEmitter = NodeJS.EventEmitter
import { Promise as BluebirdPromise } from "bluebird"
import * as path from "path"
import { pack, ElectronPackagerOptions, userIgnoreFilter } from "electron-packager-tf"
import { readdir, unlink, remove, realpath } from "fs-extra-p"
import { statOrNull, use } from "./util/util"
import { readdir, remove, realpath } from "fs-extra-p"
import { statOrNull, use, unlinkIfExists } from "./util/util"
import { Packager } from "./packager"
import { AsarOptions } from "asar"
import { archiveApp } from "./targets/archive"
Expand Down Expand Up @@ -75,6 +75,10 @@ export class Target {
}
}

export abstract class TargetEx extends Target {
abstract async build(appOutDir: string, arch: Arch): Promise<any>
}

export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions> {
readonly options: PackagerOptions

Expand Down Expand Up @@ -196,18 +200,15 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
copyFiltered(this.info.appDir, appPath, filter, true)
: createAsarArchive(this.info.appDir, resourcesPath, asarOptions, filter)

const promises = [promise]
const promises = [promise, unlinkIfExists(path.join(resourcesPath, "default_app.asar")), unlinkIfExists(path.join(appOutDir, "version"))]
if (this.info.electronVersion[0] === "0") {
// electron release >= 0.37.4 - the default_app/ folder is a default_app.asar file
promises.push(remove(path.join(resourcesPath, "default_app.asar")), remove(path.join(resourcesPath, "default_app")))
}
else {
promises.push(unlink(path.join(resourcesPath, "default_app.asar")))
promises.push(remove(path.join(resourcesPath, "default_app")))
}

await BluebirdPromise.all(promises)
}
await task(`Packaging for platform ${options.platform} ${options.arch} using electron ${options.version} to ${path.relative(this.projectDir, appOutDir)}`, pack(options))
await task(`Packaging for platform ${this.platform.name} ${options.arch} using electron ${options.version} to ${path.relative(this.projectDir, appOutDir)}`, pack(options))

await this.doCopyExtraFiles(true, appOutDir, arch, platformSpecificBuildOptions)
await this.doCopyExtraFiles(false, appOutDir, arch, platformSpecificBuildOptions)
Expand All @@ -225,26 +226,27 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>

protected async computePackOptions(outDir: string, appOutDir: string, arch: Arch): Promise<ElectronPackagerOptions> {
//noinspection JSUnusedGlobalSymbols
const appInfo = this.appInfo
const options: any = deepAssign({
dir: this.info.appDir,
"app-bundle-id": this.appInfo.id,
"app-bundle-id": appInfo.id,
out: outDir,
name: this.appInfo.productName,
productName: this.appInfo.productName,
name: appInfo.productName,
productName: appInfo.productName,
platform: this.platform.nodeName,
arch: Arch[arch],
version: this.info.electronVersion,
icon: await this.getIconPath(),
overwrite: true,
"app-version": this.appInfo.version,
"app-copyright": this.appInfo.copyright,
"build-version": this.appInfo.buildVersion,
"app-version": appInfo.version,
"app-copyright": appInfo.copyright,
"build-version": appInfo.buildVersion,
tmpdir: false,
generateFinalBasename: () => path.basename(appOutDir),
}, this.devMetadata.build)

if (this.platform === Platform.WINDOWS) {
options["version-string"] = this.appInfo.versionString
options["version-string"] = appInfo.versionString
}

delete options.osx
Expand Down Expand Up @@ -369,11 +371,11 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
return archiveApp(this.devMetadata.build.compression, format, outFile, this.platform === Platform.MAC ? path.join(appOutDir, `${this.appInfo.productFilename}.app`) : appOutDir)
}

generateName(ext: string, arch: Arch, deployment: boolean): string {
generateName(ext: string | null, arch: Arch, deployment: boolean): string {
return this.generateName2(ext, arch === Arch.x64 ? null : Arch[arch], deployment)
}

generateName1(ext: string, arch: Arch, classifier: string, deployment: boolean): string {
generateName1(ext: string | null, arch: Arch, classifier: string, deployment: boolean): string {
let c = arch === Arch.x64 ? null : Arch[arch]
if (c == null) {
c = classifier
Expand All @@ -384,8 +386,9 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
return this.generateName2(ext, c, deployment)
}

generateName2(ext: string, classifier: string | n, deployment: boolean): string {
return `${deployment ? this.appInfo.name : this.appInfo.productFilename}-${this.appInfo.version}${classifier == null ? "" : `-${classifier}`}.${ext}`
generateName2(ext: string | null, classifier: string | n, deployment: boolean): string {
const dotExt = ext == null ? "" : `.${ext}`
return `${deployment ? this.appInfo.name : this.appInfo.productFilename}-${this.appInfo.version}${classifier == null ? "" : `-${classifier}`}${dotExt}`
}

protected async getDefaultIcon(ext: string) {
Expand Down
Loading

0 comments on commit 11e6d0f

Please sign in to comment.