From 32209382f68fa4c55c77f8a308df3bed04742478 Mon Sep 17 00:00:00 2001 From: Emil Widlund Date: Sat, 2 Nov 2024 12:41:50 +0100 Subject: [PATCH] add uploading status --- package.json | 21 +++++---------------- src/product.ts | 7 ++++++- src/ui/upload.tsx | 16 ++++++++++++++++ 3 files changed, 27 insertions(+), 17 deletions(-) create mode 100644 src/ui/upload.tsx diff --git a/package.json b/package.json index 630f57f..0a325ab 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "checkout-link", - "version": "0.1.5", + "version": "0.1.6", "license": "Apache-2.0", "bin": "bin/cli.js", "type": "module", @@ -13,10 +13,7 @@ "test": "prettier --check . && xo && ava", "check": "biome check --write ./src" }, - "files": [ - "dist", - "bin" - ], + "files": ["dist", "bin"], "dependencies": { "@inkjs/ui": "^2.0.0", "@polar-sh/sdk": "^0.13.3", @@ -24,22 +21,15 @@ "cross-spawn": "^7.0.3", "ink": "^4.4.1", "ink-link": "^4.1.0", - "listr": "^0.14.3", "meow": "^11.0.0", "mime-types": "^2.1.35", - "next": "^15.0.1", - "nuxt": "^3.0.0", "open": "^10.1.0", "prompts": "^2.4.2", - "react": "^18.2.0", - "standardwebhooks": "1.0.0", - "tsup": "^8.3.0", - "zod": "^3.23.8" + "react": "^18.2.0" }, "devDependencies": { "@biomejs/biome": "1.9.4", "@sindresorhus/tsconfig": "^3.0.1", - "@types/listr": "^0.14.9", "@types/mime-types": "^2.1.4", "@types/prompts": "^2.4.9", "@types/react": "^18.3.11", @@ -52,6 +42,7 @@ "ink-testing-library": "^3.0.0", "prettier": "^2.8.7", "ts-node": "^10.9.1", + "tsup": "^8.3.0", "typescript": "^5.0.3", "xo": "^0.53.1" }, @@ -60,9 +51,7 @@ "ts": "module", "tsx": "module" }, - "nodeArguments": [ - "--loader=ts-node/esm" - ] + "nodeArguments": ["--loader=ts-node/esm"] }, "xo": { "extends": "xo-react", diff --git a/src/product.ts b/src/product.ts index db2fe4b..16a3586 100644 --- a/src/product.ts +++ b/src/product.ts @@ -4,6 +4,7 @@ import type { Polar } from "@polar-sh/sdk"; import type { FileRead, Organization } from "@polar-sh/sdk/models/components"; import type { ProductsCreateProductCreate } from "@polar-sh/sdk/models/operations"; import mime from "mime-types"; +import { uploadMessage } from "./ui/upload.js"; import { Upload } from "./upload.js"; export const createProduct = async ( @@ -21,7 +22,7 @@ export const createProduct = async ( const readStream = fs.createReadStream(absoluteFilePath); const mimeType = mime.lookup(absoluteFilePath) || "application/octet-stream"; - const fileUpload = await new Promise((resolve) => { + const fileUploadPromise = new Promise((resolve) => { const upload = new Upload(api, { organization, file: { @@ -37,6 +38,10 @@ export const createProduct = async ( upload.run(); }); + await uploadMessage(fileUploadPromise); + + const fileUpload = await fileUploadPromise; + const benefit = await api.benefits.create({ type: "downloadables", description: productCreate.name, diff --git a/src/ui/upload.tsx b/src/ui/upload.tsx new file mode 100644 index 0000000..4052b2b --- /dev/null +++ b/src/ui/upload.tsx @@ -0,0 +1,16 @@ +import { Spinner } from "@inkjs/ui"; +import { render } from "ink"; +import React from "react"; + +export const uploadMessage = async (fileUploadPromise: Promise) => { + const { unmount, clear, waitUntilExit } = render( + , + ); + + fileUploadPromise.then(() => { + clear(); + unmount(); + }); + + await waitUntilExit(); +};