Skip to content

Commit

Permalink
refactor: extract electron-builder-squirrel-windows
Browse files Browse the repository at this point in the history
BREAKING CHANGE: To use Squirrel.Windows please install `electron-builder-squirrel-windows` dependency.
  • Loading branch information
develar committed Jan 5, 2017
1 parent 479193e commit 6256432
Show file tree
Hide file tree
Showing 34 changed files with 245 additions and 279 deletions.
3 changes: 3 additions & 0 deletions .idea/electron-builder.iml

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

5 changes: 4 additions & 1 deletion docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@ Please note — on macOS [you need to register an `open-url` event handler](http

<a name="SquirrelWindowsOptions"></a>
### `.build.squirrelWindows`

To use Squirrel.Windows please install `electron-builder-squirrel-windows` dependency.

| Name | Description
| --- | ---
| iconUrl | <a name="SquirrelWindowsOptions-iconUrl"></a><p>A URL to an ICO file to use as the application icon (displayed in Control Panel &gt; Programs and Features). Defaults to the Electron icon.</p> <p>Please note — [local icon file url is not accepted](https://github.com/atom/grunt-electron-installer/issues/73), must be https/http.</p> <ul> <li>If you don’t plan to build windows installer, you can omit it.</li> <li>If your project repository is public on GitHub, it will be <code>https://github.com/${u}/${p}/blob/master/build/icon.ico?raw=true</code> by default.</li> </ul>
Expand All @@ -260,7 +263,7 @@ Windows specific build options.

| Name | Description
| --- | ---
| target | <a name="WinBuildOptions-target"></a><p>Target package type: list of <code>nsis</code>, <code>appx</code>, <code>squirrel</code>, <code>7z</code>, <code>zip</code>, <code>tar.xz</code>, <code>tar.lz</code>, <code>tar.gz</code>, <code>tar.bz2</code>, <code>dir</code>. Defaults to <code>nsis</code>.</p> <p>AppX package can be built only on Windows 10.</p>
| target | <a name="WinBuildOptions-target"></a><p>Target package type: list of <code>nsis</code>, <code>appx</code>, <code>squirrel</code>, <code>7z</code>, <code>zip</code>, <code>tar.xz</code>, <code>tar.lz</code>, <code>tar.gz</code>, <code>tar.bz2</code>, <code>dir</code>. Defaults to <code>nsis</code>.</p> <p>AppX package can be built only on Windows 10.</p> <p>To use Squirrel.Windows please install <code>electron-builder-squirrel-windows</code> dependency.</p>
| signingHashAlgorithms | <a name="WinBuildOptions-signingHashAlgorithms"></a><p>Array of signing algorithms used. Defaults to <code>['sha1', 'sha256']</code></p> <p>For AppX <code>sha256</code> is always used.</p>
| icon | <a name="WinBuildOptions-icon"></a>The path to application icon. Defaults to `build/icon.ico` (consider using this convention instead of complicating your configuration).
| legalTrademarks | <a name="WinBuildOptions-legalTrademarks"></a>The trademarks and registered trademarks.
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"private": true,
"license": "MIT",
"scripts": {
"compile": "ts-babel packages/electron-builder-http packages/electron-builder-util packages/electron-builder packages/electron-auto-updater test",
"lint": "node ./packages/lint.js",
"compile": "ts-babel packages/electron-builder-http packages/electron-builder-core packages/electron-builder-util packages/electron-builder packages/electron-builder-squirrel-windows packages/electron-auto-updater test",
"lint": "node test/out/helpers/lint.js",
"pretest": "node ./test/vendor/yarn.js compile && node ./test/vendor/yarn.js lint && node ./test/vendor/yarn.js check-deps",
"check-deps": "node ./test/out/helpers/checkDeps.js",
"test": "node ./test/out/helpers/runTests.js",
Expand Down Expand Up @@ -56,7 +56,8 @@
"testRegex": "\\.js$",
"modulePaths": [
"<rootDir>/packages",
"<rootDir>/packages/electron-builder/node_modules"
"<rootDir>/packages/electron-builder/node_modules",
"<rootDir>/packages/electron-builder-util/node_modules"
],
"setupTestFrameworkScriptFile": "<rootDir>/test/jestSetup.js"
},
Expand Down
137 changes: 0 additions & 137 deletions packages/check-release.js

This file was deleted.

14 changes: 14 additions & 0 deletions packages/electron-builder-core/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "electron-builder-core",
"version": "0.0.0-semantic-release",
"main": "out/core.js",
"author": "Vladimir Krivosheev",
"license": "MIT",
"repository": "electron-userland/electron-builder",
"bugs": "https://github.com/electron-userland/electron-builder/issues",
"homepage": "https://github.com/electron-userland/electron-builder",
"files": [
"out"
],
"typings": "./out/electron-builder-core.d.ts"
}
86 changes: 86 additions & 0 deletions packages/electron-builder-core/src/core.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
export enum Arch {
ia32, x64, armv7l
}

export function getArchSuffix(arch: Arch): string {
return arch === Arch.x64 ? "" : `-${Arch[arch]}`
}

export function archFromString(name: string): Arch {
if (name === "x64") {
return Arch.x64
}
if (name === "ia32") {
return Arch.ia32
}
if (name === "armv7l") {
return Arch.armv7l
}

throw new Error(`Unsupported arch ${name}`)
}

export class Platform {
static MAC = new Platform("mac", "mac", "darwin")
static LINUX = new Platform("linux", "linux", "linux")
static WINDOWS = new Platform("windows", "win", "win32")

// deprecated
//noinspection JSUnusedGlobalSymbols
static OSX = Platform.MAC

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

toString() {
return this.name
}

createTarget(type?: string | Array<string> | null, ...archs: Array<Arch>): Map<Platform, Map<Arch, Array<string>>> {
const archToType = new Map()
if (this === Platform.MAC) {
archs = [Arch.x64]
}

for (const arch of (archs == null || archs.length === 0 ? [archFromString(process.arch)] : archs)) {
archToType.set(arch, type == null ? [] : (Array.isArray(type) ? type : [type]))
}
return new Map([[this, archToType]])
}

static current(): Platform {
return Platform.fromString(process.platform)
}

static fromString(name: string): Platform {
name = name.toLowerCase()
switch (name) {
case Platform.MAC.nodeName:
case Platform.MAC.name:
return Platform.MAC

case Platform.WINDOWS.nodeName:
case Platform.WINDOWS.name:
case Platform.WINDOWS.buildConfigurationKey:
return Platform.WINDOWS

case Platform.LINUX.nodeName:
return Platform.LINUX

default:
throw new Error(`Unknown platform: ${name}`)
}
}
}


export abstract class Target {
constructor(public readonly name: string, public readonly isAsyncSupported: boolean = true) {
}

abstract build(appOutDir: string, arch: Arch): Promise<any>

finishBuild(): Promise<any> {
return Promise.resolve()
}
}
12 changes: 12 additions & 0 deletions packages/electron-builder-core/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "../tsconfig-base.json",
"compilerOptions": {
"outDir": "out"
},
"declaration": {
"electron-builder-core": "out/electron-builder-core.d.ts"
},
"include": [
"src/**/*.ts"
]
}
21 changes: 21 additions & 0 deletions packages/electron-builder-squirrel-windows/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "electron-builder-squirrel-windows",
"version": "0.0.0-semantic-release",
"main": "out/squirrelWindows.js",
"author": "Vladimir Krivosheev",
"license": "MIT",
"repository": "electron-userland/electron-builder",
"bugs": "https://github.com/electron-userland/electron-builder/issues",
"homepage": "https://github.com/electron-userland/electron-builder",
"files": [
"out"
],
"dependencies": {
"electron-builder-util": "0.0.0-semantic-release",
"electron-builder-core": "0.0.0-semantic-release",
"bluebird-lst-c": "^1.0.5",
"fs-extra-p": "^3.0.3",
"archiver": "^1.3.0"
},
"typings": "./out/electron-builder-squirrel-windows.d.ts"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as path from "path"
import BluebirdPromise from "bluebird-lst-c"
import { remove, copy, createWriteStream, unlink, ensureDir, stat } from "fs-extra-p"
import { spawn, exec, prepareArgs, execWine, debug } from "electron-builder-util"
import { WinPackager } from "../winPackager"
import { WinPackager } from "electron-builder/out/winPackager"
import { log } from "electron-builder-util/out/log"
import { walk, copyFile } from "electron-builder-util/out/fs"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { WinPackager } from "../winPackager"
import { getArchSuffix } from "../platformPackager"
import { Arch } from "../metadata"
import { WinPackager } from "electron-builder/out/winPackager"
import * as path from "path"
import { warn, log } from "electron-builder-util/out/log"
import { getRepositoryInfo } from "../repositoryInfo"
import { getBinFromBintray } from "electron-builder-util/out/binDownload"
import { buildInstaller, convertVersion, SquirrelOptions } from "./squirrelPack"
import { SquirrelWindowsOptions } from "../options/winOptions"
import { Target } from "./targetFactory"
import { SquirrelWindowsOptions } from "electron-builder/out/options/winOptions"
import { Target, Arch, getArchSuffix } from "electron-builder-core"

const SW_VERSION = "1.5.1.4"
//noinspection SpellCheckingInspection
Expand Down Expand Up @@ -53,7 +50,7 @@ export default class SquirrelWindowsTarget extends Target {
const packager = this.packager
let iconUrl = this.options.iconUrl || packager.config.iconUrl
if (iconUrl == null) {
const info = await getRepositoryInfo(packager.appInfo.metadata, packager.info.devMetadata)
const info = await packager.getRepositoryInfo()
if (info != null) {
iconUrl = `https://github.com/${info.user}/${info.project}/blob/master/${packager.relativeBuildResourcesDirname}/icon.ico?raw=true`
}
Expand Down Expand Up @@ -93,7 +90,7 @@ export default class SquirrelWindowsTarget extends Target {
}

if (options.remoteReleases === true) {
const info = await getRepositoryInfo(packager.appInfo.metadata, packager.info.devMetadata)
const info = await packager.getRepositoryInfo()
if (info == null) {
warn("remoteReleases set to true, but cannot get repository info")
}
Expand Down
Loading

0 comments on commit 6256432

Please sign in to comment.