Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: #1547 Added pkg license #2212

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/electron-builder/src/options/macOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ export interface PkgOptions extends TargetSpecificOptions {
* The name of certificate to use when signing. Consider using environment variables [CSC_LINK or CSC_NAME](../code-signing.md) instead of specifying this option.
*/
readonly identity?: string | null

/**
* The path to EULA license file. Defaults to `license.txt`. In addition to `txt, `rtf` and `html` supported (don't forget to use `target="_blank"` for links).
* @default build/license.txt
*/
readonly license?: string | null
}

export interface DmgOptions extends TargetSpecificOptions {
Expand Down
14 changes: 13 additions & 1 deletion packages/electron-builder/src/targets/pkg.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import BluebirdPromise from "bluebird-lst"
import { Arch, debug, exec, use } from "builder-util"
import { statOrNull } from "builder-util/out/fs"
import { getLicenseFiles } from "builder-util/out/license"
import { readFile, unlink, writeFile } from "fs-extra-p"
import * as path from "path"
import { findIdentity, Identity } from "../codeSign"
Expand All @@ -19,7 +20,8 @@ export class PkgTarget extends Target {
readonly options: PkgOptions = {
allowAnywhere: true,
allowCurrentUserHome: true,
allowRootDirectory: true, ...this.packager.config.pkg}
allowRootDirectory: true,
license: "build/licence.txt", ...this.packager.config.pkg}

constructor(private readonly packager: MacPackager, readonly outDir: string) {
super("pkg")
Expand Down Expand Up @@ -70,6 +72,16 @@ export class PkgTarget extends Target {
let distInfo = await readFile(distInfoFile, "utf-8")
const insertIndex = distInfo.lastIndexOf("</installer-gui-script>")
distInfo = distInfo.substring(0, insertIndex) + ` <domains enable_anywhere="${options.allowAnywhere}" enable_currentUserHome="${options.allowCurrentUserHome}" enable_localSystem="${options.allowRootDirectory}" />\n` + distInfo.substring(insertIndex)

if (options.license !== null) {
const licenseFiles = await getLicenseFiles(this.packager)
const license = await this.packager.getResource(options.license, ...licenseFiles.map(f => f.file))
if (license != null) {
const licensePath = path.join(this.packager.info.projectDir, license)
distInfo = distInfo.substring(0, insertIndex) + ` <license file="${licensePath}"/>\n` + distInfo.substring(insertIndex)
}
}

debug(distInfo)
await writeFile(distInfoFile, distInfo)
}
Expand Down