From b7b8727d5f1090963e3404271130f52d1e7c1c3e Mon Sep 17 00:00:00 2001 From: Furkan Date: Mon, 5 Feb 2024 18:53:07 +0300 Subject: [PATCH] Automatic package metadata insertion for popular packages Since versions remain in old versions even if they are renewed, it creates it using the updated metadata of the current package. --- .../src/mocks/popularPackages.mock.js | 96 ++----------------- .../src/pages/Home/index.tsx | 92 +++++++++++++----- 2 files changed, 76 insertions(+), 112 deletions(-) diff --git a/wally-registry-frontend/src/mocks/popularPackages.mock.js b/wally-registry-frontend/src/mocks/popularPackages.mock.js index 63947b64..95150148 100644 --- a/wally-registry-frontend/src/mocks/popularPackages.mock.js +++ b/wally-registry-frontend/src/mocks/popularPackages.mock.js @@ -1,94 +1,10 @@ const mockPopularPackages = [ - { - package: { - name: "evaera/cmdr", - version: "1.8.5", - registry: "https://github.com/upliftgames/wally-test-index", - realm: "shared", - description: "Extensible command console for Roblox developers", - license: "MIT", - authors: ["evaera "], - }, - dependencies: {}, - "dev-dependencies": {}, - "server-dependencies": {}, - }, - { - package: { - authors: [], - description: "A view management library for Roblox Lua similar to React", - license: "Apache-2.0", - name: "roblox/roact", - realm: "shared", - registry: "https://github.com/UpliftGames/wally-index", - version: "1.4.2", - }, - dependencies: {}, - "dev-dependencies": {}, - "server-dependencies": {}, - }, - { - package: { - name: "evaera/promise", - version: "3.1.0", - registry: "https://github.com/UpliftGames/wally-index", - realm: "shared", - description: "Promise implementation for Roblox", - license: "MIT", - authors: [], - }, - dependencies: {}, - "dev-dependencies": {}, - "server-dependencies": {}, - }, - { - dependencies: {}, - "dev-dependencies": {}, - package: { - authors: [], - description: "BDD-style test and assertion library for Roblox Lua", - license: "Apache2", - name: "roblox/testez", - realm: "shared", - registry: "https://github.com/UpliftGames/wally-index", - version: "0.4.1", - }, - "server-dependencies": {}, - }, - { - dependencies: { - Comm: "sleitnick/comm@>=0.1.0, <0.2.0", - Loader: "sleitnick/loader@>=1.0.0, <2.0.0", - Promise: "evaera/promise@>=3.1.0, <4.0.0", - Signal: "sleitnick/signal@>=1.0.0, <2.0.0", - TableUtil: "sleitnick/table-util@>=1.0.0, <2.0.0", - }, - "dev-dependencies": {}, - package: { - authors: [], - description: "Knit is a lightweight game framework", - license: "MIT", - name: "sleitnick/knit", - realm: "shared", - registry: "https://github.com/UpliftGames/wally-index", - version: "1.0.9", - }, - "server-dependencies": {}, - }, - { - dependencies: {}, - "dev-dependencies": {}, - package: { - authors: [], - description: "Garbage collector object implementation for Roblox", - license: null, - name: "howmanysmall/janitor", - realm: "shared", - registry: "https://github.com/UpliftGames/wally-index", - version: "1.13.13", - }, - "server-dependencies": {}, - }, + "evaera/cmdr", + "roblox/roact", + "evaera/promise", + "roblox/testez", + "sleitnick/knit", + "howmanysmall/janitor", ] export default mockPopularPackages diff --git a/wally-registry-frontend/src/pages/Home/index.tsx b/wally-registry-frontend/src/pages/Home/index.tsx index 925af5a3..b580df79 100644 --- a/wally-registry-frontend/src/pages/Home/index.tsx +++ b/wally-registry-frontend/src/pages/Home/index.tsx @@ -1,4 +1,4 @@ -import React from "react" +import React, { useState, useEffect } from "react" import styled from "styled-components" import { ButtonLink } from "../../components/Button" import CallToActionContainer from "../../components/CallToActionContainer" @@ -6,6 +6,9 @@ import ContentSection from "../../components/ContentSection" import PackageTag from "../../components/PackageTag" import { Code, Heading, ResponsiveParagraph } from "../../components/Typography" import mockPopularPackages from "../../mocks/popularPackages.mock" +import { getWallyPackageMetadata } from "../../services/wally.api" +import { WallyPackageMetadata } from "../../types/wally" +import capitalize from "../../utils/capitalize" const Flex = styled.div` display: flex; @@ -15,31 +18,76 @@ const Flex = styled.div` margin: 1.5rem 0; ` +const SplitPackageFullName = ( + fullName: string +): { Scope: string; Name: string } => { + const [scope, name] = fullName.split("/") + return { Scope: scope, Name: name } +} + const PopularPackages = () => { - const popularPackagesList = [...mockPopularPackages].map( - (popPackage, index) => ( - -

{popPackage.package.description} 

-
- ) - ) + const [popularPackages, setPopularPackages] = useState< + WallyPackageMetadata[] + >([]) + + const fetchPopularPackages = async () => { + const popularPackagesList = [] + + for (const fullName of [...mockPopularPackages]) { + const { Scope, Name } = SplitPackageFullName(fullName) + const packageData = await getWallyPackageMetadata(Scope, Name) + if (!packageData) continue + + // boatbomber src/pages/Package.tsx is an excerpt from the code snippet he wrote + const filteredPackageData = packageData.versions.some( + (pack: WallyPackageMetadata) => !pack.package.version.includes("-") + ) + ? packageData.versions.filter( + (pack: WallyPackageMetadata) => !pack.package.version.includes("-") + ) + : packageData.versions + + const latestVersion = filteredPackageData[0].package.version + const packageMetadata = filteredPackageData?.find( + (item: WallyPackageMetadata) => item.package.version === latestVersion + ) - if (popularPackagesList.length % 2 !== 0) { - popularPackagesList.push(