Created
December 6, 2019 15:58
-
-
Save MrJadaml/7ab0da2df9b61f0791f1f76a7b588c60 to your computer and use it in GitHub Desktop.
A script to capture historical commit sizes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const gitlog = require('gitlog'); | |
const util = require('util'); | |
const path = require('path') | |
const fs = require('fs') | |
const exec = util.promisify(require('child_process').exec); | |
const execSync = require('child_process').execSync; | |
async function asyncForEach(array, callback, done) { | |
for (let index = 0; index < array.length; index++) { | |
await callback(array[index], index, array); | |
if(index === array.length - 1) { | |
if(done) done() | |
} | |
} | |
} | |
console.log(path.join(__dirname, '../ecom-web-app')) | |
const options = { | |
repo: path.join(__dirname, '../ecom-web-app'), | |
number: 2, | |
fields: | |
['hash', | |
'abbrevHash', | |
'subject', | |
'authorName', | |
'authorDateRel', | |
], | |
execOptions: | |
{ | |
maxBuffer: 1000 * 1024, | |
}, | |
}; | |
// Asynchronous (with Callback) | |
// gitlog(options, (error, commits) => { | |
// // Commits is an array of commits in the repo | |
// console.log(commits); | |
// }); | |
// Synchronous | |
let commits = gitlog(options); | |
const waitFor = (ms) => new Promise(r => setTimeout(r, ms)); | |
const store = [] | |
asyncForEach(commits, async (commit) => { | |
await exec( | |
`git reset --hard; git checkout ${commit.hash}`, | |
{ | |
stdio: 'inherit', | |
cwd: path.join(__dirname , '../ecom-web-app') | |
}, | |
); | |
execSync( | |
`source ~/.bashrc; nvm use v8.10 && yarn`, | |
{ | |
stdio: 'inherit', | |
cwd: path.join(__dirname , '../ecom-web-app') | |
}, | |
); | |
execSync( | |
`source ~/.bashrc; nvm use v8.10 && NODE_ENV=production ./node_modules/.bin/webpack -p --config webpack/client.prod.config.js --profile --json > stats.json`, | |
{ | |
stdio: 'inherit', | |
cwd: path.join(__dirname , '../ecom-web-app') | |
}, | |
); | |
const {stdout} = await exec( | |
`npx webpack-bundle-size-analyzer --json stats.json`, | |
{ | |
cwd: path.join(__dirname, '../ecom-web-app') | |
}, | |
); | |
const objToPass = Object.assign({}, JSON.parse(stdout)[0], commit) | |
store.push(objToPass) | |
}, ()=>{ | |
fs.writeFileSync('store.json', JSON.stringify(store)) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment