Skip to content

Commit

Permalink
feat: simplify the contributor table generation script and reduce the…
Browse files Browse the repository at this point in the history
… number of dependencies
  • Loading branch information
okineadev committed Jan 13, 2025
1 parent 3437669 commit 8bd3c16
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 173 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ icons/clones

# Ignore specific HTML files in scripts directories
src/scripts/preview/*.html
src/scripts/contributors/*.html

# Ignore cache directory
.cache
Expand Down
17 changes: 0 additions & 17 deletions bun.lock
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"@types/chroma-js": "^2.4.4",
"@types/puppeteer": "^7.0.0",
"@types/vscode": "~1.55.0",
"axios": "^1.7.2",
"bun-types": "^1.1.20",
"changelogen": "^0.5.7",
"commitlint": "^19.5.0",
Expand Down Expand Up @@ -189,10 +188,6 @@

"ast-types": ["[email protected]", "", { "dependencies": { "tslib": "^2.0.1" } }, "sha512-x1FCFnFifvYDDzTaLII71vG5uvDwgtmDTEVWAxrgeiR8VjMONcCXJx7E+USjDtHlwFmt9MysbqgF9b9Vjr6w+w=="],

"asynckit": ["[email protected]", "", {}, "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="],

"axios": ["[email protected]", "", { "dependencies": { "follow-redirects": "^1.15.6", "form-data": "^4.0.0", "proxy-from-env": "^1.1.0" } }, "sha512-2A8QhOMrbomlDuiLeK9XibIBzuHeRcqqNOHp0Cyp5EoJ1IFDh+XZH3A6BkXtv0K4gFGCI0Y4BM7B1wOEi0Rmgw=="],

"b4a": ["[email protected]", "", {}, "sha512-5Tk1HLk6b6ctmjIkAcU/Ujv/1WqiDl0F0JdRCR80VsOcUlHcu7pWeWRlOqQLHfDEsVx9YH/aif5AG4ehoCtTmg=="],

"balanced-match": ["[email protected]", "", {}, "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw=="],
Expand Down Expand Up @@ -257,8 +252,6 @@

"colorette": ["[email protected]", "", {}, "sha512-IfEDxwoWIjkeXL1eXcDiow4UbKjhLdq6/EuSVR9GMN7KVH3r9gQ83e73hsz1Nd1T3ijd5xv1wcWRYO+D6kCI2w=="],

"combined-stream": ["[email protected]", "", { "dependencies": { "delayed-stream": "~1.0.0" } }, "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg=="],

"commander": ["[email protected]", "", {}, "sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA=="],

"commitlint": ["[email protected]", "", { "dependencies": { "@commitlint/cli": "^19.5.0", "@commitlint/types": "^19.5.0" }, "bin": { "commitlint": "cli.js" } }, "sha512-lCtwxgFulvMnCgBc8MVPlVMf+PNOqQSBhHpEnjV2JjEQEAhxjVDtC7IeuEtR+hHpGvHt6CwlLtm3uZNyEby5dQ=="],
Expand Down Expand Up @@ -311,8 +304,6 @@

"degenerator": ["[email protected]", "", { "dependencies": { "ast-types": "^0.13.4", "escodegen": "^2.1.0", "esprima": "^4.0.1" } }, "sha512-TllpMR/t0M5sqCXfj85i4XaAzxmS5tVA16dqvdkMwGmzI+dXLXnw3J+3Vdv7VKw+ThlTMboK6i9rnZ6Nntj5CQ=="],

"delayed-stream": ["[email protected]", "", {}, "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ=="],

"destr": ["[email protected]", "", {}, "sha512-2N3BOUU4gYMpTP24s5rF5iP7BDr7uNTCs4ozw3kf/eKfvWSIu93GEBi5m427YoyJoeOzQ5smuu4nNAPGb8idSQ=="],

"devtools-protocol": ["[email protected]", "", {}, "sha512-BlmkSqV0V84E2WnEnoPnwyix57rQxAM5SKJjf4TbYOCGLAWtz8CDH8RIaGOjPgPCXo2Mce3kxSY497OySidY3Q=="],
Expand Down Expand Up @@ -379,12 +370,8 @@

"find-up": ["[email protected]", "", { "dependencies": { "locate-path": "^7.2.0", "path-exists": "^5.0.0", "unicorn-magic": "^0.1.0" } }, "sha512-YyZM99iHrqLKjmt4LJDj58KI+fYyufRLBSYcqycxf//KpBk9FoewoGX0450m9nB44qrZnovzC2oeP5hUibxc/g=="],

"follow-redirects": ["[email protected]", "", {}, "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA=="],

"foreground-child": ["[email protected]", "", { "dependencies": { "cross-spawn": "^7.0.0", "signal-exit": "^4.0.1" } }, "sha512-PXUUyLqrR2XCWICfv6ukppP96sdFwWbNEnfEMt7jNsISjMsvaLNinAHNDYyvkyU+SZG2BTSbT5NjG+vZslfGTA=="],

"form-data": ["[email protected]", "", { "dependencies": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", "mime-types": "^2.1.12" } }, "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww=="],

"fs-extra": ["[email protected]", "", { "dependencies": { "graceful-fs": "^4.2.0", "jsonfile": "^6.0.1", "universalify": "^2.0.0" } }, "sha512-PmDi3uwK5nFuXh7XDTlVnS17xJS7vW36is2+w3xcv8SVxiB4NyATf4ctkVY5bkSjX0Y4nbvZCq1/EjtEyr9ktw=="],

"fs-minipass": ["[email protected]", "", { "dependencies": { "minipass": "^3.0.0" } }, "sha512-V/JgOLFCS+R6Vcq0slCuaeWEdNC3ouDlJMNIsacH2VtALiu9mV4LPrHc5cDl8k5aw6J8jwgWWpiTo5RYhmIzvg=="],
Expand Down Expand Up @@ -539,10 +526,6 @@

"micromatch": ["[email protected]", "", { "dependencies": { "braces": "^3.0.3", "picomatch": "^2.3.1" } }, "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA=="],

"mime-db": ["[email protected]", "", {}, "sha512-QBmA/G2y+IfeS4oktet3qRZ+P5kPhCKRXxXnQEudYqUaEioAU1/Lq2us3D/t1Jfo4hE9REQPrbB7K5sOczJVIw=="],

"mime-types": ["[email protected]", "", { "dependencies": { "mime-db": "1.47.0" } }, "sha512-crmjA4bLtR8m9qLpHvgxSChT+XoSlZi8J4n/aIdn3z92e/U47Z0V/yl+Wh9W046GgFVAmoNR/fmdbZYcSSIUeg=="],

"mimic-fn": ["[email protected]", "", {}, "sha512-vqiC06CuhBTUdZH+RYl8sFrL096vA45Ok5ISO6sE/Mr1jRbGH4Csnhi8f3wKVl7x8mO4Au7Ir9D3Oyv1VYMFJw=="],

"mimic-function": ["[email protected]", "", {}, "sha512-VP79XUPxV2CigYP3jWwAUFSku2aKqBH7uTAapFWCBqutsbmDo96KY5o8uh6U+/YSIn5OxJnXp73beVkpqMIGhA=="],
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,6 @@
"@types/chroma-js": "^2.4.4",
"@types/puppeteer": "^7.0.0",
"@types/vscode": "~1.55.0",
"axios": "^1.7.2",
"bun-types": "^1.1.20",
"changelogen": "^0.5.7",
"commitlint": "^19.5.0",
Expand Down
24 changes: 0 additions & 24 deletions src/scripts/contributors/contributors.css

This file was deleted.

137 changes: 22 additions & 115 deletions src/scripts/contributors/contributors.ts
Original file line number Diff line number Diff line change
@@ -1,121 +1,28 @@
import { join } from 'node:path';
import axios, { type AxiosRequestConfig } from 'axios';
import { writeToFile } from '../../core';
import { green, red, yellow } from '../helpers/painter';
import { createScreenshot } from '../helpers/screenshots';
import type { Contributor } from '../models/scripts/contributors/contributor';

/**
* Parse link header
* @param linkHeader Link header as string
* @returns Object that contains the page numbers of `prev`, `next` and `last`.
*/
const parseLinkHeader = (linkHeader: string) => {
const nextPagePattern = new RegExp(/\bpage=(\d+)>;\srel="next"/);
const lastPagePattern = new RegExp(/\bpage=(\d+)>;\srel="last"/);
const prevPagePattern = new RegExp(/\bpage=(\d+)>;\srel="prev"/);

const nextPage = nextPagePattern.exec(linkHeader) ?? '';
const lastPage = lastPagePattern.exec(linkHeader) ?? '';
const prevPage = prevPagePattern.exec(linkHeader) ?? '';

return { nextPage, lastPage, prevPage };
};

/**
* Get all contributors from GitHub API.
*/
const fetchContributors = (
page: string
): Promise<{ contributorsOfPage: Contributor[]; nextPage: string }> => {
return new Promise((resolve, reject) => {
const config: AxiosRequestConfig = {
method: 'get',
url: `https://api.github.com/repos/pkief/vscode-material-icon-theme/contributors`,
params: { page },
headers: {
accept: 'application/json',
'User-Agent': 'Contributors script',
},
};

axios
.request(config)
.then((res) => {
const { nextPage, lastPage, prevPage } = parseLinkHeader(
res.headers?.link?.toString() ?? ''
);
console.log(
'> Material Icon Theme:',
yellow(
`[${page}/${
lastPage ? lastPage[1] : +prevPage[1] + 1
}] Loading contributors from GitHub...`
)
);

resolve({ contributorsOfPage: res.data, nextPage: nextPage?.[1] });
})
.catch((err) => {
reject(err);
});
const imageUrl = 'https://contributors-table.vercel.app/image';
const outputPath = './images/contributors.png';

async function fetchImage() {
const params = new URLSearchParams({
repo: 'material-extensions/vscode-material-icon-theme',
max: '294',
type: 'png',
}).toString();

const response = await fetch(`${imageUrl}?${params}`, {
method: 'GET',
headers: {
'User-Agent': 'Material Icon Theme contributors script',
},
});
};

const createContributorsList = async (contributors: Contributor[]) => {
const list = contributors
.map((c) => {
return `<li title="${c.login}"><img src="${c.avatar_url}" alt="${c.login}"/></li>`;
})
.join('\n');

const htmlDoctype = '<!DOCTYPE html>';
const styling = '<link rel="stylesheet" href="contributors.css">';
const generatedHtml = `${htmlDoctype}${styling}<ul>${list}</ul>`;

const outputPath = join(__dirname, 'contributors.html');
await writeToFile(outputPath, generatedHtml);
return outputPath;
};

const init = async () => {
const contributorsList: Contributor[] = [];
let page = '1';

// iterate over the pages of GitHub API
while (page !== undefined) {
const result = await fetchContributors(page);
contributorsList.push(...result.contributorsOfPage);
page = result.nextPage;
if (response.status !== 200) {
throw new Error(`Failed to fetch image: ${response.statusText}`);
}

if (contributorsList.length > 0) {
console.log(
'> Material Icon Theme:',
green('Successfully fetched all contributors from GitHub!')
);
} else {
console.log(
'> Material Icon Theme:',
red('Error: Could not fetch contributors from GitHub!')
);
throw Error();
}
const outputPath = await createContributorsList(contributorsList);
const image = response;

// create the image
console.log('> Material Icon Theme:', yellow('Creating image...'));
const fileName = 'contributors';
createScreenshot(outputPath, fileName)
.then(() => {
console.log(
'> Material Icon Theme:',
green(`Successfully created ${fileName} image!`)
);
})
.catch(() => {
throw Error(red(`Error while creating ${fileName} image`));
});
};
Bun.write(outputPath, image);
console.log(`Image saved to ${outputPath}`);
}

init();
fetchImage().catch((error) => console.error(error));
5 changes: 0 additions & 5 deletions src/scripts/models/scripts/contributors/contributor.ts

This file was deleted.

10 changes: 0 additions & 10 deletions src/scripts/models/scripts/contributors/contributorsConfig.ts

This file was deleted.

0 comments on commit 8bd3c16

Please sign in to comment.