|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +project_name="${1:-}" |
| 5 | +if [[ -z "$project_name" ]]; then |
| 6 | + echo "usage: bash scripts/init-artifact.sh <project-name>" >&2 |
| 7 | + exit 2 |
| 8 | +fi |
| 9 | +script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 10 | + |
| 11 | +if [[ -e "$project_name" ]]; then |
| 12 | + echo "error: target already exists: $project_name" >&2 |
| 13 | + exit 1 |
| 14 | +fi |
| 15 | + |
| 16 | +mkdir -p "$project_name/src/components/ui" |
| 17 | +cd "$project_name" |
| 18 | + |
| 19 | +cat > package.json <<'JSON' |
| 20 | +{ |
| 21 | + "type": "module", |
| 22 | + "scripts": { |
| 23 | + "dev": "vite --host 0.0.0.0", |
| 24 | + "build": "vite build", |
| 25 | + "bundle": "bash scripts/bundle-artifact.sh" |
| 26 | + }, |
| 27 | + "dependencies": { |
| 28 | + "@vitejs/plugin-react": "^4.3.0", |
| 29 | + "autoprefixer": "^10.4.19", |
| 30 | + "clsx": "^2.1.1", |
| 31 | + "lucide-react": "^0.468.0", |
| 32 | + "postcss": "^8.4.38", |
| 33 | + "react": "^18.2.0", |
| 34 | + "react-dom": "^18.2.0", |
| 35 | + "tailwind-merge": "^2.3.0", |
| 36 | + "tailwindcss": "^3.4.1", |
| 37 | + "typescript": "^5.4.5", |
| 38 | + "vite": "^5.2.0" |
| 39 | + }, |
| 40 | + "devDependencies": { |
| 41 | + "@types/react": "^18.2.66", |
| 42 | + "@types/react-dom": "^18.2.22", |
| 43 | + "html-inline": "^1.2.0", |
| 44 | + "parcel": "^2.12.0" |
| 45 | + } |
| 46 | +} |
| 47 | +JSON |
| 48 | + |
| 49 | +cat > index.html <<'HTML' |
| 50 | +<!doctype html> |
| 51 | +<html lang="en"> |
| 52 | + <head> |
| 53 | + <meta charset="UTF-8" /> |
| 54 | + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
| 55 | + <title>Claude Artifact</title> |
| 56 | + </head> |
| 57 | + <body> |
| 58 | + <div id="root"></div> |
| 59 | + <script type="module" src="/src/main.tsx"></script> |
| 60 | + </body> |
| 61 | +</html> |
| 62 | +HTML |
| 63 | + |
| 64 | +cat > src/main.tsx <<'TSX' |
| 65 | +import React from "react"; |
| 66 | +import { createRoot } from "react-dom/client"; |
| 67 | +import { App } from "./App"; |
| 68 | +import "./index.css"; |
| 69 | +
|
| 70 | +createRoot(document.getElementById("root")!).render( |
| 71 | + <React.StrictMode> |
| 72 | + <App /> |
| 73 | + </React.StrictMode> |
| 74 | +); |
| 75 | +TSX |
| 76 | + |
| 77 | +cat > src/App.tsx <<'TSX' |
| 78 | +export function App() { |
| 79 | + return ( |
| 80 | + <main className="min-h-screen bg-zinc-950 text-zinc-50"> |
| 81 | + <section className="mx-auto flex min-h-screen max-w-5xl flex-col justify-center px-8"> |
| 82 | + <p className="mb-4 text-sm uppercase tracking-[0.2em] text-cyan-300">Claude Artifact</p> |
| 83 | + <h1 className="max-w-3xl text-5xl font-semibold leading-tight"> |
| 84 | + Replace this starter with the user's actual interactive experience. |
| 85 | + </h1> |
| 86 | + <p className="mt-6 max-w-2xl text-lg text-zinc-300"> |
| 87 | + Use React state, focused components, and Tailwind utilities. Keep the final artifact |
| 88 | + self-contained by running the bundle script from the project root. |
| 89 | + </p> |
| 90 | + </section> |
| 91 | + </main> |
| 92 | + ); |
| 93 | +} |
| 94 | +TSX |
| 95 | + |
| 96 | +cat > src/index.css <<'CSS' |
| 97 | +@tailwind base; |
| 98 | +@tailwind components; |
| 99 | +@tailwind utilities; |
| 100 | +
|
| 101 | +* { |
| 102 | + box-sizing: border-box; |
| 103 | +} |
| 104 | +
|
| 105 | +body { |
| 106 | + margin: 0; |
| 107 | +} |
| 108 | +CSS |
| 109 | + |
| 110 | +cat > src/components/ui/README.md <<'MD' |
| 111 | +# UI Components |
| 112 | +
|
| 113 | +Put small reusable shadcn/ui-style components here. Keep component APIs narrow |
| 114 | +and prefer plain Tailwind classes unless a reusable abstraction removes real |
| 115 | +duplication. |
| 116 | +MD |
| 117 | + |
| 118 | +cat > tsconfig.json <<'JSON' |
| 119 | +{ |
| 120 | + "compilerOptions": { |
| 121 | + "target": "ES2020", |
| 122 | + "useDefineForClassFields": true, |
| 123 | + "lib": ["DOM", "DOM.Iterable", "ES2020"], |
| 124 | + "allowJs": false, |
| 125 | + "skipLibCheck": true, |
| 126 | + "esModuleInterop": true, |
| 127 | + "allowSyntheticDefaultImports": true, |
| 128 | + "strict": true, |
| 129 | + "forceConsistentCasingInFileNames": true, |
| 130 | + "module": "ESNext", |
| 131 | + "moduleResolution": "Node", |
| 132 | + "resolveJsonModule": true, |
| 133 | + "isolatedModules": true, |
| 134 | + "noEmit": true, |
| 135 | + "jsx": "react-jsx", |
| 136 | + "baseUrl": ".", |
| 137 | + "paths": { |
| 138 | + "@/*": ["src/*"] |
| 139 | + } |
| 140 | + }, |
| 141 | + "include": ["src"], |
| 142 | + "references": [] |
| 143 | +} |
| 144 | +JSON |
| 145 | + |
| 146 | +cat > vite.config.ts <<'TS' |
| 147 | +import react from "@vitejs/plugin-react"; |
| 148 | +import { defineConfig } from "vite"; |
| 149 | +
|
| 150 | +export default defineConfig({ |
| 151 | + plugins: [react()], |
| 152 | + resolve: { |
| 153 | + alias: { |
| 154 | + "@": "/src", |
| 155 | + }, |
| 156 | + }, |
| 157 | +}); |
| 158 | +TS |
| 159 | + |
| 160 | +cat > tailwind.config.js <<'JS' |
| 161 | +/** @type {import('tailwindcss').Config} */ |
| 162 | +export default { |
| 163 | + content: ["./index.html", "./src/**/*.{ts,tsx}"], |
| 164 | + theme: { |
| 165 | + extend: {}, |
| 166 | + }, |
| 167 | + plugins: [], |
| 168 | +}; |
| 169 | +JS |
| 170 | + |
| 171 | +cat > postcss.config.js <<'JS' |
| 172 | +export default { |
| 173 | + plugins: { |
| 174 | + tailwindcss: {}, |
| 175 | + autoprefixer: {}, |
| 176 | + }, |
| 177 | +}; |
| 178 | +JS |
| 179 | + |
| 180 | +cat > .parcelrc <<'JSON' |
| 181 | +{ |
| 182 | + "extends": "@parcel/config-default" |
| 183 | +} |
| 184 | +JSON |
| 185 | + |
| 186 | +mkdir -p scripts |
| 187 | +cp "$script_dir/bundle-artifact.sh" scripts/bundle-artifact.sh |
| 188 | +chmod +x scripts/bundle-artifact.sh |
| 189 | + |
| 190 | +echo "Created artifact project: $project_name" |
| 191 | +echo "Next: cd $project_name && npm install && npm run dev" |
0 commit comments