-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
338 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import * as path from "path" | ||
import { ElectronPackagerOptions } from "./dirPackager" | ||
|
||
export function userIgnoreFilter(opts: ElectronPackagerOptions, appDir: string) { | ||
let ignore = opts.ignore || [] | ||
let ignoreFunc: any | ||
|
||
if (typeof (ignore) === "function") { | ||
ignoreFunc = function (file: string) { return !ignore(file) } | ||
} | ||
else { | ||
if (!Array.isArray(ignore)) { | ||
ignore = [ignore] | ||
} | ||
|
||
ignoreFunc = function (file: string) { | ||
for (let i = 0; i < ignore.length; i++) { | ||
if (file.match(ignore[i])) { | ||
return false | ||
} | ||
} | ||
|
||
return true | ||
} | ||
} | ||
|
||
return function filter(file: string) { | ||
let name = file.split(path.resolve(appDir))[1] | ||
if (path.sep === "\\") { | ||
// convert slashes so unix-format ignores work | ||
name = name.replace(/\\/g, "/") | ||
} | ||
return ignoreFunc(name) | ||
} | ||
} | ||
|
||
export function initializeApp(opts: any, buildDir: string, appRelativePath: string) { | ||
return opts.initializeApp(opts, buildDir, appRelativePath) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { Promise as BluebirdPromise } from "bluebird" | ||
import { emptyDir } from "fs-extra-p" | ||
import { warn } from "../util/log" | ||
import { AppInfo } from "../appInfo" | ||
|
||
const downloadElectron: (options: any) => Promise<any> = BluebirdPromise.promisify(require("electron-download")) | ||
const extract: any = BluebirdPromise.promisify(require("extract-zip")) | ||
|
||
//noinspection JSUnusedLocalSymbols | ||
const __awaiter = require("../util/awaiter") | ||
|
||
export interface ElectronPackagerOptions { | ||
"extend-info"?: string | ||
"app-category-type"?: string | ||
appBundleId: string | ||
|
||
protocols?: any | ||
|
||
appInfo: AppInfo | ||
|
||
icon?: string; | ||
|
||
"app-bundle-id"?: string | null; | ||
|
||
"helper-bundle-id"?: string | null; | ||
|
||
ignore?: any | ||
|
||
initializeApp?: (opts: ElectronPackagerOptions, buildDir: string, appRelativePath: string) => Promise<any> | ||
} | ||
|
||
const supportedPlatforms: any = { | ||
// Maps to module ID for each platform (lazy-required if used) | ||
darwin: "./mac", | ||
linux: "./linux", | ||
mas: "./mac", // map to darwin | ||
win32: "./win32" | ||
} | ||
|
||
function createDownloadOpts(opts: any, platform: string, arch: string, electronVersion: string) { | ||
const downloadOpts = Object.assign({ | ||
cache: opts.cache, | ||
strictSSL: opts["strict-ssl"] | ||
}, opts.download) | ||
|
||
subOptionWarning(downloadOpts, "download", "platform", platform) | ||
subOptionWarning(downloadOpts, "download", "arch", arch) | ||
subOptionWarning(downloadOpts, "download", "version", electronVersion) | ||
return downloadOpts | ||
} | ||
|
||
function subOptionWarning (properties: any, optionName: any, parameter: any, value: any) { | ||
if (properties.hasOwnProperty(parameter)) { | ||
warn(`${optionName}.${parameter} will be inferred from the main options`) | ||
} | ||
properties[parameter] = value | ||
} | ||
|
||
export async function pack(opts: ElectronPackagerOptions, out: string, platform: string, arch: string, electronVersion: string) { | ||
const zipPath = await downloadElectron(createDownloadOpts(opts, platform, arch, electronVersion)) | ||
await emptyDir(out) | ||
await extract(zipPath, {dir: out}) | ||
await require(supportedPlatforms[platform]).createApp(opts, out) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { rename } from "fs-extra-p" | ||
import * as path from "path" | ||
import { initializeApp } from "./common" | ||
import { ElectronPackagerOptions } from "./dirPackager" | ||
import { Promise as BluebirdPromise } from "bluebird" | ||
|
||
export function createApp(opts: ElectronPackagerOptions, buildDir: string) { | ||
return BluebirdPromise.all([ | ||
initializeApp(opts, buildDir, path.join("resources", "app")), | ||
rename(path.join(buildDir, "electron"), path.join(buildDir, opts.appInfo.productFilename)) | ||
]) | ||
} |
Oops, something went wrong.