Skip to content

Commit

Permalink
feat: do not require "author"
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Jun 8, 2017
1 parent 1dc9328 commit e700b78
Show file tree
Hide file tree
Showing 24 changed files with 153 additions and 118 deletions.
47 changes: 26 additions & 21 deletions docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,25 +75,6 @@ You can use macros in the file patterns, artifact file name patterns and publish
* `${env.ENV_NAME}` — any environment variable.
* Any property of [AppInfo](https://github.com/electron-userland/electron-builder/wiki/electron-builder#AppInfo) (e.g. `buildVersion`, `buildNumber`).

## Source and Destination Directories
You may also specify custom source and destination directories by using JSON objects instead of simple glob patterns.
Note this only works for [extraFiles](#Config-extraFiles) and [extraResources](#Config-extraResources).
```js
[
{
"from": "path/to/source",
"to": "path/to/destination",
"filter": ["**/*", "!foo/*.js"]
}
]
```
If `from` is given as a relative path, it is relative to the project directory.
If `to` is given as a relative path, it is relative to the app's content directory for `extraFiles` and the app's resource directory for `extraResources`.

`from` and `to` can be files and you can use this to [rename](https://github.com/electron-userland/electron-builder/issues/1119) a file while packaging.

You can use [file macros](#file-macros) in the `from` and `to` fields as well.

### Default File Pattern

[files](#Config-files) defaults to:
Expand All @@ -108,6 +89,11 @@ You can use [file macros](#file-macros) in the `from` and `to` fields as well.

`${ext}` macro is supported in addition to [file macros](#file-macros).

## How to Read Docs

* Name of optional property is normal, **required** is bold.
* Type is specified after property name: `Array<String> | String`. Union like this means that you can specify or string (`**/*`), or array of strings (`["**/*", "!foo.js"]`).

<!-- do not edit. start of generated block -->
<a name="Config"></a>

Expand All @@ -121,10 +107,29 @@ Configuration Options
* <a name="Config-copyright"></a>`copyright` = `Copyright © year ${author}` String - The human-readable copyright line for the app.
* <a name="Config-productName"></a>`productName` String - As [name](#Metadata-name), but allows you to specify a product name for your executable which contains spaces and other special characters not allowed in the [name property](https://docs.npmjs.com/files/package.json#name}).
* <a name="Config-files"></a>`files` Array&lt;String&gt; | String - A [glob patterns](#file-patterns) relative to the [app directory](#MetadataDirectories-app), which specifies which files to include when copying files to create the package.
* <a name="Config-extraResources"></a>`extraResources` Array&lt;String | [FilePattern](electron-builder-core#FilePattern)&gt; | [FilePattern](electron-builder-core#FilePattern) | String - A [glob patterns](#file-patterns) relative to the project directory, when specified, copy the file or directory with matching names directly into the app's resources directory (`Contents/Resources` for MacOS, `resources` for Linux/Windows).
* <a name="Config-extraResources"></a>`extraResources` Array&lt;String | [FilePattern](#FilePattern)&gt; | [FilePattern](#FilePattern) | String<a name="FilePattern"></a> - A [glob patterns](#file-patterns) relative to the project directory, when specified, copy the file or directory with matching names directly into the app's resources directory (`Contents/Resources` for MacOS, `resources` for Linux/Windows).

Glob rules the same as for [files](#multiple-glob-patterns).
* <a name="Config-extraFiles"></a>`extraFiles` Array&lt;String | [FilePattern](electron-builder-core#FilePattern)&gt; | [FilePattern](electron-builder-core#FilePattern) | String - The same as [extraResources](#Config-extraResources) but copy into the app's content directory (`Contents` for MacOS, root directory for Linux/Windows).

You may also specify custom source and destination directories by using JSON objects instead of simple glob patterns. Note this only works for [extraFiles](#Config-extraFiles) and [extraResources](#Config-extraResources).

```json
[
{
"from": "path/to/source",
"to": "path/to/destination",
"filter": ["**/*", "!foo/*.js"]
}
]
```

`from` and `to` can be files and you can use this to [rename](https://github.com/electron-userland/electron-builder/issues/1119) a file while packaging.

You can use [file macros](#file-macros) in the `from` and `to` fields as well.
* <a name="FilePattern-from"></a>`from` String - The source path relative to the project directory.
* <a name="FilePattern-to"></a>`to` String - The destination path relative to the app's content directory for `extraFiles` and the app's resource directory for `extraResources`.
* <a name="FilePattern-filter"></a>`filter` Array&lt;String&gt; | String - The [glob patterns](#file-patterns).
* <a name="Config-extraFiles"></a>`extraFiles` Array&lt;String | [FilePattern](#FilePattern)&gt; | [FilePattern](#FilePattern) | String - The same as [extraResources](#Config-extraResources) but copy into the app's content directory (`Contents` for MacOS, root directory for Linux/Windows).
* <a name="Config-asar"></a>`asar` = `true` Boolean | [AsarOptions](#AsarOptions)<a name="AsarOptions"></a> - Whether to package the application's source code into an archive, using [Electron's archive format](http://electron.atom.io/docs/tutorial/application-packaging/).

Node modules, that must be unpacked, will be detected automatically, you don't need to explicitly set [asarUnpack](#Config-asarUnpack) - please file issue if this doesn't work.
Expand Down
13 changes: 0 additions & 13 deletions docs/api/electron-builder-core.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

* [electron-builder-core](#module_electron-builder-core)
* [`.BeforeBuildContext`](#BeforeBuildContext)
* [`.FilePattern`](#FilePattern)
* [`.SourceRepositoryInfo`](#SourceRepositoryInfo)
* [`.TargetConfig`](#TargetConfig)
* [`.TargetSpecificOptions`](#TargetSpecificOptions)
Expand Down Expand Up @@ -34,18 +33,6 @@
| **platform**| <code>[Platform](#Platform)</code> |
| **arch**| <code>String</code> |

<a name="FilePattern"></a>

### `FilePattern`
**Kind**: interface of [<code>electron-builder-core</code>](#module_electron-builder-core)
**Properties**

| Name | Type |
| --- | --- |
| from| <code>String</code> |
| to| <code>String</code> |
| filter| <code>Array&lt;String&gt;</code> \| <code>String</code> |

<a name="SourceRepositoryInfo"></a>

### `SourceRepositoryInfo`
Expand Down
4 changes: 2 additions & 2 deletions docs/api/electron-builder.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@
| Name | Type |
| --- | --- |
| files| <code>Array&lt;String&gt;</code> \| <code>String</code> \| <code>null</code> |
| extraFiles| <code>Array&lt;String \| [FilePattern](electron-builder-core#FilePattern)&gt;</code> \| <code>[FilePattern](electron-builder-core#FilePattern)</code> \| <code>String</code> \| <code>null</code> |
| extraResources| <code>Array&lt;String \| [FilePattern](electron-builder-core#FilePattern)&gt;</code> \| <code>[FilePattern](electron-builder-core#FilePattern)</code> \| <code>String</code> \| <code>null</code> |
| extraFiles| <code>Array&lt;String \| [FilePattern](Options#FilePattern)&gt;</code> \| <code>[FilePattern](Options#FilePattern)</code> \| <code>String</code> \| <code>null</code> |
| extraResources| <code>Array&lt;String \| [FilePattern](Options#FilePattern)&gt;</code> \| <code>[FilePattern](Options#FilePattern)</code> \| <code>String</code> \| <code>null</code> |
| asarUnpack| <code>Array&lt;String&gt;</code> \| <code>String</code> \| <code>null</code> |
| asar| <code>[AsarOptions](Options#AsarOptions)</code> \| <code>Boolean</code> \| <code>null</code> |
| target| <code>Array&lt;String \| [TargetConfig](electron-builder-core#TargetConfig)&gt;</code> \| <code>String</code> \| <code>[TargetConfig](electron-builder-core#TargetConfig)</code> \| <code>null</code> |
Expand Down
16 changes: 13 additions & 3 deletions jsdoc/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function renderMemberListDescription(text, indent) {
return dmdHelper.inlineLinks(text)
.replace(/<br>/g, "\n")
.replace(/\n/g, "\n" + indent)
.replace('"**\\/*"', '"**/*"')
}

function getInlinedChild(types) {
Expand All @@ -45,7 +46,16 @@ function getInlinedChild(types) {
}

const arrayTypePrefix = "Array.<"
types = types.filter(it => it !== "null" && !isPrimitiveType(it) && !(it.startsWith(arrayTypePrefix) && types.includes(it.substring(arrayTypePrefix.length, it.indexOf(">")))))
types = types.filter(it => {
if (it === "null" || isPrimitiveType(it)) {
return false
}
if (it.startsWith(arrayTypePrefix)) {
it = it.replace("string|", "").replace("<(", "<").replace(")>", ">")
return !types.includes(it.substring(arrayTypePrefix.length, it.indexOf(">")))
}
return true
})
return types.length === 1 ? resolveById(types[0]) : null
}

Expand All @@ -71,7 +81,7 @@ function renderProperties(object, root, level) {

const types = member.type.names
let child = getInlinedChild(types)
if (child != null && !child.inlined) {
if (child != null && (!child.inlined || child.rendered)) {
child = null
}

Expand All @@ -93,7 +103,7 @@ function renderProperties(object, root, level) {
}

if (child != null) {
child.inlined = true
child.rendered = true
result += "\n"
result += renderProperties(child, root, level + 1)
}
Expand Down
6 changes: 0 additions & 6 deletions packages/electron-builder-core/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,6 @@ export const DIR_TARGET = "dir"

export type CompressionLevel = "store" | "normal" | "maximum"

export interface FilePattern {
from?: string
to?: string
filter?: Array<string> | string
}

export interface BeforeBuildContext {
readonly appDir: string
readonly electronVersion: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export interface SquirrelOptions {
version: string
msi?: any

owners?: string
description?: string
iconUrl?: string
authors?: string
Expand Down Expand Up @@ -112,7 +111,7 @@ async function pack(options: SquirrelOptions, directory: string, updateFile: str
})
archive.pipe(archiveOut)

const author = options.authors || options.owners
const author = options.authors
const copyright = options.copyright || `Copyright © ${new Date().getFullYear()} ${author}`
const nuspecContent = `<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
Expand All @@ -121,7 +120,6 @@ async function pack(options: SquirrelOptions, directory: string, updateFile: str
<version>${version}</version>
<title>${options.productName}</title>
<authors>${author}</authors>
<owners>${options.owners || options.authors}</owners>
<iconUrl>${options.iconUrl}</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>${options.description}</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ export default class SquirrelWindowsTarget extends Target {
appId: this.options.useAppIdAsId ? appInfo.id : appInfo.name,
version: appInfo.version,
description: appInfo.description,
authors: appInfo.companyName,
// better to explicitly set to empty string, to avoid any nugget errors
authors: appInfo.companyName || "",
iconUrl: iconUrl,
extraMetadataSpecs: projectUrl == null ? null : `\n <projectUrl>${projectUrl}</projectUrl>`,
copyright: appInfo.copyright,
Expand Down
5 changes: 3 additions & 2 deletions packages/electron-builder/src/appInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ export class AppInfo {
return `${parsedVersion.major}.${parsedVersion.minor}.${parsedVersion.patch}.${this.buildNumber || "0"}`
}

get companyName() {
return this.metadata.author!.name
get companyName(): string | null {
const author = this.metadata.author
return author == null ? null : author.name
}

get id(): string {
Expand Down
3 changes: 1 addition & 2 deletions packages/electron-builder/src/fileMatcher.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import BluebirdPromise from "bluebird-lst"
import { FilePattern } from "electron-builder-core"
import { asArray, debug } from "electron-builder-util"
import { copyDir, copyFile, Filter, statOrNull } from "electron-builder-util/out/fs"
import { warn } from "electron-builder-util/out/log"
import { mkdirs } from "fs-extra-p"
import { Minimatch } from "minimatch"
import * as path from "path"
import { Config, PlatformSpecificBuildOptions } from "./metadata"
import { Config, FilePattern, PlatformSpecificBuildOptions } from "./metadata"
import { BuildInfo } from "./packagerApi"
import { createFilter, hasMagic } from "./util/filter"

Expand Down
2 changes: 1 addition & 1 deletion packages/electron-builder/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export { Packager, BuildResult } from "./packager"
export { PackagerOptions, ArtifactCreated, BuildInfo } from "./packagerApi"
export { getArchSuffix, Platform, Arch, archFromString, Target, DIR_TARGET } from "electron-builder-core"
export { BuildOptions, build, CliOptions, createTargets } from "./builder"
export { Metadata, Config, AfterPackContext, MetadataDirectories, Protocol, FileAssociation, PlatformSpecificBuildOptions, AuthorMetadata, RepositoryInfo, AsarOptions } from "./metadata"
export { Metadata, Config, AfterPackContext, MetadataDirectories, Protocol, FileAssociation, PlatformSpecificBuildOptions, AuthorMetadata, RepositoryInfo, AsarOptions, FilePattern } from "./metadata"
export { MacOptions, DmgOptions, MasBuildOptions, MacOsTargetName, PkgOptions, DmgContent, DmgWindow } from "./options/macOptions"
export { WinBuildOptions, NsisOptions, SquirrelWindowsOptions, AppXOptions, NsisWebOptions, PortableOptions, CommonNsisOptions } from "./options/winOptions"
export { LinuxBuildOptions, DebOptions, SnapOptions, CommonLinuxOptions, LinuxTargetSpecificOptions } from "./options/linuxOptions"
Expand Down
34 changes: 33 additions & 1 deletion packages/electron-builder/src/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AsarIntegrityOptions } from "asar-integrity"
import { Arch, BeforeBuildContext, CompressionLevel, FilePattern, Target, TargetConfig, TargetSpecificOptions } from "electron-builder-core"
import { Arch, BeforeBuildContext, CompressionLevel, Target, TargetConfig, TargetSpecificOptions } from "electron-builder-core"
import { Publish } from "electron-builder-http/out/publishOptions"
import { DebOptions, LinuxBuildOptions, LinuxTargetSpecificOptions, SnapOptions } from "./options/linuxOptions"
import { DmgOptions, MacOptions, MasBuildOptions, PkgOptions } from "./options/macOptions"
Expand Down Expand Up @@ -92,6 +92,23 @@ export interface Config extends PlatformSpecificBuildOptions {
* A [glob patterns](#file-patterns) relative to the project directory, when specified, copy the file or directory with matching names directly into the app's resources directory (`Contents/Resources` for MacOS, `resources` for Linux/Windows).
*
* Glob rules the same as for [files](#multiple-glob-patterns).
*
* You may also specify custom source and destination directories by using JSON objects instead of simple glob patterns.
* Note this only works for [extraFiles](#Config-extraFiles) and [extraResources](#Config-extraResources).
*
*```json<br>
* [<br>
* {<br>
* "from": "path/to/source",<br>
* "to": "path/to/destination",<br>
* "filter": ["**\/*", "!foo/*.js"]<br>
* }<br>
* ]<br>
* ```
*
* `from` and `to` can be files and you can use this to [rename](https://github.com/electron-userland/electron-builder/issues/1119) a file while packaging.
*
* You can use [file macros](#file-macros) in the `from` and `to` fields as well.
*/
readonly extraResources?: Array<FilePattern | string> | FilePattern | string | null

Expand Down Expand Up @@ -392,4 +409,19 @@ export interface AsarOptions extends AsarIntegrityOptions {
smartUnpack?: boolean

ordering?: string | null
}

export interface FilePattern {
/**
* The source path relative to the project directory.
*/
from?: string
/**
* The destination path relative to the app's content directory for `extraFiles` and the app's resource directory for `extraResources`.
*/
to?: string
/**
* The [glob patterns](#file-patterns).
*/
filter?: Array<string> | string
}
54 changes: 10 additions & 44 deletions packages/electron-builder/src/packager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,6 @@ export class Packager implements BuildInfo {
debug(`Effective config: ${safeStringifyJson(this.config)}`)
}

checkConflictingOptions(this.config)

this.electronVersion = await getElectronVersion(this.config, projectDir, this.isPrepackedAppAsar ? this.metadata : null)
this.muonVersion = this.config.muonVersion

Expand Down Expand Up @@ -332,51 +330,27 @@ export class Packager implements BuildInfo {
}
}

const appMetadata = this.metadata
const metadata = this.metadata

checkNotEmpty("name", appMetadata.name)
checkNotEmpty("name", metadata.name)

if (isEmptyOrSpaces(appMetadata.description)) {
if (isEmptyOrSpaces(metadata.description)) {
warn(`description is missed in the package.json (${appPackageFile})`)
}
checkNotEmpty("version", appMetadata.version)
if (!metadata.author) {
warn(`author is missed in the package.json (${appPackageFile})`)
}
checkNotEmpty("version", metadata.version)

checkDependencies(this.devMetadata.dependencies, errors)
if ((<any>appMetadata) !== this.devMetadata) {
checkDependencies(appMetadata.dependencies, errors)
if ((<any>metadata) !== this.devMetadata) {
checkDependencies(metadata.dependencies, errors)

if ((<any>appMetadata).build != null) {
if ((<any>metadata).build != null) {
errors.push(`'build' in the application package.json (${appPackageFile}) is not supported since 3.0 anymore. Please move 'build' into the development package.json (${devAppPackageFile})`)
}
}

const config = <any>this.config
if (config["osx-sign"] != null) {
errors.push("osx-sign is deprecated and not supported — please see https://github.com/electron-userland/electron-builder/wiki/Code-Signing")
}
if (config["osx"] != null) {
errors.push(`osx is deprecated and not supported — please use mac instead`)
}
if (config["app-copyright"] != null) {
errors.push(`app-copyright is deprecated and not supported — please use copyright instead`)
}
if (config["app-category-type"] != null) {
errors.push(`app-category-type is deprecated and not supported — please use mac.category instead`)
}

const author = appMetadata.author
if (author == null) {
errors.push(`Please specify "author" in the application package.json (${appPackageFile}) — it is used as company name and copyright owner.`)
}

if (config.name != null) {
errors.push(`'name' in the config is forbidden. Please move 'name' into the package.json (${appPackageFile})`)
}

if (config.prune != null) {
errors.push("prune is deprecated — development dependencies are never copied in any case")
}

if (errors.length > 0) {
throw new Error(errors.join("\n"))
}
Expand Down Expand Up @@ -453,14 +427,6 @@ export function normalizePlatforms(rawPlatforms: Array<string | Platform> | stri
}
}

function checkConflictingOptions(options: any) {
for (const name of ["all", "out", "tmpdir", "version", "platform", "dir", "arch", "name", "extra-resource"]) {
if (name in options) {
throw new Error(`Option ${name} is ignored, do not specify it.`)
}
}
}

/**
* @private
*/
Expand Down
6 changes: 5 additions & 1 deletion packages/electron-builder/src/targets/appx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ export default class AppXTarget extends Target {
return publisher

case "publisherDisplayName":
return this.options.publisherDisplayName || appInfo.companyName
const name = this.options.publisherDisplayName || appInfo.companyName
if (name == null) {
throw new Error(`Please specify "author" in the application package.json — it is required because "appx.publisherDisplayName" is not set.`)
}
return name

case "version":
return appInfo.versionInWeirdWindowsForm
Expand Down
Loading

0 comments on commit e700b78

Please sign in to comment.