Skip to content

Commit

Permalink
fix: check that electron-packager create out directory
Browse files Browse the repository at this point in the history
Allow osx as platform id

Closes #301
  • Loading branch information
develar committed Apr 15, 2016
1 parent bc6e4e9 commit e015b61
Show file tree
Hide file tree
Showing 16 changed files with 134 additions and 108 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
"validate-commit-msg": "validate-commit-msg",
"//": "Update wiki if docs changed. Update only if functionalily are generally available (latest release, not next)",
"update-wiki": "git subtree split -b wiki --prefix docs/ && git push https://github.com/electron-userland/electron-builder.wiki.git wiki:master"
"update-wiki": "git subtree split -b wiki --prefix docs/ && git push wiki wiki:master"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -56,7 +56,7 @@
"dependencies": {
"bluebird": "^3.3.5",
"command-line-args": "^2.1.6",
"electron-packager-tf": "^6.0.3-beta.1",
"electron-packager-tf": "^6.0.3-beta.3",
"electron-winstaller-fixed": "^2.2.1-beta.0",
"fs-extra": "^0.26.7",
"fs-extra-p": "^0.2.0",
Expand Down Expand Up @@ -87,12 +87,12 @@
"plist": "^1.2.0",
"pre-commit": "^1.1.2",
"semantic-release": "^4.3.5",
"should": "^8.3.0",
"should": "^8.3.1",
"ts-babel": "^0.7.0",
"tsconfig-glob": "^0.4.3",
"tslint": "next",
"typescript": "1.9.0-dev.20160409",
"validate-commit-msg": "^2.5.0"
"typescript": "^1.9.0-dev.20160414",
"validate-commit-msg": "^2.6.0"
},
"babel": {
"plugins": [
Expand Down
4 changes: 3 additions & 1 deletion src/builder.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Packager } from "./packager"
import { Packager, normalizePlatforms } from "./packager"
import { PackagerOptions } from "./platformPackager"
import { PublishOptions, Publisher, GitHubPublisher } from "./gitHubPublisher"
import { executeFinally } from "./promise"
Expand Down Expand Up @@ -34,6 +34,8 @@ export async function build(originalOptions?: BuildOptions): Promise<void> {
cscKeyPassword: process.env.CSC_KEY_PASSWORD,
githubToken: process.env.GH_TOKEN || process.env.GH_TEST_TOKEN,
}, originalOptions)

options.platform = normalizePlatforms(originalOptions.platform)

const lifecycleEvent = process.env.npm_lifecycle_event
if (options.publish) {
Expand Down
4 changes: 2 additions & 2 deletions src/linuxPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class LinuxPackager extends PlatformPackager<LinuxBuildOptions> {
}
}

protected get platform() {
get platform() {
return Platform.LINUX
}

Expand All @@ -50,7 +50,7 @@ export class LinuxPackager extends PlatformPackager<LinuxBuildOptions> {

promises.push(this.computeDesktop(tempDir))

return Array.prototype.concat.apply([], await BluebirdPromise.all(promises))
return [].concat(...await BluebirdPromise.all(promises))
}

private async computeDesktop(tempDir: string): Promise<Array<string>> {
Expand Down
4 changes: 2 additions & 2 deletions src/macPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ export default class MacPackager extends PlatformPackager<OsXBuildOptions> {
}
}

protected get platform() {
get platform() {
return Platform.OSX
}

async pack(outDir: string, appOutDir: string, arch: string): Promise<any> {
await super.pack(outDir, appOutDir, arch)
const codeSigningInfo = await this.codeSigningInfo
return await this.signMac(path.join(appOutDir, this.appName + ".app"), codeSigningInfo)
await this.signMac(path.join(appOutDir, this.appName + ".app"), codeSigningInfo)
}

private signMac(distPath: string, codeSigningInfo: CodeSigningInfo): Promise<any> {
Expand Down
16 changes: 12 additions & 4 deletions src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,19 @@ export class Platform {
return this.name
}

public static fromNodePlatform(name: string): Platform {
public static fromString(name: string): Platform {
switch (name) {
case Platform.OSX.nodeName: return Platform.OSX
case Platform.WINDOWS.nodeName: return Platform.WINDOWS
case Platform.LINUX.nodeName: return Platform.LINUX
case Platform.OSX.nodeName:
case Platform.OSX.name:
return Platform.OSX

case Platform.WINDOWS.nodeName:
case Platform.WINDOWS.name:
case Platform.WINDOWS.buildConfigurationKey:
return Platform.WINDOWS

case Platform.LINUX.nodeName:
return Platform.LINUX
}

throw new Error("Unknown platform: " + name)
Expand Down
45 changes: 21 additions & 24 deletions src/packager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { all, executeFinally } from "./promise"
import { EventEmitter } from "events"
import { Promise as BluebirdPromise } from "bluebird"
import { InfoRetriever } from "./repositoryInfo"
import { AppMetadata, DevMetadata } from "./metadata"
import { AppMetadata, DevMetadata, Platform } from "./metadata"
import { PackagerOptions, PlatformPackager, BuildInfo, ArtifactCreated, use } from "./platformPackager"
import MacPackager from "./macPackager"
import { WinPackager } from "./winPackager"
Expand Down Expand Up @@ -50,7 +50,7 @@ export class Packager implements BuildInfo {
async build(): Promise<any> {
const devPackageFile = this.devPackageFile
const appPackageFile = this.projectDir === this.appDir ? devPackageFile : path.join(this.appDir, "package.json")
const platforms = normalizePlatforms(this.options.platform)
const platforms = this.options.platform

const metadataList = await BluebirdPromise.map(Array.from(new Set([devPackageFile, appPackageFile])), readPackageJson)
this.metadata = metadataList[metadataList.length - 1]
Expand All @@ -63,7 +63,7 @@ export class Packager implements BuildInfo {
return executeFinally(this.doBuild(platforms, cleanupTasks), () => all(cleanupTasks.map(it => it())))
}

private async doBuild(platforms: Array<string>, cleanupTasks: Array<() => Promise<any>>): Promise<any> {
private async doBuild(platforms: Array<Platform>, cleanupTasks: Array<() => Promise<any>>): Promise<any> {
const distTasks: Array<Promise<any>> = []
const outDir = path.resolve(this.projectDir, use(this.devMetadata.directories, it => it.output) || "dist")

Expand All @@ -72,7 +72,7 @@ export class Packager implements BuildInfo {
for (let arch of normalizeArchs(platform, this.options.arch)) {
await this.installAppDependencies(arch)
// electron-packager uses productName in the directory name
const appOutDir = path.join(outDir, helper.appName + "-" + platform + "-" + arch)
const appOutDir = path.join(outDir, `${helper.appName}-${platform.nodeName}-${arch}`)
await helper.pack(outDir, appOutDir, arch)
if (this.options.dist) {
distTasks.push(helper.packageInDistributableFormat(outDir, appOutDir, arch))
Expand All @@ -83,32 +83,29 @@ export class Packager implements BuildInfo {
return await BluebirdPromise.all(distTasks)
}

private createHelper(platform: string, cleanupTasks: Array<() => Promise<any>>): PlatformPackager<any> {
private createHelper(platform: Platform, cleanupTasks: Array<() => Promise<any>>): PlatformPackager<any> {
if (this.options.platformPackagerFactory != null) {
return this.options.platformPackagerFactory(this, platform, cleanupTasks)
}

switch (platform) {
case "darwin":
case "osx":
case Platform.OSX:
{
const helperClass: typeof MacPackager = require("./macPackager").default
return new helperClass(this, cleanupTasks)
}

case "win32":
case "win":
case "windows":
case Platform.WINDOWS:
{
const helperClass: typeof WinPackager = require("./winPackager").WinPackager
return new helperClass(this, cleanupTasks)
}

case "linux":
case Platform.LINUX:
return new (require("./linuxPackager").LinuxPackager)(this)

default:
throw new Error("Unsupported platform: " + platform)
throw new Error("Unknown platform: " + platform)
}
}

Expand Down Expand Up @@ -137,7 +134,7 @@ export class Packager implements BuildInfo {
return absoluteAppPath
}

private checkMetadata(appPackageFile: string, devAppPackageFile: string, platforms: Array<string>): void {
private checkMetadata(appPackageFile: string, devAppPackageFile: string, platforms: Array<Platform>): void {
const reportError = (missedFieldName: string) => {
throw new Error("Please specify '" + missedFieldName + "' in the application package.json ('" + appPackageFile + "')")
}
Expand All @@ -163,7 +160,7 @@ export class Packager implements BuildInfo {
if (author == null) {
reportError("author")
}
else if (this.options.dist && author.email == null && platforms.includes("linux")) {
else if (this.options.dist && author.email == null && platforms.includes(Platform.LINUX)) {
throw new Error(util.format(errorMessages.authorEmailIsMissed, appPackageFile))
}
}
Expand All @@ -180,32 +177,32 @@ export class Packager implements BuildInfo {
}
}

export function normalizeArchs(platform: string, arch?: string) {
if (platform === "darwin") {
export function normalizeArchs(platform: Platform, arch?: string) {
if (platform === Platform.OSX) {
return ["x64"]
}
else {
return arch == null ? [process.arch] : (arch === "all" ? ["ia32", "x64"] : [arch])
}
}

export function normalizePlatforms(platforms: Array<string>): Array<string> {
export function normalizePlatforms(platforms: Array<string | Platform>): Array<Platform> {
if (platforms == null || platforms.length === 0) {
return [process.platform]
return [Platform.fromString(process.platform)]
}
else if (platforms[0] === "all") {
if (process.platform === "darwin") {
return ["darwin", "linux", "win32"]
if (process.platform === Platform.OSX.nodeName) {
return [Platform.OSX, Platform.LINUX, Platform.WINDOWS]
}
else if (process.platform === "linux") {
else if (process.platform === Platform.LINUX.nodeName) {
// OS X code sign works only on OS X
return ["linux", "win32"]
return [Platform.LINUX, Platform.WINDOWS]
}
else {
return ["win32"]
return [Platform.WINDOWS]
}
}
else {
return platforms
return platforms.map(it => it instanceof Platform ? it : Platform.fromString(it))
}
}
26 changes: 17 additions & 9 deletions src/platformPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import * as path from "path"
import packager = require("electron-packager-tf")
import globby = require("globby")
import { copy } from "fs-extra-p"
import { Packager } from "./packager";
import { statOrNull } from "./util"
import { Packager } from "./packager"

//noinspection JSUnusedLocalSymbols
const __awaiter = require("./awaiter")
Expand All @@ -21,7 +22,7 @@ export interface PackagerOptions {

sign?: string

platform?: Array<string>
platform?: Array<Platform>
target?: Array<string>

appDir?: string
Expand All @@ -32,7 +33,7 @@ export interface PackagerOptions {
csaLink?: string
cscKeyPassword?: string

platformPackagerFactory?: (packager: Packager, platform: string, cleanupTasks: Array<() => Promise<any>>) => PlatformPackager<any>
platformPackagerFactory?: (packager: Packager, platform: Platform, cleanupTasks: Array<() => Promise<any>>) => PlatformPackager<any>
}

export interface BuildInfo extends ProjectMetadataProvider {
Expand Down Expand Up @@ -62,7 +63,7 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>

readonly appName: string

protected abstract get platform(): Platform
public abstract get platform(): Platform

constructor(protected info: BuildInfo) {
this.options = info.options
Expand Down Expand Up @@ -90,20 +91,19 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
}

async pack(outDir: string, appOutDir: string, arch: string): Promise<any> {
await this.doPack(outDir, arch)
await this.doPack(outDir, appOutDir, arch)
await this.copyExtraResources(appOutDir, arch)
}

protected async doPack(outDir: string, arch: string) {
protected async doPack(outDir: string, appOutDir: string, arch: string) {
const version = this.metadata.version
let buildVersion = version
const buildNumber = this.computeBuildNumber()
if (buildNumber != null) {
buildVersion += "." + buildNumber
}

const electronPackagerOptions = this.devMetadata.build
checkConflictingOptions(electronPackagerOptions)
checkConflictingOptions(this.devMetadata.build)

const options = Object.assign({
dir: this.info.appDir,
Expand All @@ -124,7 +124,7 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
ProductName: this.appName,
InternalName: this.appName,
}
}, electronPackagerOptions)
}, this.devMetadata.build)

delete options.osx
delete options.win
Expand All @@ -133,6 +133,14 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
delete options.iconUrl

await pack(options)

const outStat = await statOrNull(appOutDir)
if (outStat == null) {
throw new Error(`Output directory ${appOutDir} does not exists. Seems like a wrong configuration.`)
}
else if (!outStat.isDirectory()) {
throw new Error(`Output directory ${appOutDir} is a file. Seems like a wrong configuration.`)
}
}

protected getExtraResources(arch: string): Promise<Array<string>> {
Expand Down
16 changes: 15 additions & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Promise as BluebirdPromise } from "bluebird"
import readPackageJsonAsync = require("read-package-json")
import * as os from "os"
import * as path from "path"
import { readJson } from "fs-extra-p"
import { readJson, stat } from "fs-extra-p"

//noinspection JSUnusedLocalSymbols
const __awaiter = require("./awaiter")
Expand Down Expand Up @@ -119,4 +119,18 @@ export async function getElectronVersion(packageData: any, packageJsonPath: stri

const firstChar = electronPrebuiltDep[0]
return firstChar === "^" || firstChar === "~" ? electronPrebuiltDep.substring(1) : electronPrebuiltDep
}

export async function statOrNull(file: string) {
try {
return await stat(file)
}
catch (e) {
if (e.code === "ENOENT") {
return null
}
else {
throw e
}
}
}
Loading

0 comments on commit e015b61

Please sign in to comment.