From a3bbb3fb292f547cf015dc1b1a3f5fc656e21582 Mon Sep 17 00:00:00 2001 From: develar Date: Mon, 23 May 2016 08:48:06 +0200 Subject: [PATCH] fix: check that description is not empty Closes #392 --- package.json | 2 +- src/packager.ts | 28 +++++++++++++++++----------- test/src/BuildTest.ts | 7 +++++++ 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 96f67649669..544daefb2a1 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/packager.ts b/src/packager.ts index ca4dd75c3f7..c788be5ac85 100644 --- a/src/packager.ts +++ b/src/packager.ts @@ -126,20 +126,22 @@ export class Packager implements BuildInfo { private checkMetadata(appPackageFile: string, devAppPackageFile: string, platforms: Array): 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 (appMetadata.name == null) { - reportError("name") - } - else if (appMetadata.description == null) { - reportError("description") - } - else if (appMetadata.version == null) { - reportError("version") + const checkNotEmpty = (name: string, value: string) => { + if (isEmptyOrSpaces(value)) { + reportError(name) + } } - else if ((appMetadata) !== this.devMetadata) { + + const appMetadata = this.metadata + + checkNotEmpty("name", appMetadata.name) + checkNotEmpty("description", appMetadata.description) + checkNotEmpty("version", appMetadata.version) + + if ((appMetadata) !== this.devMetadata) { if ((appMetadata).build != null) { throw new Error(util.format(errorMessages.buildInAppSpecified, appPackageFile, devAppPackageFile)) } @@ -251,4 +253,8 @@ async function checkWineVersion(checkPromise: Promise) { 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 } \ No newline at end of file diff --git a/test/src/BuildTest.ts b/test/src/BuildTest.ts index f573ffc6be1..c91f4a8c902 100755 --- a/test/src/BuildTest.ts +++ b/test/src/BuildTest.ts @@ -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: { + 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"