Skip to content

Commit f5c1dad

Browse files
committed
feat(adapter-cf): add initial Cloudflare adapter module for StatikAPI
1 parent 128158c commit f5c1dad

8 files changed

Lines changed: 698 additions & 1 deletion

File tree

.gitignore

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,12 @@ example/**/api-out
2020
project_dump.txt
2121

2222
packages/cli/ui
23-
packages/ui/dist
23+
packages/ui/dist
24+
25+
# Cloudflare Workers / local dev
26+
example/**/wrangler.toml
27+
.wrangler/
28+
.mf/ # Miniflare cache
29+
.dev.vars # local secrets (DO NOT COMMIT)
30+
worker-*.mjs
31+
**/worker-*.mjs
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name = "statikapi-cf-demo"
2+
main = "dist/worker.mjs"
3+
compatibility_date = "2025-01-01"
4+
5+
[[r2_buckets]]
6+
binding = "STATIK_BUCKET"
7+
bucket_name = "REPLACE_ME_BUCKET"
8+
9+
[[kv_namespaces]]
10+
binding = "STATIK_MANIFEST"
11+
id = "REPLACE_ME_KV_NAMESPACE_ID"
12+
13+
[vars]
14+
STATIK_BUILD_TOKEN = "REPLACE_ME_STATIK_BUILD_TOKEN"

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@
1515
"dev": "concurrently -n API,UI -c cyan,magenta \"pnpm -C example/basic dev --no-ui --keep-alive\" \"pnpm -C packages/ui dev\"",
1616
"ui:preview": "pnpm -C packages/ui preview",
1717
"ui:build": "pnpm -C packages/ui build && node packages/cli/scripts/embed-ui.js",
18+
"cf:bundle": "statikapi-cf --src src-api --out dist/worker.mjs",
1819
"prepublishOnly": "pnpm -r test"
1920
},
2021
"devDependencies": {
2122
"@eslint/js": "^9",
23+
"@statikapi/adapter-cf": "workspace:^",
2224
"concurrently": "^9.0.0",
2325
"eslint": "^9.36.0",
2426
"eslint-config-prettier": "^9.1.2",
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env node
2+
import { bundle } from '../src/node/bundle.js';
3+
4+
const args = process.argv.slice(2);
5+
let srcDir = 'src-api';
6+
let outFile = 'dist/worker.mjs';
7+
let prettyDefault = false;
8+
9+
for (let i = 0; i < args.length; i++) {
10+
const a = args[i];
11+
if (a === '--src' && args[i + 1]) {
12+
srcDir = args[++i];
13+
} else if (a === '--out' && args[i + 1]) {
14+
outFile = args[++i];
15+
} else if (a === '--pretty') {
16+
prettyDefault = true;
17+
} else if (a === '--help' || a === '-h') {
18+
console.log(`Usage: statikapi-cf bundle [--src src-api] [--out dist/worker.mjs] [--pretty]`);
19+
process.exit(0);
20+
}
21+
}
22+
23+
bundle({ srcDir, outFile, prettyDefault })
24+
.then(() => {
25+
console.log(`✔ worker emitted → ${outFile}`);
26+
})
27+
.catch((e) => {
28+
console.error(e?.stack || e?.message || String(e));
29+
process.exit(1);
30+
});
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "@statikapi/adapter-cf",
3+
"version": "0.6.0",
4+
"type": "module",
5+
"bin": {
6+
"statikapi-cf": "bin/statikapi-cf.js"
7+
},
8+
"exports": {
9+
".": {
10+
"import": "./src/index.js"
11+
}
12+
},
13+
"files": [
14+
"bin",
15+
"src",
16+
"README.md",
17+
"LICENSE"
18+
],
19+
"scripts": {
20+
"test": "node --test"
21+
},
22+
"dependencies": {
23+
"esbuild": "^0.24.0"
24+
},
25+
"devDependencies": {},
26+
"license": "MIT",
27+
"repository": {
28+
"type": "git",
29+
"url": "https://github.com/zonayedpca/statikapi",
30+
"directory": "packages/adapter-cloudflare"
31+
},
32+
"publishConfig": {
33+
"access": "public",
34+
"provenance": true
35+
}
36+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { bundle } from './node/bundle.js';

0 commit comments

Comments
 (0)