From fc0064f6a0ed4c66a726a93786f7e1bb39bcfe80 Mon Sep 17 00:00:00 2001 From: Indrajith K L Date: Sat, 13 May 2023 11:17:27 +0530 Subject: Initial Commit * Implements Basic Routing and API * Implements Package.json file select and json parse * Displays Project Name, Version & Desc from the package.json * Fetch all package details using npm registry API and map it based on package name --- routes/analyze.tsx | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 routes/analyze.tsx (limited to 'routes/analyze.tsx') diff --git a/routes/analyze.tsx b/routes/analyze.tsx new file mode 100644 index 0000000..0889986 --- /dev/null +++ b/routes/analyze.tsx @@ -0,0 +1,39 @@ +import { Handlers, PageProps } from "$fresh/server.ts"; +import ListPackageDetails from "../islands/ListPackageDetails.tsx"; +import { handler as fetchPackages } from "./api/npm.ts"; + +export const handler: Handlers = { + async POST(req, ctx) { + const form = await req.formData(); + const fileData = form.get("packagefile") as File; + const packagejson = await parsePackageJson(fileData); + const packages = {...packagejson.dependencies, ...packagejson.devDependencies}; + const {name, version, description} = packagejson + return ctx.render({packages, name, version, description}); + }, +}; + +const parsePackageJson = (fileData: File) => { + return new Promise((resolve, reject) => { + const reader = new FileReader(); + reader.readAsText(fileData); + reader.addEventListener("load", (event: any) => { + resolve(JSON.parse(reader.result as string)); + }); + }); +}; + +export default function Analyze({ data }: PageProps) { + const {packages, name, version, description} = data; + return ( +
+ Analyzer + +
+ ); +} -- cgit v1.2.3