Skip to content

Instantly share code, notes, and snippets.

@mihkeleidast
Last active July 18, 2022 10:25
Show Gist options
  • Save mihkeleidast/bfc00676ace81de370d4c120cabb48af to your computer and use it in GitHub Desktop.
Save mihkeleidast/bfc00676ace81de370d4c120cabb48af to your computer and use it in GitHub Desktop.
common-ui analytics
const { execSync } = require('child_process');
const scanComponents = require('./scan-components');
const scanMetadata = require('./scan-metadata');
const currentDirectory = __dirname;
const repositories = [
{
name: 'customer-web',
rootPath: '/packages/customer-web/'
},
{
name: 'login-web',
rootPath: '/'
},
];
const currentTime = new Date();
for (const project of repositories) {
const { name, rootPath } = project;
process.chdir(`./${name}`);
const sha = execSync('git rev-parse HEAD').toString().replace('\n', '');
const time = currentTime.valueOf();
scanMetadata({ sha, time, project, rootPath });
scanComponents({ time, project, rootPath })
process.chdir(currentDirectory);
}
const path = require('path');
module.exports = {
crawlFrom: path.join(__dirname, `./${process.env.scanProjectPath}src`),
includeSubComponents: true,
importedFrom: '@sixfold/common-ui',
processors: [['raw-report', { outputTo: `./historic_data/${process.env.scanProject}/${process.env.scanTime}/report.json` }]],
};
const { execSync } = require('child_process');
module.exports = ({ time, project, rootPath }) => {
process.env.scanTime = time;
process.env.scanProject = project;
process.env.scanProjectPath = project + rootPath;
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, rootPath }) => {
const { dependencies, name } = importFresh(`./${project}${rootPath}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