mirror of
https://github.com/LukeHagar/sveltesociety.dev.git
synced 2025-12-06 12:47:44 +00:00
* Fix Tag.svelte a11y warnings * Fix types in scripts * Remove unused CardList.svelte * Revert "Remove unused CardList.svelte" This reverts commit acd01fd4fdb57487521de9721e175e9d8d4c72cf. * Clearer import * Format
33 lines
1.1 KiB
JavaScript
33 lines
1.1 KiB
JavaScript
// @ts-check
|
|
|
|
import { writeFileSync } from 'node:fs';
|
|
import { promisify } from 'node:util';
|
|
import { exec } from 'node:child_process';
|
|
import { packagesSchema } from '../src/lib/schemas.js';
|
|
import packages from '../src/routes/packages/packages.json' assert { type: 'json' };
|
|
|
|
const execAsync = promisify(exec);
|
|
|
|
const data = packagesSchema.parse(packages);
|
|
|
|
const npm = await Promise.all(
|
|
data.map((pkg) => processPackage(pkg).catch((error) => console.log(error.message)))
|
|
).then((values) => {
|
|
return values.reduce(
|
|
(result, value) => Object.assign(result, value),
|
|
/** @type {Record<string, any>} */ ({})
|
|
);
|
|
});
|
|
|
|
writeFileSync('src/lib/data/npm.json', JSON.stringify(npm));
|
|
|
|
/** @param {import('zod').infer<typeof packagesSchema>[0]} pkg */
|
|
async function processPackage(pkg) {
|
|
const { stdout } = await execAsync(`npm view ${pkg.npm} --json`);
|
|
const data = JSON.parse(stdout.toString());
|
|
const version = data.version;
|
|
const date = data.time[version];
|
|
const support = data.peerDependencies?.svelte ? data.peerDependencies.svelte : 'Unknown';
|
|
return { [pkg.npm]: { version: version, date: date, support: support } };
|
|
}
|