// Post-process Scully output to insert top-level third party script tags. const globby = require('globby'); const fs = require('fs'); const path = require('path'); const myArgs = process.argv.slice(2); if (myArgs.length !== 2) { console.error('Usage: '); console.error( 'Fragment will be inserted at the start of the in each index.html' ); process.exit(1); } const [distDir, fragmentFile] = myArgs; const htmls = globby.sync(path.join(distDir, '**/index.html')); const utf8 = { encoding: 'UTF-8' }; const fragment = fs.readFileSync(fragmentFile, utf8); htmls.forEach(fn => { const contents = fs.readFileSync(fn, utf8); const fixed = contents.replace(//, match => match + fragment); fs.writeFileSync(fn, fixed, utf8); });