Skip to content

Commit

Permalink
feat(linux): check required fields before build
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Dec 8, 2017
1 parent 04787fa commit fbc59e8
Show file tree
Hide file tree
Showing 15 changed files with 114 additions and 81 deletions.
4 changes: 3 additions & 1 deletion docs/multi-platform-build.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ Don't expect that you can build app for all platforms on one platform.
[prebuild](https://www.npmjs.com/package/prebuild) is a solution, but most node modules [don't provide](https://github.com/atom/node-keytar/issues/27) prebuilt binaries.
* macOS Code Signing works only on macOS. [Cannot be fixed](http://stackoverflow.com/a/12156576).

Don't think that mentioned issues are major, you should use build servers — e.g. [AppVeyor](http://www.appveyor.com/) to build Windows app and [Travis](https://travis-ci.org) to build MacOS/Linux apps.
Free public [electron-build-service](https://github.com/electron-userland/electron-build-service) is used to build Electron app for Linux on Windows. On macOS/Linux you can build Electron app for Windows locally, except Appx for Windows Store (in the future (feel free to file issue) electron-build-service will support Appx target).

You can use build servers — e.g. [Travis](https://travis-ci.org) to build macOS/Linux apps and [AppVeyor](http://www.appveyor.com/) to build Windows app.

By default build for current platform and current arch. Use CLI flags `--mac`, `--win`, `--linux` to specify platforms. And `--ia32`, `--x64` to specify arch.

Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"jsdoc": "ts2jsdoc packages/builder-util-runtime packages/electron-updater packages/builder-util packages/electron-builder packages/electron-publish",
"jsdoc2md": "node scripts/jsdoc2md.js",
"docs": "tsc -p ./scripts/renderer/tsconfig.json && yarn jsdoc && yarn jsdoc2md && gitbook",
"deploy-docs": "./scripts/publish.sh",
"deploy-docs": "rm -rf _book && gitbook && ./scripts/publish.sh",
"serve-docs": "gitbook && http-server _book -c-1"
},
"//": "repository must be specified otherwise conventional-changelog will use forked repo (currently cloned)",
Expand All @@ -31,7 +31,7 @@
"7zip-bin": "^2.3.4",
"archiver": "^2.1.0",
"async-exit-hook": "^2.0.1",
"aws-sdk": "^2.163.0",
"aws-sdk": "^2.166.0",
"bluebird-lst": "^1.0.5",
"chalk": "^2.3.0",
"chromium-pickle-js": "^0.2.0",
Expand All @@ -49,7 +49,7 @@
"is-ci": "^1.0.10",
"isbinaryfile": "^3.0.2",
"js-yaml": "^3.10.0",
"lazy-val": "^1.0.2",
"lazy-val": "^1.0.3",
"lodash.isequal": "^4.5.0",
"mime": "^2.0.3",
"minimatch": "^3.0.4",
Expand All @@ -58,7 +58,7 @@
"parse-color": "^1.0.0",
"plist": "^2.1.0",
"rabin-bindings": "~1.7.4",
"read-config-file": "1.2.0",
"read-config-file": "1.2.1",
"sanitize-filename": "^1.6.1",
"sax": "^1.2.4",
"semver": "^5.4.1",
Expand Down Expand Up @@ -95,11 +95,11 @@
"gitbook-plugin-analytics": "^0.2.1",
"gitbook-plugin-develar-toolbar-buttons": "^1.0.2",
"gitbook-plugin-edit-link": "^2.0.2",
"gitbook-plugin-github": "^3.0.0",
"gitbook-plugin-github": "^2.0.0",
"gitbook-plugin-github-buttons": "^3.0.0",
"globby": "^7.1.1",
"jest-cli": "^21.2.1",
"jest-junit": "^3.3.0",
"jest-junit": "^3.4.0",
"jsdoc-to-markdown": "^3.0.2",
"path-sort": "^0.1.0",
"ts-babel": "^4.1.8",
Expand Down
2 changes: 1 addition & 1 deletion packages/builder-util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"ini": "^1.3.5",
"tunnel-agent": "^0.6.0",
"semver": "^5.4.1",
"lazy-val": "^1.0.2",
"lazy-val": "^1.0.3",
"js-yaml": "^3.10.0"
},
"typings": "./out/util.d.ts"
Expand Down
4 changes: 2 additions & 2 deletions packages/electron-builder-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@
"is-ci": "^1.0.10",
"isbinaryfile": "^3.0.2",
"js-yaml": "^3.10.0",
"read-config-file": "1.2.0",
"read-config-file": "1.2.1",
"minimatch": "^3.0.4",
"normalize-package-data": "^2.4.0",
"plist": "^2.1.0",
"sanitize-filename": "^1.6.1",
"semver": "^5.4.1",
"debug": "^3.1.0",
"asar-integrity": "0.0.0-semantic-release",
"lazy-val": "^1.0.2",
"lazy-val": "^1.0.3",
"temp-file": "^3.0.0",
"ejs": "^2.5.7",
"dmg-builder": "0.0.0-semantic-release"
Expand Down
4 changes: 4 additions & 0 deletions packages/electron-builder-lib/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ export abstract class Target {
constructor(readonly name: string, readonly isAsyncSupported: boolean = true) {
}

async checkOptions(): Promise<any> {
// ignore
}

abstract build(appOutDir: string, arch: Arch): Promise<any>

finishBuild(): Promise<any> {
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-builder-lib/src/errorMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ export const authorEmailIsMissed = `Please specify author 'email' in the applica
See https://docs.npmjs.com/files/package.json#people-fields-author-contributors
It is required to set Linux .deb package maintainer. Or you can set maintainer in the custom linux options.
(see https://github.com/electron-userland/electron-builder#distributable-format-configuration).
(see https://www.electron.build/configuration/linux).
`
5 changes: 3 additions & 2 deletions packages/electron-builder-lib/src/linuxPackager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Arch } from "builder-util"
import { Arch, log } from "builder-util"
import { rename } from "fs-extra-p"
import * as path from "path"
import sanitizeFileName from "sanitize-filename"
Expand Down Expand Up @@ -108,7 +108,8 @@ class RemoteTarget extends Target {
}

async build(appOutDir: string, arch: Arch) {
console.log(`Schedule remote ${this.target.name} build for arch ${Arch[arch]}`)
log(`Schedule remote ${this.target.name} build for arch ${Arch[arch]}`)
await this.target.checkOptions()
this.remoteBuilder.scheduleBuild(this.target, arch, appOutDir)
}
}
68 changes: 50 additions & 18 deletions packages/electron-builder-lib/src/targets/fpm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ import { getTemplatePath } from "../util/pathManager"
import { installPrefix, LinuxTargetHelper } from "./LinuxTargetHelper"
import { fpmPath, getLinuxToolsPath } from "./tools"

interface FpmOptions {
maintainer: string | undefined
vendor: string
url: string
}

export default class FpmTarget extends Target {
readonly options: LinuxTargetSpecificOptions = {...this.packager.platformSpecificBuildOptions, ...(this.packager.config as any)[this.name]}

Expand Down Expand Up @@ -46,7 +52,44 @@ export default class FpmTarget extends Target {
])
}

checkOptions(): Promise<any> {
return this.computeFpmMetaInfoOptions()
}

private async computeFpmMetaInfoOptions(): Promise<FpmOptions> {
const packager = this.packager
const projectUrl = await packager.appInfo.computePackageUrl()
const errors: Array<string> = []
if (projectUrl == null) {
errors.push("Please specify project homepage, see https://electron.build/configuration/configuration#Metadata-homepage")
}

const options = this.options
let author = options.maintainer
if (author == null) {
const a = packager.info.metadata.author
if (a == null || a.email == null) {
errors.push(errorMessages.authorEmailIsMissed)
}
else {
author = `${a.name} <${a.email}>`
}
}

if (errors.length > 0) {
throw new Error(errors.join("\n\n"))
}

return {
maintainer: author!!,
url: projectUrl!!,
vendor: options.vendor || author!!,
}
}

async build(appOutDir: string, arch: Arch): Promise<any> {
const fpmMetaInfoOptions = await this.computeFpmMetaInfoOptions()

const target = this.name

log(`Building ${target}`)
Expand All @@ -72,22 +115,7 @@ export default class FpmTarget extends Target {
const scripts = await this.scriptFiles
const packager = this.packager
const appInfo = packager.appInfo

const projectUrl = await appInfo.computePackageUrl()
if (projectUrl == null) {
throw new Error("Please specify project homepage, see https://electron.build/configuration/configuration#Metadata-homepage")
}

const options = this.options
let author = options.maintainer
if (author == null) {
const a = packager.info.metadata.author!
if (a.email == null) {
throw new Error(errorMessages.authorEmailIsMissed)
}
author = `${a.name} <${a.email}>`
}

const synopsis = options.synopsis
const args = [
"-s", "dir",
Expand All @@ -98,13 +126,17 @@ export default class FpmTarget extends Target {
"--after-install", scripts[0],
"--after-remove", scripts[1],
"--description", smarten(target === "rpm" ? this.helper.getDescription(options)! : `${synopsis || ""}\n ${this.helper.getDescription(options)}`),
"--maintainer", author,
"--vendor", options.vendor || author,
"--version", appInfo.version,
"--package", destination,
"--url", projectUrl,
]

for (const key of Object.keys(fpmMetaInfoOptions)) {
const value = (fpmMetaInfoOptions as any)[key]
if (value != null) {
args.push(`--${key}`, value)
}
}

if (debug.enabled) {
args.push(
"--log", "debug",
Expand Down
4 changes: 2 additions & 2 deletions packages/electron-builder-lib/src/util/packageMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { isEmptyOrSpaces, log, warn } from "builder-util"
import { readFile, readJson } from "fs-extra-p"
import * as path from "path"
import { Metadata } from "../options/metadata"
import * as semver from "semver"
import { Metadata } from "../options/metadata"

const normalizeData = require("normalize-package-data")

Expand Down Expand Up @@ -54,7 +54,7 @@ export function checkMetadata(metadata: Metadata, devMetadata: any | null, appPa
if (isEmptyOrSpaces(metadata.description)) {
warn(`description is missed in the package.json (${appPackageFile})`)
}
if (!metadata.author) {
if (metadata.author == null) {
warn(`author is missed in the package.json (${appPackageFile})`)
}
checkNotEmpty("version", metadata.version)
Expand Down
4 changes: 2 additions & 2 deletions packages/electron-builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@
"builder-util": "0.0.0-semantic-release",
"fs-extra-p": "^4.4.4",
"is-ci": "^1.0.10",
"read-config-file": "1.2.0",
"read-config-file": "1.2.1",
"sanitize-filename": "^1.6.1",
"update-notifier": "^2.3.0",
"yargs": "^10.0.3",
"lazy-val": "^1.0.2",
"lazy-val": "^1.0.3",
"electron-builder-lib": "0.0.0-semantic-release",
"electron-download-tf": "4.3.4"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-publisher-s3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],
"dependencies": {
"fs-extra-p": "^4.4.4",
"aws-sdk": "^2.163.0",
"aws-sdk": "^2.166.0",
"mime": "^2.0.3",
"electron-publish": "~0.0.0-semantic-release",
"builder-util": "^0.0.0-semantic-release",
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-updater/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"out"
],
"dependencies": {
"lazy-val": "^1.0.2",
"lazy-val": "^1.0.3",
"bluebird-lst": "^1.0.5",
"fs-extra-p": "^4.4.4",
"js-yaml": "^3.10.0",
Expand Down
2 changes: 1 addition & 1 deletion scripts/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ set -e

cd _book

mkdir sponsor-logos
mkdir sponsor-logos || true
cp ../scripts/sponsor-logos/*.svg sponsor-logos/

# do not use force push - netlify doesn't trigger deploy for forced push
Expand Down
2 changes: 1 addition & 1 deletion test/out/linux/__snapshots__/linuxPackagerTest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,6 @@ exports[`no-author-email 1`] = `
See https://docs.npmjs.com/files/package.json#people-fields-author-contributors
It is required to set Linux .deb package maintainer. Or you can set maintainer in the custom linux options.
(see https://github.com/electron-userland/electron-builder#distributable-format-configuration).
(see https://www.electron.build/configuration/linux).
"
`;
Loading

0 comments on commit fbc59e8

Please sign in to comment.