somewhat working project initialization

This commit is contained in:
Ishaan Dey 2024-04-23 17:46:51 -04:00
parent ffee1b60c7
commit 75ac23094b
13 changed files with 177 additions and 17 deletions

View File

@ -7,6 +7,9 @@
"": { "": {
"name": "storage", "name": "storage",
"version": "0.0.0", "version": "0.0.0",
"dependencies": {
"zod": "^3.23.4"
},
"devDependencies": { "devDependencies": {
"@cloudflare/vitest-pool-workers": "^0.1.0", "@cloudflare/vitest-pool-workers": "^0.1.0",
"@cloudflare/workers-types": "^4.20240419.0", "@cloudflare/workers-types": "^4.20240419.0",
@ -2990,10 +2993,9 @@
} }
}, },
"node_modules/zod": { "node_modules/zod": {
"version": "3.23.0", "version": "3.23.4",
"resolved": "https://registry.npmjs.org/zod/-/zod-3.23.0.tgz", "resolved": "https://registry.npmjs.org/zod/-/zod-3.23.4.tgz",
"integrity": "sha512-OFLT+LTocvabn6q76BTwVB0hExEBS0IduTr3cqZyMqEDbOnYmcU+y0tUAYbND4uwclpBGi4I4UUBGzylWpjLGA==", "integrity": "sha512-/AtWOKbBgjzEYYQRNfoGKHObgfAZag6qUJX1VbHo2PRBgS+wfWagEY2mizjfyAPcGesrJOcx/wcl0L9WnVrHFw==",
"dev": true,
"funding": { "funding": {
"url": "https://github.com/sponsors/colinhacks" "url": "https://github.com/sponsors/colinhacks"
} }

View File

@ -15,5 +15,8 @@
"typescript": "^5.0.4", "typescript": "^5.0.4",
"vitest": "1.3.0", "vitest": "1.3.0",
"wrangler": "^3.0.0" "wrangler": "^3.0.0"
},
"dependencies": {
"zod": "^3.23.4"
} }
} }

View File

@ -1,22 +1,43 @@
const success = new Response('Success', { status: 200 }); import { z } from 'zod';
const notFound = new Response('Not Found', { status: 404 }); import startercode from './startercode';
const methodNotAllowed = new Response('Method Not Allowed', { status: 405 });
export interface Env { export interface Env {
DB: D1Database;
R2: R2Bucket; R2: R2Bucket;
} }
export default { export default {
async fetch( async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
request: Request, const success = new Response('Success', { status: 200 });
env: Env, const notFound = new Response('Not Found', { status: 404 });
ctx: ExecutionContext // : Promise<Response> const methodNotAllowed = new Response('Method Not Allowed', { status: 405 });
) {
const url = new URL(request.url); const url = new URL(request.url);
const path = url.pathname; const path = url.pathname;
const method = request.method; const method = request.method;
if (method === 'GET') {
if (path === '/api/init' && method === 'POST') {
const initSchema = z.object({
sandboxId: z.string(),
type: z.enum(['react', 'node']),
});
const body = await request.json();
const { sandboxId, type } = initSchema.parse(body);
// startercode.node.forEach(async (file) => {
// await env.R2.put(`${sandboxId}/${file.name}`, file.body);
// });
// parallel data fetching with promise.all:
await Promise.all(
startercode.node.map(async (file) => {
await env.R2.put(`projects/${sandboxId}/${file.name}`, file.body);
})
);
return success;
} else {
return notFound;
} }
}, },
}; };

View File

@ -0,0 +1 @@
console.log('Hello World!');

View File

@ -0,0 +1,12 @@
{
"name": "nodejs",
"version": "1.0.0",
"description": "",
"main": "index.js",
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@types/node": "^18.0.6"
}
}

View File

@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>React Starter Code</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.jsx"></script>
</body>
</html>

View File

@ -0,0 +1,26 @@
{
"name": "react",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/react": "^18.2.66",
"@types/react-dom": "^18.2.22",
"@vitejs/plugin-react": "^4.2.1",
"eslint": "^8.57.0",
"eslint-plugin-react": "^7.34.1",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.6",
"vite": "^5.2.0"
}
}

View File

@ -0,0 +1,23 @@
div {
width: 100%;
height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
h1 {
color: #fff;
margin: 0;
}
p {
color: #777;
margin: 0;
}
button {
padding: 8px 16px;
margin-top: 16px;
}

View File

@ -0,0 +1,21 @@
import './App.css'
import { useState } from 'react'
function App() {
const [count, setCount] = useState(0)
return (
<div>
<h1>React Starter Code</h1>
<p>
Edit App.jsx to get started.
</p>
<button onClick={() => setCount(count => count + 1)}>
Clicked {count} times
</button>
</div>
)
}
export default App

View File

@ -0,0 +1,9 @@
import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App.jsx'
ReactDOM.createRoot(document.getElementById('root')).render(
<React.StrictMode>
<App />
</React.StrictMode>,
)

View File

@ -0,0 +1,7 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
})

View File

@ -0,0 +1,22 @@
const startercode = {
node: [
{ name: 'index.js', body: `console.log("Hello World!")` },
{
name: 'package.json',
body: `{
"name": "nodejs",
"version": "1.0.0",
"description": "",
"main": "index.js",
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@types/node": "^18.0.6"
}
}`,
},
],
};
export default startercode;

View File

@ -76,15 +76,15 @@
} }
.gradient-button-bg { .gradient-button-bg {
background: radial-gradient(circle at top, #a5b4fc 0%, #3730a3 50%); /* violet 300 -> 800 */ background: radial-gradient(circle at top, #a5b4fc -10%, #3730a3 30%); /* violet 300 -> 800 */
} }
.gradient-button { .gradient-button {
background: radial-gradient(circle at bottom, #312e81 0%, hsl(0 0% 3.9%) 80%); /* violet 900 -> bg */ background: radial-gradient(circle at bottom, #312e81 -20%, hsl(0 0% 3.9%) 50%); /* violet 900 -> bg */
} }
.gradient-button-bg > div:hover { .gradient-button-bg > div:hover {
background: radial-gradient(circle at bottom, #312e81 0%, hsl(0 0% 3.9%) 130%); /* violet 900 -> bg */ background: radial-gradient(circle at bottom, #312e81 -20%, hsl(0 0% 3.9%) 100%); /* violet 900 -> bg */
} }
.gradient-project-card-bg { .gradient-project-card-bg {