mirror of
https://github.com/LukeHagar/sveltesociety.dev.git
synced 2025-12-09 20:57:44 +00:00
* Add zod schemas for CI validation * Require npm field for components.json * Remove svelte-layout-resizable * Stricter Zod validation * Stricter repository field validation * Implement requested changes * Add back accidentally removed field * Move SvelteStore to templates.json * Update category and tags * Add script to get npm data * Re-run updateNpm.js * Implement initial feedback * Update npm.js * Switch async/await to then/catch Co-authored-by: MacFJA <MacFJA@users.noreply.github.com> * Fix prettier * Run script * Re-run updateNpm * Also read tools.json * Add @types/node * Restructure npm.json output * Display last update on components page * Add to weekly workflow * Clarify updating npm data * Update src/lib/utils/injectNpmData.ts Co-authored-by: MacFJA <MacFJA@users.noreply.github.com> * Smaller date font, add version * Improve error text * Fix property title --------- Co-authored-by: MacFJA <MacFJA@users.noreply.github.com>
34 lines
1.3 KiB
JavaScript
34 lines
1.3 KiB
JavaScript
// @ts-check
|
|
|
|
import { writeFileSync } from 'node:fs';
|
|
import { promisify } from 'node:util';
|
|
import { exec } from 'node:child_process';
|
|
import { componentsSchema, toolsSchema } from '../src/lib/schemas.js';
|
|
import components from '../src/routes/components/components.json' assert { type: 'json' };
|
|
import tools from '../src/routes/tools/tools.json' assert { type: 'json' };
|
|
|
|
const execAsync = promisify(exec);
|
|
|
|
const data = [...componentsSchema.parse(components), ...toolsSchema.parse(tools)];
|
|
|
|
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/npm.json', JSON.stringify(npm));
|
|
|
|
/** @param {ReturnType<typeof data>[0]} pkg */
|
|
async function processPackage(pkg) {
|
|
if (!pkg.npm) {
|
|
throw new Error(`npm field missing from ${pkg.title} (skipping)`);
|
|
}
|
|
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 } };
|
|
}
|