From 8bd3c162e1d1580860aff2b45cb0d84f0a1406de Mon Sep 17 00:00:00 2001 From: Okinea Dev Date: Mon, 13 Jan 2025 15:27:25 +0200 Subject: [PATCH] feat: simplify the contributor table generation script and reduce the number of dependencies --- .gitignore | 1 - bun.lock | 17 --- package.json | 1 - src/scripts/contributors/contributors.css | 24 --- src/scripts/contributors/contributors.ts | 137 +++--------------- .../scripts/contributors/contributor.ts | 5 - .../contributors/contributorsConfig.ts | 10 -- 7 files changed, 22 insertions(+), 173 deletions(-) mode change 100755 => 100644 bun.lock delete mode 100644 src/scripts/contributors/contributors.css delete mode 100644 src/scripts/models/scripts/contributors/contributor.ts delete mode 100644 src/scripts/models/scripts/contributors/contributorsConfig.ts diff --git a/.gitignore b/.gitignore index b9d46366d5..44e125123f 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/bun.lock b/bun.lock old mode 100755 new mode 100644 index a61297df4c..36871830a4 --- a/bun.lock +++ b/bun.lock @@ -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", @@ -189,10 +188,6 @@ "ast-types": ["ast-types@0.13.4", "", { "dependencies": { "tslib": "^2.0.1" } }, "sha512-x1FCFnFifvYDDzTaLII71vG5uvDwgtmDTEVWAxrgeiR8VjMONcCXJx7E+USjDtHlwFmt9MysbqgF9b9Vjr6w+w=="], - "asynckit": ["asynckit@0.4.0", "", {}, "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="], - - "axios": ["axios@1.7.2", "", { "dependencies": { "follow-redirects": "^1.15.6", "form-data": "^4.0.0", "proxy-from-env": "^1.1.0" } }, "sha512-2A8QhOMrbomlDuiLeK9XibIBzuHeRcqqNOHp0Cyp5EoJ1IFDh+XZH3A6BkXtv0K4gFGCI0Y4BM7B1wOEi0Rmgw=="], - "b4a": ["b4a@1.6.6", "", {}, "sha512-5Tk1HLk6b6ctmjIkAcU/Ujv/1WqiDl0F0JdRCR80VsOcUlHcu7pWeWRlOqQLHfDEsVx9YH/aif5AG4ehoCtTmg=="], "balanced-match": ["balanced-match@1.0.2", "", {}, "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw=="], @@ -257,8 +252,6 @@ "colorette": ["colorette@2.0.20", "", {}, "sha512-IfEDxwoWIjkeXL1eXcDiow4UbKjhLdq6/EuSVR9GMN7KVH3r9gQ83e73hsz1Nd1T3ijd5xv1wcWRYO+D6kCI2w=="], - "combined-stream": ["combined-stream@1.0.8", "", { "dependencies": { "delayed-stream": "~1.0.0" } }, "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg=="], - "commander": ["commander@12.1.0", "", {}, "sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA=="], "commitlint": ["commitlint@19.5.0", "", { "dependencies": { "@commitlint/cli": "^19.5.0", "@commitlint/types": "^19.5.0" }, "bin": { "commitlint": "cli.js" } }, "sha512-lCtwxgFulvMnCgBc8MVPlVMf+PNOqQSBhHpEnjV2JjEQEAhxjVDtC7IeuEtR+hHpGvHt6CwlLtm3uZNyEby5dQ=="], @@ -311,8 +304,6 @@ "degenerator": ["degenerator@5.0.1", "", { "dependencies": { "ast-types": "^0.13.4", "escodegen": "^2.1.0", "esprima": "^4.0.1" } }, "sha512-TllpMR/t0M5sqCXfj85i4XaAzxmS5tVA16dqvdkMwGmzI+dXLXnw3J+3Vdv7VKw+ThlTMboK6i9rnZ6Nntj5CQ=="], - "delayed-stream": ["delayed-stream@1.0.0", "", {}, "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ=="], - "destr": ["destr@2.0.3", "", {}, "sha512-2N3BOUU4gYMpTP24s5rF5iP7BDr7uNTCs4ozw3kf/eKfvWSIu93GEBi5m427YoyJoeOzQ5smuu4nNAPGb8idSQ=="], "devtools-protocol": ["devtools-protocol@0.0.1354347", "", {}, "sha512-BlmkSqV0V84E2WnEnoPnwyix57rQxAM5SKJjf4TbYOCGLAWtz8CDH8RIaGOjPgPCXo2Mce3kxSY497OySidY3Q=="], @@ -379,12 +370,8 @@ "find-up": ["find-up@7.0.0", "", { "dependencies": { "locate-path": "^7.2.0", "path-exists": "^5.0.0", "unicorn-magic": "^0.1.0" } }, "sha512-YyZM99iHrqLKjmt4LJDj58KI+fYyufRLBSYcqycxf//KpBk9FoewoGX0450m9nB44qrZnovzC2oeP5hUibxc/g=="], - "follow-redirects": ["follow-redirects@1.15.6", "", {}, "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA=="], - "foreground-child": ["foreground-child@3.2.1", "", { "dependencies": { "cross-spawn": "^7.0.0", "signal-exit": "^4.0.1" } }, "sha512-PXUUyLqrR2XCWICfv6ukppP96sdFwWbNEnfEMt7jNsISjMsvaLNinAHNDYyvkyU+SZG2BTSbT5NjG+vZslfGTA=="], - "form-data": ["form-data@4.0.0", "", { "dependencies": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", "mime-types": "^2.1.12" } }, "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww=="], - "fs-extra": ["fs-extra@11.2.0", "", { "dependencies": { "graceful-fs": "^4.2.0", "jsonfile": "^6.0.1", "universalify": "^2.0.0" } }, "sha512-PmDi3uwK5nFuXh7XDTlVnS17xJS7vW36is2+w3xcv8SVxiB4NyATf4ctkVY5bkSjX0Y4nbvZCq1/EjtEyr9ktw=="], "fs-minipass": ["fs-minipass@2.1.0", "", { "dependencies": { "minipass": "^3.0.0" } }, "sha512-V/JgOLFCS+R6Vcq0slCuaeWEdNC3ouDlJMNIsacH2VtALiu9mV4LPrHc5cDl8k5aw6J8jwgWWpiTo5RYhmIzvg=="], @@ -539,10 +526,6 @@ "micromatch": ["micromatch@4.0.8", "", { "dependencies": { "braces": "^3.0.3", "picomatch": "^2.3.1" } }, "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA=="], - "mime-db": ["mime-db@1.47.0", "", {}, "sha512-QBmA/G2y+IfeS4oktet3qRZ+P5kPhCKRXxXnQEudYqUaEioAU1/Lq2us3D/t1Jfo4hE9REQPrbB7K5sOczJVIw=="], - - "mime-types": ["mime-types@2.1.30", "", { "dependencies": { "mime-db": "1.47.0" } }, "sha512-crmjA4bLtR8m9qLpHvgxSChT+XoSlZi8J4n/aIdn3z92e/U47Z0V/yl+Wh9W046GgFVAmoNR/fmdbZYcSSIUeg=="], - "mimic-fn": ["mimic-fn@4.0.0", "", {}, "sha512-vqiC06CuhBTUdZH+RYl8sFrL096vA45Ok5ISO6sE/Mr1jRbGH4Csnhi8f3wKVl7x8mO4Au7Ir9D3Oyv1VYMFJw=="], "mimic-function": ["mimic-function@5.0.1", "", {}, "sha512-VP79XUPxV2CigYP3jWwAUFSku2aKqBH7uTAapFWCBqutsbmDo96KY5o8uh6U+/YSIn5OxJnXp73beVkpqMIGhA=="], diff --git a/package.json b/package.json index 076c06e028..0d7c4beb33 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/scripts/contributors/contributors.css b/src/scripts/contributors/contributors.css deleted file mode 100644 index 6fb06b9e87..0000000000 --- a/src/scripts/contributors/contributors.css +++ /dev/null @@ -1,24 +0,0 @@ -body { - margin: 0; - padding: 0; -} - -ul { - list-style: none; - margin: 0; - padding: 0; - width: 100%; -} - -li { - width: 40px; - height: 40px; - float: left; - margin: 3px; -} - -img { - width: 100%; - height: 100%; - border-radius: 5px; -} diff --git a/src/scripts/contributors/contributors.ts b/src/scripts/contributors/contributors.ts index 1728f10a8f..3bd7e640b0 100644 --- a/src/scripts/contributors/contributors.ts +++ b/src/scripts/contributors/contributors.ts @@ -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 `
  • ${c.login}
  • `; - }) - .join('\n'); - - const htmlDoctype = ''; - const styling = ''; - const generatedHtml = `${htmlDoctype}${styling}`; - - 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)); diff --git a/src/scripts/models/scripts/contributors/contributor.ts b/src/scripts/models/scripts/contributors/contributor.ts deleted file mode 100644 index 30e7b87bb2..0000000000 --- a/src/scripts/models/scripts/contributors/contributor.ts +++ /dev/null @@ -1,5 +0,0 @@ -export type Contributor = { - login: string; - // biome-ignore lint/style/useNamingConvention: - avatar_url: string; -}; diff --git a/src/scripts/models/scripts/contributors/contributorsConfig.ts b/src/scripts/models/scripts/contributors/contributorsConfig.ts deleted file mode 100644 index f81ecff22d..0000000000 --- a/src/scripts/models/scripts/contributors/contributorsConfig.ts +++ /dev/null @@ -1,10 +0,0 @@ -export type ContributorsConfig = { - /** Owner of the repository */ - owner: string; - - /** Name of the repository */ - repo: string; - - /** Size of a contributor's profile image in pixels */ - imageSize: number; -};