Skip to content
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.next
examples/**/*.lock
dist
node_modules
6 changes: 2 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@

_(This will install the `polydev` binary globally.)_

1. `yarn dev`
1. `yarn dev EXAMPLE_NAME`

_(This is for "development" mode)_

1. `yarn start`
1. `yarn start EXAMPLE_NAME`

_(This is for "production" mode)_

This project is a living example of how to use Polydev!

## How to Publish

1. `yarn release`
11 changes: 0 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,6 @@ Route handlers can be any of the following:

This is good for when you want to have a separate API server open on `process.env.PORT` that's not part of your application.

## Roadmap

- [ ] [Reload browser on double-save](/../../issues/1)
- [ ] [Loading screen, for slow routes](/../../issues/2)
- [ ] [Option to install missing modules](/../../issues/3)
- [ ] [ESM support](/../../issues/4)
- [x] [TypeScript support](/../../issues/5)
- [ ] [Better errors for broken routes/modules](/../../issues/6)
- [ ] [Storybook example](/../../issues/7)
- [ ] [View All][issues]

## Contributing

> See [CONTRIBUTING.md](/CONTRIBUTING.md).
Expand Down
File renamed without changes.
9 changes: 9 additions & 0 deletions examples/404/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"private": true,
"name": "404-example",
"version": "0.0.0",
"scripts": {
"dev": "polydev",
"start": "NODE_ENV=production polydev"
}
}
9 changes: 9 additions & 0 deletions examples/500/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"private": true,
"name": "404-example",
"version": "0.0.0",
"scripts": {
"dev": "polydev",
"start": "NODE_ENV=production polydev"
}
}
2 changes: 1 addition & 1 deletion routes/error/index.js → examples/500/routes/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = async (req, res) => {
module.exports = (req, res) => {
throw new Error("💥 Whoopsiedoodle! 🤷‍♂️ ")
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@
"dependencies": {
"apollo-server": "^2.3.1",
"graphql": "^14.0.2"
},
"scripts": {
"dev": "polydev",
"start": "NODE_ENV=production polydev"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ const apollo = new ApolloServer({
const app = express()

// Mount GraphQL at the root, not `/graphql` by default
apollo.applyMiddleware({ app, path: "/apollo-server" })
apollo.applyMiddleware({ app, path: "/" })

module.exports = app
12 changes: 12 additions & 0 deletions examples/custom-server/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"private": true,
"name": "custom-server-example",
"version": "0.0.0",
"scripts": {
"dev": "polydev",
"start": "NODE_ENV=production polydev"
},
"dependencies": {
"express": "^4.16.4"
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Request, Response } from "express"

let hits = 0

export default (req: Request, res: Response) => {
module.exports = (req, res) => {
hits++

res.send(`
Expand All @@ -14,7 +12,7 @@ export default (req: Request, res: Response) => {
<section>
<main>
<h1>
👋 Howdy from <kbd>TypeScript</kbd>
👋 Howdy from a <kbd>custom-server</kbd>
</h1>

<p>
Expand Down
File renamed without changes.
9 changes: 9 additions & 0 deletions examples/dev-only/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"private": true,
"name": "dev-only-example",
"version": "0.0.0",
"scripts": {
"dev": "polydev",
"start": "NODE_ENV=production polydev"
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@
"version": "0.0.0",
"dependencies": {
"express": "^4.16.4"
},
"scripts": {
"dev": "polydev",
"start": "NODE_ENV=production polydev"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const express = require("express")

let hits = 0

module.exports = express().get("/express", (req, res) => {
module.exports = express().get("/", (req, res) => {
hits++

res.send(`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@
"express-graphql": "^0.7.1",
"graphql": "^14.0.2",
"graphql-tools": "^4.0.3"
},
"scripts": {
"dev": "polydev",
"start": "NODE_ENV=production polydev"
}
}
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions examples/logo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"private": true,
"name": "logo-example",
"version": "0.0.0",
"scripts": {
"dev": "polydev",
"start": "NODE_ENV=production polydev"
}
}
File renamed without changes.
9 changes: 9 additions & 0 deletions examples/missing-module/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"private": true,
"name": "missing-module-example",
"version": "0.0.0",
"scripts": {
"dev": "polydev",
"start": "NODE_ENV=production polydev"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const humanize = require("humanize")
const THIS_PACKAGE_WONT_EXIST = require("THIS_PACKAGE_WONT_EXIST")

module.exports = (req, res) => {
res.send(`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"react-dom": "^16.7.0"
},
"scripts": {
"build": "next build"
"dev": "polydev",
"prestart": "next build",
"start": "NODE_ENV=production polydev"
}
}
File renamed without changes.
10 changes: 10 additions & 0 deletions examples/next/routes/index.*.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const express = require("express")
const next = require("next")

const dev = process.env.NODE_ENV !== "production"
const pages = next({ dev })
const handle = pages.getRequestHandler()

module.exports = pages.prepare().then(() => {
return express().get("*", (req, res) => handle(req, res))
})
9 changes: 9 additions & 0 deletions examples/params/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"private": true,
"name": "params-example",
"version": "0.0.0",
"scripts": {
"dev": "polydev",
"start": "NODE_ENV=production polydev"
}
}
1 change: 1 addition & 0 deletions examples/params/routes/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = (req, res) => res.redirect("/users/howdy")
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@
"dependencies": {
"@toverux/expresse": "^2.4.0",
"express": "^4.16.4"
},
"scripts": {
"dev": "polydev",
"start": "NODE_ENV=production polydev"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const path = require("path")
const time = () => new Date().toLocaleTimeString("en-US")

module.exports = express()
.get("/sse", (req, res) => {
.get("/", (req, res) => {
const eventUrl = path.join(req.originalUrl, "time")

res.send(`
Expand Down Expand Up @@ -45,7 +45,7 @@ module.exports = express()
</script>
`)
})
.get("/sse/time", sse(), (req, res) => {
.get("/time", sse(), (req, res) => {
let messageId = parseInt(req.header("Last-Event-ID"), 10) || 0

setInterval(() => {
Expand Down
19 changes: 19 additions & 0 deletions examples/typescript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"private": true,
"name": "typescript-example",
"version": "0.0.0",
"devDependencies": {
"ts-node": "^8.0.3",
"typescript": "^3.3.3333"
},
"scripts": {
"dev": "polydev --require ts-node/register",
"prestart": "tsc",
"start": "cd dist && NODE_ENV=production polydev"
},
"dependencies": {
"@types/express": "^4.16.1",
"react": "^16.8.4",
"react-dom": "^16.8.4"
}
}
39 changes: 39 additions & 0 deletions examples/typescript/routes/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Request, Response } from "express"
import * as React from "react"
import { renderToStaticMarkup } from "react-dom/server"

let hits = 0

export default (req: Request, res: Response) => {
hits++

res.send(
renderToStaticMarkup(
<>
<link
href="https://fonts.googleapis.com/css?family=Quicksand:300,500"
rel="stylesheet"
/>
<link href="/_polydev/styles.css" rel="stylesheet" />

<div id="splash" />

<section>
<main>
<h1>
👋 Howdy from <kbd>TypeScript</kbd>
</h1>

<p>
<kbd>{hits}</kbd> {hits ? "hits" : "hit"}
</p>
</main>

<footer>
<a href="/">&laquo; Back</a>
</footer>
</section>
</>
)
)
}
8 changes: 8 additions & 0 deletions examples/typescript/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"allowJs": true,
"jsx": "react",
"outDir": "dist",
"rootDir": "."
}
}
45 changes: 35 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,39 @@
{
"private": true,
"name": "polydev",
"version": "1.5.0",
"bin": "./bin/polydev",
"main": "./src/index.js",
"repository": "git@github.com:ericclemmons/polydev.git",
"author": "Eric Clemmons <eric@smarterspam.com>",
"license": "MIT",
"files": [
"bin",
"src"
],
"scripts": {
"postinstall": "yarn workspace polydev link",
"dev": "DEBUG=polydev polydev -r ts-node/register",
"dev:server": "DEBUG=polydev node server",
"release": "cd packages/polydev && npx np --yolo",
"prestart": "yarn workspace next-example build",
"prestart:server": "yarn workspace next-example build",
"start": "NODE_ENV=production polydev",
"start:server": "NODE_ENV=production node server"
"dev": "./scripts/dev.js",
"start": "./scripts/start.js",
"postinstall": "yarn link",
"release": "np --yolo"
},
"workspaces": ["packages/*"]
"dependencies": {
"ansi-to-html": "^0.6.10",
"chokidar": "^2.0.4",
"common-tags": "^1.8.0",
"debug": "^4.1.1",
"express": "^4.16.4",
"fs-jetpack": "^2.2.0",
"hot-module-replacement": "^3.0.3",
"hot-replacement-module": "https://github.com/ericclemmons/hot-module-replacement.git",
"opn": "^5.4.0",
"strip-ansi": "^5.1.0",
"uuid": "^3.3.2",
"wait-on": "^3.2.0",
"wait-port": "^0.2.2",
"youch": "^2.0.10",
"youch-terminal": "^1.0.0"
},
"devDependencies": {
"np": "^4.0.2"
}
}
21 changes: 0 additions & 21 deletions packages/next-example/index.js

This file was deleted.

Loading