Skip to content

Commit e015b61

Browse files
committed
fix: check that electron-packager create out directory
Allow osx as platform id Closes #301
1 parent bc6e4e9 commit e015b61

16 files changed

+134
-108
lines changed

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
2222
"validate-commit-msg": "validate-commit-msg",
2323
"//": "Update wiki if docs changed. Update only if functionalily are generally available (latest release, not next)",
24-
"update-wiki": "git subtree split -b wiki --prefix docs/ && git push https://github.com/electron-userland/electron-builder.wiki.git wiki:master"
24+
"update-wiki": "git subtree split -b wiki --prefix docs/ && git push wiki wiki:master"
2525
},
2626
"repository": {
2727
"type": "git",
@@ -56,7 +56,7 @@
5656
"dependencies": {
5757
"bluebird": "^3.3.5",
5858
"command-line-args": "^2.1.6",
59-
"electron-packager-tf": "^6.0.3-beta.1",
59+
"electron-packager-tf": "^6.0.3-beta.3",
6060
"electron-winstaller-fixed": "^2.2.1-beta.0",
6161
"fs-extra": "^0.26.7",
6262
"fs-extra-p": "^0.2.0",
@@ -87,12 +87,12 @@
8787
"plist": "^1.2.0",
8888
"pre-commit": "^1.1.2",
8989
"semantic-release": "^4.3.5",
90-
"should": "^8.3.0",
90+
"should": "^8.3.1",
9191
"ts-babel": "^0.7.0",
9292
"tsconfig-glob": "^0.4.3",
9393
"tslint": "next",
94-
"typescript": "1.9.0-dev.20160409",
95-
"validate-commit-msg": "^2.5.0"
94+
"typescript": "^1.9.0-dev.20160414",
95+
"validate-commit-msg": "^2.6.0"
9696
},
9797
"babel": {
9898
"plugins": [

src/builder.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Packager } from "./packager"
1+
import { Packager, normalizePlatforms } from "./packager"
22
import { PackagerOptions } from "./platformPackager"
33
import { PublishOptions, Publisher, GitHubPublisher } from "./gitHubPublisher"
44
import { executeFinally } from "./promise"
@@ -34,6 +34,8 @@ export async function build(originalOptions?: BuildOptions): Promise<void> {
3434
cscKeyPassword: process.env.CSC_KEY_PASSWORD,
3535
githubToken: process.env.GH_TOKEN || process.env.GH_TEST_TOKEN,
3636
}, originalOptions)
37+
38+
options.platform = normalizePlatforms(originalOptions.platform)
3739

3840
const lifecycleEvent = process.env.npm_lifecycle_event
3941
if (options.publish) {

src/linuxPackager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class LinuxPackager extends PlatformPackager<LinuxBuildOptions> {
3636
}
3737
}
3838

39-
protected get platform() {
39+
get platform() {
4040
return Platform.LINUX
4141
}
4242

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

5151
promises.push(this.computeDesktop(tempDir))
5252

53-
return Array.prototype.concat.apply([], await BluebirdPromise.all(promises))
53+
return [].concat(...await BluebirdPromise.all(promises))
5454
}
5555

5656
private async computeDesktop(tempDir: string): Promise<Array<string>> {

src/macPackager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ export default class MacPackager extends PlatformPackager<OsXBuildOptions> {
2626
}
2727
}
2828

29-
protected get platform() {
29+
get platform() {
3030
return Platform.OSX
3131
}
3232

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

3939
private signMac(distPath: string, codeSigningInfo: CodeSigningInfo): Promise<any> {

src/metadata.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,19 @@ export class Platform {
217217
return this.name
218218
}
219219

220-
public static fromNodePlatform(name: string): Platform {
220+
public static fromString(name: string): Platform {
221221
switch (name) {
222-
case Platform.OSX.nodeName: return Platform.OSX
223-
case Platform.WINDOWS.nodeName: return Platform.WINDOWS
224-
case Platform.LINUX.nodeName: return Platform.LINUX
222+
case Platform.OSX.nodeName:
223+
case Platform.OSX.name:
224+
return Platform.OSX
225+
226+
case Platform.WINDOWS.nodeName:
227+
case Platform.WINDOWS.name:
228+
case Platform.WINDOWS.buildConfigurationKey:
229+
return Platform.WINDOWS
230+
231+
case Platform.LINUX.nodeName:
232+
return Platform.LINUX
225233
}
226234

227235
throw new Error("Unknown platform: " + name)

src/packager.ts

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { all, executeFinally } from "./promise"
55
import { EventEmitter } from "events"
66
import { Promise as BluebirdPromise } from "bluebird"
77
import { InfoRetriever } from "./repositoryInfo"
8-
import { AppMetadata, DevMetadata } from "./metadata"
8+
import { AppMetadata, DevMetadata, Platform } from "./metadata"
99
import { PackagerOptions, PlatformPackager, BuildInfo, ArtifactCreated, use } from "./platformPackager"
1010
import MacPackager from "./macPackager"
1111
import { WinPackager } from "./winPackager"
@@ -50,7 +50,7 @@ export class Packager implements BuildInfo {
5050
async build(): Promise<any> {
5151
const devPackageFile = this.devPackageFile
5252
const appPackageFile = this.projectDir === this.appDir ? devPackageFile : path.join(this.appDir, "package.json")
53-
const platforms = normalizePlatforms(this.options.platform)
53+
const platforms = this.options.platform
5454

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

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

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

86-
private createHelper(platform: string, cleanupTasks: Array<() => Promise<any>>): PlatformPackager<any> {
86+
private createHelper(platform: Platform, cleanupTasks: Array<() => Promise<any>>): PlatformPackager<any> {
8787
if (this.options.platformPackagerFactory != null) {
8888
return this.options.platformPackagerFactory(this, platform, cleanupTasks)
8989
}
9090

9191
switch (platform) {
92-
case "darwin":
93-
case "osx":
92+
case Platform.OSX:
9493
{
9594
const helperClass: typeof MacPackager = require("./macPackager").default
9695
return new helperClass(this, cleanupTasks)
9796
}
9897

99-
case "win32":
100-
case "win":
101-
case "windows":
98+
case Platform.WINDOWS:
10299
{
103100
const helperClass: typeof WinPackager = require("./winPackager").WinPackager
104101
return new helperClass(this, cleanupTasks)
105102
}
106103

107-
case "linux":
104+
case Platform.LINUX:
108105
return new (require("./linuxPackager").LinuxPackager)(this)
109106

110107
default:
111-
throw new Error("Unsupported platform: " + platform)
108+
throw new Error("Unknown platform: " + platform)
112109
}
113110
}
114111

@@ -137,7 +134,7 @@ export class Packager implements BuildInfo {
137134
return absoluteAppPath
138135
}
139136

140-
private checkMetadata(appPackageFile: string, devAppPackageFile: string, platforms: Array<string>): void {
137+
private checkMetadata(appPackageFile: string, devAppPackageFile: string, platforms: Array<Platform>): void {
141138
const reportError = (missedFieldName: string) => {
142139
throw new Error("Please specify '" + missedFieldName + "' in the application package.json ('" + appPackageFile + "')")
143140
}
@@ -163,7 +160,7 @@ export class Packager implements BuildInfo {
163160
if (author == null) {
164161
reportError("author")
165162
}
166-
else if (this.options.dist && author.email == null && platforms.includes("linux")) {
163+
else if (this.options.dist && author.email == null && platforms.includes(Platform.LINUX)) {
167164
throw new Error(util.format(errorMessages.authorEmailIsMissed, appPackageFile))
168165
}
169166
}
@@ -180,32 +177,32 @@ export class Packager implements BuildInfo {
180177
}
181178
}
182179

183-
export function normalizeArchs(platform: string, arch?: string) {
184-
if (platform === "darwin") {
180+
export function normalizeArchs(platform: Platform, arch?: string) {
181+
if (platform === Platform.OSX) {
185182
return ["x64"]
186183
}
187184
else {
188185
return arch == null ? [process.arch] : (arch === "all" ? ["ia32", "x64"] : [arch])
189186
}
190187
}
191188

192-
export function normalizePlatforms(platforms: Array<string>): Array<string> {
189+
export function normalizePlatforms(platforms: Array<string | Platform>): Array<Platform> {
193190
if (platforms == null || platforms.length === 0) {
194-
return [process.platform]
191+
return [Platform.fromString(process.platform)]
195192
}
196193
else if (platforms[0] === "all") {
197-
if (process.platform === "darwin") {
198-
return ["darwin", "linux", "win32"]
194+
if (process.platform === Platform.OSX.nodeName) {
195+
return [Platform.OSX, Platform.LINUX, Platform.WINDOWS]
199196
}
200-
else if (process.platform === "linux") {
197+
else if (process.platform === Platform.LINUX.nodeName) {
201198
// OS X code sign works only on OS X
202-
return ["linux", "win32"]
199+
return [Platform.LINUX, Platform.WINDOWS]
203200
}
204201
else {
205-
return ["win32"]
202+
return [Platform.WINDOWS]
206203
}
207204
}
208205
else {
209-
return platforms
206+
return platforms.map(it => it instanceof Platform ? it : Platform.fromString(it))
210207
}
211208
}

src/platformPackager.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import * as path from "path"
66
import packager = require("electron-packager-tf")
77
import globby = require("globby")
88
import { copy } from "fs-extra-p"
9-
import { Packager } from "./packager";
9+
import { statOrNull } from "./util"
10+
import { Packager } from "./packager"
1011

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

2223
sign?: string
2324

24-
platform?: Array<string>
25+
platform?: Array<Platform>
2526
target?: Array<string>
2627

2728
appDir?: string
@@ -32,7 +33,7 @@ export interface PackagerOptions {
3233
csaLink?: string
3334
cscKeyPassword?: string
3435

35-
platformPackagerFactory?: (packager: Packager, platform: string, cleanupTasks: Array<() => Promise<any>>) => PlatformPackager<any>
36+
platformPackagerFactory?: (packager: Packager, platform: Platform, cleanupTasks: Array<() => Promise<any>>) => PlatformPackager<any>
3637
}
3738

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

6364
readonly appName: string
6465

65-
protected abstract get platform(): Platform
66+
public abstract get platform(): Platform
6667

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

9293
async pack(outDir: string, appOutDir: string, arch: string): Promise<any> {
93-
await this.doPack(outDir, arch)
94+
await this.doPack(outDir, appOutDir, arch)
9495
await this.copyExtraResources(appOutDir, arch)
9596
}
9697

97-
protected async doPack(outDir: string, arch: string) {
98+
protected async doPack(outDir: string, appOutDir: string, arch: string) {
9899
const version = this.metadata.version
99100
let buildVersion = version
100101
const buildNumber = this.computeBuildNumber()
101102
if (buildNumber != null) {
102103
buildVersion += "." + buildNumber
103104
}
104105

105-
const electronPackagerOptions = this.devMetadata.build
106-
checkConflictingOptions(electronPackagerOptions)
106+
checkConflictingOptions(this.devMetadata.build)
107107

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

129129
delete options.osx
130130
delete options.win
@@ -133,6 +133,14 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
133133
delete options.iconUrl
134134

135135
await pack(options)
136+
137+
const outStat = await statOrNull(appOutDir)
138+
if (outStat == null) {
139+
throw new Error(`Output directory ${appOutDir} does not exists. Seems like a wrong configuration.`)
140+
}
141+
else if (!outStat.isDirectory()) {
142+
throw new Error(`Output directory ${appOutDir} is a file. Seems like a wrong configuration.`)
143+
}
136144
}
137145

138146
protected getExtraResources(arch: string): Promise<Array<string>> {

src/util.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Promise as BluebirdPromise } from "bluebird"
33
import readPackageJsonAsync = require("read-package-json")
44
import * as os from "os"
55
import * as path from "path"
6-
import { readJson } from "fs-extra-p"
6+
import { readJson, stat } from "fs-extra-p"
77

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

120120
const firstChar = electronPrebuiltDep[0]
121121
return firstChar === "^" || firstChar === "~" ? electronPrebuiltDep.substring(1) : electronPrebuiltDep
122+
}
123+
124+
export async function statOrNull(file: string) {
125+
try {
126+
return await stat(file)
127+
}
128+
catch (e) {
129+
if (e.code === "ENOENT") {
130+
return null
131+
}
132+
else {
133+
throw e
134+
}
135+
}
122136
}

0 commit comments

Comments
 (0)