Skip to content

Commit

Permalink
feat: force application signing
Browse files Browse the repository at this point in the history
Babel config moved to .babelrc because:

 * jest invalidate cache on config file modification
 * json5 can be used instead of ugly raw json

config option added as preparation to additional config file in yaml.

Closes #975
  • Loading branch information
develar committed Dec 12, 2016
1 parent 88ce3b7 commit 4faa3fb
Show file tree
Hide file tree
Showing 46 changed files with 330 additions and 344 deletions.
43 changes: 43 additions & 0 deletions .babelrc
@@ -0,0 +1,43 @@
{
env: {
development: {
plugins: [
[
"transform-async-to-module-method",
{
module: "bluebird-lst-c",
method: "coroutine"
}
],
"transform-es2015-parameters",
"transform-es2015-spread",
"transform-es2015-destructuring",
"array-includes",
[
"transform-inline-imports-commonjs",
{
excludeModules: ["path"]
}
],
],
},
test: {
sourceMaps: "inline",
plugins: [
[
"transform-async-to-module-method",
{
module: "bluebird-lst-c",
method: "coroutine"
}
],
[
"transform-inline-imports-commonjs",
{
excludeModules: ["path"]
}
],
]
}
}
}
3 changes: 3 additions & 0 deletions .idea/codeStyleSettings.xml

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

4 changes: 4 additions & 0 deletions .idea/dictionaries/develar.xml

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

3 changes: 3 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

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

3 changes: 3 additions & 0 deletions .idea/scopes/json5.xml

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

3 changes: 2 additions & 1 deletion docs/Options.md
Expand Up @@ -58,7 +58,6 @@ Don't customize paths to background and icon, — just follow conventions.
| Name | Description
| --- | ---
| **build** | <a name="DevMetadata-build"></a>See [.build](#BuildMetadata).
| directories | <a name="DevMetadata-directories"></a>See [.directories](#MetadataDirectories)

<a name="BuildMetadata"></a>
## `.build`
Expand Down Expand Up @@ -91,6 +90,8 @@ Don't customize paths to background and icon, — just follow conventions.
| electronDist | <a name="BuildMetadata-electronDist"></a>The path to custom Electron build (e.g. `~/electron/out/R`). Only macOS supported, file issue if need for Linux or Windows.
| electronDownload | <a name="BuildMetadata-electronDownload"></a>The [electron-download](https://github.com/electron-userland/electron-download#usage) options.
| publish | <a name="BuildMetadata-publish"></a>See [.build.publish](#PublishConfiguration).
| forceCodeSigning | <a name="BuildMetadata-forceCodeSigning"></a>Whether to fail if application will be not signed (to prevent unsigned app if code signing configuration is not correct).
| directories | <a name="BuildMetadata-directories"></a>See [.directories](#MetadataDirectories)

<a name="DmgOptions"></a>
### `.build.dmg`
Expand Down
2 changes: 1 addition & 1 deletion docs/programmaticUsage.js
Expand Up @@ -6,7 +6,7 @@ const builder = require("electron-builder")
builder.build({
platform: [builder.Platform.MAC],
"//": "platform, arch and other properties, see PackagerOptions in the node_modules/electron-builder/out/electron-builder.d.ts",
devMetadata: {
config: {
"//": "build and other properties, see https://goo.gl/5jVxoO"
}
})
Expand Down
45 changes: 0 additions & 45 deletions package.json
Expand Up @@ -120,51 +120,6 @@
"typescript": "^2.1.4",
"whitespace": "^2.1.0"
},
"babel": {
"plugins": [
[
"transform-async-to-module-method",
{
"module": "bluebird-lst-c",
"method": "coroutine"
}
],
"transform-es2015-parameters",
"transform-es2015-spread",
"transform-es2015-destructuring",
"array-includes",
[
"transform-inline-imports-commonjs",
{
"excludeModules": [
"path"
]
}
]
],
"env": {
"test": {
"sourceMaps": "inline",
"plugins": [
[
"transform-async-to-module-method",
{
"module": "bluebird-lst-c",
"method": "coroutine"
}
],
[
"transform-inline-imports-commonjs",
{
"excludeModules": [
"path"
]
}
]
]
}
}
},
"jest": {
"testEnvironment": "node",
"testPathDirs": [
Expand Down
29 changes: 13 additions & 16 deletions src/appInfo.ts
@@ -1,4 +1,4 @@
import { DevMetadata, AppMetadata } from "./metadata"
import { DevMetadata, AppMetadata, BuildMetadata } from "./metadata"
import { warn } from "./util/log"
import { smarten } from "./platformPackager"
import { isEmptyOrSpaces } from "./util/util"
Expand All @@ -15,10 +15,14 @@ export class AppInfo {
readonly productName: string
readonly productFilename: string

private get config(): BuildMetadata {
return this.devMetadata.build
}

constructor(public metadata: AppMetadata, private devMetadata: DevMetadata, buildVersion?: string | null) {
this.version = metadata.version!

this.buildNumber = (<any>this.devMetadata.build)["build-version"] || process.env.TRAVIS_BUILD_NUMBER || process.env.APPVEYOR_BUILD_NUMBER || process.env.CIRCLE_BUILD_NUM || process.env.BUILD_NUMBER
this.buildNumber = (<any>this.config)["build-version"] || process.env.TRAVIS_BUILD_NUMBER || process.env.APPVEYOR_BUILD_NUMBER || process.env.CIRCLE_BUILD_NUM || process.env.BUILD_NUMBER

if (isEmptyOrSpaces(buildVersion)) {
buildVersion = this.version
Expand All @@ -31,7 +35,7 @@ export class AppInfo {
this.buildVersion = buildVersion!
}

this.productName = getProductName(this.metadata, this.devMetadata)
this.productName = this.config.productName || metadata.productName || metadata.name
this.productFilename = sanitizeFileName(this.productName)
}

Expand All @@ -45,13 +49,13 @@ export class AppInfo {
}

get id(): string {
let appId = this.devMetadata.build["app-bundle-id"]
let appId = this.config["app-bundle-id"]
if (appId != null) {
warn("app-bundle-id is deprecated, please use appId")
}

if (this.devMetadata.build.appId != null) {
appId = this.devMetadata.build.appId
if (this.config.appId != null) {
appId = this.config.appId
}

const generateDefaultAppId = () => {
Expand All @@ -72,27 +76,20 @@ export class AppInfo {
}

get copyright(): string {
const copyright = this.devMetadata.build.copyright
const copyright = this.config.copyright
if (copyright != null) {
return copyright
}
return `Copyright © ${new Date().getFullYear()} ${this.metadata.author!.name || this.productName}`
}

async computePackageUrl(): Promise<string | null> {
const url = this.metadata.homepage || this.devMetadata.homepage
const url = this.metadata.homepage
if (url != null) {
return url
}

const info = await getRepositoryInfo(this.metadata, this.devMetadata)
if (info != null) {
return `https://github.com/${info.user}/${info.project}`
}
return null
return info == null ? null : `https://github.com/${info.user}/${info.project}`
}
}

function getProductName(metadata: AppMetadata, devMetadata: DevMetadata) {
return devMetadata.build.productName || metadata.productName || metadata.name
}
4 changes: 2 additions & 2 deletions src/cli/install-app-deps.ts
@@ -1,5 +1,5 @@
#! /usr/bin/env node
import { computeDefaultAppDirectory, getElectronVersion, use } from "../util/util"
import { computeDefaultAppDirectory, getElectronVersion, use, getDirectoriesConfig } from "../util/util"
import { printErrorAndExit } from "../util/promise"
import * as path from "path"
import BluebirdPromise from "bluebird-lst-c"
Expand All @@ -19,7 +19,7 @@ async function main() {

const devMetadata: DevMetadata = await readPackageJson(devPackageFile)
const results: Array<string> = await BluebirdPromise.all([
computeDefaultAppDirectory(projectDir, use(devMetadata.directories, it => it!.app)),
computeDefaultAppDirectory(projectDir, use(getDirectoriesConfig(devMetadata), it => it!.app)),
getElectronVersion(devMetadata, devPackageFile)
])

Expand Down
10 changes: 5 additions & 5 deletions src/macPackager.ts
Expand Up @@ -32,11 +32,11 @@ export default class MacPackager extends PlatformPackager<MacOptions> {
}

protected prepareAppInfo(appInfo: AppInfo): AppInfo {
return new AppInfo(appInfo.metadata, this.devMetadata, this.platformSpecificBuildOptions.bundleVersion)
return new AppInfo(appInfo.metadata, this.info.devMetadata, this.platformSpecificBuildOptions.bundleVersion)
}

async getIconPath(): Promise<string | null> {
let iconPath = this.platformSpecificBuildOptions.icon || this.devMetadata.build.icon
let iconPath = this.platformSpecificBuildOptions.icon || this.config.icon
if (iconPath != null && !iconPath.endsWith(".icns")) {
iconPath += ".icns"
}
Expand Down Expand Up @@ -82,7 +82,7 @@ export default class MacPackager extends PlatformPackager<MacOptions> {

if (hasMas) {
const appOutDir = path.join(outDir, "mas")
const masBuildOptions = deepAssign({}, this.platformSpecificBuildOptions, (<any>this.devMetadata.build).mas)
const masBuildOptions = deepAssign({}, this.platformSpecificBuildOptions, (<any>this.config).mas)
await this.doPack(outDir, appOutDir, "mas", arch, masBuildOptions)
await this.sign(appOutDir, masBuildOptions)
}
Expand Down Expand Up @@ -113,7 +113,7 @@ export default class MacPackager extends PlatformPackager<MacOptions> {

if (name == null) {
let message = `App is not signed: cannot find valid ${isMas ? '"3rd Party Mac Developer Application" identity' : `"Developer ID Application" identity or custom non-Apple code signing certificate`}, see https://github.com/electron-userland/electron-builder/wiki/Code-Signing`
if (isMas) {
if (isMas || this.platformSpecificBuildOptions.forceCodeSigning) {
throw new Error(message)
}
else {
Expand Down Expand Up @@ -172,7 +172,7 @@ export default class MacPackager extends PlatformPackager<MacOptions> {
}

async findInstallerIdentity(isMas: boolean, keychainName: string | n): Promise<string> {
const targetSpecificOptions: MacOptions = (<any>this.devMetadata.build)[isMas ? "mas" : "pkg"] || this.platformSpecificBuildOptions
const targetSpecificOptions: MacOptions = (<any>this.config)[isMas ? "mas" : "pkg"] || this.platformSpecificBuildOptions
const name = isMas ? "3rd Party Mac Developer Installer" : "Developer ID Installer"
let installerName = await findIdentity(name, targetSpecificOptions.identity, keychainName)
if (installerName != null) {
Expand Down
23 changes: 12 additions & 11 deletions src/metadata.ts
Expand Up @@ -58,17 +58,6 @@ export interface DevMetadata extends Metadata {
See [.build](#BuildMetadata).
*/
readonly build: BuildMetadata

// deprecated
readonly homepage?: string | null

// deprecated
readonly license?: string | null

/*
See [.directories](#MetadataDirectories)
*/
readonly directories?: MetadataDirectories | null
}

export interface RepositoryInfo {
Expand Down Expand Up @@ -241,6 +230,16 @@ export interface BuildMetadata {
See [.build.publish](#PublishConfiguration).
*/
readonly publish?: Publish

/*
Whether to fail if application will be not signed (to prevent unsigned app if code signing configuration is not correct).
*/
readonly forceCodeSigning?: boolean

/*
See [.directories](#MetadataDirectories)
*/
readonly directories?: MetadataDirectories | null
}

export interface AfterPackContext {
Expand Down Expand Up @@ -344,6 +343,8 @@ export interface PlatformSpecificBuildOptions {
readonly fileAssociations?: Array<FileAssociation> | FileAssociation

readonly publish?: Publish

readonly forceCodeSigning?: boolean
}

export class Platform {
Expand Down

0 comments on commit 4faa3fb

Please sign in to comment.