-
-
Notifications
You must be signed in to change notification settings - Fork 512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(plugin-local-electron): add plugin-local-electron #501
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7f36bae
feat(plugin-local-electron): add plugin-local-electron
MarshallOfSound 4402136
docs(plugin-local-electron): add docs for the config options
MarshallOfSound bd8bb41
fix(core): fromBuildIdentifier moved to the utils object
MarshallOfSound ca45d97
test(plugin-local-electron): add tests for the local electron plugin
MarshallOfSound File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,25 @@ | ||
{ | ||
"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": "mocha --require ts-node/register test/**/*_spec.ts test/**/**/*_spec.ts --opts ../../../mocha.opts" | ||
}, | ||
"devDependencies": { | ||
"chai": "^4.0.0", | ||
"fs-extra": "^5.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,32 @@ | ||
export interface LocalElectronPluginConfig { | ||
/** | ||
* Whether or not the plugin is enabled. | ||
* | ||
* Can be handy to set this to an environment variable for quick personal | ||
* toggling of this plugin. | ||
* | ||
* Default: `true` | ||
*/ | ||
enabled?: boolean; | ||
/** | ||
* An absolute path to the folder containing your built version of Electron. | ||
* | ||
* Normally this looks like `/path/to/electron/out/D` | ||
*/ | ||
electronPath: string; | ||
/** | ||
* The platform your local build of Electron is for. You only need to set | ||
* this if you have a local build for a platform that isn't your system's | ||
* platform. | ||
* | ||
* Default: process.platform | ||
*/ | ||
electronPlatform?: string; | ||
/** | ||
* The arch your local build of Electron is for. You only need to set this if | ||
* you have a local build for an arch that isn't your system's arch. | ||
* | ||
* Default: process.arch | ||
*/ | ||
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,57 @@ | ||
import PluginBase 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'; | ||
|
||
constructor(config: LocalElectronPluginConfig) { | ||
super(config); | ||
if (typeof this.config.enabled === 'undefined') { | ||
this.config = { | ||
...this.config, | ||
enabled: true, | ||
}; | ||
} | ||
} | ||
|
||
async startLogic() { | ||
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); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
plugin or plugins?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
plugin
, it's consistent withinstaller
andmaker
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
util
perhaps 😄There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup will follow up on that