Finish up metadata generation
This commit is contained in:
parent
fd00b10f2e
commit
1841e43686
4 changed files with 1185 additions and 58 deletions
1066
metadata/project.json
Normal file
1066
metadata/project.json
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -10,7 +10,8 @@
|
||||||
"dev": "parcel index.html",
|
"dev": "parcel index.html",
|
||||||
"build": "parcel build index.html",
|
"build": "parcel build index.html",
|
||||||
"deploy": "./deploy.sh",
|
"deploy": "./deploy.sh",
|
||||||
"dev:meta": "nodemon ./scripts/get-metadata.js "
|
"dev:meta": "nodemon --ignore '**/*.json' ./scripts/get-metadata.js",
|
||||||
|
"generate": "node ./scripts/get-metadata.js"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@octokit/core": "^3.5.1",
|
"@octokit/core": "^3.5.1",
|
||||||
|
|
@ -18,6 +19,7 @@
|
||||||
"@types/lodash": "^4.14.171",
|
"@types/lodash": "^4.14.171",
|
||||||
"@types/p5": "^1.3.0",
|
"@types/p5": "^1.3.0",
|
||||||
"get-folder-size": "^3.1.0",
|
"get-folder-size": "^3.1.0",
|
||||||
|
"glob": "^7.1.7",
|
||||||
"node-fetch": "^2.6.1",
|
"node-fetch": "^2.6.1",
|
||||||
"nodemon": "^2.0.12",
|
"nodemon": "^2.0.12",
|
||||||
"parcel-bundler": "^1.12.5",
|
"parcel-bundler": "^1.12.5",
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,18 @@
|
||||||
import { resolve } from 'path';
|
import { resolve } from 'path';
|
||||||
import { readdir } from 'fs/promises';
|
import { readdir, writeFile } from 'fs/promises';
|
||||||
import getItemSize from 'get-folder-size';
|
import getItemSize from 'get-folder-size';
|
||||||
import { getProjectContributors } from './helpers.js';
|
import {
|
||||||
|
getLegaciesForSubproject,
|
||||||
|
getLinksForSubproject,
|
||||||
|
getPackagesForSubproject,
|
||||||
|
getProjectContributors,
|
||||||
|
} from './helpers.js';
|
||||||
|
|
||||||
|
const __dirname = resolve();
|
||||||
|
export const PROJECT_PATH = resolve(__dirname, 'sourceproject/ethereumjs-monorepo');
|
||||||
|
export const SUBPACKAGE_PATH = resolve(PROJECT_PATH, 'packages');
|
||||||
|
|
||||||
const main = async () => {
|
const main = async () => {
|
||||||
/* CONSTANTS */
|
|
||||||
const __dirname = resolve();
|
|
||||||
const PROJECT_PATH = resolve(__dirname, 'sourceproject/ethereumjs-monorepo');
|
|
||||||
const SUBPACKAGE_PATH = resolve(PROJECT_PATH, 'packages');
|
|
||||||
|
|
||||||
const subprojectPaths = await readdir(SUBPACKAGE_PATH);
|
const subprojectPaths = await readdir(SUBPACKAGE_PATH);
|
||||||
const subprojectOverviewData = await Promise.all(
|
const subprojectOverviewData = await Promise.all(
|
||||||
subprojectPaths.map(async (subprojectPath) => {
|
subprojectPaths.map(async (subprojectPath) => {
|
||||||
|
|
@ -27,28 +31,38 @@ const main = async () => {
|
||||||
(subprojectData) => subprojectData.name !== 'vm' && subprojectData.name !== 'ethereum-tests'
|
(subprojectData) => subprojectData.name !== 'vm' && subprojectData.name !== 'ethereum-tests'
|
||||||
);
|
);
|
||||||
|
|
||||||
/*const subprojectsWithRevealables = await Promise.all(
|
|
||||||
subprojects.map(async (subproject) => {
|
|
||||||
const contributors = await getContributorsForSubproject(subproject);
|
|
||||||
const revealables = [...contributors];
|
|
||||||
const subprojectWithRevealables = {
|
|
||||||
...subproject,
|
|
||||||
revealables,
|
|
||||||
};
|
|
||||||
console.log(revealables);
|
|
||||||
|
|
||||||
return subprojectWithRevealables;
|
|
||||||
})
|
|
||||||
);*/
|
|
||||||
|
|
||||||
const projectContributors = await getProjectContributors();
|
const projectContributors = await getProjectContributors();
|
||||||
|
|
||||||
console.log('overall contribs', projectContributors);
|
console.log(projectContributors.length);
|
||||||
|
|
||||||
// console.log('Resulting metadata:');
|
const subprojectsWithRevealables = await Promise.all(
|
||||||
/* console.log({
|
subprojects.map(async (subproject, i) => {
|
||||||
|
const packages = await getPackagesForSubproject(subproject);
|
||||||
|
const links = await getLinksForSubproject(subproject);
|
||||||
|
const legacies = await getLegaciesForSubproject(subproject);
|
||||||
|
const contributors = [
|
||||||
|
projectContributors[0 + i],
|
||||||
|
projectContributors[10 + i],
|
||||||
|
projectContributors[20 + i],
|
||||||
|
];
|
||||||
|
|
||||||
|
return {
|
||||||
|
...subproject,
|
||||||
|
links,
|
||||||
|
revealables: [...packages, ...contributors, ...legacies],
|
||||||
|
};
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
const jsonToWrite = JSON.stringify(
|
||||||
|
{
|
||||||
subprojects: subprojectsWithRevealables,
|
subprojects: subprojectsWithRevealables,
|
||||||
});*/
|
},
|
||||||
|
null,
|
||||||
|
2
|
||||||
|
);
|
||||||
|
|
||||||
|
writeFile(resolve(__dirname, 'metadata/project.json'), jsonToWrite);
|
||||||
};
|
};
|
||||||
|
|
||||||
main();
|
main();
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,49 @@
|
||||||
import { resolve } from 'path';
|
import { resolve, basename } from 'path';
|
||||||
import { readFile } from 'fs/promises';
|
import { readFile } from 'fs/promises';
|
||||||
|
import { promisify } from 'util';
|
||||||
import { Octokit } from '@octokit/core';
|
import { Octokit } from '@octokit/core';
|
||||||
|
import child_process from 'child_process';
|
||||||
|
import nodeGlob from 'glob';
|
||||||
|
import { PROJECT_PATH, SUBPACKAGE_PATH } from './get-metadata.js';
|
||||||
|
|
||||||
|
const exec = promisify(child_process.exec);
|
||||||
|
const glob = promisify(nodeGlob);
|
||||||
|
|
||||||
const octokit = new Octokit({
|
const octokit = new Octokit({
|
||||||
auth: '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',
|
auth: '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',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export async function getLegaciesForSubproject(subproject) {
|
||||||
|
// Get all paths to project files
|
||||||
|
const files = await glob(resolve(SUBPACKAGE_PATH, subproject.name, '**/*.ts'));
|
||||||
|
const filteredFilePaths = files.filter(
|
||||||
|
(filePath) =>
|
||||||
|
!filePath.includes('spec.') && !filePath.includes('/test/') && !filePath.includes('@types')
|
||||||
|
);
|
||||||
|
|
||||||
|
// Get line counts for files
|
||||||
|
const filesWithWordCounts = await Promise.all(
|
||||||
|
filteredFilePaths.map(async (filteredFilePath) => {
|
||||||
|
const { stdout } = await exec(`wc -l < ${filteredFilePath}`);
|
||||||
|
|
||||||
|
return {
|
||||||
|
path: filteredFilePath,
|
||||||
|
count: Number(stdout.replace('\n', '')),
|
||||||
|
};
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
const largestFiles = filesWithWordCounts
|
||||||
|
.sort((fwcA, fwcB) => fwcB.count - fwcA.count)
|
||||||
|
.slice(0, 2);
|
||||||
|
|
||||||
|
// Transform to legacy object
|
||||||
|
const legacies = largestFiles.map((largeFile) => createLegacy(largeFile));
|
||||||
|
|
||||||
|
// Return 2 highest line counts
|
||||||
|
return legacies;
|
||||||
|
}
|
||||||
|
|
||||||
export async function getProjectContributors() {
|
export async function getProjectContributors() {
|
||||||
const contribs = await octokit.request('/repos/ethereumjs/ethereumjs-monorepo/contributors');
|
const contribs = await octokit.request('/repos/ethereumjs/ethereumjs-monorepo/contributors');
|
||||||
const contributors = await Promise.all(
|
const contributors = await Promise.all(
|
||||||
|
|
@ -15,27 +53,37 @@ export async function getProjectContributors() {
|
||||||
return contributors;
|
return contributors;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*export async function getContributorsForSubproject(subproject) {
|
export async function getLinksForSubproject(subproject) {
|
||||||
const subprojectPackageJson = await readFile(
|
const subprojectPackageJson = await readFile(
|
||||||
resolve(subproject.filePath, 'package.json'),
|
resolve(subproject.filePath, 'package.json'),
|
||||||
'utf8'
|
'utf8'
|
||||||
);
|
);
|
||||||
const parsedPackageJson = JSON.parse(subprojectPackageJson);
|
const { dependencies } = JSON.parse(subprojectPackageJson);
|
||||||
|
const links = Object.keys(dependencies).filter((dependency) =>
|
||||||
try {
|
dependency.includes('@ethereumjs')
|
||||||
if (parsedPackageJson.contributors && parsedPackageJson.contributors.length > 0) {
|
|
||||||
const contributors = await Promise.all(
|
|
||||||
parsedPackageJson.contributors.map(async (cntrb) => await createContributor(cntrb))
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return contributors.filter((contributor) => !!contributor);
|
return links;
|
||||||
} else {
|
}
|
||||||
return [];
|
|
||||||
}
|
export async function getPackagesForSubproject(subproject) {
|
||||||
} catch (e) {
|
const subprojectPackageJson = await readFile(
|
||||||
return [];
|
resolve(subproject.filePath, 'package.json'),
|
||||||
}
|
'utf8'
|
||||||
}*/
|
);
|
||||||
|
const { dependencies } = JSON.parse(subprojectPackageJson);
|
||||||
|
const relevantDependencies = Object.keys(dependencies)
|
||||||
|
.filter((dependency) => !dependency.includes('ethereumjs') && !dependency.includes('@types'))
|
||||||
|
.slice(0, 3)
|
||||||
|
.map((dependencyKey) => ({
|
||||||
|
name: dependencyKey,
|
||||||
|
version: dependencies[dependencyKey],
|
||||||
|
}));
|
||||||
|
|
||||||
|
const formattedDependencies = relevantDependencies.map((dep) => createPackage(dep));
|
||||||
|
|
||||||
|
return formattedDependencies;
|
||||||
|
}
|
||||||
|
|
||||||
const createContributor = async (contrib) => {
|
const createContributor = async (contrib) => {
|
||||||
if (!contrib) return;
|
if (!contrib) return;
|
||||||
|
|
@ -65,33 +113,30 @@ const createContributor = async (contrib) => {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const createPackage = (pkg) => {
|
const createPackage = ({ name, version }) => {
|
||||||
const path = 'path.to.package.json';
|
const path = 'path.to.package.json';
|
||||||
const size = 0;
|
const size = 0;
|
||||||
const contents = '';
|
|
||||||
const url = '';
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type: 'PACKAGE',
|
type: 'PACKAGE',
|
||||||
name: pkg,
|
name,
|
||||||
path,
|
path,
|
||||||
|
version,
|
||||||
size,
|
size,
|
||||||
contents,
|
contents: '',
|
||||||
url,
|
url: `https://www.npmjs.com/package/${name}`,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const createLegacy = (lgcy) => {
|
const createLegacy = ({ path, count }) => {
|
||||||
const size = 0;
|
const projectPath = path.replace(PROJECT_PATH, '');
|
||||||
const contents = '';
|
|
||||||
const url = '';
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type: 'LEGACY',
|
type: 'LEGACY',
|
||||||
name: 'filename',
|
name: basename(projectPath),
|
||||||
path: 'filePath',
|
path: projectPath,
|
||||||
size,
|
size: count,
|
||||||
contents,
|
contents: '',
|
||||||
url,
|
url: `https://github.com/ethereumjs/ethereumjs-monorepo/blob/master${projectPath}`,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Reference in a new issue