Skip to content

Commit 6256432

Browse files
committed
refactor: extract electron-builder-squirrel-windows
BREAKING CHANGE: To use Squirrel.Windows please install `electron-builder-squirrel-windows` dependency.
1 parent 479193e commit 6256432

34 files changed

+245
-279
lines changed

.idea/electron-builder.iml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/Options.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,9 @@ Please note — on macOS [you need to register an `open-url` event handler](http
244244

245245
<a name="SquirrelWindowsOptions"></a>
246246
### `.build.squirrelWindows`
247+
248+
To use Squirrel.Windows please install `electron-builder-squirrel-windows` dependency.
249+
247250
| Name | Description
248251
| --- | ---
249252
| 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>
@@ -260,7 +263,7 @@ Windows specific build options.
260263

261264
| Name | Description
262265
| --- | ---
263-
| 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>
266+
| 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>
264267
| 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>
265268
| 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).
266269
| legalTrademarks | <a name="WinBuildOptions-legalTrademarks"></a>The trademarks and registered trademarks.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"private": true,
33
"license": "MIT",
44
"scripts": {
5-
"compile": "ts-babel packages/electron-builder-http packages/electron-builder-util packages/electron-builder packages/electron-auto-updater test",
6-
"lint": "node ./packages/lint.js",
5+
"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",
6+
"lint": "node test/out/helpers/lint.js",
77
"pretest": "node ./test/vendor/yarn.js compile && node ./test/vendor/yarn.js lint && node ./test/vendor/yarn.js check-deps",
88
"check-deps": "node ./test/out/helpers/checkDeps.js",
99
"test": "node ./test/out/helpers/runTests.js",
@@ -56,7 +56,8 @@
5656
"testRegex": "\\.js$",
5757
"modulePaths": [
5858
"<rootDir>/packages",
59-
"<rootDir>/packages/electron-builder/node_modules"
59+
"<rootDir>/packages/electron-builder/node_modules",
60+
"<rootDir>/packages/electron-builder-util/node_modules"
6061
],
6162
"setupTestFrameworkScriptFile": "<rootDir>/test/jestSetup.js"
6263
},

packages/check-release.js

Lines changed: 0 additions & 137 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "electron-builder-core",
3+
"version": "0.0.0-semantic-release",
4+
"main": "out/core.js",
5+
"author": "Vladimir Krivosheev",
6+
"license": "MIT",
7+
"repository": "electron-userland/electron-builder",
8+
"bugs": "https://github.com/electron-userland/electron-builder/issues",
9+
"homepage": "https://github.com/electron-userland/electron-builder",
10+
"files": [
11+
"out"
12+
],
13+
"typings": "./out/electron-builder-core.d.ts"
14+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
export enum Arch {
2+
ia32, x64, armv7l
3+
}
4+
5+
export function getArchSuffix(arch: Arch): string {
6+
return arch === Arch.x64 ? "" : `-${Arch[arch]}`
7+
}
8+
9+
export function archFromString(name: string): Arch {
10+
if (name === "x64") {
11+
return Arch.x64
12+
}
13+
if (name === "ia32") {
14+
return Arch.ia32
15+
}
16+
if (name === "armv7l") {
17+
return Arch.armv7l
18+
}
19+
20+
throw new Error(`Unsupported arch ${name}`)
21+
}
22+
23+
export class Platform {
24+
static MAC = new Platform("mac", "mac", "darwin")
25+
static LINUX = new Platform("linux", "linux", "linux")
26+
static WINDOWS = new Platform("windows", "win", "win32")
27+
28+
// deprecated
29+
//noinspection JSUnusedGlobalSymbols
30+
static OSX = Platform.MAC
31+
32+
constructor(public name: string, public buildConfigurationKey: string, public nodeName: string) {
33+
}
34+
35+
toString() {
36+
return this.name
37+
}
38+
39+
createTarget(type?: string | Array<string> | null, ...archs: Array<Arch>): Map<Platform, Map<Arch, Array<string>>> {
40+
const archToType = new Map()
41+
if (this === Platform.MAC) {
42+
archs = [Arch.x64]
43+
}
44+
45+
for (const arch of (archs == null || archs.length === 0 ? [archFromString(process.arch)] : archs)) {
46+
archToType.set(arch, type == null ? [] : (Array.isArray(type) ? type : [type]))
47+
}
48+
return new Map([[this, archToType]])
49+
}
50+
51+
static current(): Platform {
52+
return Platform.fromString(process.platform)
53+
}
54+
55+
static fromString(name: string): Platform {
56+
name = name.toLowerCase()
57+
switch (name) {
58+
case Platform.MAC.nodeName:
59+
case Platform.MAC.name:
60+
return Platform.MAC
61+
62+
case Platform.WINDOWS.nodeName:
63+
case Platform.WINDOWS.name:
64+
case Platform.WINDOWS.buildConfigurationKey:
65+
return Platform.WINDOWS
66+
67+
case Platform.LINUX.nodeName:
68+
return Platform.LINUX
69+
70+
default:
71+
throw new Error(`Unknown platform: ${name}`)
72+
}
73+
}
74+
}
75+
76+
77+
export abstract class Target {
78+
constructor(public readonly name: string, public readonly isAsyncSupported: boolean = true) {
79+
}
80+
81+
abstract build(appOutDir: string, arch: Arch): Promise<any>
82+
83+
finishBuild(): Promise<any> {
84+
return Promise.resolve()
85+
}
86+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"extends": "../tsconfig-base.json",
3+
"compilerOptions": {
4+
"outDir": "out"
5+
},
6+
"declaration": {
7+
"electron-builder-core": "out/electron-builder-core.d.ts"
8+
},
9+
"include": [
10+
"src/**/*.ts"
11+
]
12+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "electron-builder-squirrel-windows",
3+
"version": "0.0.0-semantic-release",
4+
"main": "out/squirrelWindows.js",
5+
"author": "Vladimir Krivosheev",
6+
"license": "MIT",
7+
"repository": "electron-userland/electron-builder",
8+
"bugs": "https://github.com/electron-userland/electron-builder/issues",
9+
"homepage": "https://github.com/electron-userland/electron-builder",
10+
"files": [
11+
"out"
12+
],
13+
"dependencies": {
14+
"electron-builder-util": "0.0.0-semantic-release",
15+
"electron-builder-core": "0.0.0-semantic-release",
16+
"bluebird-lst-c": "^1.0.5",
17+
"fs-extra-p": "^3.0.3",
18+
"archiver": "^1.3.0"
19+
},
20+
"typings": "./out/electron-builder-squirrel-windows.d.ts"
21+
}

packages/electron-builder/src/targets/squirrelPack.ts renamed to packages/electron-builder-squirrel-windows/src/squirrelPack.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as path from "path"
22
import BluebirdPromise from "bluebird-lst-c"
33
import { remove, copy, createWriteStream, unlink, ensureDir, stat } from "fs-extra-p"
44
import { spawn, exec, prepareArgs, execWine, debug } from "electron-builder-util"
5-
import { WinPackager } from "../winPackager"
5+
import { WinPackager } from "electron-builder/out/winPackager"
66
import { log } from "electron-builder-util/out/log"
77
import { walk, copyFile } from "electron-builder-util/out/fs"
88

packages/electron-builder/src/targets/squirrelWindows.ts renamed to packages/electron-builder-squirrel-windows/src/squirrelWindows.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
import { WinPackager } from "../winPackager"
2-
import { getArchSuffix } from "../platformPackager"
3-
import { Arch } from "../metadata"
1+
import { WinPackager } from "electron-builder/out/winPackager"
42
import * as path from "path"
53
import { warn, log } from "electron-builder-util/out/log"
6-
import { getRepositoryInfo } from "../repositoryInfo"
74
import { getBinFromBintray } from "electron-builder-util/out/binDownload"
85
import { buildInstaller, convertVersion, SquirrelOptions } from "./squirrelPack"
9-
import { SquirrelWindowsOptions } from "../options/winOptions"
10-
import { Target } from "./targetFactory"
6+
import { SquirrelWindowsOptions } from "electron-builder/out/options/winOptions"
7+
import { Target, Arch, getArchSuffix } from "electron-builder-core"
118

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

9592
if (options.remoteReleases === true) {
96-
const info = await getRepositoryInfo(packager.appInfo.metadata, packager.info.devMetadata)
93+
const info = await packager.getRepositoryInfo()
9794
if (info == null) {
9895
warn("remoteReleases set to true, but cannot get repository info")
9996
}

0 commit comments

Comments
 (0)