Skip to content
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

Esbuild refactor #23

Merged
merged 7 commits into from
Oct 17, 2022
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
8 changes: 8 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
5 changes: 5 additions & 0 deletions .changeset/brown-spiders-occur.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@stevent-team/epoxy": patch
---

Switched from parcel to esbuild for transpiling routes and package
11 changes: 11 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://unpkg.com/@changesets/config@2.2.0/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
}
5 changes: 5 additions & 0 deletions .changeset/great-ties-notice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@stevent-team/epoxy": minor
---

**Breaking:** Swapped out the cli argument parser from `yargs` to `commander`. `epoxy serve` is no longer a valid command. Use `epoxy` instead.
5 changes: 5 additions & 0 deletions .changeset/tiny-cheetahs-admire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@stevent-team/epoxy": patch
---

Add changesets for versioning
34 changes: 0 additions & 34 deletions .github/workflows/main.yml

This file was deleted.

30 changes: 30 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Release

on:
push:
branches: ['main']
paths:
- '**/package.json'
- '.changeset/**'
- '.github/workflows/release.yml'

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-node@v3
with:
node-version: 17
cache: 'yarn'
cache-dependency-path: '**/yarn.lock'
- run: yarn install --immutable && yarn --cwd helpers install --immutable
- uses: changesets/action@v1
with:
publish: yarn ci:release
commit: 'ci: release'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
58 changes: 58 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# @stevent-team/epoxy

## 2.1.0

### Minor Changes

- In-memory caching of routes

### Patch Changes

- Escape HTML special characters from the content of meta tags

## 2.0.1

### Patch Changes

- Fix GitHub actions

## 2.0.0

### Major Changes

- **Breaking:** Separate cli `build` command

## 1.1.3

### Patch Changes

- Use memory cache to compile routes
- Catch errors within route handlers

## 1.1.0

### Minor Changes

- Epoxy can now build routes file with command line command

### Patch Changes

- Fix error reporting

## 1.0.1

### Patch Changes

- Fix path resolution

## 1.0.0

### Major Changes

- Refactor to nodejs and express
- Updated the namespace of the library to `@stevent-team`

### Minor Changes

- Update README with library usage
- Added the `createMeta` helper
46 changes: 29 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
# 🪣 Epoxy

[![npm version](https://img.shields.io/npm/v/@stevent-team/epoxy)](https://www.npmjs.com/package/@stevent-team/epoxy)
[![minzip size](https://img.shields.io/bundlephobia/minzip/@stevent-team/epoxy)](https://bundlephobia.com/package/@stevent-team/epoxy)

Simple server-side per-route html injection

## Purpose

Epoxy allows for running middleware on select HTTP routes that inject HTML into the served content.
Simply point it at a static directory, define some routes in a script and you're off to the races! :horse:

Epoxy comes with `esbuild`, which is used for transpiling a route handler file.

## Usage

Add as a dependency
Expand All @@ -19,35 +24,40 @@ yarn add @stevent-team/epoxy

You can also run `npx epoxy --help` to see this information.

#### `epoxy serve` or `epoxy`
#### `epoxy`

```
epoxy <target> [routeFile] [options]
Usage: epoxy <target> [routeFile] [options]

Serve the provided static folder

target Path to static directory
routeFile Path to cjs router script (can use ES6 with --build option)
Arguments:
target Path to static directory
routeFile Path to cjs router script (can use ES6 with --build option)

Options:
--help Show help [boolean]
--version Show version number [boolean]
-p, --port port to use for http server [string] [default: 8080]
-h, --host host to use for http server [string] [default: "0.0.0.0"]
-i, --index path to index html inside of target [string] [default: "index.html"]
-b, --build build routes file in memory [boolean] [default: false]
--cache use --no-cache to disable all route caching [boolean] [default: true]
-V, --version output the version number
-p, --port <port> port to use for http server (default: 8080)
-h, --host <url> host to use for http server (default: "0.0.0.0")
-i, --index <path> path to index html inside of target (default: "index.html")
-b, --build build routes file in memory (default: false)
--no-cache disable all route handler result caching
--help display help for command
```

#### `epoxy build`

```
epoxy build <routeFile>
Usage: epoxy build <routeFile> [options]

routeFile Path to ES6 router script
Build a routes file

Arguments:
routeFile Path to ES6 router script

Options:
--help Show help [boolean]
--version Show version number [boolean]
-o, --outputDir folder to output built routes file [string] [default: "dist"]
-o, --outputDir <path> folder to output built routes file (default: "dist")
-h, --help display help for command
```

## Example
Expand Down Expand Up @@ -127,7 +137,7 @@ If you have a deployment that will need to start and stop your Epoxy server ofte
}
```

Alternatively, you could also write your routes file in CommonJS so it doesn't require building; the `epoxy serve` command only build if the flag `--build` is specified.
Alternatively, you could also write your routes file in CommonJS so it doesn't require building; the `epoxy` command only builds if the flag `--build` is specified.

## API

Expand Down Expand Up @@ -157,6 +167,8 @@ Each route must have a function to handle it, which will receive a `request` obj

PRs and Issues are more than welcome :)

This library uses [changesets](https://github.com/changesets/changesets). If the changes you've made would constitute a version bump, run `yarn changeset` and follow the prompts to document the changes you've made. Changesets are consumed on releases, and used to generate a changelog and bump version number.

## License

Created by Stevent (2022) and licensed under MIT
8 changes: 3 additions & 5 deletions helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Helpers for epoxy",
"main": "./dist/index.js",
"source": "./index.ts",
"types": "dist/types.d.ts",
"types": "dist/index.d.ts",
"author": "Stevent",
"license": "MIT",
"repository": {
Expand All @@ -13,12 +13,10 @@
"directory": "helpers"
},
"scripts": {
"build": "parcel build"
"build": "tsc -d --emitDeclarationOnly --declarationMap --outDir dist && esbuild index.ts --platform=node --target=node16 --format=cjs --bundle --sourcemap --outfile=dist/index.js"
},
"devDependencies": {
"@parcel/packager-ts": "2.5.0",
"@parcel/transformer-typescript-types": "2.5.0",
"parcel": "^2.5.0",
"esbuild": "^0.15.10",
"typescript": "^4.6.4"
}
}
Loading