mirror of
https://github.com/LukeHagar/sveltesociety.dev.git
synced 2025-12-07 12:47:45 +00:00
feat: Submitted data restructure (#533)
* 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
This commit is contained in:
@@ -3,13 +3,12 @@
|
||||
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' };
|
||||
import { packagesSchema } from '../src/lib/schemas.js';
|
||||
import packages from '../src/routes/packages/packages.json' assert { type: 'json' };
|
||||
|
||||
const execAsync = promisify(exec);
|
||||
|
||||
const data = [...componentsSchema.parse(components), ...toolsSchema.parse(tools)];
|
||||
const data = packagesSchema.parse(packages);
|
||||
|
||||
const npm = await Promise.all(
|
||||
data.map((pkg) => processPackage(pkg).catch((error) => console.log(error.message)))
|
||||
@@ -19,11 +18,8 @@ const npm = await Promise.all(
|
||||
|
||||
writeFileSync('src/lib/data/npm.json', JSON.stringify(npm));
|
||||
|
||||
/** @param {ReturnType<typeof data>[0]} pkg */
|
||||
/** @param {import('zod').infer<typeof packagesSchema>[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;
|
||||
|
||||
Reference in New Issue
Block a user