trigger-cloudflare-cron 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +86 -0
  2. package/dist/index.js +3 -0
  3. package/package.json +39 -0
package/README.md ADDED
@@ -0,0 +1,86 @@
1
+ # trigger-cloudflare-cron
2
+
3
+ Script to manually trigger Cloudflare Worker cron jobs locally.
4
+
5
+ ## Usage
6
+
7
+ After publishing to npm, you can run it with:
8
+
9
+ ```bash
10
+ npx trigger-cloudflare-cron
11
+ ```
12
+
13
+ ### Examples
14
+
15
+ ```bash
16
+ # Use defaults (cron: "* * * * *", port: 8787)
17
+ npx trigger-cloudflare-cron
18
+
19
+ # Specify cron pattern
20
+ npx trigger-cloudflare-cron -cron "* * * * *"
21
+
22
+ # Specify cron pattern and port
23
+ npx trigger-cloudflare-cron -cron "* * * * *" -port 3000
24
+
25
+ # Use positional arguments
26
+ npx trigger-cloudflare-cron "* * * * *" 1234567890 3000
27
+
28
+ # Use named arguments
29
+ npx trigger-cloudflare-cron --cron "*/10 * * * *" --time 1234567890 --port 3000
30
+ ```
31
+
32
+ ### Arguments
33
+
34
+ - `-cron` / `--cron`: Cron pattern (default: `"* * * * *"`)
35
+ - `-time` / `--time`: Scheduled time timestamp (optional)
36
+ - `-port` / `--port`: Port number (default: `8787` or `PORT` environment variable)
37
+
38
+ ## Development
39
+
40
+ To install dependencies:
41
+
42
+ ```bash
43
+ bun install
44
+ # or
45
+ npm install
46
+ ```
47
+
48
+ ### Building
49
+
50
+ Build the TypeScript source to JavaScript:
51
+
52
+ ```bash
53
+ bun run build
54
+ ```
55
+
56
+ This compiles `index.ts` to `dist/index.js` using Bun.
57
+
58
+ ### Development Scripts
59
+
60
+ - `bun run build` - Build the project (compiles TS to JS in `dist/` folder)
61
+ - `bun run dev` - Run the TypeScript source directly during development
62
+
63
+ ### Testing Locally
64
+
65
+ To test the compiled version locally:
66
+
67
+ ```bash
68
+ # Build first
69
+ bun run build
70
+
71
+ # Then link and test
72
+ npm link
73
+ trigger-cloudflare-cron
74
+ ```
75
+
76
+ Or run the TypeScript source directly during development:
77
+
78
+ ```bash
79
+ bun run dev
80
+ ```
81
+
82
+ Or run the compiled version directly:
83
+
84
+ ```bash
85
+ node dist/index.js
86
+ ```
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ function H(){let j={cron:null,time:null,port:null},q=process.argv.slice(2);for(let w=0;w<q.length;w++){let y=q[w],z=q[w+1];if((y==="-cron"||y==="--cron")&&z)j.cron=z,w++;else if((y==="-time"||y==="--time")&&z)j.time=z,w++;else if((y==="-port"||y==="--port")&&z)j.port=Number(z),w++}if(!j.cron&&!j.time&&!j.port&&q.length>0)j.cron=q[0]||null,j.time=q[1]||null,j.port=q[2]?Number(q[2]):null;return j}var D=H(),E=D.cron||"* * * * *",B=D.time||null,G=D.port||Number(process.env.PORT)||8787,C=new URL(`http://localhost:${G}/cdn-cgi/handler/scheduled`);C.searchParams.set("cron",E);if(B)C.searchParams.set("time",B);console.log("Triggering cron job...");console.log(` URL: ${C.toString()}`);console.log(` Cron: ${E}`);if(B)console.log(` Time: ${B}`);console.log("");fetch(C.toString()).then(async(j)=>{let q=await j.text();if(console.log(`Status: ${j.status} ${j.statusText}`),q)console.log(`Response: ${q}`);if(!j.ok)process.exit(1)}).catch((j)=>{console.error(`Error: ${j.message}`),console.error(`
3
+ Make sure 'wrangler dev' is running on port`,G),process.exit(1)});
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "trigger-cloudflare-cron",
3
+ "version": "1.0.0",
4
+ "description": "Script to manually trigger Cloudflare Worker cron jobs locally",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "bin": {
8
+ "trigger-cloudflare-cron": "./dist/index.js"
9
+ },
10
+ "files": [
11
+ "dist"
12
+ ],
13
+ "scripts": {
14
+ "build": "bun build index.ts --outdir dist --target node --minify",
15
+ "dev": "bun run index.ts",
16
+ "prepare": "bun run build && node -e \"try { require('fs').chmodSync('dist/index.js', 0o755); } catch(e) {}\""
17
+ },
18
+ "engines": {
19
+ "node": ">=18.0.0"
20
+ },
21
+ "devDependencies": {
22
+ "@types/bun": "latest",
23
+ "@types/node": "^20.0.0"
24
+ },
25
+ "peerDependencies": {
26
+ "typescript": "^5"
27
+ },
28
+ "keywords": [
29
+ "cloudflare",
30
+ "workers",
31
+ "cron",
32
+ "wrangler"
33
+ ],
34
+ "author": {
35
+ "name": "Jeff Njoroge",
36
+ "email": "jeff283@users.noreply.github.com"
37
+ },
38
+ "license": "MIT"
39
+ }