Skip to content

Commit

Permalink
feat: use productName from app/package.json if present #204
Browse files Browse the repository at this point in the history
Closes #204
  • Loading branch information
develar committed Mar 8, 2016
1 parent 26d6ddc commit a49223c
Show file tree
Hide file tree
Showing 20 changed files with 229 additions and 143 deletions.
9 changes: 9 additions & 0 deletions .idea/runConfigurations/winPackagerTest.xml

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

2 changes: 1 addition & 1 deletion lib/linux.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ function _buildPackage( options, scripts, tmpFolder, destination, callback ) {
'-t', linux.target,
'--architecture', linux.archName,
'--rpm-os', 'linux',
'--name', linux.title,
'--name', linux.name || linux.title,
'--force',
'--after-install', scripts[0],
'--after-remove', scripts[1],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"bluebird": "^3.3.4",
"command-line-args": "^2.1.6",
"electron-packager-tf": "^5.2.3",
"electron-winstaller-fixed": "^2.0.5-beta.4",
"electron-winstaller-fixed": "^2.0.5-beta.7",
"fs-extra": "^0.26.5",
"fs-extra-p": "^0.1.0",
"gm": "^1.21.1",
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import * as path from "path"
import * as fs from "fs-extra-p"

export { Packager } from "./packager"
export { PackagerOptions, Platform } from "./platformPackager"
export { PackagerOptions } from "./platformPackager"
export { AppMetadata, DevMetadata, Platform, getProductName } from "./metadata"

/**
* Prototype for electron-builder
Expand Down
15 changes: 8 additions & 7 deletions src/linuxPackager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as path from "path"
import { Promise as BluebirdPromise } from "bluebird"
import { init } from "../lib/linux"
import { PlatformPackager, BuildInfo, Platform } from "./platformPackager"
import { PlatformPackager, BuildInfo } from "./platformPackager"
import { Platform } from "./metadata"
import { dir as _tpmDir, TmpOptions } from "tmp"
import { exec, log } from "./util"
import { State as Gm } from "gm"
Expand Down Expand Up @@ -47,9 +48,9 @@ export class LinuxPackager extends PlatformPackager<DebOptions> {
})
}

const appName = this.metadata.name
const name = this.metadata.name
function createMapping(size: string) {
return `${tempDir}/icon_${size}x${size}x32.png=/usr/share/icons/hicolor/${size}x${size}/apps/${appName}.png`
return `${tempDir}/icon_${size}x${size}x32.png=/usr/share/icons/hicolor/${size}x${size}/apps/${name}.png`
}

return [
Expand All @@ -65,16 +66,16 @@ export class LinuxPackager extends PlatformPackager<DebOptions> {
async packageInDistributableFormat(outDir: string, appOutDir: string, arch: string): Promise<any> {
const specification: DebOptions = {
version: this.metadata.version,
title: this.metadata.name,
name: this.metadata.name,
comment: this.metadata.description,
maintainer: `${this.metadata.author.name} <${this.metadata.author.email}>`,
arch: arch === "ia32" ? 32 : 64,
target: "deb",
executable: this.metadata.name,
desktop: `[Desktop Entry]
Name=${this.metadata.name}
Name=${this.appName}
Comment=${this.metadata.description}
Exec=${this.metadata.name}
Exec=${this.appName}
Terminal=false
Type=Application
Icon=${this.metadata.name}
Expand All @@ -98,7 +99,7 @@ export class LinuxPackager extends PlatformPackager<DebOptions> {
}

export interface DebOptions {
title: string
name: string
comment: string

version: string
Expand Down
16 changes: 8 additions & 8 deletions src/macPackager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PlatformPackager, BuildInfo, Platform } from "./platformPackager"
import { PlatformPackager, BuildInfo } from "./platformPackager"
import { Platform } from "./metadata"
import * as path from "path"
import { Promise as BluebirdPromise } from "bluebird"
import { log, spawn } from "./util"
Expand Down Expand Up @@ -30,7 +31,7 @@ export default class MacPackager extends PlatformPackager<appdmg.Specification>
async pack(platform: string, outDir: string, appOutDir: string, arch: string): Promise<any> {
await super.pack(platform, outDir, appOutDir, arch)
let codeSigningInfo = await this.codeSigningInfo
return await this.signMac(path.join(appOutDir, this.metadata.name + ".app"), codeSigningInfo)
return await this.signMac(path.join(appOutDir, this.appName + ".app"), codeSigningInfo)
}

private signMac(distPath: string, codeSigningInfo: CodeSigningInfo): Promise<any> {
Expand All @@ -55,7 +56,7 @@ export default class MacPackager extends PlatformPackager<appdmg.Specification>
log("Creating DMG")

const specification: appdmg.Specification = {
title: this.metadata.name,
title: this.appName,
icon: path.join(this.buildResourcesDir, "icon.icns"),
"icon-size": 80,
background: path.join(this.buildResourcesDir, "background.png"),
Expand All @@ -74,10 +75,10 @@ export default class MacPackager extends PlatformPackager<appdmg.Specification>
}

if (specification.title == null) {
specification.title = this.metadata.name
specification.title = this.appName
}

specification.contents[1].path = path.join(appOutDir, this.metadata.name + ".app")
specification.contents[1].path = path.join(appOutDir, this.appName + ".app")

const emitter = require("appdmg")({
target: artifactPath,
Expand All @@ -96,10 +97,9 @@ export default class MacPackager extends PlatformPackager<appdmg.Specification>

private zipMacApp(outDir: string): Promise<string> {
log("Creating ZIP for Squirrel.Mac")
const appName = this.metadata.name
// -y param is important - "store symbolic links as the link instead of the referenced file"
const resultPath = `${appName}-${this.metadata.version}-mac.zip`
const args = ["-ryXq", resultPath, appName + ".app"]
const resultPath = `${this.metadata.name}-${this.metadata.version}-mac.zip`
const args = ["-ryXq", resultPath, this.appName + ".app"]

// todo move to options
if (process.env.TEST_MODE === "true") {
Expand Down
75 changes: 75 additions & 0 deletions src/metadata.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
export interface AppMetadata extends Metadata {
readonly version: string

/** The application name */
readonly name: string

/**
* As {@link 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]{@link https://docs.npmjs.com/files/package.json#name}.
*/
readonly productName?: string

readonly description: string
readonly author: AuthorMetadata

readonly build: BuildMetadata
}

export function getProductName(metadata: AppMetadata) {
return metadata.build.productName || metadata.productName || metadata.name
}

export interface DevMetadata extends Metadata {
readonly build: DevBuildMetadata

readonly directories?: MetadataDirectories
}

export interface BuildMetadata {
readonly "app-bundle-id": string
readonly "app-category-type": string

readonly iconUrl: string

/**
* See {@link AppMetadata#productName}.
*/
readonly productName?: string
}

export interface RepositoryInfo {
readonly url: string
}

export interface Metadata {
readonly repository: string | RepositoryInfo
}

export interface AuthorMetadata {
readonly name: string
readonly email: string
}

export interface MetadataDirectories {
readonly buildResources?: string
}

export interface DevBuildMetadata {
readonly osx: appdmg.Specification
readonly win: any,
readonly linux: any
}

export class Platform {
public static OSX = new Platform("osx", "osx")
public static LINUX = new Platform("linux", "linux")
public static WINDOWS = new Platform("windows", "win")

constructor(public name: string, public buildConfigurationKey: string) {
}

toString() {
return this.name
}
}
15 changes: 8 additions & 7 deletions src/packager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import { DEFAULT_APP_DIR_NAME, installDependencies, log, getElectronVersion, rea
import { all, executeFinally } from "./promise"
import { EventEmitter } from "events"
import { Promise as BluebirdPromise } from "bluebird"
import { AppMetadata, InfoRetriever } from "./repositoryInfo"
import { PackagerOptions, PlatformPackager, BuildInfo, DevMetadata, Platform } from "./platformPackager"
import { InfoRetriever } from "./repositoryInfo"
import { AppMetadata, Platform, DevMetadata } from "./metadata"
import { PackagerOptions, PlatformPackager, BuildInfo } from "./platformPackager"
import MacPackager from "./macPackager"
import WinPackager from "./winPackager"
import * as errorMessages from "./errorMessages"
Expand All @@ -19,9 +20,8 @@ function addHandler(emitter: EventEmitter, event: string, handler: Function) {
}

export class Packager implements BuildInfo {
projectDir: string

appDir: string
readonly projectDir: string
readonly appDir: string

metadata: AppMetadata
devMetadata: DevMetadata
Expand All @@ -30,7 +30,7 @@ export class Packager implements BuildInfo {

electronVersion: string

eventEmitter = new EventEmitter()
readonly eventEmitter = new EventEmitter()

//noinspection JSUnusedLocalSymbols
constructor(public options: PackagerOptions, public repositoryInfo: InfoRetriever = null) {
Expand Down Expand Up @@ -72,7 +72,8 @@ export class Packager implements BuildInfo {
await this.installAppDependencies(arch)

const outDir = path.join(this.projectDir, "dist")
const appOutDir = path.join(outDir, this.metadata.name + "-" + platform + "-" + arch)
// electron-packager uses productName in the directory name
const appOutDir = path.join(outDir, helper.appName + "-" + platform + "-" + arch)
await helper.pack(platform, outDir, appOutDir, arch)
if (this.options.dist) {
distTasks.push(helper.packageInDistributableFormat(outDir, appOutDir, arch))
Expand Down
42 changes: 9 additions & 33 deletions src/platformPackager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AppMetadata, InfoRetriever, ProjectMetadataProvider, Metadata } from "./repositoryInfo"
import { InfoRetriever, ProjectMetadataProvider } from "./repositoryInfo"
import { AppMetadata, DevMetadata, Platform, getProductName } from "./metadata"
import EventEmitter = NodeJS.EventEmitter
import { Promise as BluebirdPromise } from "bluebird"
import * as path from "path"
Expand All @@ -9,35 +10,6 @@ const __awaiter = require("./awaiter")

const pack = BluebirdPromise.promisify(packager)

export class Platform {
public static OSX = new Platform("osx", "osx")
public static LINUX = new Platform("linux", "linux")
public static WINDOWS = new Platform("windows", "win")

constructor(public name: string, public buildConfigurationKey: string) {
}

toString() {
return this.name
}
}

export interface DevMetadata extends Metadata {
build: DevBuildMetadata

directories?: MetadataDirectories
}

export interface MetadataDirectories {
buildResources?: string
}

export interface DevBuildMetadata {
osx: appdmg.Specification
win: any,
linux: any
}

export interface PackagerOptions {
arch?: string

Expand Down Expand Up @@ -82,6 +54,8 @@ export abstract class PlatformPackager<DC> implements ProjectMetadataProvider {

customDistOptions: DC

readonly appName: string

protected abstract get platform(): Platform

constructor(protected info: BuildInfo) {
Expand All @@ -96,6 +70,8 @@ export abstract class PlatformPackager<DC> implements ProjectMetadataProvider {
const buildMetadata: any = info.devMetadata.build
this.customDistOptions = buildMetadata == null ? buildMetadata : buildMetadata[this.platform.buildConfigurationKey]
}

this.appName = getProductName(this.metadata)
}

protected get relativeBuildResourcesDirname() {
Expand All @@ -118,7 +94,7 @@ export abstract class PlatformPackager<DC> implements ProjectMetadataProvider {
const options = Object.assign({
dir: this.info.appDir,
out: outDir,
name: this.metadata.name,
name: this.appName,
platform: platform,
arch: arch,
version: this.info.electronVersion,
Expand All @@ -132,8 +108,8 @@ export abstract class PlatformPackager<DC> implements ProjectMetadataProvider {
FileDescription: this.metadata.description,
ProductVersion: version,
FileVersion: buildVersion,
ProductName: this.metadata.name,
InternalName: this.metadata.name,
ProductName: this.appName,
InternalName: this.appName,
}
}, this.metadata.build, {"tmpdir": false})

Expand Down
29 changes: 1 addition & 28 deletions src/repositoryInfo.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,11 @@
import { fromUrl as parseRepositoryUrl, Info } from "hosted-git-info"
import { readText } from "./promisifed-fs"
import { AppMetadata, Metadata } from "./metadata"
import * as path from "path"

const __awaiter = require("./awaiter")
Array.isArray(__awaiter)

export interface RepositoryInfo {
url: string
}

export interface Metadata {
repository: string | RepositoryInfo
}

export interface MetadataAuthor {
name: string
email: string
}

export interface AppMetadata extends Metadata {
version: string
name: string
description: string
author: MetadataAuthor

build: BuildMetadata

windowsPackager: any
}

export interface BuildMetadata {
iconUrl: string
}

export interface ProjectMetadataProvider {
metadata: AppMetadata
devMetadata: Metadata
Expand Down
Loading

0 comments on commit a49223c

Please sign in to comment.