Skip to content
Snippets Groups Projects
Commit 7544f46c authored by yisding's avatar yisding
Browse files

prettier

parent 3e488cb9
No related branches found
No related tags found
No related merge requests found
Showing with 91 additions and 91 deletions
...@@ -79,10 +79,10 @@ const program = new Commander.Command(packageJson.name) ...@@ -79,10 +79,10 @@ const program = new Commander.Command(packageJson.name)
const packageManager = !!program.useNpm const packageManager = !!program.useNpm
? "npm" ? "npm"
: !!program.usePnpm : !!program.usePnpm
? "pnpm" ? "pnpm"
: !!program.useYarn : !!program.useYarn
? "yarn" ? "yarn"
: getPkgManager(); : getPkgManager();
async function run(): Promise<void> { async function run(): Promise<void> {
const conf = new Conf({ projectName: "create-llama" }); const conf = new Conf({ projectName: "create-llama" });
...@@ -235,8 +235,8 @@ async function run(): Promise<void> { ...@@ -235,8 +235,8 @@ async function run(): Promise<void> {
program.framework === "express" program.framework === "express"
? "Express " ? "Express "
: program.framework === "fastapi" : program.framework === "fastapi"
? "FastAPI (Python) " ? "FastAPI (Python) "
: "", : "",
); );
const { frontend } = await prompts({ const { frontend } = await prompts({
onState: onPromptState, onState: onPromptState,
...@@ -364,8 +364,8 @@ async function notifyUpdate(): Promise<void> { ...@@ -364,8 +364,8 @@ async function notifyUpdate(): Promise<void> {
packageManager === "yarn" packageManager === "yarn"
? "yarn global add create-llama@latest" ? "yarn global add create-llama@latest"
: packageManager === "pnpm" : packageManager === "pnpm"
? "pnpm add -g create-llama@latest" ? "pnpm add -g create-llama@latest"
: "npm i -g create-llama@latest"; : "npm i -g create-llama@latest";
console.log( console.log(
yellow(bold("A new version of `create-llama` is available!")) + yellow(bold("A new version of `create-llama` is available!")) +
......
"use client" "use client";
import React, { FC, memo } from "react" import { Check, Copy, Download } from "lucide-react";
import { Check, Copy, Download } from "lucide-react" import { FC, memo } from "react";
import { Prism, SyntaxHighlighterProps } from "react-syntax-highlighter" import { Prism, SyntaxHighlighterProps } from "react-syntax-highlighter";
import { coldarkDark } from "react-syntax-highlighter/dist/cjs/styles/prism" import { coldarkDark } from "react-syntax-highlighter/dist/cjs/styles/prism";
import { Button } from "../button" import { Button } from "../button";
import { useCopyToClipboard } from "./use-copy-to-clipboard" import { useCopyToClipboard } from "./use-copy-to-clipboard";
// TODO: Remove this when @type/react-syntax-highlighter is updated // 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 { interface Props {
language: string language: string;
value: string value: string;
} }
interface languageMap { interface languageMap {
[key: string]: string | undefined [key: string]: string | undefined;
} }
export const programmingLanguages: languageMap = { export const programmingLanguages: languageMap = {
...@@ -45,52 +45,52 @@ export const programmingLanguages: languageMap = { ...@@ -45,52 +45,52 @@ export const programmingLanguages: languageMap = {
html: ".html", html: ".html",
css: ".css", css: ".css",
// add more file extensions here, make sure the key is same as language prop in CodeBlock.tsx component // 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) => { export const generateRandomString = (length: number, lowercase = false) => {
const chars = "ABCDEFGHJKLMNPQRSTUVWXY3456789" // excluding similar looking characters like Z, 2, I, 1, O, 0 const chars = "ABCDEFGHJKLMNPQRSTUVWXY3456789"; // excluding similar looking characters like Z, 2, I, 1, O, 0
let result = "" let result = "";
for (let i = 0; i < length; i++) { 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 CodeBlock: FC<Props> = memo(({ language, value }) => {
const { isCopied, copyToClipboard } = useCopyToClipboard({ timeout: 2000 }) const { isCopied, copyToClipboard } = useCopyToClipboard({ timeout: 2000 });
const downloadAsFile = () => { const downloadAsFile = () => {
if (typeof window === "undefined") { if (typeof window === "undefined") {
return return;
} }
const fileExtension = programmingLanguages[language] || ".file" const fileExtension = programmingLanguages[language] || ".file";
const suggestedFileName = `file-${generateRandomString( const suggestedFileName = `file-${generateRandomString(
3, 3,
true true,
)}${fileExtension}` )}${fileExtension}`;
const fileName = window.prompt("Enter file name" || "", suggestedFileName) const fileName = window.prompt("Enter file name" || "", suggestedFileName);
if (!fileName) { if (!fileName) {
// User pressed cancel on prompt. // User pressed cancel on prompt.
return return;
} }
const blob = new Blob([value], { type: "text/plain" }) const blob = new Blob([value], { type: "text/plain" });
const url = URL.createObjectURL(blob) const url = URL.createObjectURL(blob);
const link = document.createElement("a") const link = document.createElement("a");
link.download = fileName link.download = fileName;
link.href = url link.href = url;
link.style.display = "none" link.style.display = "none";
document.body.appendChild(link) document.body.appendChild(link);
link.click() link.click();
document.body.removeChild(link) document.body.removeChild(link);
URL.revokeObjectURL(url) URL.revokeObjectURL(url);
} };
const onCopy = () => { const onCopy = () => {
if (isCopied) return if (isCopied) return;
copyToClipboard(value) copyToClipboard(value);
} };
return ( return (
<div className="codeblock relative w-full bg-zinc-950 font-sans"> <div className="codeblock relative w-full bg-zinc-950 font-sans">
...@@ -132,8 +132,8 @@ const CodeBlock: FC<Props> = memo(({ language, value }) => { ...@@ -132,8 +132,8 @@ const CodeBlock: FC<Props> = memo(({ language, value }) => {
{value} {value}
</SyntaxHighlighter> </SyntaxHighlighter>
</div> </div>
) );
}) });
CodeBlock.displayName = "CodeBlock" CodeBlock.displayName = "CodeBlock";
export { CodeBlock } export { CodeBlock };
...@@ -2,4 +2,4 @@ import ChatInput from "./chat-input"; ...@@ -2,4 +2,4 @@ import ChatInput from "./chat-input";
import ChatMessages from "./chat-messages"; import ChatMessages from "./chat-messages";
export { type ChatHandler, type Message } from "./chat.interface"; export { type ChatHandler, type Message } from "./chat.interface";
export { ChatMessages, ChatInput }; export { ChatInput, ChatMessages };
import { FC, memo } from "react" import { FC, memo } from "react";
import ReactMarkdown, { Options } from "react-markdown" import ReactMarkdown, { Options } from "react-markdown";
import remarkGfm from "remark-gfm" import remarkGfm from "remark-gfm";
import remarkMath from "remark-math" import remarkMath from "remark-math";
import { CodeBlock } from "./codeblock" import { CodeBlock } from "./codeblock";
const MemoizedReactMarkdown: FC<Options> = memo( const MemoizedReactMarkdown: FC<Options> = memo(
ReactMarkdown, ReactMarkdown,
(prevProps, nextProps) => (prevProps, nextProps) =>
prevProps.children === nextProps.children && prevProps.children === nextProps.children &&
prevProps.className === nextProps.className prevProps.className === nextProps.className,
) );
export default function Markdown({ content }: { content: string }) { export default function Markdown({ content }: { content: string }) {
return ( return (
...@@ -19,27 +19,27 @@ export default function Markdown({ content }: { content: string }) { ...@@ -19,27 +19,27 @@ export default function Markdown({ content }: { content: string }) {
remarkPlugins={[remarkGfm, remarkMath]} remarkPlugins={[remarkGfm, remarkMath]}
components={{ components={{
p({ children }) { 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 }) { code({ node, inline, className, children, ...props }) {
if (children.length) { if (children.length) {
if (children[0] == "") { if (children[0] == "") {
return ( return (
<span className="mt-1 animate-pulse cursor-default"></span> <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) { if (inline) {
return ( return (
<code className={className} {...props}> <code className={className} {...props}>
{children} {children}
</code> </code>
) );
} }
return ( return (
...@@ -49,11 +49,11 @@ export default function Markdown({ content }: { content: string }) { ...@@ -49,11 +49,11 @@ export default function Markdown({ content }: { content: string }) {
value={String(children).replace(/\n$/, "")} value={String(children).replace(/\n$/, "")}
{...props} {...props}
/> />
) );
}, },
}} }}
> >
{content} {content}
</MemoizedReactMarkdown> </MemoizedReactMarkdown>
) );
} }
'use client' "use client";
import * as React from 'react' import * as React from "react";
export interface useCopyToClipboardProps { export interface useCopyToClipboardProps {
timeout?: number timeout?: number;
} }
export function useCopyToClipboard({ export function useCopyToClipboard({
timeout = 2000 timeout = 2000,
}: useCopyToClipboardProps) { }: useCopyToClipboardProps) {
const [isCopied, setIsCopied] = React.useState<Boolean>(false) const [isCopied, setIsCopied] = React.useState<Boolean>(false);
const copyToClipboard = (value: string) => { const copyToClipboard = (value: string) => {
if (typeof window === 'undefined' || !navigator.clipboard?.writeText) { if (typeof window === "undefined" || !navigator.clipboard?.writeText) {
return return;
} }
if (!value) { if (!value) {
return return;
} }
navigator.clipboard.writeText(value).then(() => { navigator.clipboard.writeText(value).then(() => {
setIsCopied(true) setIsCopied(true);
setTimeout(() => { setTimeout(() => {
setIsCopied(false) setIsCopied(false);
}, timeout) }, timeout);
}) });
} };
return { isCopied, copyToClipboard } return { isCopied, copyToClipboard };
} }
...@@ -3,4 +3,4 @@ import ChatMessages from "./chat-messages"; ...@@ -3,4 +3,4 @@ import ChatMessages from "./chat-messages";
export type { ChatInputProps } from "./chat-input"; export type { ChatInputProps } from "./chat-input";
export type { Message } from "./chat-messages"; export type { Message } from "./chat-messages";
export { ChatMessages, ChatInput }; export { ChatInput, ChatMessages };
/** @type {import('next').NextConfig} */ /** @type {import('next').NextConfig} */
const nextConfig = { const nextConfig = {
experimental: { experimental: {
serverComponentsExternalPackages: ["llamaindex"], serverComponentsExternalPackages: ["llamaindex"],
}, },
} };
module.exports = nextConfig module.exports = nextConfig;
...@@ -3,4 +3,4 @@ module.exports = { ...@@ -3,4 +3,4 @@ module.exports = {
tailwindcss: {}, tailwindcss: {},
autoprefixer: {}, autoprefixer: {},
}, },
} };
...@@ -3,4 +3,4 @@ import ChatMessages from "./chat-messages"; ...@@ -3,4 +3,4 @@ import ChatMessages from "./chat-messages";
export type { ChatInputProps } from "./chat-input"; export type { ChatInputProps } from "./chat-input";
export type { Message } from "./chat-messages"; export type { Message } from "./chat-messages";
export { ChatMessages, ChatInput }; export { ChatInput, ChatMessages };
/** @type {import('next').NextConfig} */ /** @type {import('next').NextConfig} */
const nextConfig = { const nextConfig = {
experimental: { experimental: {
serverComponentsExternalPackages: ["llamaindex"], serverComponentsExternalPackages: ["llamaindex"],
}, },
} };
module.exports = nextConfig module.exports = nextConfig;
...@@ -3,4 +3,4 @@ module.exports = { ...@@ -3,4 +3,4 @@ module.exports = {
tailwindcss: {}, tailwindcss: {},
autoprefixer: {}, autoprefixer: {},
}, },
} };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment