Permalink
Please
sign in to comment.
Browse files
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
Showing
with
177 additions
and 37 deletions.
- +2 −1 package.json
- +8 −1 packages/api/core/src/api/package.ts
- +10 −32 packages/api/core/src/api/start.ts
- +0 −1 packages/api/core/src/util/plugin-interface.ts
- +23 −0 packages/plugin/base/package.json
- +25 −0 packages/plugin/base/src/Plugin.ts
- +24 −0 packages/plugin/local-electron/package.json
- +6 −0 packages/plugin/local-electron/src/Config.ts
- +47 −0 packages/plugin/local-electron/src/LocalElectronPlugin.ts
- +32 −2 packages/utils/types/src/index.ts
@@ -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" | ||
} | ||
} |
@@ -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; | ||
} | ||
} |
@@ -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" | ||
} | ||
} |
@@ -0,0 +1,6 @@ | ||
export interface LocalElectronPluginConfig { | ||
enabled: boolean; | ||
electronPath: string; | ||
electronPlatform?: string; | ||
electronArch?: string; | ||
} |
@@ -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); | ||
} | ||
} |
0 comments on commit
8af9268