Skip to content

Commit

Permalink
refactor: split playground into examples
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Apr 7, 2022
1 parent 9388b7d commit 62bf44d
Show file tree
Hide file tree
Showing 29 changed files with 150 additions and 54 deletions.
3 changes: 3 additions & 0 deletions examples/api-routes/api/hello.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { defineEventHandler } from 'h3'

export default defineEventHandler(() => 'Nitro is amazing!')
File renamed without changes.
4 changes: 4 additions & 0 deletions examples/api-routes/nitro.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { defineNitroConfig } from 'nitropack'

export default defineNitroConfig({
})
11 changes: 11 additions & 0 deletions examples/api-routes/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "example-api-routes",
"private": true,
"scripts": {
"dev": "nitro dev",
"build": "nitro build"
},
"devDependencies": {
"nitropack": "latest"
}
}
2 changes: 2 additions & 0 deletions examples/api-routes/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<a href="/api/hello">/api/hello</a><br>
<a href="/api/hello/world">/api/hello/world</a><br>
3 changes: 3 additions & 0 deletions examples/api-routes/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "./.nitro/types/tsconfig.json"
}
6 changes: 6 additions & 0 deletions examples/cached-handler/api/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { defineCachedEventHandler } from '#nitro'

export default defineCachedEventHandler(async () => {
await new Promise(resolve => setTimeout(resolve, 1000))
return `Response generated at ${new Date().toISOString()} (took 1 second)`
})
4 changes: 4 additions & 0 deletions examples/cached-handler/nitro.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { defineNitroConfig } from 'nitropack'

export default defineNitroConfig({
})
11 changes: 11 additions & 0 deletions examples/cached-handler/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "example-cached-handler",
"private": true,
"scripts": {
"dev": "nitro dev",
"build": "nitro build"
},
"devDependencies": {
"nitropack": "latest"
}
}
3 changes: 3 additions & 0 deletions examples/cached-handler/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "./.nitro/types/tsconfig.json"
}
4 changes: 4 additions & 0 deletions examples/hello-world/nitro.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { defineNitroConfig } from 'nitropack'

export default defineNitroConfig({
})
4 changes: 2 additions & 2 deletions examples/hello-world/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "nitro-example-hello-world",
"name": "example-hello-world",
"private": true,
"scripts": {
"dev": "nitro dev",
"build": "nitro build"
},
"devDependencies": {
"nitropack-edge": "latest"
"nitropack": "latest"
}
}
3 changes: 3 additions & 0 deletions examples/hello-world/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "./.nitro/types/tsconfig.json"
}
File renamed without changes.
4 changes: 4 additions & 0 deletions examples/middleware/nitro.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { defineNitroConfig } from 'nitropack'

export default defineNitroConfig({
})
11 changes: 11 additions & 0 deletions examples/middleware/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "example-middleware",
"private": true,
"scripts": {
"dev": "nitro dev",
"build": "nitro build"
},
"devDependencies": {
"nitropack": "latest"
}
}
3 changes: 3 additions & 0 deletions examples/middleware/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "./.nitro/types/tsconfig.json"
}
7 changes: 7 additions & 0 deletions examples/plugins/nitro.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineNitroConfig } from 'nitropack'

export default defineNitroConfig({
plugins: [
'~/plugins/test'
]
})
11 changes: 11 additions & 0 deletions examples/plugins/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "example-plugins",
"private": true,
"scripts": {
"dev": "nitro dev",
"build": "nitro build"
},
"devDependencies": {
"nitropack": "latest"
}
}
File renamed without changes.
3 changes: 3 additions & 0 deletions examples/plugins/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "./.nitro/types/tsconfig.json"
}
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
"description": "Next Generation Web Tooling",
"license": "MIT",
"type": "module",
"workspaces": [
"./examples/**"
],
"resolutions": {
"nitropack": "link:."
},
"exports": {
".": "./dist/index.mjs",
"./cli": "./dist/cli.mjs",
Expand All @@ -22,6 +28,7 @@
"scripts": {
"build": "unbuild",
"dev": "yarn nitro dev playground",
"example": "yarn workspace example-$0 dev",
"dev:build": "yarn nitro build playground",
"dev:start": "node playground/.output/server/index.mjs",
"lint": "eslint --ext .ts,.mjs,.cjs .",
Expand Down
5 changes: 0 additions & 5 deletions playground/api/error.ts

This file was deleted.

9 changes: 0 additions & 9 deletions playground/api/swr.ts

This file was deleted.

3 changes: 0 additions & 3 deletions playground/api/test.ts

This file was deleted.

25 changes: 1 addition & 24 deletions playground/app.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,3 @@
import { eventHandler } from 'h3'

export default eventHandler(() => {
const links = [
'/api/hello/you',
'/api/test',
'/api/swr',
'/api/error'
]
return `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="icon" type="image/x-icon" href="/favicon.ico">
<title>Nitro Playground</title>
</head>
<body>
<h1>Welcome to Nitro playground!</h1>
<ul>
${links.map(link => ` <li><a href="${link}">${link}</a></li>`).join('\n')}
</ul>
</body>
</html>`
})
export default eventHandler(() => '<h1>Hello Nitro!</h1>')
12 changes: 1 addition & 11 deletions playground/nitro.config.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
import { defineNitroConfig } from '../src'

export default defineNitroConfig({
renderer: './app',
prerender: {
crawlLinks: true
},
// baseURL: '/app',
routes: {
'/api/swr': { swr: true }
},
plugins: [
'~/plugins/test'
]
renderer: '~/app'
})
Binary file removed playground/public/favicon.ico
Binary file not shown.
46 changes: 46 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3442,6 +3442,46 @@ __metadata:
languageName: node
linkType: hard

"example-api-routes@workspace:examples/api-routes":
version: 0.0.0-use.local
resolution: "example-api-routes@workspace:examples/api-routes"
dependencies:
nitropack: latest
languageName: unknown
linkType: soft

"example-cached-handler@workspace:examples/cached-handler":
version: 0.0.0-use.local
resolution: "example-cached-handler@workspace:examples/cached-handler"
dependencies:
nitropack: latest
languageName: unknown
linkType: soft

"example-hello-world@workspace:examples/hello-world":
version: 0.0.0-use.local
resolution: "example-hello-world@workspace:examples/hello-world"
dependencies:
nitropack: latest
languageName: unknown
linkType: soft

"example-middleware@workspace:examples/middleware":
version: 0.0.0-use.local
resolution: "example-middleware@workspace:examples/middleware"
dependencies:
nitropack: latest
languageName: unknown
linkType: soft

"example-plugins@workspace:examples/plugins":
version: 0.0.0-use.local
resolution: "example-plugins@workspace:examples/plugins"
dependencies:
nitropack: latest
languageName: unknown
linkType: soft

"execa@npm:^5.1.1":
version: 5.1.1
resolution: "execa@npm:5.1.1"
Expand Down Expand Up @@ -5602,6 +5642,12 @@ __metadata:
languageName: node
linkType: hard

"nitropack@link:.::locator=nitropack%40workspace%3A.":
version: 0.0.0-use.local
resolution: "nitropack@link:.::locator=nitropack%40workspace%3A."
languageName: node
linkType: soft

"nitropack@workspace:.":
version: 0.0.0-use.local
resolution: "nitropack@workspace:."
Expand Down

0 comments on commit 62bf44d

Please sign in to comment.