Created
April 5, 2022 06:43
-
-
Save mihkeleidast/9859771782adf1cb00767f640184f998 to your computer and use it in GitHub Desktop.
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 { 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)); | |
} |
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 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` }]], | |
}; |
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 { 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'}); | |
} |
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 { 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