1. const fs = require('fs');
    
  2. const path = require('path');
    
  3. const child_process = require('child_process');
    
  4. 
    
  5. const fixtureDirs = fs.readdirSync(__dirname).filter(file => {
    
  6.   return fs.statSync(path.join(__dirname, file)).isDirectory();
    
  7. });
    
  8. 
    
  9. const cmdArgs = [
    
  10.   {cmd: 'yarn', args: ['install']},
    
  11.   {cmd: 'yarn', args: ['build']},
    
  12. ];
    
  13. 
    
  14. function buildFixture(cmdArg, path) {
    
  15.   const opts = {
    
  16.     cwd: path,
    
  17.     stdio: 'inherit',
    
  18.   };
    
  19.   const result = child_process.spawnSync(cmdArg.cmd, cmdArg.args, opts);
    
  20.   if (result.status !== 0) {
    
  21.     throw new Error(`Failed to build fixtures!`);
    
  22.   }
    
  23. }
    
  24. 
    
  25. fixtureDirs.forEach(dir => {
    
  26.   cmdArgs.forEach(cmdArg => {
    
  27.     // we only care about directories that have DEV and PROD directories in
    
  28.     // otherwise they don't need to be built
    
  29.     const devPath = path.join(__dirname, dir, 'dev');
    
  30. 
    
  31.     if (fs.existsSync(devPath)) {
    
  32.       buildFixture(cmdArg, devPath);
    
  33.     }
    
  34.     const prodPath = path.join(__dirname, dir, 'prod');
    
  35. 
    
  36.     if (fs.existsSync(prodPath)) {
    
  37.       buildFixture(cmdArg, prodPath);
    
  38.     }
    
  39.   });
    
  40. });
    
  41. 
    
  42. console.log('-------------------------');
    
  43. console.log('All fixtures were built!');
    
  44. console.log('Now ensure all frames display a welcome message:');
    
  45. console.log('  npm install -g serve');
    
  46. console.log('  serve ../..');
    
  47. console.log('  open http://localhost:5000/fixtures/packaging/');
    
  48. console.log('-------------------------');