mirror of
https://github.com/LukeHagar/sveltesociety.dev.git
synced 2025-12-06 12:47:44 +00:00
fix: Run updateNpm.js and updatePublint.js in chunked pages (#536)
* fix: Run `updateNpm` and `updatePublint` in chunked pages * Object shorthand
This commit is contained in:
@@ -5,21 +5,33 @@ 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' };
|
||||
import { chunk } from './chunk.js';
|
||||
|
||||
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>} */ ({})
|
||||
);
|
||||
});
|
||||
console.log('Found ' + data.length + ' packages');
|
||||
|
||||
writeFileSync('src/lib/data/npm.json', JSON.stringify(npm));
|
||||
const pagedData = chunk(data, 100);
|
||||
const lines = [];
|
||||
|
||||
for (let index = 0; index < pagedData.length; index++) {
|
||||
const page = pagedData[index];
|
||||
console.log('Running for page ' + (index + 1) + '/' + pagedData.length);
|
||||
await Promise.all(
|
||||
page.map((pkg) => processPackage(pkg).catch((error) => console.log(error.message)))
|
||||
).then((values) => {
|
||||
lines.push(...values);
|
||||
});
|
||||
}
|
||||
|
||||
const output = lines.reduce(
|
||||
(result, value) => Object.assign(result, value),
|
||||
/** @type {Record<string, any>} */ ({})
|
||||
);
|
||||
|
||||
writeFileSync('src/lib/data/npm.json', JSON.stringify(output));
|
||||
|
||||
/** @param {import('zod').infer<typeof packagesSchema>[0]} pkg */
|
||||
async function processPackage(pkg) {
|
||||
@@ -28,5 +40,5 @@ async function processPackage(pkg) {
|
||||
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 } };
|
||||
return { [pkg.npm]: { version, date, support } };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user