-
-
Notifications
You must be signed in to change notification settings - Fork 512
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(plugin-compile): add the electron compile plugin into the monorepo
- Loading branch information
1 parent
37a1e07
commit 5907de5
Showing
7 changed files
with
97 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "@electron-forge/plugin-compile", | ||
"version": "6.0.0-beta.21", | ||
"description": "Electron Compile plugin for Electron Forge", | ||
"repository": "https://github.com/electron-userland/electron-forge", | ||
"author": "Samuel Attard", | ||
"license": "MIT", | ||
"main": "dist/CompilePlugin.js", | ||
"typings": "dist/CompilePlugin.d.ts", | ||
"scripts": { | ||
"test": "exit 0" | ||
}, | ||
"devDependencies": { | ||
"chai": "^4.0.0", | ||
"mocha": "^5.0.0" | ||
}, | ||
"engines": { | ||
"node": ">= 6.0" | ||
}, | ||
"dependencies": { | ||
"@electron-forge/async-ora": "6.0.0-beta.21", | ||
"@electron-forge/plugin-base": "6.0.0-beta.21", | ||
"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,25 @@ | ||
import PluginBase, { StartOptions } from '@electron-forge/plugin-base'; | ||
import * as path from 'path'; | ||
|
||
import { CompilePluginConfig } from './Config'; | ||
import { createCompileHook } from './lib/compile-hook'; | ||
|
||
export default class LocalElectronPlugin extends PluginBase<CompilePluginConfig> { | ||
name = 'electron-compile'; | ||
private dir!: string; | ||
|
||
init(dir: string) { | ||
this.dir = dir; | ||
} | ||
|
||
getHook(hookName: string) { | ||
if (hookName === 'packageAfterCopy') { | ||
return createCompileHook(this.dir); | ||
} | ||
return null; | ||
} | ||
|
||
async startLogic(opts: StartOptions) { | ||
return [process.execPath, path.resolve(this.dir, 'node_modules/electron-prebuilt-compile/lib/cli')]; | ||
} | ||
} |
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,2 @@ | ||
export interface CompilePluginConfig { | ||
} |
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,38 @@ | ||
import { asyncOra } from '@electron-forge/async-ora'; | ||
import fs from 'fs-extra'; | ||
import path from 'path'; | ||
|
||
export const createCompileHook = (originalDir: string) => | ||
async (_: any, buildPath: string) => { | ||
await asyncOra('Compiling Application', async () => { | ||
const compileCLI = require(path.resolve(originalDir, 'node_modules/electron-compile/lib/cli.js')); | ||
|
||
async function compileAndShim(appDir: string) { | ||
for (const entry of await fs.readdir(appDir)) { | ||
if (!entry.match(/^(node_modules|bower_components)$/)) { | ||
const fullPath = path.join(appDir, entry); | ||
|
||
if ((await fs.stat(fullPath)).isDirectory()) { | ||
const log = console.log; | ||
console.log = () => {}; | ||
await compileCLI.main(appDir, [fullPath]); | ||
console.log = log; | ||
} | ||
} | ||
} | ||
|
||
const packageJSON = await fs.readJson(path.resolve(appDir, 'package.json')); | ||
|
||
const index = packageJSON.main || 'index.js'; | ||
packageJSON.originalMain = index; | ||
packageJSON.main = 'es6-shim.js'; | ||
|
||
await fs.writeFile(path.join(appDir, 'es6-shim.js'), | ||
await fs.readFile(path.join(path.resolve(originalDir, 'node_modules/electron-compile/lib/es6-shim.js')), 'utf8')); | ||
|
||
await fs.writeJson(path.join(appDir, 'package.json'), packageJSON, { spaces: 2 }); | ||
} | ||
|
||
await compileAndShim(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