-
-
Notifications
You must be signed in to change notification settings - Fork 513
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(plugin-local-electron): add plugin-local-electron
used to run a local version of electron instead of the version the electron module downloads
- Loading branch information
1 parent
fef9bcd
commit 8af9268
Showing
10 changed files
with
177 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "@electron-forge/plugin-base", | ||
"version": "6.0.0-beta.5", | ||
"description": "Base plugin for Electron Forge", | ||
"repository": "https://github.com/electron-userland/electron-forge", | ||
"author": "Samuel Attard", | ||
"license": "MIT", | ||
"main": "dist/Plugin.js", | ||
"typings": "dist/Plugin.d.ts", | ||
"scripts": { | ||
"test": "exit 0" | ||
}, | ||
"devDependencies": { | ||
"chai": "^4.0.0", | ||
"mocha": "^5.0.0" | ||
}, | ||
"engines": { | ||
"node": ">= 6.0" | ||
}, | ||
"dependencies": { | ||
"@electron-forge/shared-types": "6.0.0-beta.5" | ||
} | ||
} |
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,25 @@ | ||
import { ForgeHookFn, StartOptions } from '@electron-forge/shared-types'; | ||
import { ChildProcess } from 'child_process'; | ||
|
||
export { StartOptions }; | ||
|
||
export default abstract class Plugin<C> { | ||
public abstract name: string; | ||
__isElectronForgePlugin!: true; | ||
|
||
constructor(public config: C) { | ||
Object.defineProperty(this, '__isElectronForgePlugin', { | ||
value: true, | ||
enumerable: false, | ||
configurable: false, | ||
}); | ||
} | ||
|
||
getHook(hookName: string): ForgeHookFn | null { | ||
return null; | ||
} | ||
|
||
async startLogic(startOpts: StartOptions): Promise<ChildProcess | string | false> { | ||
return false; | ||
} | ||
} |
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,24 @@ | ||
{ | ||
"name": "@electron-forge/plugin-local-electron", | ||
"version": "6.0.0-beta.5", | ||
"description": "Local Electron plugin for Electron Forge, let's you use a local build of Electron", | ||
"repository": "https://github.com/electron-userland/electron-forge", | ||
"author": "Samuel Attard", | ||
"license": "MIT", | ||
"main": "dist/LocalElectronPlugin.js", | ||
"typings": "dist/LocalElectronPlugin.d.ts", | ||
"scripts": { | ||
"test": "exit 0" | ||
}, | ||
"devDependencies": { | ||
"chai": "^4.0.0", | ||
"mocha": "^5.0.0" | ||
}, | ||
"engines": { | ||
"node": ">= 6.0" | ||
}, | ||
"dependencies": { | ||
"@electron-forge/plugin-base": "6.0.0-beta.5", | ||
"fs-extra": "^5.0.0" | ||
} | ||
} |
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,6 @@ | ||
export interface LocalElectronPluginConfig { | ||
enabled: boolean; | ||
electronPath: string; | ||
electronPlatform?: string; | ||
electronArch?: string; | ||
} |
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,47 @@ | ||
import PluginBase, { StartOptions } from '@electron-forge/plugin-base'; | ||
import { spawn } from 'child_process'; | ||
import fs from 'fs-extra'; | ||
|
||
import { LocalElectronPluginConfig } from './Config'; | ||
|
||
export default class LocalElectronPlugin extends PluginBase<LocalElectronPluginConfig> { | ||
name = 'local-electron'; | ||
|
||
async startLogic(startOpts: StartOptions) { | ||
if (this.config.enabled) { | ||
this.checkPlatform(process.platform); | ||
process.env.ELECTRON_OVERRIDE_DIST_PATH = this.config.electronPath; | ||
} | ||
return false as any; | ||
} | ||
|
||
getHook(hookName: string) { | ||
if (hookName === 'packageAfterExtract') { | ||
return this.afterExtract; | ||
} | ||
return null; | ||
} | ||
|
||
private checkPlatform = (platform: string) => { | ||
if ((this.config.electronPlatform || process.platform) !== platform) { | ||
throw `Can not use local Electron version, required platform "${platform}" but local platform is "${this.config.electronPlatform || process.platform}"` | ||
} | ||
} | ||
|
||
private checkArch = (arch: string) => { | ||
if ((this.config.electronArch || process.arch) !== arch) { | ||
throw `Can not use local Electron version, required arch "${arch}" but local arch is "${this.config.electronArch || process.arch}"` | ||
} | ||
} | ||
|
||
private afterExtract = async (_: any, buildPath: string, __: any, platform: string, arch: string) => { | ||
if (!this.config.enabled) return; | ||
|
||
this.checkPlatform(platform); | ||
this.checkArch(arch); | ||
|
||
await fs.remove(buildPath); | ||
|
||
await fs.copy(this.config.electronPath, buildPath); | ||
} | ||
} |
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