Skip to content

Commit

Permalink
feat(dmg): dmg license
Browse files Browse the repository at this point in the history
Close #1491
  • Loading branch information
develar committed Apr 23, 2017
1 parent 17ac619 commit d6f0c57
Show file tree
Hide file tree
Showing 11 changed files with 913 additions and 248 deletions.
1 change: 1 addition & 0 deletions .idea/dictionaries/develar.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,9 @@ Debian Package Specific Options
### `DmgOptions` ⇐ <code>[TargetSpecificOptions](electron-builder-core#TargetSpecificOptions)</code>
macOS DMG Options ([dmg](#Config-dmg)).

To add license to DMG, create file `license_LANG_CODE.txt` in the build resources. Multiple license files in different languages are supported — use lang postfix (e.g. `_de`, `_ru`)). For example, create files `license_de.txt` and `license_en.txt` in the build resources.
If OS language is german, `license_de.txt` will be displayed. See map of [language code to name](https://github.com/meikidd/iso-639-1/blob/master/src/data.js).

**Kind**: interface of <code>[electron-builder](#module_electron-builder)</code>
**Extends**: <code>[TargetSpecificOptions](electron-builder-core#TargetSpecificOptions)</code>
**Properties**
Expand Down Expand Up @@ -611,6 +614,7 @@ Windows Specific Options ([win](#Config-win)).
| certificatePassword| <code>string</code> | <a name="WinBuildOptions-certificatePassword"></a>The password to the certificate provided in `certificateFile`. Please use it only if you cannot use env variable `CSC_KEY_PASSWORD` (`WIN_CSC_KEY_PASSWORD`) for some reason. Please see [Code Signing](https://github.com/electron-userland/electron-builder/wiki/Code-Signing). |
| certificateSubjectName| <code>string</code> | <a name="WinBuildOptions-certificateSubjectName"></a>The name of the subject of the signing certificate. Required only for EV Code Signing and works only on Windows. |
| certificateSha1| <code>string</code> | <a name="WinBuildOptions-certificateSha1"></a>The SHA1 hash of the signing certificate. The SHA1 hash is commonly specified when multiple certificates satisfy the criteria specified by the remaining switches. Works only on Windows. |
| additionalCertificateFile| <code>string</code> | <a name="WinBuildOptions-additionalCertificateFile"></a>The path to an additional certificate file you want to add to the signature block. |
| rfc3161TimeStampServer| <code>string</code> | <a name="WinBuildOptions-rfc3161TimeStampServer"></a>The URL of the RFC 3161 time stamp server. Defaults to `http://timestamp.comodoca.com/rfc3161`. |
| timeStampServer| <code>string</code> | <a name="WinBuildOptions-timeStampServer"></a>The URL of the time stamp server. Defaults to `http://timestamp.verisign.com/scripts/timstamp.dll`. |
| publisherName| <code>string</code> \| <code>Array&lt;string&gt;</code> \| <code>null</code> | <a name="WinBuildOptions-publisherName"></a>[The publisher name](https://github.com/electron-userland/electron-builder/issues/1187#issuecomment-278972073), exactly as in your code signed certificate. Several names can be provided. Defaults to common name from your code signing certificate. |
Expand Down
64 changes: 63 additions & 1 deletion docs/api/electron-builder.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,12 @@ Developer API only. See [[Options]] for user documentation.
<dd></dd>
<dt><a href="#module_electron-builder/out/targets/dmg">electron-builder/out/targets/dmg</a></dt>
<dd></dd>
<dt><a href="#module_electron-builder/out/targets/dmgLicense">electron-builder/out/targets/dmgLicense</a></dt>
<dd></dd>
<dt><a href="#module_electron-builder/out/targets/fpm">electron-builder/out/targets/fpm</a></dt>
<dd></dd>
<dt><a href="#module_electron-builder/out/targets/license">electron-builder/out/targets/license</a></dt>
<dd></dd>
<dt><a href="#module_electron-builder/out/targets/LinuxTargetHelper">electron-builder/out/targets/LinuxTargetHelper</a></dt>
<dd></dd>
<dt><a href="#module_electron-builder/out/targets/nsis">electron-builder/out/targets/nsis</a></dt>
Expand Down Expand Up @@ -1570,7 +1574,7 @@ Developer API only. See [[Options]] for user documentation.
| Name | Type |
| --- | --- |
| publishTasks=| <code>Array&lt;Promise&lt;any&gt;&gt;</code> |
| progress = <code>(&lt;NodeJS.WritableStream&gt;process.stdout).isTTY ? new MultiProgress() : null</code>| <code>null</code> \| <code>[MultiProgress](electron-publish#MultiProgress)</code> |
| progress = <code>(&lt;TtyWriteStream&gt;process.stdout).isTTY ? new MultiProgress() : null</code>| <code>null</code> \| <code>[MultiProgress](electron-publish#MultiProgress)</code> |


* [.PublishManager](#PublishManager) ⇐ <code>[PublishContext](electron-publish#PublishContext)</code>
Expand Down Expand Up @@ -1885,6 +1889,19 @@ Developer API only. See [[Options]] for user documentation.
| readWrite | <code>boolean</code> |
| task | <code>callback</code> |

<a name="module_electron-builder/out/targets/dmgLicense"></a>

## electron-builder/out/targets/dmgLicense
<a name="module_electron-builder/out/targets/dmgLicense.addLicenseToDmg"></a>

### `electron-builder/out/targets/dmgLicense.addLicenseToDmg(packager, dmgPath)` ⇒ <code>Promise&lt;void&gt;</code>
**Kind**: method of <code>[electron-builder/out/targets/dmgLicense](#module_electron-builder/out/targets/dmgLicense)</code>

| Param | Type |
| --- | --- |
| packager | <code>[PlatformPackager](#PlatformPackager)&lt;any&gt;</code> |
| dmgPath | <code>string</code> |

<a name="module_electron-builder/out/targets/fpm"></a>

## electron-builder/out/targets/fpm
Expand Down Expand Up @@ -1914,6 +1931,51 @@ Developer API only. See [[Options]] for user documentation.
| appOutDir | <code>string</code> |
| arch | <code>[Arch](electron-builder-core#Arch)</code> |

<a name="module_electron-builder/out/targets/license"></a>

## electron-builder/out/targets/license

* [electron-builder/out/targets/license](#module_electron-builder/out/targets/license)
* [`.LicenseFile`](#LicenseFile)
* [`.lcid`](#module_electron-builder/out/targets/license.lcid) : <code>any</code>
* [`.getLicenseFiles(packager)`](#module_electron-builder/out/targets/license.getLicenseFiles) ⇒ <code>Promise&lt;Array&lt;[LicenseFile](#LicenseFile)&gt;&gt;</code>
* [`.toLangWithRegion(lang)`](#module_electron-builder/out/targets/license.toLangWithRegion) ⇒ <code>string</code>

<a name="LicenseFile"></a>

### `LicenseFile`
**Kind**: interface of <code>[electron-builder/out/targets/license](#module_electron-builder/out/targets/license)</code>
**Properties**

| Name | Type |
| --- | --- |
| **file**| <code>string</code> |
| **lang**| <code>string</code> |
| **langWithRegion**| <code>string</code> |
| **langName**| <code>string</code> |

<a name="module_electron-builder/out/targets/license.lcid"></a>

### `electron-builder/out/targets/license.lcid` : <code>any</code>
**Kind**: constant of <code>[electron-builder/out/targets/license](#module_electron-builder/out/targets/license)</code>
<a name="module_electron-builder/out/targets/license.getLicenseFiles"></a>

### `electron-builder/out/targets/license.getLicenseFiles(packager)` ⇒ <code>Promise&lt;Array&lt;[LicenseFile](#LicenseFile)&gt;&gt;</code>
**Kind**: method of <code>[electron-builder/out/targets/license](#module_electron-builder/out/targets/license)</code>

| Param | Type |
| --- | --- |
| packager | <code>[PlatformPackager](#PlatformPackager)&lt;any&gt;</code> |

<a name="module_electron-builder/out/targets/license.toLangWithRegion"></a>

### `electron-builder/out/targets/license.toLangWithRegion(lang)` ⇒ <code>string</code>
**Kind**: method of <code>[electron-builder/out/targets/license](#module_electron-builder/out/targets/license)</code>

| Param | Type |
| --- | --- |
| lang | <code>string</code> |

<a name="module_electron-builder/out/targets/LinuxTargetHelper"></a>

## electron-builder/out/targets/LinuxTargetHelper
Expand Down
3 changes: 3 additions & 0 deletions packages/electron-builder/src/options/macOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ export interface PkgOptions extends TargetSpecificOptions {

/**
* macOS DMG Options ([dmg](#Config-dmg)).
*
* To add license to DMG, create file `license_LANG_CODE.txt` in the build resources. Multiple license files in different languages are supported — use lang postfix (e.g. `_de`, `_ru`)). For example, create files `license_de.txt` and `license_en.txt` in the build resources.
* If OS language is german, `license_de.txt` will be displayed. See map of [language code to name](https://github.com/meikidd/iso-639-1/blob/master/src/data.js).
*/
export interface DmgOptions extends TargetSpecificOptions {
/**
Expand Down
3 changes: 3 additions & 0 deletions packages/electron-builder/src/targets/dmg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import * as path from "path"
import sanitizeFileName from "sanitize-filename"
import { DmgOptions, MacOptions } from "../options/macOptions"
import { PlatformPackager } from "../platformPackager"
import { addLicenseToDmg } from "./dmgLicense"

export class DmgTarget extends Target {
readonly options = this.packager.config.dmg
Expand Down Expand Up @@ -175,6 +176,8 @@ export class DmgTarget extends Target {
await spawn("hdiutil", addVerboseIfNeed(args))
await exec("hdiutil", addVerboseIfNeed(["internet-enable", "-no"]).concat(artifactPath))

await addLicenseToDmg(packager, artifactPath)

this.packager.dispatchArtifactCreated(artifactPath, this, arch, `${appInfo.name}-${appInfo.version}.dmg`)
}

Expand Down
42 changes: 42 additions & 0 deletions packages/electron-builder/src/targets/dmgLicense.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { debug, exec } from "electron-builder-util"
import { readFile, writeFile } from "fs-extra-p"
import * as path from "path"
import { PlatformPackager } from "../platformPackager"
import { getLicenseFiles } from "./license"

// http://www.owsiak.org/?p=700
export async function addLicenseToDmg(packager: PlatformPackager<any>, dmgPath: string) {
const licenseFiles = await getLicenseFiles(packager)
if (licenseFiles.length === 0) {
return
}

if (debug.enabled) {
debug(`License files: ${licenseFiles.join(" ")}`)
}

const tempFile = await packager.getTempFile(".r")
let data = await readFile(path.join(__dirname, "..", "..", "templates", "dmg", "license.txt"), "utf8")
let counter = 5000
for (const item of licenseFiles) {
const kind = item.file.toLowerCase().endsWith(".rtf") ? "RTF" : "TEXT"
data += `data '${kind}' (${counter}, "${item.langName} SLA") {\n`

data += '$"' + (await readFile(item.file)).toString("hex").toUpperCase() + '"\n'
data += "};\n\n"
// noinspection SpellCheckingInspection
data += `data 'styl' (${counter}, "${item.langName} SLA") {
$"0003 0000 0000 000C 0009 0015 0000 0000"
$"0000 0000 0000 0000 002A 000C 0009 0015"
$"0100 0000 0000 0000 0000 0000 002E 000C"
$"0009 0015 0000 0000 0000 0000 0000"
};`

counter++
}

await writeFile(tempFile, data)
await exec("hdiutil", ["unflatten", dmgPath])
await exec("Rez", ["-a", tempFile, "-o", dmgPath])
await exec("hdiutil", ["flatten", dmgPath])
}
Loading

0 comments on commit d6f0c57

Please sign in to comment.