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
36 changes: 36 additions & 0 deletions .github/utils/update-version.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Update the package.json version property for the given package
* to a pre-release version based off the current SHA.
*
* Usage:
*
* ```
* node ./.github/utils/version-script.js <package-name>
* ```
*/

const { readFileSync, writeFileSync } = require("node:fs");
const { execSync } = require("node:child_process");
const assert = require("node:assert");

try {
const packagePath = getArgs()[0];
assert(packagePath, "Required package path missing.");
const packageJsonPath = `${packagePath}/package.json`;
const pkg = JSON.parse(readFileSync(packageJsonPath));
const stdout = execSync("git rev-parse --short HEAD", { encoding: "utf8" });
pkg.version = "0.0.0-" + stdout.trim();
writeFileSync(packageJsonPath, JSON.stringify(pkg, null, "\t") + "\n");
} catch (error) {
console.error(error);
process.exit(1);
}

/**
* Get the command line args, stripping `node` and script filename, etc.
*/
function getArgs() {
const args = Array.from(process.argv);
while (args.shift() !== module.filename) {}
return args;
}
44 changes: 44 additions & 0 deletions .github/workflows/prereleases.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Publish prereleases
on:
push:
branches:
- main

jobs:
release:
if: ${{ github.repository_owner == 'flarelabs-net' }}
name: Publish builder package
runs-on: ubuntu-latest

steps:
- name: Checkout Repo
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 9.10.0

- name: Install Node.js 20
uses: actions/setup-node@v4
with:
node-version: 20
cache: "pnpm"
registry-url: "https://registry.npmjs.org"

- name: Install Dependencies
uses: pnpm i --frozen-lockfile

- name: Build
run: pnpm -F builder run build

- name: Update package.json version
run: node .github/utils/version-script.cjs builder

- name: Publish to NPM
run: pnpm publish -F cloudflare --no-git-checks
env:
NODE_ENV: "production"
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
23 changes: 14 additions & 9 deletions builder/README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
# Next.js builder for Cloudflare

## Build your app
## Configure your app

- add the following `devDependency` to the `package.json`:

```json
"node-url": "npm:url@^0.11.4",
"wrangler": "^3.77.0"
```bash
pnpm add -D wrangler@latest @opennextjs/cloudflare
```

- Execute `npx @flarelabs-net/builder@latest` in your app folder

## Serve your app

- build the app and adapt it for Cloudflare

```bash
pnpx cloudflare
```

- add a `wrangler.toml` at the root of your project

```toml
Expand All @@ -22,11 +25,13 @@

compatibility_date = "2024-08-29"
compatibility_flags = ["nodejs_compat_v2"]
workers_dev = true
minify = false

# Use the new Workers + Assets to host the static frontend files
experimental_assets = { directory = ".worker-next/assets", binding = "ASSETS" }
```

- Use `wrangler dev`
- Preview the app in Wrangler

```bash
pnpm wrangler dev
```
2 changes: 1 addition & 1 deletion builder/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@flarelabs-net/builder",
"name": "@opennextjs/cloudflare",
"description": "Cloudflare builder for next apps",
"version": "0.0.1",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions examples/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"build": "next build",
"start": "next start",
"lint": "next lint",
"build:worker": "pnpm builder",
"build:worker": "pnpm cloudflare",
"dev:worker": "wrangler dev --port 8770",
"preview:worker": "pnpm build:worker && pnpm dev:worker",
"e2e": "playwright test"
Expand All @@ -18,7 +18,7 @@
"react-dom": "catalog:"
},
"devDependencies": {
"@flarelabs-net/builder": "workspace:*",
"@opennextjs/cloudflare": "workspace:*",
"@playwright/test": "catalog:",
"@types/node": "catalog:",
"wrangler": "catalog:"
Expand Down
4 changes: 2 additions & 2 deletions examples/create-next-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"build": "next build",
"start": "next start",
"lint": "next lint",
"build:worker": "pnpm builder",
"build:worker": "pnpm cloudflare",
"dev:worker": "wrangler dev --port 8771",
"preview:worker": "pnpm build:worker && pnpm dev:worker",
"e2e": "playwright test -c e2e/playwright.config.ts"
Expand All @@ -18,7 +18,7 @@
"next": "catalog:"
},
"devDependencies": {
"@flarelabs-net/builder": "workspace:*",
"@opennextjs/cloudflare": "workspace:*",
"@playwright/test": "catalog:",
"@types/node": "catalog:",
"@types/react": "catalog:",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"scripts": {
"prettier:check": "prettier --check .",
"prettier:fix": "prettier --write .",
"postinstall": "pnpm --filter builder build",
"postinstall": "pnpm --filter cloudflare build",
"install-playwright": "playwright install --with-deps",
"e2e": "pnpm -r e2e"
}
Expand Down
40 changes: 16 additions & 24 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.