tambahan
This commit is contained in:
160
bin/src/app-create.ts
Normal file
160
bin/src/app-create.ts
Normal file
@@ -0,0 +1,160 @@
|
||||
import ora from "ora"
|
||||
|
||||
const appRoutesTemplate = `
|
||||
import { BrowserRouter, Routes, Route } from "react-router-dom";
|
||||
import Home from "./pages/Home";
|
||||
import NotFound from "./pages/NotFound";
|
||||
|
||||
export default function AppRoutes() {
|
||||
return (
|
||||
<BrowserRouter>
|
||||
<Routes>
|
||||
<Route path="/" element={<Home />} />
|
||||
<Route path="*" element={<NotFound />} />
|
||||
</Routes>
|
||||
</BrowserRouter>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
`
|
||||
|
||||
const postCssTemplate = `
|
||||
module.exports = {
|
||||
plugins: {
|
||||
'postcss-preset-mantine': {},
|
||||
'postcss-simple-vars': {
|
||||
variables: {
|
||||
'mantine-breakpoint-xs': '36em',
|
||||
'mantine-breakpoint-sm': '48em',
|
||||
'mantine-breakpoint-md': '62em',
|
||||
'mantine-breakpoint-lg': '75em',
|
||||
'mantine-breakpoint-xl': '88em',
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
`
|
||||
|
||||
const appTemplate = `
|
||||
import '@mantine/core/styles.css';
|
||||
|
||||
import { MantineProvider } from '@mantine/core';
|
||||
import AppRoutes from './AppRoutes';
|
||||
|
||||
export function App() {
|
||||
return <MantineProvider>
|
||||
<AppRoutes />
|
||||
</MantineProvider>;
|
||||
}
|
||||
`
|
||||
|
||||
const homeTemplate = `
|
||||
export default function Home() {
|
||||
return (
|
||||
<div>
|
||||
<h1>Home</h1>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
`
|
||||
|
||||
const serverTemplate = `
|
||||
import Elysia from "elysia";
|
||||
import Swagger from "@elysiajs/swagger";
|
||||
import html from "./index.html"
|
||||
|
||||
const Docs = new Elysia({})
|
||||
.use(Swagger({
|
||||
path: "/docs",
|
||||
}))
|
||||
|
||||
|
||||
const Api = new Elysia({
|
||||
prefix: "/api",
|
||||
})
|
||||
.use(Docs)
|
||||
.post("/hello", () => "Hello, world!")
|
||||
|
||||
|
||||
const app = new Elysia()
|
||||
.use(Api)
|
||||
.get("/*", html)
|
||||
.listen(3000, () => {
|
||||
console.log("Server running at http://localhost:3000");
|
||||
});
|
||||
|
||||
|
||||
export type Server = typeof app;
|
||||
`
|
||||
|
||||
const notFoundTemplate = `
|
||||
export default function NotFound() {
|
||||
return (
|
||||
<div>
|
||||
<h1>404 Not Found</h1>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
`
|
||||
|
||||
|
||||
|
||||
const cmd = (appName: string) => `
|
||||
bun init --react ${appName}
|
||||
echo "init react"
|
||||
cd ${appName}
|
||||
echo "cd ${appName}"
|
||||
bun add react-router-dom
|
||||
echo "add react-router-dom"
|
||||
bun add @mantine/core @mantine/hooks
|
||||
echo "add @mantine/core @mantine/hooks"
|
||||
bun add --dev postcss postcss-preset-mantine postcss-simple-vars
|
||||
echo "add --dev postcss postcss-preset-mantine postcss-simple-vars"
|
||||
bun add elysia @elysiajs/cors @elysiajs/swagger @elysiajs/eden
|
||||
echo "add elysia @elysiajs/cors @elysiajs/swagger @elysiajs/eden"
|
||||
cat <<EOF > postcss.config.js
|
||||
${postCssTemplate}
|
||||
EOF
|
||||
echo "postcss.config.js"
|
||||
cat <<EOF > src/App.tsx
|
||||
${appTemplate}
|
||||
EOF
|
||||
echo "src/App.tsx"
|
||||
|
||||
cat <<EOF > src/AppRoutes.tsx
|
||||
${appRoutesTemplate}
|
||||
EOF
|
||||
echo "src/AppRoutes.tsx"
|
||||
|
||||
mkdir src/pages
|
||||
echo "mkdir src/pages"
|
||||
cat <<EOF > src/pages/Home.tsx
|
||||
${homeTemplate}
|
||||
EOF
|
||||
echo "src/pages/Home.tsx"
|
||||
|
||||
cat <<EOF > src/index.tsx
|
||||
${serverTemplate}
|
||||
EOF
|
||||
echo "src/index.tsx"
|
||||
|
||||
cat <<EOF > src/pages/NotFound.tsx
|
||||
${notFoundTemplate}
|
||||
EOF
|
||||
echo "src/pages/NotFound.tsx"
|
||||
|
||||
rm src/APITester.tsx
|
||||
|
||||
ls
|
||||
|
||||
echo "✅ done"
|
||||
`
|
||||
|
||||
|
||||
export default async function appCreate({ appName }: { appName: string }) {
|
||||
const spinner = ora(`Creating app ${appName}...`).start();
|
||||
const { stdout } = Bun.spawnSync(["bash", "-c", cmd(appName)]);
|
||||
spinner.stop();
|
||||
console.log(stdout.toString());
|
||||
}
|
||||
Reference in New Issue
Block a user