Skip to content

Commit

Permalink
fix: check that description is not empty
Browse files Browse the repository at this point in the history
Closes #392
  • Loading branch information
develar committed May 23, 2016
1 parent b2ab07f commit a3bbb3f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"deep-assign": "^2.0.0",
"electron-osx-sign-tf": "0.4.0-beta.0",
"electron-packager-tf": "~7.1.0",
"electron-winstaller-fixed": "~2.8.3",
"electron-winstaller-fixed": "~2.9.0",
"fs-extra-p": "^1.0.1",
"globby": "^4.1.0",
"hosted-git-info": "^2.1.5",
Expand Down
28 changes: 17 additions & 11 deletions src/packager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,20 +126,22 @@ export class Packager implements BuildInfo {

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 + "')")
throw new Error(`Please specify '${missedFieldName}' in the application package.json ('${appPackageFile}')`)
}

const appMetadata = this.metadata
if (<any>appMetadata.name == null) {
reportError("name")
}
else if (<any>appMetadata.description == null) {
reportError("description")
}
else if (<any>appMetadata.version == null) {
reportError("version")
const checkNotEmpty = (name: string, value: string) => {
if (isEmptyOrSpaces(value)) {
reportError(name)
}
}
else if ((<any>appMetadata) !== this.devMetadata) {

const appMetadata = this.metadata

checkNotEmpty("name", appMetadata.name)
checkNotEmpty("description", appMetadata.description)
checkNotEmpty("version", appMetadata.version)

if ((<any>appMetadata) !== this.devMetadata) {
if ((<any>appMetadata).build != null) {
throw new Error(util.format(errorMessages.buildInAppSpecified, appPackageFile, devAppPackageFile))
}
Expand Down Expand Up @@ -251,4 +253,8 @@ async function checkWineVersion(checkPromise: Promise<Buffer[]>) {
if (compareVersions(wineVersion, "1.8") === -1) {
throw new Error(wineError(`wine 1.8+ is required, but your version is ${wineVersion}`))
}
}

function isEmptyOrSpaces(s: string | n) {
return s == null || s.trim().length === 0
}
7 changes: 7 additions & 0 deletions test/src/BuildTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ test("name in the build", t => t.throws(assertPack("test-app-one", currentPlatfo
})
}), /'name' in the 'build' is forbidden/))

test("empty description", t => t.throws(assertPack("test-app-one", {
platform: [Platform.LINUX],
devMetadata: <any>{
description: "",
}
}), /Please specify 'description'/))

test("invalid main in the app package.json", t => t.throws(assertPack("test-app", allPlatforms(false), {
tempDirCreated: projectDir => modifyPackageJson(projectDir, data => {
data.main = "main.js"
Expand Down

0 comments on commit a3bbb3f

Please sign in to comment.