All files / util compile-hook.js

100% Statements 18/18
83.33% Branches 5/6
100% Functions 4/4
100% Lines 18/18
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43              2x 2x     2x 14x 12x   12x 2x 2x 2x 2x         2x   2x 2x 2x   2x     2x         2x   2x    
import fs from 'fs-promise';
import path from 'path';
 
import asyncOra from './ora-handler';
import readPackageJSON from './read-package-json';
 
export default async(originalDir, buildPath, electronVersion, pPlatform, pArch, done) => {
  await asyncOra('Compiling Application', async () => {
    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 = await readPackageJSON(appDir);
 
      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);
  });
  done();
};