feat: Add script to get npm package data (#499)

* 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>
This commit is contained in:
Lachlan Collins
2023-12-18 10:37:40 +11:00
committed by GitHub
parent 3ee0d8f570
commit 77451078d7
10 changed files with 1562 additions and 30 deletions

View File

@@ -2,6 +2,7 @@
import Tag from '../Tag.svelte';
import { copyToClipboard } from '$lib/utils/clipboard';
import { packageManager as manager } from '$stores/packageManager';
import { relativeDate } from '$utils/relativeDate';
export let active = false;
export let title = '';
@@ -11,6 +12,8 @@
export let url = '';
export let npm = '';
export let repository = undefined;
export let date = undefined;
export let version = undefined;
let clipboardCopy = false;
@@ -33,15 +36,35 @@
</script>
<div class="card" class:active id="component-{title}">
<h3>
<a href="#component-{title}">#</a>
{#if url || repository}<a href={url || repository}>{title}</a>{:else}<span>{title}</span>{/if}
{#if npm}<Tag
click={() => copy()}
variant="copy"
title={clipboardCopy ? 'copied!' : `${packageManagers[$manager]} ${cleanupNpm(npm)}`}
/>{/if}
</h3>
<div class="card__top">
<div>
<h3>
<a href="#component-{title}">#</a>
{#if url || repository}<a href={url || repository}>{title}</a>{:else}<span>{title}</span
>{/if}
</h3>
</div>
<div>
{#if (repository || url || '').includes('github')}
<a class="repo" title="Go to the source code" href={repository || url}
><img style="display:inline" src="/images/github_logo.svg" alt="github logo" /></a
>
{:else if (repository || url || '').includes('gitlab')}
<a class="repo" title="Go to the source code" href={repository || url}
><img style="display:inline" src="/images/gitlab_logo.svg" alt="gitlab logo" /></a
>
<!-- {:else} -->
{/if}
</div>
</div>
{#if npm}
<Tag
click={() => copy()}
variant="copy"
title={clipboardCopy ? 'copied!' : `${packageManagers[$manager]} ${cleanupNpm(npm)}`}
/>
{/if}
<p class="flex-grow">{description}</p>
{#if tags}
<div class="card__tags">
@@ -51,26 +74,13 @@
</div>
{/if}
<div class="card__bottom">
<div>
{#if (repository || url || '').includes('github')}
<a title="Go to the source code" href={repository || url}
><img style="display:inline" src="/images/github_logo.svg" alt="github logo" /></a
>
{:else if (repository || url || '').includes('gitlab')}
<a title="Go to the source code" href={repository || url}
><img style="display:inline" src="/images/gitlab_logo.svg" alt="gitlab logo" /></a
>
<!-- {:else} -->
{/if}
</div>
<div>
{#if typeof stars !== 'undefined'}
&#9733;
<code>{stars}</code>
{/if}
</div>
<!-- commenting out dates just cause it is not very updated yet - all the cards show same date. put back in when we have better scraping -->
<!-- <datetime value={addedOn}>{new Intl.DateTimeFormat('en-Us').format(Date.parse(addedOn))}</datetime> -->
{#if date && version}<span class="date">Updated {relativeDate(date)} ({version})</span>{/if}
</div>
</div>
@@ -97,6 +107,11 @@
flex-wrap: wrap;
margin-bottom: 1rem;
}
.card__top {
display: flex;
justify-content: space-between;
align-items: top;
}
.card__bottom {
display: flex;
justify-content: space-between;
@@ -105,7 +120,7 @@
.card__bottom > * {
white-space: nowrap;
}
.card__bottom a {
.repo {
border-bottom: none;
aspect-ratio: 1/1;
display: flex;
@@ -117,10 +132,12 @@
background-color: rgba(0, 0, 0, 0);
transition: background-color 200ms ease-out;
}
.card__bottom a:hover {
.repo:hover {
background-color: rgba(0, 0, 0, 0.25);
}
.date {
font-size: 14px;
}
.flex-grow {
flex-grow: 1;
}