Skip to content

Commit

Permalink
fix update integration script (#1055)
Browse files Browse the repository at this point in the history
  • Loading branch information
itsMapleLeaf authored Apr 5, 2024
1 parent 139a51c commit 84338b4
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 21 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@biomejs/biome": "1.6.3",
"@octokit/graphql": "^7.0.2",
"@playwright/test": "^1.40.1",
"@types/json-to-pretty-yaml": "1.2.1",
"@types/node": "^20.10.4",
"@types/quill": "^2.0.14",
"@typescript-eslint/eslint-plugin": "^6.14.0",
Expand Down
7 changes: 7 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions scripts/npm.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ const PAGE_SIZE = 100;
/**
* Gets the number of weekly downloads for an npm package.
*
* @param {String} pkg Name of the package published on npm
* @returns {Promise<Number>} The number of weekly downloads for the package
* @param {string} pkg Name of the package published on npm
* @returns {Promise<number>} The number of weekly downloads for the package
*/
export function fetchDownloadsForPackage(pkg) {
return fetchJson(`${API_BASE_URL}downloads/point/${START_DATE}:${END_DATE}/${pkg}`)
Expand All @@ -34,8 +34,8 @@ export function fetchDownloadsForPackage(pkg) {
/**
* Gets details for a package from the npm registry
*
* @param {String} pkg Name of the package published to npm
* @returns {Object} JSON data as returned by the npm registry
* @param {string} pkg Name of the package published to npm
* @returns {Promise<any>} JSON data as returned by the npm registry
*/
export function fetchDetailsForPackage(pkg) {
return fetchJson(`${REGISTRY_BASE_URL}${pkg}`);
Expand All @@ -44,9 +44,9 @@ export function fetchDetailsForPackage(pkg) {
/**
* Searches npm for a specific keyword and returns a map, keyed by package name.
*
* @param {String} keyword The keyword used to search npm, ex: `astro-component`
* @param {String | undefined} ranking The sort order for results, default: `quality`
* @returns {Map} Map of search results, keyed by package name
* @param {string} keyword The keyword used to search npm, ex: `astro-component`
* @param {string | undefined} ranking The sort order for results, default: `quality`
* @returns {Promise<Map<string, any>>} Map of search results, keyed by package name
*/
export async function searchByKeyword(keyword, ranking = "quality") {
const objects = [];
Expand Down
24 changes: 10 additions & 14 deletions scripts/update-integrations.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ function updateLastModified() {
fs.writeFileSync(pathname, JSON.stringify(data, null, "\t"), { encoding: "utf8" });
}

async function getIntegrationFiles() {
return await glob("src/content/integrations/*.md", {
cwd: path.resolve(fileURLToPath(import.meta.url), "../.."),
});
}

function normalizePackageDetails(data, pkg) {
const keywordCategories = (data.keywords ?? []).flatMap(getCategoriesForKeyword);

Expand Down Expand Up @@ -106,11 +112,7 @@ async function unsafeUpdateAllIntegrations() {
[...packagesMap.keys(), ...allowlist].filter((pkg) => !blocklist.includes(pkg)),
);

const pathname = path.resolve(
path.dirname(fileURLToPath(import.meta.url)),
"../src/content/integrations/*.md",
);
const entries = await glob(pathname);
const entries = await getIntegrationFiles();

const existingIntegrations = new Set();
const deprecatedIntegrations = [];
Expand All @@ -133,10 +135,9 @@ async function unsafeUpdateAllIntegrations() {
const frontmatter = yaml.stringify({
...data,
...details,
badges: undefined,
});

frontmatter.badges = undefined;

fs.writeFileSync(
entry,
`---
Expand Down Expand Up @@ -188,11 +189,7 @@ Updated: ${existingIntegrations.size - deprecatedIntegrations.length} integratio
}

async function safeUpdateExistingIntegrations() {
const pathname = path.resolve(
path.dirname(fileURLToPath(import.meta.url)),
"../src/content/integrations/*.md",
);
const entries = await glob(pathname);
const entries = await getIntegrationFiles();

for (const entry of entries) {
const { data } = matter.read(entry);
Expand All @@ -203,10 +200,9 @@ async function safeUpdateExistingIntegrations() {
const frontmatter = yaml.stringify({
...data,
downloads,
badges: undefined,
});

frontmatter.badges = undefined;

fs.writeFileSync(
entry,
`---
Expand Down

0 comments on commit 84338b4

Please sign in to comment.