这是indexloc提供的服务,不要输入任何密码
Skip to content

Add kitchen sink example #198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions examples/kitchen-sink/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.DS_Store
node_modules
.turbo
*.log
.next
dist
dist-ssr
*.local
.env
.cache
server/dist
public/dist
.turbo
9 changes: 9 additions & 0 deletions examples/kitchen-sink/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
node_modules
.next
build
dist
*.tsbuildinfo
*.gitignore
*.svg
*.lock
*.npmignore
4 changes: 4 additions & 0 deletions examples/kitchen-sink/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": false,
"semi": true
}
29 changes: 29 additions & 0 deletions examples/kitchen-sink/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# `turborepo` kitchen sink starter

This is an official Yarn v1 starter Turborepo with multiple meta-frameworks all working in harmony and sharing packages.

## What's inside?

This Turborepo includes the following packages and apps:

### Apps and Packages

- `api`: an [Express](https://expressjs.com/) server
- `storefront`: a [Next.js](https://nextjs.org) app
- `admin`: a [Vite](https://vitejs.dev/) single page app
- `blog`: a [Remix](https://remix.run/) blog
- `logger`: isomorphic logger (a small wrapper around console.log)
- `ui`: a dummy React UI library (which contains a single `<CounterButton>` component)
- `scripts`: Jest and eslint configurations
- `tsconfig`: tsconfig.json;s used throughout the monorepo

Each package and app is 100% [Typescript](https://www.typescriptlang.org/).

### Utilities

This turborepo has some additional tools already setup for you:

- [Typescript](https://www.typescriptlang.org/) for static type checking
- [ESLint](https://eslint.org/) for code linting
- [Jest](https://jestjs.io) test runner for all things JavaScript
- [Prettier](https://prettier.io) for code formatting
1 change: 1 addition & 0 deletions examples/kitchen-sink/apps/admin/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require("scripts/eslint-preset");
12 changes: 12 additions & 0 deletions examples/kitchen-sink/apps/admin/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
26 changes: 26 additions & 0 deletions examples/kitchen-sink/apps/admin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "admin",
"private": true,
"version": "0.0.0",
"scripts": {
"dev": "vite --port 3001 --clearScreen false",
"build": "vite build",
"deploy": "vercel deploy dist --team=turborepo --confirm",
"lint": "TIMING=1 eslint src/**/*.tsx --fix && tsc --noEmit",
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
},
"dependencies": {
"react": "^17.0.2",
"react-dom": "^17.0.2",
"ui": "*"
},
"devDependencies": {
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"@vitejs/plugin-react-refresh": "^1.3.6",
"scripts": "*",
"tsconfig": "*",
"typescript": "^4.2.4",
"vite": "^2.6.14"
}
}
42 changes: 42 additions & 0 deletions examples/kitchen-sink/apps/admin/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
.App {
text-align: center;
}

.App-logo {
height: 40vmin;
pointer-events: none;
}

@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
}

.App-header {
background-color: #282c34;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}

.App-link {
color: #61dafb;
}

@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}

button {
font-size: calc(10px + 2vmin);
}
43 changes: 43 additions & 0 deletions examples/kitchen-sink/apps/admin/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import * as React from "react";
import logo from "./logo.svg";
import "./App.css";
import { CounterButton } from "ui";

function App() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<h1>Turborepo Admin</h1>
<p>This app is powered by Vite.</p>
<p>
<CounterButton />
</p>
<p>
Edit <code>App.tsx</code> and save to test HMR updates.
</p>
<p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
{" | "}
<a
className="App-link"
href="https://vitejs.dev/guide/features.html"
target="_blank"
rel="noopener noreferrer"
>
Vite Docs
</a>
</p>
</header>
</div>
);
}

export default App;
8 changes: 8 additions & 0 deletions examples/kitchen-sink/apps/admin/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
"Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
7 changes: 7 additions & 0 deletions examples/kitchen-sink/apps/admin/src/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions examples/kitchen-sink/apps/admin/src/main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as React from "react";
import * as ReactDOM from "react-dom";
import "./index.css";
import App from "./App";

ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById("root")
);
9 changes: 9 additions & 0 deletions examples/kitchen-sink/apps/admin/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"exclude": ["node_modules"],
"extends": "tsconfig/vite.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "dist"
},
"include": ["src"]
}
6 changes: 6 additions & 0 deletions examples/kitchen-sink/apps/admin/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import reactRefresh from "@vitejs/plugin-react-refresh";
import { defineConfig } from "vite";

export default defineConfig({
plugins: [reactRefresh()],
});
1 change: 1 addition & 0 deletions examples/kitchen-sink/apps/api/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require("scripts/eslint-preset");
36 changes: 36 additions & 0 deletions examples/kitchen-sink/apps/api/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "api",
"version": "0.0.0",
"private": true,
"scripts": {
"test": "jest --detectOpenHandles",
"dev": "nodemon --exec \"node -r esbuild-register ./src/index.ts\" -e .ts",
"start": "node -r esbuild-register ./src/index.ts",
"build": "tsc",
"lint": "tsc --noEmit && TIMING=1 eslint src --fix",
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
},
"devDependencies": {
"scripts": "*",
"tsconfig": "*",
"@types/body-parser": "^1.19.0",
"@types/cors": "^2.8.10",
"@types/express": "^4.17.12",
"@types/morgan": "^1.9.2",
"@types/node": "^15.12.2",
"@types/supertest": "^2.0.11",
"esbuild-register": "^2.5.0",
"supertest": "^6.1.3",
"typescript": "^4.2.4"
},
"jest": {
"preset": "scripts/jest/node"
},
"dependencies": {
"logger": "*",
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"express": "^4.17.1",
"morgan": "^1.10.0"
}
}
22 changes: 22 additions & 0 deletions examples/kitchen-sink/apps/api/src/__tests__/server.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import supertest from "supertest";
import { createServer } from "../server";

describe("server", () => {
it("health check returns 200", async () => {
await supertest(createServer())
.get("/healthz")
.expect(200)
.then((res) => {
expect(res.body.ok).toBe(true);
});
});

it("message endpoint says hello", async () => {
await supertest(createServer())
.get("/message/jared")
.expect(200)
.then((res) => {
expect(res.body).toEqual({ message: "hello jared" });
});
});
});
4 changes: 4 additions & 0 deletions examples/kitchen-sink/apps/api/src/__tests__/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.json",
"include": [".", "../."]
}
9 changes: 9 additions & 0 deletions examples/kitchen-sink/apps/api/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { createServer } from "./server";
import { log } from "logger";

const port = process.env.PORT || 5000;
const server = createServer();

server.listen(port, () => {
log(`api running on ${port}`);
});
22 changes: 22 additions & 0 deletions examples/kitchen-sink/apps/api/src/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { json, urlencoded } from "body-parser";
import express from "express";
import morgan from "morgan";
import cors from "cors";

export const createServer = () => {
const app = express();
app
.disable("x-powered-by")
.use(morgan("dev"))
.use(urlencoded({ extended: true }))
.use(json())
.use(cors())
.get("/message/:name", (req, res) => {
return res.json({ message: `hello ${req.params.name}` });
})
.get("/healthz", (req, res) => {
return res.json({ ok: true });
});

return app;
};
11 changes: 11 additions & 0 deletions examples/kitchen-sink/apps/api/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"lib": ["ES2015"],
"module": "CommonJS",
"outDir": "./dist",
"rootDir": "./src"
},
"exclude": ["node_modules"],
"extends": "tsconfig/base.json",
"include": ["src"]
}
8 changes: 8 additions & 0 deletions examples/kitchen-sink/apps/blog/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules

.cache
.vercel
.output

public/build
api/build
34 changes: 34 additions & 0 deletions examples/kitchen-sink/apps/blog/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Welcome to Remix!

- [Remix Docs](https://remix.run/docs)

## Deployment

After having run the `create-remix` command and selected "Vercel" as a deployment target, you only need to [import your Git repository](https://vercel.com/new) into Vercel, and it will be deployed.

If you'd like to avoid using a Git repository, you can also deploy the directory by running [Vercel CLI](https://vercel.com/cli):

```sh
npm i -g vercel
vercel
```

It is generally recommended to use a Git repository, because future commits will then automatically be deployed by Vercel, through its [Git Integration](https://vercel.com/docs/concepts/git).

## Development

To run your Remix app locally, make sure your project's local dependencies are installed:

```sh
npm install
```

Afterwards, start the Remix development server like so:

```sh
npm run dev
```

Open up [http://localhost:3000](http://localhost:3000) and you should be ready to go!

If you're used to using the `vercel dev` command provided by [Vercel CLI](https://vercel.com/cli) instead, you can also use that, but it's not needed.
5 changes: 5 additions & 0 deletions examples/kitchen-sink/apps/blog/api/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const { createRequestHandler } = require("@remix-run/vercel");

module.exports = createRequestHandler({
build: require("./build"),
});
Loading