Skip to content

Commit

Permalink
feat(forge): makers for forge should use electron-builder-lib to redu…
Browse files Browse the repository at this point in the history
…ce number of dependencies
  • Loading branch information
develar committed Feb 1, 2018
1 parent 10ccea8 commit d3aa530
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 59 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import * as path from "path"
import { build, CliOptions } from "../builder"
import { build } from "./index"
import { PackagerOptions } from "./packagerApi"

export interface ForgeOptions {
readonly dir: string
}

export function buildForge(forgeOptions: ForgeOptions, options: CliOptions) {
export function buildForge(forgeOptions: ForgeOptions, options: PackagerOptions) {
const appDir = forgeOptions.dir
return build({
prepackaged: appDir,
Expand Down
52 changes: 52 additions & 0 deletions packages/electron-builder-lib/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
import { CancellationToken } from "builder-util-runtime/out/CancellationToken"
import { executeFinally } from "builder-util/out/promise"
import { PublishOptions } from "electron-publish/out/publisher"
import { log } from "builder-util"
import { Packager } from "./packager"
import { PackagerOptions } from "./packagerApi"
import BluebirdPromise from "bluebird-lst"
import { PublishManager } from "./publish/PublishManager"

export { Packager, BuildResult } from "./packager"
export { PackagerOptions, ArtifactCreated } from "./packagerApi"
export { TargetConfiguration, Platform, Target, DIR_TARGET, BeforeBuildContext, SourceRepositoryInfo, TargetSpecificOptions, TargetConfigType, DEFAULT_TARGET, CompressionLevel } from "./core"
Expand All @@ -21,3 +30,46 @@ export { CancellationToken } from "builder-util-runtime"
export { PublishOptions, UploadTask } from "electron-publish"
export { PublishManager } from "./publish/PublishManager"
export { PlatformPackager } from "./platformPackager"
export { buildForge, ForgeOptions } from "./forge-maker"

export async function build(options: PackagerOptions & PublishOptions, cancellationToken: CancellationToken = new CancellationToken()): Promise<Array<string>> {
const packager = new Packager(options, cancellationToken)

let electronDownloader: any = null
packager.electronDownloader = options => {
if (electronDownloader == null) {
electronDownloader = BluebirdPromise.promisify(require("electron-download-tf"))
}
return electronDownloader(options)
}

// because artifact event maybe dispatched several times for different publish providers
const artifactPaths = new Set<string>()
packager.artifactCreated(event => {
if (event.file != null) {
artifactPaths.add(event.file)
}
})

const publishManager = new PublishManager(packager, options)
const sigIntHandler = () => {
log.warn("cancelled by SIGINT")
cancellationToken.cancel()
publishManager.cancelTasks()
}
process.once("SIGINT", sigIntHandler)

return await executeFinally(packager.build().then(() => Array.from(artifactPaths)), errorOccurred => {
let promise: Promise<any>
if (errorOccurred) {
publishManager.cancelTasks()
promise = Promise.resolve(null)
}
else {
promise = publishManager.awaitTasks()
}

return promise
.then(() => process.removeListener("SIGINT", sigIntHandler))
})
}
49 changes: 2 additions & 47 deletions packages/electron-builder/src/builder.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import BluebirdPromise from "bluebird-lst"
import { addValue, Arch, archFromString, InvalidConfigurationError, log } from "builder-util"
import { CancellationToken } from "builder-util-runtime"
import { executeFinally } from "builder-util/out/promise"
import chalk from "chalk"
import { Configuration, DIR_TARGET, PackagerOptions, Platform, PublishManager } from "electron-builder-lib"
import { Packager } from "electron-builder-lib/out/packager"
import { Configuration, DIR_TARGET, PackagerOptions, Platform } from "electron-builder-lib"
import { build as _build } from "electron-builder-lib"
import { PublishOptions } from "electron-publish"
import { deepAssign } from "read-config-file/out/deepAssign"

Expand Down Expand Up @@ -218,48 +215,6 @@ export function build(rawOptions?: CliOptions): Promise<Array<string>> {
return _build(normalizeOptions(rawOptions || {}))
}

export async function _build(options: PackagerOptions & PublishOptions, cancellationToken: CancellationToken = new CancellationToken()): Promise<Array<string>> {
const packager = new Packager(options, cancellationToken)

let electronDownloader: any = null
packager.electronDownloader = options => {
if (electronDownloader == null) {
electronDownloader = BluebirdPromise.promisify(require("electron-download-tf"))
}
return electronDownloader(options)
}

// because artifact event maybe dispatched several times for different publish providers
const artifactPaths = new Set<string>()
packager.artifactCreated(event => {
if (event.file != null) {
artifactPaths.add(event.file)
}
})

const publishManager = new PublishManager(packager, options)
const sigIntHandler = () => {
log.warn("cancelled by SIGINT")
cancellationToken.cancel()
publishManager.cancelTasks()
}
process.once("SIGINT", sigIntHandler)

return await executeFinally(packager.build().then(() => Array.from(artifactPaths)), errorOccurred => {
let promise: Promise<any>
if (errorOccurred) {
publishManager.cancelTasks()
promise = Promise.resolve(null)
}
else {
promise = publishManager.awaitTasks()
}

return promise
.then(() => process.removeListener("SIGINT", sigIntHandler))
})
}

/**
* @private
* @internal
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-builder/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ export {
Metadata, AuthorMetadata, RepositoryInfo, AppInfo,
UploadTask, PublishManager, PublishOptions
} from "electron-builder-lib"
export { buildForge, ForgeOptions } from "./forge/forge-maker"
export { buildForge, ForgeOptions } from "electron-builder-lib"
export { CancellationToken } from "builder-util-runtime"
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
value: true
})

const buildForge = require("electron-builder").buildForge
const buildForge = require("electron-builder-lib").buildForge

exports.isSupportedOnCurrentPlatform = () => Promise.resolve(true)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "electron-installer-appimage",
"name": "electron-forge-maker-appimage",
"version": "0.0.0-semantic-release",
"main": "main.js",
"author": "Vladimir Krivosheev",
Expand All @@ -11,6 +11,6 @@
"*.js"
],
"dependencies": {
"electron-builder": "^0.0.0-semantic-release"
"electron-builder-lib": "^0.0.0-semantic-release"
}
}
2 changes: 1 addition & 1 deletion packages/electron-forge-maker-nsis-web/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
value: true
})

const buildForge = require("electron-builder").buildForge
const buildForge = require("electron-builder-lib").buildForge

exports.isSupportedOnCurrentPlatform = () => Promise.resolve(true)

Expand Down
2 changes: 1 addition & 1 deletion packages/electron-forge-maker-nsis-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"*.js"
],
"dependencies": {
"electron-builder": "^19.30.3"
"electron-builder-lib": "^19.30.3"
}
}
2 changes: 1 addition & 1 deletion packages/electron-forge-maker-nsis/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
value: true
})

const buildForge = require("electron-builder").buildForge
const buildForge = require("electron-builder-lib").buildForge

exports.isSupportedOnCurrentPlatform = () => Promise.resolve(true)

Expand Down
2 changes: 1 addition & 1 deletion packages/electron-forge-maker-nsis/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"*.js"
],
"dependencies": {
"electron-builder": "^0.0.0-semantic-release"
"electron-builder-lib": "^0.0.0-semantic-release"
}
}
2 changes: 1 addition & 1 deletion packages/electron-forge-maker-snap/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
value: true
})

const buildForge = require("electron-builder").buildForge
const buildForge = require("electron-builder-lib").buildForge

exports.isSupportedOnCurrentPlatform = () => Promise.resolve(true)

Expand Down
2 changes: 1 addition & 1 deletion packages/electron-forge-maker-snap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"*.js"
],
"dependencies": {
"electron-builder": "^0.0.0-semantic-release"
"electron-builder-lib": "^0.0.0-semantic-release"
}
}

0 comments on commit d3aa530

Please sign in to comment.