Skip to content

Instantly share code, notes, and snippets.

@mihkeleidast
Created April 5, 2022 06:43
Show Gist options
  • Save mihkeleidast/9859771782adf1cb00767f640184f998 to your computer and use it in GitHub Desktop.
Save mihkeleidast/9859771782adf1cb00767f640184f998 to your computer and use it in GitHub Desktop.
const { execSync } = require('child_process');
const scanComponents = require('./scan-components');
const scanMetadata = require('./scan-metadata');
const currentDirectory = __dirname;
const PROJECT_TO_SCAN = 'customer-web';
process.chdir(`./${PROJECT_TO_SCAN}`);
const earliestTime = new Date('2021-01-01');
const startTime = new Date('2022-04-04 12:00');
const getCommand = (time) => `git checkout \`git rev-list -n 1 --first-parent --before="${time}" master\``;
let currentTime = startTime;
while (currentTime > earliestTime) {
const prevMonday = getPreviousMonday(currentTime);
const command = getCommand(prevMonday);
execSync(command);
const sha = execSync('git rev-parse HEAD').toString().replace('\n', '');
const time = prevMonday.valueOf();
// need to run the scan commands
scanMetadata({ sha, time, project: PROJECT_TO_SCAN });
scanComponents({ time, project: PROJECT_TO_SCAN })
currentTime = prevMonday;
}
process.chdir(currentDirectory);
function getPreviousMonday(date) {
const prevMonday = new Date(date);
return new Date(prevMonday.setDate(prevMonday.getDate() - 7));
}
const path = require('path');
module.exports = {
crawlFrom: path.join(__dirname, './customer-web/src'),
includeSubComponents: true,
importedFrom: '@sixfold/common-ui',
processors: [['raw-report', { outputTo: `./historic_data/${process.env.scanProject}/${process.env.scanTime}/report.json` }]],
};
const { dependencies, name } = require('../customer-web/package.json');
const { execSync } = require('child_process');
const path = require('path');
module.exports = ({ time, project }) => {
process.env.scanTime = time;
process.env.scanProject = project;
execSync('npx react-scanner -c ../react-scanner.config.js', {stdio: 'inherit'});
}
const { writeFileSync, mkdirSync } = require('fs');
const path = require('path');
const importFresh = require('import-fresh');
const scan = ({ sha, time, project }) => {
const { dependencies, name } = importFresh(`./${project}/package.json`);
const result = {
dirName: process.cwd(),
repository: name,
version: dependencies['@sixfold/common-ui'],
commitSha: sha,
commitTime: time,
};
mkdirSync(path.join(__dirname, `historic_data/${project}/${time}/`), { recursive: true }, (err) => {
if (err) throw err;
});
writeFileSync(path.join(__dirname, `historic_data/${project}/${time}/metadata.json`), JSON.stringify(result, null, 2));
}
module.exports = scan;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment