/**
 * Adapted from redux
 * Runs an ordered set of commands within each of the build directories.
 */

import fs from 'fs';
import path from 'path';
import { spawnSync } from 'child_process';

var exampleDirs = fs.readdirSync(__dirname).filter((file) => {
  return fs.statSync(path.join(__dirname, file)).isDirectory();
});

// Ordering is important here. `npm install` must come first.
var cmdArgs = [
  { cmd: 'npm', args: [ 'install' ] },
  { cmd: 'webpack', args: [ 'index.js' ] }
];

for (const dir of exampleDirs) {
  for (const cmdArg of cmdArgs) {
    // declare opts in this scope to avoid https://github.com/joyent/node/issues/9158
    const opts = {
      cwd: path.join(__dirname, dir),
      stdio: 'inherit'
    };
    let result = {};
    if (process.platform === 'win32') {
      result = spawnSync(cmdArg.cmd + '.cmd', cmdArg.args, opts);
    } else {
      result = spawnSync(cmdArg.cmd, cmdArg.args, opts);
    }
    if (result.status !== 0) {
      throw new Error('Building examples exited with non-zero');
    }
  }
}

@@ -420,17 +420,16 @@
  args: %5B
- 
 'install
@@ -429,17 +429,16 @@
 install'
- 
 %5D %7D,%0A  %7B
@@ -461,17 +461,16 @@
  args: %5B
- 
 'index.j
@@ -471,17 +471,16 @@
 ndex.js'
- 
 %5D %7D%0A%5D;%0A%0A
@@ -797,32 +797,35 @@
 ult = spawnSync(
+%60$%7B
 cmdArg.cmd + '.c
@@ -822,17 +822,14 @@
 .cmd
- + '
+%7D
 .cmd
-'
+%60
 , cm

fix eslint issues