'use strict';

const fs = require('fs');
const path = require('path');
const { spawnSync } = require('child_process');
const glob = require('glob-gitignore');

const packagesDir = path.join(__dirname, 'packages');

const packages = (process.argv.length > 2 ? [process.argv[2]] : glob.sync('*', { cwd: packagesDir }))
  .map(name => JSON.parse(fs.readFileSync(path.join(packagesDir, name, 'package.json'))))
  .filter(x => !x.private && x.name !== 'enzyme-example-mocha');

packages.forEach((pkg) => {
  const tag = `${pkg.name}@${pkg.version}`;
  const log = spawnSync('git', ['log', '--oneline', `${tag}..HEAD`, path.join(packagesDir, pkg.name)], { stdio: 'pipe' });
  if (log.stdout.length > 0 || log.stderr.length > 0) {
    console.log(tag);
    spawnSync('git', ['log', '--oneline', `${tag}..HEAD`, path.join(packagesDir, pkg.name)], { stdio: 'inherit' });
    console.log('\n');
  }
});

@@ -206,16 +206,62 @@
 kages');
+%0Aconst docsDir = path.join(__dirname, 'docs');
 %0A%0Aconst 
@@ -565,16 +565,49 @@
 pkg.name
+ === 'docs' ? 'enzyme' : pkg.name
 %7D@$%7Bpkg.
@@ -629,101 +629,192 @@
 nst 
-log
+dir
  = 
-s
 pa
-wnSync('git', %5B'log', '--oneline', %60$%7Btag%7D..HEAD%60, path.join(packagesDir, pkg.name)%5D
+th.join(packagesDir, pkg.name);%0A  const logArgs = %5B'log', '--oneline', %60$%7Btag%7D..HEAD%60, dir%5D.concat(pkg.name === 'enzyme' ? docsDir : %5B%5D);%0A  const log = spawnSync('git', logArgs
 , %7B 
@@ -934,78 +934,15 @@
 t', 
-%5B'
 log
-', '--oneline', %60$%7Btag%7D..HEAD%60, path.join(packagesDir, pkg.name)%5D
+Args
 , %7B 

improve `npm run since` to include docs