mirror of
https://github.com/LukeHagar/sveltesociety.dev.git
synced 2025-12-06 04:21:38 +00:00
* Merge tools into components and resources * Rename components to packages * Format * Redirect with code 302 * Fix text on submitting page * Validate misc.json, format * Permanent redirects * Implement feedback for resources * Fix lint * Improve updateNpm.js types * Fix repo links
30 lines
1.1 KiB
JavaScript
30 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), {});
|
|
});
|
|
|
|
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 } };
|
|
}
|