Skip to content

Commit

Permalink
add uploading status
Browse files Browse the repository at this point in the history
  • Loading branch information
emilwidlund committed Nov 2, 2024
1 parent f090f55 commit 3220938
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
21 changes: 5 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -13,33 +13,23 @@
"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",
"@types/cross-spawn": "^6.0.6",
"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",
Expand All @@ -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"
},
Expand All @@ -60,9 +51,7 @@
"ts": "module",
"tsx": "module"
},
"nodeArguments": [
"--loader=ts-node/esm"
]
"nodeArguments": ["--loader=ts-node/esm"]
},
"xo": {
"extends": "xo-react",
Expand Down
7 changes: 6 additions & 1 deletion src/product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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<FileRead>((resolve) => {
const fileUploadPromise = new Promise<FileRead>((resolve) => {
const upload = new Upload(api, {
organization,
file: {
Expand All @@ -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,
Expand Down
16 changes: 16 additions & 0 deletions src/ui/upload.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Spinner } from "@inkjs/ui";
import { render } from "ink";
import React from "react";

export const uploadMessage = async <T,>(fileUploadPromise: Promise<T>) => {
const { unmount, clear, waitUntilExit } = render(
<Spinner label="Uploading file..." />,
);

fileUploadPromise.then(() => {
clear();
unmount();
});

await waitUntilExit();
};

0 comments on commit 3220938

Please sign in to comment.