-
-
Notifications
You must be signed in to change notification settings - Fork 535
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(packager): move packager compile logic to a electron-package…
…r afterCopy hook ISSUES CLOSED: Fixes #7
- Loading branch information
1 parent
9ab19b5
commit c10bcd2
Showing
3 changed files
with
56 additions
and
77 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,42 @@ | ||
import fs from 'fs-promise'; | ||
import ora from 'ora'; | ||
import path from 'path'; | ||
|
||
export default async(originalDir, buildPath, electronVersion, pPlatform, pArch, done) => { | ||
const compileSpinner = ora.ora('Compiling Application').start(); | ||
|
||
const compileCLI = require(path.resolve(originalDir, 'node_modules/electron-compile/lib/cli.js')); | ||
|
||
async function compileAndShim(appDir) { | ||
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 = JSON.parse(await fs.readFile(path.join(appDir, 'package.json'), 'utf8')); | ||
|
||
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.writeFile( | ||
path.join(appDir, 'package.json'), | ||
JSON.stringify(packageJson, null, 2)); | ||
} | ||
|
||
await compileAndShim(buildPath); | ||
|
||
compileSpinner.succeed(); | ||
done(); | ||
}; |