From 7544f46c87eabbb4f341e700c5bedb503dbd186d Mon Sep 17 00:00:00 2001 From: yisding <yi.s.ding@gmail.com> Date: Tue, 14 Nov 2023 16:02:55 -0800 Subject: [PATCH] prettier --- index.ts | 16 ++-- .../components/ui/shadcn/chat/codeblock.tsx | 84 +++++++++---------- templates/components/ui/shadcn/chat/index.ts | 2 +- .../components/ui/shadcn/chat/markdown.tsx | 28 +++---- .../ui/shadcn/chat/use-copy-to-clipboard.tsx | 28 +++---- .../nextjs/app/components/ui/chat/index.ts | 2 +- templates/types/simple/nextjs/next.config.js | 8 +- .../types/simple/nextjs/postcss.config.js | 2 +- .../nextjs/app/components/ui/chat/index.ts | 2 +- .../types/streaming/nextjs/next.config.js | 8 +- .../types/streaming/nextjs/postcss.config.js | 2 +- 11 files changed, 91 insertions(+), 91 deletions(-) diff --git a/index.ts b/index.ts index bcd1507d..8d87124d 100644 --- a/index.ts +++ b/index.ts @@ -79,10 +79,10 @@ const program = new Commander.Command(packageJson.name) const packageManager = !!program.useNpm ? "npm" : !!program.usePnpm - ? "pnpm" - : !!program.useYarn - ? "yarn" - : getPkgManager(); + ? "pnpm" + : !!program.useYarn + ? "yarn" + : getPkgManager(); async function run(): Promise<void> { const conf = new Conf({ projectName: "create-llama" }); @@ -235,8 +235,8 @@ async function run(): Promise<void> { program.framework === "express" ? "Express " : program.framework === "fastapi" - ? "FastAPI (Python) " - : "", + ? "FastAPI (Python) " + : "", ); const { frontend } = await prompts({ onState: onPromptState, @@ -364,8 +364,8 @@ async function notifyUpdate(): Promise<void> { packageManager === "yarn" ? "yarn global add create-llama@latest" : packageManager === "pnpm" - ? "pnpm add -g create-llama@latest" - : "npm i -g create-llama@latest"; + ? "pnpm add -g create-llama@latest" + : "npm i -g create-llama@latest"; console.log( yellow(bold("A new version of `create-llama` is available!")) + diff --git a/templates/components/ui/shadcn/chat/codeblock.tsx b/templates/components/ui/shadcn/chat/codeblock.tsx index 10598223..014a0fc3 100644 --- a/templates/components/ui/shadcn/chat/codeblock.tsx +++ b/templates/components/ui/shadcn/chat/codeblock.tsx @@ -1,23 +1,23 @@ -"use client" +"use client"; -import React, { FC, memo } from "react" -import { Check, Copy, Download } from "lucide-react" -import { Prism, SyntaxHighlighterProps } from "react-syntax-highlighter" -import { coldarkDark } from "react-syntax-highlighter/dist/cjs/styles/prism" +import { Check, Copy, Download } from "lucide-react"; +import { FC, memo } from "react"; +import { Prism, SyntaxHighlighterProps } from "react-syntax-highlighter"; +import { coldarkDark } from "react-syntax-highlighter/dist/cjs/styles/prism"; -import { Button } from "../button" -import { useCopyToClipboard } from "./use-copy-to-clipboard" +import { Button } from "../button"; +import { useCopyToClipboard } from "./use-copy-to-clipboard"; // TODO: Remove this when @type/react-syntax-highlighter is updated -const SyntaxHighlighter = Prism as unknown as FC<SyntaxHighlighterProps> +const SyntaxHighlighter = Prism as unknown as FC<SyntaxHighlighterProps>; interface Props { - language: string - value: string + language: string; + value: string; } interface languageMap { - [key: string]: string | undefined + [key: string]: string | undefined; } export const programmingLanguages: languageMap = { @@ -45,52 +45,52 @@ export const programmingLanguages: languageMap = { html: ".html", css: ".css", // add more file extensions here, make sure the key is same as language prop in CodeBlock.tsx component -} +}; export const generateRandomString = (length: number, lowercase = false) => { - const chars = "ABCDEFGHJKLMNPQRSTUVWXY3456789" // excluding similar looking characters like Z, 2, I, 1, O, 0 - let result = "" + const chars = "ABCDEFGHJKLMNPQRSTUVWXY3456789"; // excluding similar looking characters like Z, 2, I, 1, O, 0 + let result = ""; for (let i = 0; i < length; i++) { - result += chars.charAt(Math.floor(Math.random() * chars.length)) + result += chars.charAt(Math.floor(Math.random() * chars.length)); } - return lowercase ? result.toLowerCase() : result -} + return lowercase ? result.toLowerCase() : result; +}; const CodeBlock: FC<Props> = memo(({ language, value }) => { - const { isCopied, copyToClipboard } = useCopyToClipboard({ timeout: 2000 }) + const { isCopied, copyToClipboard } = useCopyToClipboard({ timeout: 2000 }); const downloadAsFile = () => { if (typeof window === "undefined") { - return + return; } - const fileExtension = programmingLanguages[language] || ".file" + const fileExtension = programmingLanguages[language] || ".file"; const suggestedFileName = `file-${generateRandomString( 3, - true - )}${fileExtension}` - const fileName = window.prompt("Enter file name" || "", suggestedFileName) + true, + )}${fileExtension}`; + const fileName = window.prompt("Enter file name" || "", suggestedFileName); if (!fileName) { // User pressed cancel on prompt. - return + return; } - const blob = new Blob([value], { type: "text/plain" }) - const url = URL.createObjectURL(blob) - const link = document.createElement("a") - link.download = fileName - link.href = url - link.style.display = "none" - document.body.appendChild(link) - link.click() - document.body.removeChild(link) - URL.revokeObjectURL(url) - } + const blob = new Blob([value], { type: "text/plain" }); + const url = URL.createObjectURL(blob); + const link = document.createElement("a"); + link.download = fileName; + link.href = url; + link.style.display = "none"; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + URL.revokeObjectURL(url); + }; const onCopy = () => { - if (isCopied) return - copyToClipboard(value) - } + if (isCopied) return; + copyToClipboard(value); + }; return ( <div className="codeblock relative w-full bg-zinc-950 font-sans"> @@ -132,8 +132,8 @@ const CodeBlock: FC<Props> = memo(({ language, value }) => { {value} </SyntaxHighlighter> </div> - ) -}) -CodeBlock.displayName = "CodeBlock" + ); +}); +CodeBlock.displayName = "CodeBlock"; -export { CodeBlock } +export { CodeBlock }; diff --git a/templates/components/ui/shadcn/chat/index.ts b/templates/components/ui/shadcn/chat/index.ts index 0b810496..c7990f9c 100644 --- a/templates/components/ui/shadcn/chat/index.ts +++ b/templates/components/ui/shadcn/chat/index.ts @@ -2,4 +2,4 @@ import ChatInput from "./chat-input"; import ChatMessages from "./chat-messages"; export { type ChatHandler, type Message } from "./chat.interface"; -export { ChatMessages, ChatInput }; +export { ChatInput, ChatMessages }; diff --git a/templates/components/ui/shadcn/chat/markdown.tsx b/templates/components/ui/shadcn/chat/markdown.tsx index 31b78242..3ca53805 100644 --- a/templates/components/ui/shadcn/chat/markdown.tsx +++ b/templates/components/ui/shadcn/chat/markdown.tsx @@ -1,16 +1,16 @@ -import { FC, memo } from "react" -import ReactMarkdown, { Options } from "react-markdown" -import remarkGfm from "remark-gfm" -import remarkMath from "remark-math" +import { FC, memo } from "react"; +import ReactMarkdown, { Options } from "react-markdown"; +import remarkGfm from "remark-gfm"; +import remarkMath from "remark-math"; -import { CodeBlock } from "./codeblock" +import { CodeBlock } from "./codeblock"; const MemoizedReactMarkdown: FC<Options> = memo( ReactMarkdown, (prevProps, nextProps) => prevProps.children === nextProps.children && - prevProps.className === nextProps.className -) + prevProps.className === nextProps.className, +); export default function Markdown({ content }: { content: string }) { return ( @@ -19,27 +19,27 @@ export default function Markdown({ content }: { content: string }) { remarkPlugins={[remarkGfm, remarkMath]} components={{ p({ children }) { - return <p className="mb-2 last:mb-0">{children}</p> + return <p className="mb-2 last:mb-0">{children}</p>; }, code({ node, inline, className, children, ...props }) { if (children.length) { if (children[0] == "â–") { return ( <span className="mt-1 animate-pulse cursor-default">â–</span> - ) + ); } - children[0] = (children[0] as string).replace("`â–`", "â–") + children[0] = (children[0] as string).replace("`â–`", "â–"); } - const match = /language-(\w+)/.exec(className || "") + const match = /language-(\w+)/.exec(className || ""); if (inline) { return ( <code className={className} {...props}> {children} </code> - ) + ); } return ( @@ -49,11 +49,11 @@ export default function Markdown({ content }: { content: string }) { value={String(children).replace(/\n$/, "")} {...props} /> - ) + ); }, }} > {content} </MemoizedReactMarkdown> - ) + ); } diff --git a/templates/components/ui/shadcn/chat/use-copy-to-clipboard.tsx b/templates/components/ui/shadcn/chat/use-copy-to-clipboard.tsx index 62f7156d..e011d69b 100644 --- a/templates/components/ui/shadcn/chat/use-copy-to-clipboard.tsx +++ b/templates/components/ui/shadcn/chat/use-copy-to-clipboard.tsx @@ -1,33 +1,33 @@ -'use client' +"use client"; -import * as React from 'react' +import * as React from "react"; export interface useCopyToClipboardProps { - timeout?: number + timeout?: number; } export function useCopyToClipboard({ - timeout = 2000 + timeout = 2000, }: useCopyToClipboardProps) { - const [isCopied, setIsCopied] = React.useState<Boolean>(false) + const [isCopied, setIsCopied] = React.useState<Boolean>(false); const copyToClipboard = (value: string) => { - if (typeof window === 'undefined' || !navigator.clipboard?.writeText) { - return + if (typeof window === "undefined" || !navigator.clipboard?.writeText) { + return; } if (!value) { - return + return; } navigator.clipboard.writeText(value).then(() => { - setIsCopied(true) + setIsCopied(true); setTimeout(() => { - setIsCopied(false) - }, timeout) - }) - } + setIsCopied(false); + }, timeout); + }); + }; - return { isCopied, copyToClipboard } + return { isCopied, copyToClipboard }; } diff --git a/templates/types/simple/nextjs/app/components/ui/chat/index.ts b/templates/types/simple/nextjs/app/components/ui/chat/index.ts index 4ccc5492..5de7dce4 100644 --- a/templates/types/simple/nextjs/app/components/ui/chat/index.ts +++ b/templates/types/simple/nextjs/app/components/ui/chat/index.ts @@ -3,4 +3,4 @@ import ChatMessages from "./chat-messages"; export type { ChatInputProps } from "./chat-input"; export type { Message } from "./chat-messages"; -export { ChatMessages, ChatInput }; +export { ChatInput, ChatMessages }; diff --git a/templates/types/simple/nextjs/next.config.js b/templates/types/simple/nextjs/next.config.js index 0b2c2bf1..ae14c48c 100644 --- a/templates/types/simple/nextjs/next.config.js +++ b/templates/types/simple/nextjs/next.config.js @@ -1,8 +1,8 @@ /** @type {import('next').NextConfig} */ const nextConfig = { experimental: { - serverComponentsExternalPackages: ["llamaindex"], - }, -} + serverComponentsExternalPackages: ["llamaindex"], + }, +}; -module.exports = nextConfig +module.exports = nextConfig; diff --git a/templates/types/simple/nextjs/postcss.config.js b/templates/types/simple/nextjs/postcss.config.js index 33ad091d..12a703d9 100644 --- a/templates/types/simple/nextjs/postcss.config.js +++ b/templates/types/simple/nextjs/postcss.config.js @@ -3,4 +3,4 @@ module.exports = { tailwindcss: {}, autoprefixer: {}, }, -} +}; diff --git a/templates/types/streaming/nextjs/app/components/ui/chat/index.ts b/templates/types/streaming/nextjs/app/components/ui/chat/index.ts index 4ccc5492..5de7dce4 100644 --- a/templates/types/streaming/nextjs/app/components/ui/chat/index.ts +++ b/templates/types/streaming/nextjs/app/components/ui/chat/index.ts @@ -3,4 +3,4 @@ import ChatMessages from "./chat-messages"; export type { ChatInputProps } from "./chat-input"; export type { Message } from "./chat-messages"; -export { ChatMessages, ChatInput }; +export { ChatInput, ChatMessages }; diff --git a/templates/types/streaming/nextjs/next.config.js b/templates/types/streaming/nextjs/next.config.js index 0b2c2bf1..ae14c48c 100644 --- a/templates/types/streaming/nextjs/next.config.js +++ b/templates/types/streaming/nextjs/next.config.js @@ -1,8 +1,8 @@ /** @type {import('next').NextConfig} */ const nextConfig = { experimental: { - serverComponentsExternalPackages: ["llamaindex"], - }, -} + serverComponentsExternalPackages: ["llamaindex"], + }, +}; -module.exports = nextConfig +module.exports = nextConfig; diff --git a/templates/types/streaming/nextjs/postcss.config.js b/templates/types/streaming/nextjs/postcss.config.js index 33ad091d..12a703d9 100644 --- a/templates/types/streaming/nextjs/postcss.config.js +++ b/templates/types/streaming/nextjs/postcss.config.js @@ -3,4 +3,4 @@ module.exports = { tailwindcss: {}, autoprefixer: {}, }, -} +}; -- GitLab