Skip to content

Commit c62683a

Browse files
committed
feat: Linux deb — specify license, package url #242
1 parent b151ffc commit c62683a

File tree

12 files changed

+155
-65
lines changed

12 files changed

+155
-65
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ osx_image: xcode7.3
66

77
env:
88
- NODE_VERSION=4
9-
- NODE_VERSION=5.8
9+
- NODE_VERSION=5
1010

1111
language: ruby
1212

@@ -33,6 +33,7 @@ install:
3333
- nvm install $NODE_VERSION
3434
- npm install npm -g
3535
- npm prune
36+
- npm install Microsoft/TypeScript
3637
- npm install
3738

3839
script:

appveyor.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ install:
1212
- node -v
1313
- npm -v
1414
- npm prune
15+
- npm install Microsoft/TypeScript
1516
- npm install
1617

1718
build: off

docs/options.md

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,37 @@ Don't customize paths to background and icon, — just follow conventions (if yo
3131
Here documented only `electron-builder` specific options:
3232

3333
<!-- do not edit. start of generated block -->
34-
<a class="anchor" id="user-content-AppMetadata" href="#AppMetadata" aria-hidden="true"></a>
34+
35+
<a name="#AppMetadata"></a>
3536
# Application `package.json`
3637
| Name | Description
3738
| --- | ---
38-
| <a class="anchor" id="user-content-AppMetadata-name" href="#AppMetadata-name" aria-hidden="true"></a>name | The application name.
39-
| <a class="anchor" id="user-content-AppMetadata-productName" href="#AppMetadata-productName" aria-hidden="true"></a>productName | <p>As [name](#AppMetadata-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}).</p>
40-
<a class="anchor" id="user-content-DevMetadata" href="#DevMetadata" aria-hidden="true"></a>
39+
| <a name="#AppMetadata-name"></a>name | The application name.
40+
| <a name="#AppMetadata-productName"></a>productName | <p>As [name](#AppMetadata-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}).</p>
41+
42+
<a name="#DevMetadata"></a>
4143
# Development `package.json`
4244
| Name | Description
4345
| --- | ---
44-
| <a class="anchor" id="user-content-DevMetadata-homepage" href="#DevMetadata-homepage" aria-hidden="true"></a>homepage | The url to the project homepage (NuGet Package `projectUrl` or Linux Package URL).
45-
| <a class="anchor" id="user-content-DevMetadata-build" href="#DevMetadata-build" aria-hidden="true"></a>build | See [BuildMetadata](#BuildMetadata).
46-
<a class="anchor" id="user-content-BuildMetadata" href="#BuildMetadata" aria-hidden="true"></a>
46+
| <a name="#DevMetadata-homepage"></a>homepage | <p>The url to the project [homepage](https://docs.npmjs.com/files/package.json#homepage) (NuGet Package <code>projectUrl</code> (optional) or Linux Package URL (required)).</p> <p>If not specified and your project repository is public on GitHub, it will be <code>https://github.com/${user}/${project}</code> by default.</p>
47+
| <a name="#DevMetadata-license"></a>license | *linux-only.* The [license](https://docs.npmjs.com/files/package.json#license) name for this package.
48+
| <a name="#DevMetadata-build"></a>build | See [.build](#BuildMetadata).
49+
50+
<a name="#BuildMetadata"></a>
4751
## `.build`
4852
| Name | Description
4953
| --- | ---
50-
| <a class="anchor" id="user-content-BuildMetadata-iconUrl" href="#BuildMetadata-iconUrl" aria-hidden="true"></a>iconUrl | <p>*windows-only.* A URL to an ICO file to use as the application icon (displayed in Control Panel &gt; Programs and Features). Defaults to the Atom icon.</p> <p>Please note — [local icon file url is not accepted](https://github.com/atom/grunt-electron-installer/issues/73), must be https/http.</p> <ul> <li>If you don’t plan to build windows installer, you can omit it.</li> <li>If your project repository is public on GitHub, it will be <code>https://raw.githubusercontent.com/${info.user}/${info.project}/master/build/icon.ico</code> by default.</li> </ul>
51-
| <a class="anchor" id="user-content-BuildMetadata-productName" href="#BuildMetadata-productName" aria-hidden="true"></a>productName | See [AppMetadata.productName](#AppMetadata-productName).
52-
| <a class="anchor" id="user-content-BuildMetadata-extraResources" href="#BuildMetadata-extraResources" aria-hidden="true"></a>extraResources | <p>A [glob expression](https://www.npmjs.com/package/glob#glob-primer), when specified, copy the file or directory with matching names directly into the app’s directory (<code>Contents/Resources</code> for OS X).</p> <p>You can use <code>${os}</code> (expanded to osx, linux or win according to current platform) and <code>${arch}</code> in the pattern.</p> <p>If directory matched, all contents are copied. So, you can just specify <code>foo</code> to copy <code>&lt;project_dir&gt;/foo</code> directory.</p> <p>May be specified in the platform options (i.e. in the <code>build.osx</code>).</p>
53-
| <a class="anchor" id="user-content-BuildMetadata-osx" href="#BuildMetadata-osx" aria-hidden="true"></a>osx | See [OS X options](https://www.npmjs.com/package/appdmg#json-specification)
54-
| <a class="anchor" id="user-content-BuildMetadata-win" href="#BuildMetadata-win" aria-hidden="true"></a>win | See [windows-installer options](https://github.com/electronjs/windows-installer#usage)
54+
| <a name="#BuildMetadata-iconUrl"></a>iconUrl | <p>*windows-only.* A URL to an ICO file to use as the application icon (displayed in Control Panel &gt; Programs and Features). Defaults to the Atom icon.</p> <p>Please note — [local icon file url is not accepted](https://github.com/atom/grunt-electron-installer/issues/73), must be https/http.</p> <ul> <li>If you don’t plan to build windows installer, you can omit it.</li> <li>If your project repository is public on GitHub, it will be <code>https://raw.githubusercontent.com/${user}/${project}/master/build/icon.ico</code> by default.</li> </ul>
55+
| <a name="#BuildMetadata-productName"></a>productName | See [AppMetadata.productName](#AppMetadata-productName).
56+
| <a name="#BuildMetadata-extraResources"></a>extraResources | <p>A [glob expression](https://www.npmjs.com/package/glob#glob-primer), when specified, copy the file or directory with matching names directly into the app’s directory (<code>Contents/Resources</code> for OS X).</p> <p>You can use <code>${os}</code> (expanded to osx, linux or win according to current platform) and <code>${arch}</code> in the pattern.</p> <p>If directory matched, all contents are copied. So, you can just specify <code>foo</code> to copy <code>&lt;project_dir&gt;/foo</code> directory.</p> <p>May be specified in the platform options (i.e. in the <code>build.osx</code>).</p>
57+
| <a name="#BuildMetadata-osx"></a>osx | See [OS X options](https://www.npmjs.com/package/appdmg#json-specification)
58+
| <a name="#BuildMetadata-win"></a>win | See [windows-installer options](https://github.com/electronjs/windows-installer#usage)
59+
| <a name="#BuildMetadata-linux"></a>linux | See [.linux](#DebOptions).
60+
61+
<a name="#DebOptions"></a>
62+
### `.build.linux`
63+
| Name | Description
64+
| --- | ---
65+
| <a name="#DebOptions-compression"></a>compression | *deb-only.* The compression type to use, must be one of gz, bzip2, xz. (default: `xz`)
5566

5667
<!-- end of generated block -->

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
"ava-tf": "^0.12.4-beta.6",
7878
"babel-plugin-array-includes": "^2.0.3",
7979
"babel-plugin-transform-es2015-parameters": "^6.7.0",
80+
"babel-plugin-transform-es2015-spread": "^6.6.5",
8081
"decompress-zip": "^0.3.0",
8182
"electron-download": "^2.1.0",
8283
"json-parse-helpfulerror": "^1.0.3",
@@ -85,15 +86,16 @@
8586
"pre-commit": "^1.1.2",
8687
"semantic-release": "^4.3.5",
8788
"should": "^8.3.0",
88-
"ts-babel": "^0.6.5",
89+
"ts-babel": "^0.6.8",
8990
"tsconfig-glob": "^0.4.3",
9091
"tslint": "next",
91-
"typescript": "^1.9.0-dev.20160325",
92+
"typescript": "^1.9.0-dev.20160402",
9293
"validate-commit-msg": "^2.5.0"
9394
},
9495
"babel": {
9596
"plugins": [
9697
"transform-es2015-parameters",
98+
"transform-es2015-spread",
9799
"array-includes"
98100
]
99101
},

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export { Packager } from "./packager"
22
export { PackagerOptions, ArtifactCreated } from "./platformPackager"
33
export { BuildOptions, build, createPublisher } from "./builder"
4-
export { AppMetadata, DevMetadata, Platform, getProductName } from "./metadata"
4+
export { AppMetadata, DevMetadata, Platform, getProductName, BuildMetadata, DebOptions } from "./metadata"

src/linuxPackager.ts

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as path from "path"
22
import { Promise as BluebirdPromise } from "bluebird"
33
import { PlatformPackager, BuildInfo } from "./platformPackager"
4-
import { Platform } from "./metadata"
4+
import { Platform, DebOptions } from "./metadata"
55
import { dir as _tpmDir, TmpOptions } from "tmp"
66
import { exec, log } from "./util"
77
import { outputFile, readFile, readdir } from "fs-extra-p"
@@ -172,7 +172,13 @@ Icon=${this.metadata.name}
172172
const target = "deb"
173173
const destination = path.join(outDir, `${this.metadata.name}-${this.metadata.version}-${archName}.${target}`)
174174
const scripts = await this.scriptFiles
175-
await exec("fpm", [
175+
176+
const projectUrl = await this.computePackageUrl()
177+
if (projectUrl == null) {
178+
throw new Error("Please specify project homepage")
179+
}
180+
181+
const args = [
176182
"-s", "dir",
177183
"-t", target,
178184
"--architecture", archName,
@@ -186,12 +192,25 @@ Icon=${this.metadata.name}
186192
"--version", this.metadata.version,
187193
"--package", destination,
188194
"--deb-compression", options.compression || "xz",
189-
appOutDir + "/=/opt/" + this.appName,
190-
].concat(await this.packageFiles))
195+
"--url", projectUrl,
196+
]
197+
198+
use(this.devMetadata.license, it => args.push("--license", it))
199+
use(this.computeBuildNumber(), it => args.push("--iteration", it))
200+
201+
args.push(`${appOutDir}/=/opt/${this.appName}`)
202+
args.push(...(await this.packageFiles))
203+
await exec("fpm", args)
191204
return destination
192205
}
193206
}
194207

208+
function use<T>(value: T, task: (it: T) => void) {
209+
if (value != null) {
210+
task(value)
211+
}
212+
}
213+
195214
async function writeConfigFile(tempDir: string, templatePath: string, options: any): Promise<string> {
196215
const config = template(await readFile(templatePath, "utf8"),
197216
{
@@ -202,21 +221,4 @@ async function writeConfigFile(tempDir: string, templatePath: string, options: a
202221
const outputPath = path.join(tempDir, path.basename(templatePath, ".tpl"))
203222
await outputFile(outputPath, config)
204223
return outputPath
205-
}
206-
207-
export interface DebOptions {
208-
name: string
209-
comment: string
210-
211-
maintainer: string
212-
213-
/**
214-
* .desktop file template
215-
*/
216-
desktop?: string
217-
218-
afterInstall?: string
219-
afterRemove?: string
220-
221-
compression?: string
222224
}

src/metadata.ts

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,19 @@ export interface AppMetadata extends Metadata {
2929
*/
3030
export interface DevMetadata extends Metadata {
3131
/**
32-
The url to the project homepage (NuGet Package `projectUrl` or Linux Package URL).
32+
The url to the project [homepage](https://docs.npmjs.com/files/package.json#homepage) (NuGet Package `projectUrl` (optional) or Linux Package URL (required)).
33+
34+
If not specified and your project repository is public on GitHub, it will be `https://github.com/${user}/${project}` by default.
3335
*/
3436
readonly homepage?: string
3537

3638
/**
37-
See [BuildMetadata](#BuildMetadata).
39+
*linux-only.* The [license](https://docs.npmjs.com/files/package.json#license) name for this package.
40+
*/
41+
readonly license?: string
42+
43+
/**
44+
See [.build](#BuildMetadata).
3845
*/
3946
readonly build?: BuildMetadata
4047

@@ -67,7 +74,7 @@ export interface BuildMetadata {
6774
Please note — [local icon file url is not accepted](https://github.com/atom/grunt-electron-installer/issues/73), must be https/http.
6875
6976
* If you don't plan to build windows installer, you can omit it.
70-
* If your project repository is public on GitHub, it will be `https://raw.githubusercontent.com/${info.user}/${info.project}/master/build/icon.ico` by default.
77+
* If your project repository is public on GitHub, it will be `https://raw.githubusercontent.com/${user}/${project}/master/build/icon.ico` by default.
7178
*/
7279
readonly iconUrl: string
7380

@@ -97,9 +104,33 @@ export interface BuildMetadata {
97104
*/
98105
readonly win?: any,
99106

107+
/**
108+
See [.linux](#DebOptions).
109+
*/
100110
readonly linux?: any
101111
}
102112

113+
/**
114+
### `.build.linux`
115+
*/
116+
export interface DebOptions {
117+
name: string
118+
comment: string
119+
120+
maintainer: string
121+
122+
//.desktop file template
123+
desktop?: string
124+
125+
afterInstall?: string
126+
afterRemove?: string
127+
128+
/*
129+
*deb-only.* The compression type to use, must be one of gz, bzip2, xz. (default: `xz`)
130+
*/
131+
readonly compression?: string
132+
}
133+
103134
export interface PlatformSpecificBuildOptions {
104135
readonly extraResources?: Array<string>
105136
}

src/platformPackager.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
9696
protected async doPack(outDir: string, arch: string) {
9797
const version = this.metadata.version
9898
let buildVersion = version
99-
const buildNumber = process.env.TRAVIS_BUILD_NUMBER || process.env.APPVEYOR_BUILD_NUMBER || process.env.CIRCLE_BUILD_NUM
99+
const buildNumber = this.computeBuildNumber()
100100
if (buildNumber != null) {
101101
buildVersion += "." + buildNumber
102102
}
@@ -158,11 +158,30 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
158158
if (this.platform === Platform.OSX) {
159159
resourcesDir = path.join(resourcesDir, this.appName + ".app", "Contents", "Resources")
160160
}
161-
162161
return await BluebirdPromise.map(await this.getExtraResources(arch), it => copy(path.join(this.projectDir, it), path.join(resourcesDir, it)))
163162
}
164163

165164
abstract packageInDistributableFormat(outDir: string, appOutDir: string, arch: string): Promise<any>
165+
166+
protected async computePackageUrl(): Promise<string> {
167+
const url = this.devMetadata.homepage
168+
if (url != null) {
169+
return url
170+
}
171+
172+
if (this.info.repositoryInfo != null) {
173+
const info = await this.info.repositoryInfo.getInfo(this)
174+
if (info != null) {
175+
return `https://github.com/${info.user}/${info.project}`
176+
}
177+
}
178+
return null
179+
}
180+
181+
//noinspection JSMethodCanBeStatic
182+
protected computeBuildNumber(): string {
183+
return process.env.TRAVIS_BUILD_NUMBER || process.env.APPVEYOR_BUILD_NUMBER || process.env.CIRCLE_BUILD_NUM
184+
}
166185
}
167186

168187
function checkConflictingOptions(options: any): void {

src/util.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,11 @@ export function exec(file: string, args?: string[], options?: ExecOptions): Blue
7979
console.error(stdout.toString())
8080
}
8181
if (stderr.length !== 0) {
82-
console.error(stderr.toString())
82+
reject(new Error(stderr.toString() + "\n" + error.toString()))
83+
}
84+
else {
85+
reject(error)
8386
}
84-
reject(error)
8587
}
8688
})
8789
})

src/winPackager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export default class WinPackager extends PlatformPackager<WinBuildOptions> {
115115
const version = this.metadata.version
116116
const installerOutDir = WinPackager.computeDistOut(outDir, arch)
117117
const archSuffix = arch === "x64" ? "" : ("-" + arch)
118-
const projectUrl = this.devMetadata.homepage
118+
const projectUrl = await this.computePackageUrl()
119119

120120
const options = Object.assign({
121121
name: this.metadata.name,

0 commit comments

Comments
 (0)