Skip to content

Commit

Permalink
fix: Configure build resources directory #184
Browse files Browse the repository at this point in the history
Tests refactored to simplify new test addition
ESLint added to check test code

Closes #184, #196
  • Loading branch information
develar committed Mar 3, 2016
1 parent ac27220 commit 5df87d3
Show file tree
Hide file tree
Showing 30 changed files with 443 additions and 211 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test/fixtures/
test/old-cli-test.js
1 change: 0 additions & 1 deletion .idea/electron-builder.iml

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

6 changes: 5 additions & 1 deletion .idea/runConfigurations/BuildTest.xml

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

2 changes: 1 addition & 1 deletion cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ builder.build( Object.assign( cli.flags, {
* @return {Object} configuration
*/
function getConfigFromFile( configPath, property ) {
var config = JSON.parse( fs.readFileSync( configPath ) );
var config = JSON.parse( fs.readFileSync( configPath, 'utf8' ) );

if ( property ) {
if ( config[ property ] ) {
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion lib/osx.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var fs = require( 'fs' );
var path = require( 'path' );
var os = require( 'os' );
var appdmg = require( 'appdmg' );
var tmp = require( 'tmp' );

/**
* Prototype for the osx installer builder
Expand Down Expand Up @@ -39,7 +40,7 @@ var OSXBuilder = {
osx.icon = path.resolve( options.basePath, osx.icon );
osx.contents[ 1 ].path = options.appPath;

var configFilePath = path.join( os.tmpDir(), 'appdmg.json' );
var configFilePath = tmp.fileSync().name;

fs.writeFileSync( configFilePath, JSON.stringify( options.config.osx ) );

Expand Down
2 changes: 1 addition & 1 deletion lib/osx.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ if ( process.platform === 'darwin' ) {
t.equal( options.target, '/somewhere/out/there/Example App.dmg' );

var configFilePath = options.source;
var config = require( configFilePath, 'utf8' );
var config = JSON.parse( fs.readFileSync( configFilePath, 'utf8' ) );

t.equal( config.background, '/foo/boooom.png' );
t.equal( config.icon, '/foo/icon.icns' );
Expand Down
1 change: 0 additions & 1 deletion lib/win.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ var WinBuilder = {
options.log( ' $ apt-get install wine nsis -y' );
break;
}
options.log( process.env );
return callback( new Error( 'makensis failed' ) );
} );

Expand Down
48 changes: 38 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "out/index.js",
"scripts": {
"compile": "tsconfig -i 2 && ts-babel",
"lint": "eslint ./lib cli.js index.js && tslint src/*",
"lint": "eslint ./lib test cli.js index.js && tslint src/*",
"pretest": "npm run compile && npm run lint",
"test": "node ./test/helpers/runTests.js",
"test-nix": "result=\"$(tape index.spec.js ./lib/*.spec.js ./lib/**/*.spec.js)\"; echo \"$result\" | tap-spec; echo \"$result\" | tnyan; ava",
Expand Down Expand Up @@ -51,12 +51,12 @@
"dependencies": {
"bluebird": "^3.3.3",
"command-line-args": "^2.1.6",
"electron-packager-tf": "^5.2.2",
"electron-winstaller-temp-fork": "^0.1.0",
"electron-packager-tf": "^5.2.3",
"electron-winstaller-temp-fork": "^2.0.5-beta.0",
"fs-extra": "^0.26.5",
"gm": "^1.21.1",
"hosted-git-info": "^2.1.4",
"lodash.template": "^4.2.1",
"lodash.template": "^4.2.2",
"meow": "^3.7.0",
"mime": "^1.3.4",
"progress": "^1.1.8",
Expand All @@ -70,33 +70,61 @@
},
"devDependencies": {
"ava-tf": "^0.12.3",
"babel-eslint": "^6.0.0-beta.1",
"babel-plugin-array-includes": "^2.0.3",
"babel-plugin-transform-es2015-parameters": "^6.6.0",
"babel-plugin-transform-async-to-module-method": "^6.5.2",
"babel-plugin-transform-es2015-modules-commonjs": "^6.6.4",
"babel-plugin-transform-es2015-parameters": "^6.6.4",
"babel-plugin-transform-strict-mode": "^6.6.4",
"babel-register": "^6.6.0",
"electron-download": "^1.4.1",
"eslint": "^2.2.0",
"eslint-plugin-ava": "sindresorhus/eslint-plugin-ava",
"ghooks": "^1.0.3",
"json-parse-helpfulerror": "^1.0.3",
"option-chain": "^0.1.1",
"path-sort": "^0.1.0",
"plist": "^1.2.0",
"proxyquire": "^1.7.4",
"semantic-release": "^4.3.5",
"should": "^8.2.2",
"tap-nyan": "0.0.2",
"tap-spec": "^4.1.1",
"tape": "^4.4.0",
"ts-babel": "^0.4.3",
"tape": "^4.5.0",
"ts-babel": "^0.4.5",
"tsconfig-glob": "^0.4.1",
"tsd-generator": "^2.0.2",
"tslint": "^3.5.0",
"typescript": "^1.8.2",
"typescript": "^1.8.7",
"validate-commit-msg": "^2.1.0"
},
"babel": {
"plugins": [
"transform-es2015-parameters",
"array-includes"
]
],
"env": {
"test": {
"ignore": "**/out/*.js",
"plugins": [
[
"babel-plugin-transform-async-to-module-method",
{
"module": "bluebird",
"method": "coroutine"
}
],
"babel-plugin-transform-es2015-modules-commonjs",
"transform-strict-mode"
]
}
}
},
"ava": {
"verbose": true
"verbose": true,
"require": [
"babel-register"
]
},
"typings": "./out/electron-builder.d.ts",
"config": {
Expand Down
2 changes: 1 addition & 1 deletion src/linuxPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class LinuxPackager extends PlatformPackager<DebOptions> {
prefix: "png-icons"
})

const outputs = await exec("icns2png", ["-x", "-o", tempDir, path.join(this.projectDir, "build", "icon.icns")])
const outputs = await exec("icns2png", ["-x", "-o", tempDir, path.join(this.buildResourcesDir, "icon.icns")])
if (!outputs[0].toString().includes("ih32")) {
log("48x48 is not found in the icns, 128x128 will be resized")
// icns doesn't contain required 48x48, use gm to resize
Expand Down
4 changes: 2 additions & 2 deletions src/macPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ export default class MacPackager extends PlatformPackager<appdmg.Specification>

const specification: appdmg.Specification = {
title: this.metadata.name,
icon: "build/icon.icns",
icon: path.join(this.buildResourcesDir, "icon.icns"),
"icon-size": 80,
background: "build/background.png",
background: path.join(this.buildResourcesDir, "background.png"),
contents: [
{
"x": 410, "y": 220, "type": "link", "path": "/Applications"
Expand Down
9 changes: 6 additions & 3 deletions src/packager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ export class Packager implements BuildInfo {
const distTasks: Array<Promise<any>> = []
for (let platform of platforms) {
const helper = this.createHelper(platform, cleanupTasks)
const archs = platform === "darwin" ? ["x64"] : (this.options.arch == null || this.options.arch === "all" ? ["ia32", "x64"] : [this.options.arch])
for (let arch of archs) {
for (let arch of normalizeArchs(platform, this.options.arch)) {
await this.installAppDependencies(arch)

helper.currentArch = arch
Expand Down Expand Up @@ -176,7 +175,11 @@ export class Packager implements BuildInfo {
}
}

function normalizePlatforms(platforms: Array<string>): Array<string> {
export function normalizeArchs(platform: string, arch?: string) {
return platform === "darwin" ? ["x64"] : (arch == null || arch === "all" ? ["ia32", "x64"] : [arch])
}

export function normalizePlatforms(platforms: Array<string>): Array<string> {
if (platforms == null || platforms.length === 0) {
return [process.platform]
}
Expand Down
18 changes: 16 additions & 2 deletions src/platformPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ const pack = BluebirdPromise.promisify(packager)

export interface DevMetadata extends Metadata {
build: DevBuildMetadata

directories?: MetadataDirectories
}

interface MetadataDirectories {
buildResources?: string
}

export interface DevBuildMetadata {
Expand Down Expand Up @@ -57,9 +63,10 @@ export abstract class PlatformPackager<DC> implements ProjectMetadataProvider {
protected options: PackagerOptions

protected projectDir: string
protected buildResourcesDir: string

metadata: AppMetadata
devMetadata: Metadata
devMetadata: DevMetadata

customDistOptions: DC

Expand All @@ -73,12 +80,19 @@ export abstract class PlatformPackager<DC> implements ProjectMetadataProvider {
this.metadata = info.metadata
this.devMetadata = info.devMetadata

this.buildResourcesDir = path.resolve(this.projectDir, this.relativeBuildResourcesDirname)

if (this.options.dist) {
const buildMetadata: any = info.devMetadata.build
this.customDistOptions = buildMetadata == null ? buildMetadata : buildMetadata[this.getBuildConfigurationKey()]
}
}

protected get relativeBuildResourcesDirname() {
const directories = this.devMetadata.directories
return (directories == null ? null : directories.buildResources) || "build"
}

protected dispatchArtifactCreated(path: string) {
this.info.eventEmitter.emit("artifactCreated", path)
}
Expand All @@ -98,7 +112,7 @@ export abstract class PlatformPackager<DC> implements ProjectMetadataProvider {
platform: platform,
arch: this.currentArch,
version: this.info.electronVersion,
icon: path.join(this.projectDir, "build", "icon"),
icon: path.join(this.buildResourcesDir, "icon"),
asar: true,
overwrite: true,
"app-version": version,
Expand Down
13 changes: 6 additions & 7 deletions src/winPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default class WinPackager extends PlatformPackager<any> {
// on appveyor (well, yes, it is a Windows bug)
// Because NSIS support will be dropped some day, correct solution is not implemented
const iconPath = this.customDistOptions == null ? null : this.customDistOptions.icon
require("../lib/win").copyAssetsToTmpFolder(iconPath || path.join(this.projectDir, "build", "icon.ico"))
require("../lib/win").copyAssetsToTmpFolder(iconPath || path.join(this.buildResourcesDir, "icon.ico"))
}

// https://developer.mozilla.org/en-US/docs/Signing_an_executable_with_Authenticode
Expand Down Expand Up @@ -77,12 +77,12 @@ export default class WinPackager extends PlatformPackager<any> {
if (this.info.repositoryInfo != null) {
const info = await this.info.repositoryInfo.getInfo(this)
if (info != null) {
iconUrl = `https://raw.githubusercontent.com/${info.user}/${info.project}/master/build/icon.ico`
iconUrl = `https://raw.githubusercontent.com/${info.user}/${info.project}/master/${this.relativeBuildResourcesDirname}/icon.ico`
}
}

if (!iconUrl) {
throw new Error("iconUrl is not specified, please see https://github.com/develar/electron-complete-builder#in-short")
throw new Error("iconUrl is not specified, please see https://github.com/loopline-systems/electron-builder#in-short")
}
}
}
Expand All @@ -100,9 +100,9 @@ export default class WinPackager extends PlatformPackager<any> {
productName: appName,
version: version,
description: this.metadata.description,
authors: this.metadata.author,
authors: this.metadata.author.name,
iconUrl: iconUrl,
setupIcon: path.join(this.projectDir, "build", "icon.ico"),
setupIcon: path.join(this.buildResourcesDir, "icon.ico"),
certificateFile: certificateFile,
certificatePassword: this.options.cscKeyPassword,
}, this.customDistOptions)
Expand All @@ -112,8 +112,7 @@ export default class WinPackager extends PlatformPackager<any> {
}

try {
const build = <(options: any, callback: (error: Error) => void) => void>require("electron-winstaller-temp-fork").build
await BluebirdPromise.promisify(build)(options)
await require("electron-winstaller-temp-fork").createWindowsInstaller(options)
}
catch (e) {
if (!e.message.includes("Unable to set icon")) {
Expand Down
43 changes: 43 additions & 0 deletions test/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
env:
es6: true
node: true

parserOptions:
ecmaVersion: 6
sourceType: module
ecmaFeatures:
impliedStrict: true

parser: babel-eslint

plugins:
- ava

extends: "eslint:recommended"

rules:
ava/max-asserts: [0, 5]
ava/no-cb-test: 0
ava/no-identical-title: 2
ava/no-invalid-end: 2
ava/no-only-test: 2
ava/no-skip-assert: 2
ava/no-skip-test: 2
ava/prefer-power-assert: 0
ava/test-ended: 2
ava/test-title: [2, 'always']

"quotes": [ 2, "double" ]
semi: [2, "never"]
"linebreak-style": [ 2, "unix" ]
no-trailing-spaces: 2
no-var: 2
comma-dangle: 0
no-console: 0
curly: 2
eqeqeq: [2, "allow-null"]
no-throw-literal: 2
no-unused-expressions: 2
no-path-concat: 2
prefer-arrow-callback: 2
prefer-const: 2
6 changes: 3 additions & 3 deletions test/ArtifactPublisherTest.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import test from "ava-tf"
import { GitHubPublisher } from "electron-builder/out/gitHubPublisher"
import { GitHubPublisher } from "out/gitHubPublisher"
import { join } from "path"

function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
return Math.floor(Math.random() * (max - min + 1)) + min
}

function versionNumber() {
return getRandomInt(0, 99) + "." + Date.now() + "." + getRandomInt(0, 9);
return getRandomInt(0, 99) + "." + Date.now() + "." + getRandomInt(0, 9)
}

const token = new Buffer("Y2Y5NDdhZDJhYzJlMzg1OGNiNzQzYzcwOWZhNGI0OTk2NWQ4ZDg3Yg==", "base64").toString()
Expand Down
Loading

0 comments on commit 5df87d3

Please sign in to comment.