Skip to content

Commit

Permalink
install required components
Browse files Browse the repository at this point in the history
  • Loading branch information
Makisuo committed Jan 20, 2025
1 parent a62d6df commit 760d24b
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions src/commands/blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ import url from "node:url"

import { customAlphabet } from "nanoid"

import { warningText } from "@/utils/logging"
import { type } from "arktype"
import { listen } from "async-listen"
import chalk from "chalk"
import { readUser, updateUser } from "rc9"
import { add } from "./add"

const FILENAME = ".justd"
// const DOMAIN = "https://blocks.getjustd.com"
Expand All @@ -24,16 +27,50 @@ class UserCancellationError extends Error {

const nanoid = customAlphabet("123456789QAZWSXEDCRFVTGBYHNUJMIKOLP", 8)

const blockType = type({
title: "string",
slug: "string",
preview: "string",
meta: {
ui: {
"[string]": "string",
},
},
})

export const addBlock = async ({ components }: { components: string[] }) => {
const config = readUser(FILENAME)

const res = await fetch(`${DOMAIN}/api/blocks/wow`, {
if (!config.key) {
console.log(warningText("No API key found. Please login first."))
process.exit(1)
}

const res = await fetch(`${DOMAIN}/api/blocks/applications/sidebar/01`, {
headers: {
"x-api-key": config.key,
},
})

console.log(await res.text())
if (!res.ok) {
console.log(warningText(await res.text()))
process.exit(1)
}

const json = blockType(await res.json())

if (json instanceof type.errors) {
console.log(warningText(json.summary))
process.exit(1)
}

await add({
components: Object.keys(json.meta.ui).map((key) => key.replace(".tsx", "")),
successMessage: "Required components added.",
overwrite: false,
})

// TODO: Receive Block Data => On success, write block comps to file.
}

export const loginBlock = async () => {
Expand Down

0 comments on commit 760d24b

Please sign in to comment.