Skip to content

Commit

Permalink
feat: ✨ turn errors into separate package & improve readme
Browse files Browse the repository at this point in the history
* feat: ✨ monorepo

* fix: πŸ› move to npm with lerna

* fix: πŸ› move to npm

* fix: πŸ› build & tests

* fix: πŸ› build & tests

* fix: πŸ› build & tests

* chore(version): πŸ”§ πŸ“¦οΈ prerelease version bump to 0.0.6-feat-split-into-multiple-packages.0

* fix: πŸ› build

* chore(version): πŸ”§ πŸ“¦οΈ prerelease version bump to 0.0.6-feat-split-into-multiple-packages.1

* fix: πŸ› test upload

* chore(version): πŸ”§ πŸ“¦οΈ prerelease version bump to 0.0.6-feat-split-into-multiple-packages.2

* fix: πŸ› test upload

* chore(version): πŸ”§ πŸ“¦οΈ prerelease version bump to 0.0.6-feat-split-into-multiple-packages.3

* fix: πŸ› test upload

* fix: πŸ› upgrade node

* fix: πŸ› package readmes

* fix: πŸ› examples linting

* fix: πŸ› circular dependency

* fix: πŸ› test error output experiment

* fix: πŸ› add examples to readme

* fix: πŸ› add examples to readme

* chore: πŸ”§ print ./node_modules/@zhttp

* fix: πŸ› tests

* fix: πŸ› tests

* fix: πŸ› tests

* fix: πŸ› tests

* fix: πŸ› cleanup

* fix: πŸ› cleanup

---------

Co-authored-by: Evert De Spiegeleer <evert.despiegeleer@rightcrowd.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 12, 2024
1 parent c13f51b commit 5eabe6c
Show file tree
Hide file tree
Showing 41 changed files with 4,583 additions and 2,709 deletions.
9 changes: 7 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
"extends": "standard-with-typescript",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
"sourceType": "module",
"project": [
"./tsconfig.json",
"./packages/*/tsconfig.json",
"./examples/tsconfig.json"
]
},
"rules": {
"@typescript-eslint/explicit-function-return-type": "off"
Expand All @@ -16,7 +21,7 @@
{
"files": ["*.test.ts"],
"rules": {
// Disable on test files so we can usu chai `...to.be.undefined` style syntax
// Disable on test files so we can use chai `...to.be.undefined` style syntax
"@typescript-eslint/no-unused-expressions": "off"
}
}
Expand Down
54 changes: 31 additions & 23 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ jobs:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.ref }}

- name: Set Node.js 20.x
- name: Set Node.js 20.11.0
uses: actions/setup-node@v3
with:
node-version: 20.x
node-version: 20.11.0

- name: Install Dependencies
run: yarn install --frozen-lockfile
run: npm ci

- name: Lint
run: yarn lint
run: npm run lint

build:
runs-on: ubuntu-latest
Expand All @@ -38,22 +38,22 @@ jobs:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.ref }}

- name: Set Node.js 20.x
- name: Set Node.js 20.11.0
uses: actions/setup-node@v3
with:
node-version: 20.x
node-version: 20.11.0

- name: Install Dependencies
run: yarn install --frozen-lockfile
run: npm ci

- name: Build
run: yarn build
run: npm run build

- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: build
path: ./dist
path: ./packages/*/dist

test:
runs-on: ubuntu-latest
Expand All @@ -67,22 +67,29 @@ jobs:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.ref }}

- name: Set Node.js 20.x
- name: Set Node.js 20.11.0
uses: actions/setup-node@v3
with:
node-version: 20.x
node-version: 20.11.0

- name: Install Dependencies
run: yarn install --frozen-lockfile

run: npm ci
- name: Test
run: yarn test
id: test
run: npm run test

- name: Upload test artifacts
uses: actions/upload-artifact@v4
with:
name: test
path: ./packages/*/test-report.xml

- name: Test Report
if: always()
uses: EnricoMi/publish-unit-test-result-action@v2
with:
files: test-report.xml
if: always()
files: ./packages/*/test-report.xml

pr-prerelease:
if: github.event_name == 'pull_request' && github.event.action != 'closed'
Expand All @@ -98,19 +105,19 @@ jobs:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.ref }}

- name: Set Node.js 20.x
- name: Set Node.js 20.11.0
uses: actions/setup-node@v3
with:
node-version: 20.x
node-version: 20.11.0

- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: build
path: ./dist
path: ./packages

- name: Install Dependencies
run: yarn install --frozen-lockfile
run: npm ci

- name: Extract branch name
shell: bash
Expand All @@ -120,17 +127,18 @@ jobs:
- name: Configure Git
uses: fregante/setup-git-user@v1

- name: Version the package
- name: Version the packages
id: version
run: |
export VERSION=$(npm version --no-commit-hooks --no-git-tag-version prerelease --preid $(echo "${{ steps.extract_branch.outputs.branch }}" | tr -cs 'a-zA-Z0-9-' '-' | sed 's/-$//'))
./scripts/version.sh prerelease --preid $(echo "${{ steps.extract_branch.outputs.branch }}" | tr -cs 'a-zA-Z0-9-' '-' | sed 's/-$//')
export VERSION=$(cat package.json | jq -r '.version')
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Publish to npm
run: |
echo "//registry.npmjs.org/:_authToken=${{secrets.NPM_PUBLISH_TOKEN}}" >> ~/.npmrc
echo "registry=https://registry.npmjs.org" >> ~/.npmrc
npm publish --access=public --tag prerelease
npm publish --workspaces --access=public --tag prerelease
rm -f ~/.npmrc
- name: Commit and push changes
Expand Down
19 changes: 11 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,35 @@ jobs:
fetch-depth: 0
ref: ${{ github.ref }}

- name: Set Node.js 20.x
- name: Set Node.js 20.10
uses: actions/setup-node@v3
with:
node-version: 20.x
node-version: 20.10

- name: Install Dependencies
run: yarn install --frozen-lockfile
run: npm ci

- name: Build
run: yarn build
run: npm run build

- name: Configure Git
uses: fregante/setup-git-user@v1

- name: Version the package
- name: Version the packages
id: version
run: npm version --no-commit-hooks --no-git-tag-version ${{ github.event.inputs.release-type }}
run: |
./scripts/version.sh ${{ github.event.inputs.release-type }}
export VERSION=$(cat package.json | jq -r '.version')
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Publish to npm
run: |
echo "//registry.npmjs.org/:_authToken=${{secrets.NPM_PUBLISH_TOKEN}}" >> ~/.npmrc
echo "registry=https://registry.npmjs.org" >> ~/.npmrc
npm publish --access=public
npm publish --workspaces --access=public
rm -f ~/.npmrc
- name: Commit and push changes
run: |
git commit -am "chore(version): πŸ“¦ ${{ github.event.inputs.release-type }} version bump to ${{ steps.version.outputs.stdout }}"
git commit -am "chore(version): πŸ“¦ ${{ github.event.inputs.release-type }} version bump to ${{ steps.version.outputs.version }}"
git push
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn run sync:readme
npm run sync:readme
git add ./*.md

5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"dbaeumer.vscode-eslint"
]
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"typescript.enablePromptUseWorkspaceTsdk": true
}
23 changes: 23 additions & 0 deletions examples/concept-controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { z } from 'zod'
import { controller, get } from '@zhttp/core'

export const greetingController = controller('greeting')
.description('A controller that greets the world.')

greetingController.endpoint(
get('/hello', 'getGreeting')
.description('Say hello to everyone')
.input(z.object({
query: z.object({
name: z.string().optional()
})
}))
.response(z.object({
message: z.string()
}))
.handler(async ({ query }) => {
return {
message: `Hello ${query.name ?? 'everyone'}!`
}
})
)
34 changes: 34 additions & 0 deletions examples/concept-endpoint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { z } from 'zod'
import { endpoint, get } from '@zhttp/core'

const zGreetingOutput = z.object({
message: z.string()
})

const zGreetingInput = z.object({
query: z.object({
name: z.string().optional()
})
})

// ⬇ For common http methods (get, post, put, del), utility functions are available:
get('/hello', 'getGreeting')
.description('Say hello to everyone')
.input(zGreetingInput)
.response(zGreetingOutput)
.handler(async ({ query }) => {
return {
message: `Hello ${query.name ?? 'everyone'}!`
}
})

// `endpoint` is a generic function which supports every http method.
endpoint('get', '/goodbye', 'getGoodbye')
.description('Say goodbye to everyone')
.input(zGreetingInput)
.response(zGreetingOutput)
.handler(async ({ query }) => {
return {
message: `Goodbye ${query.name ?? 'everyone'}!`
}
})
20 changes: 20 additions & 0 deletions examples/concept-middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { type Request, type Response, type NextFunction } from 'express'
import { middleware, MiddlewareTypes } from '@zhttp/core'

export const lastVisitMiddleware = middleware({
name: 'lastVisitMiddleware',
type: MiddlewareTypes.BEFORE,
handler (req: Request, res: Response, next: NextFunction) {
const now = new Date()
const lastVisitCookieValue = req.cookies.beenHereBefore
const lastVisitTime = lastVisitCookieValue != null ? new Date(String(lastVisitCookieValue)) : undefined
res.cookie('beenHereBefore', now.toISOString())
if (lastVisitTime == null) {
console.log('Seems like we\'ve got a new user πŸ‘€')
next(); return
}
const daysSinceLastVisit = (now.getTime() - lastVisitTime.getTime()) / (1000 * 60 * 60 * 24)
console.log(`It's been ${daysSinceLastVisit} days since this user last visited.`)
next()
}
})
13 changes: 13 additions & 0 deletions examples/concept-server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Server } from '@zhttp/core'
import { greetingController } from './concept-controller.js'
import { lastVisitMiddleware } from './concept-middleware.js'

const server = new Server({
controllers: [greetingController],
middlewares: [lastVisitMiddleware]
}, {
port: 8080
})

// eslint-disable-next-line @typescript-eslint/no-floating-promises
server.start()
8 changes: 6 additions & 2 deletions examples/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
"extends": "../tsconfig.json",
"compilerOptions": {
"baseUrl": ".",
"rootDir": "..",
"paths": {
"@zhttp/core*": ["../src", "../src/main.ts", "../src/*"],
"@zhttp/core*": ["../packages/core/src", "../packages/core/src/main.ts", "../packages/core/src/*"],
}
},
"include": ["*"],
"include": [
"./*.ts",
"../**/*.ts"
],
}
Loading

0 comments on commit 5eabe6c

Please sign in to comment.