Skip to content
Permalink
Browse files

feat(plugin-compile): add the electron compile plugin into the monorepo

  • Loading branch information
MarshallOfSound committed Jul 4, 2018
1 parent 37a1e07 commit 5907de5de0b338255f6e488332b0eb2c8e460c4e
@@ -69,8 +69,12 @@ export default async ({
runAsNode,
inspect,
});
let prefixArgs: string[] = [];
if (typeof spawnedPluginChild === 'string') {
electronExecPath = spawnedPluginChild;
} else if (Array.isArray(spawnedPluginChild)) {
electronExecPath = spawnedPluginChild[0];
prefixArgs = spawnedPluginChild.slice(1);
} else if (spawnedPluginChild) {
await runHook(forgeConfig, 'postStart', spawnedPluginChild);
return spawnedPluginChild;
@@ -98,7 +102,7 @@ export default async ({
let spawned!: ChildProcess;

await asyncOra('Launching Application', async () => {
spawned = spawn(electronExecPath, [appPath].concat(args as string[]), spawnOpts);
spawned = spawn(electronExecPath, prefixArgs.concat([appPath]).concat(args as string[]), spawnOpts);
});

await runHook(forgeConfig, 'postStart', spawned);
@@ -21,7 +21,7 @@ export default abstract class Plugin<C> {
return null;
}

async startLogic(startOpts: StartOptions): Promise<ChildProcess | string | false> {
async startLogic(startOpts: StartOptions): Promise<ChildProcess | string | string[] | false> {
return false;
}
}
@@ -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"
}
}
@@ -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')];
}
}
@@ -0,0 +1,2 @@
export interface CompilePluginConfig {
}
@@ -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);
});
};
@@ -11,7 +11,7 @@ import { RebuildOptions } from 'electron-rebuild/lib/src/rebuild';
export interface IForgePluginInterface {
triggerHook(hookName: string, hookArgs: any[]): Promise<void>;
triggerMutatingHook<T>(hookName: string, item: T): Promise<any>;
overrideStartLogic(opts: any): Promise<ChildProcess | false>;
overrideStartLogic(opts: any): Promise<ChildProcess | string | string[] | false>;
}
export interface ForgeConfig {
/**

0 comments on commit 5907de5

Please sign in to comment.
You can’t perform that action at this time.