Skip to content

Commit

Permalink
[templates] cleanup (#4207)
Browse files Browse the repository at this point in the history
* templates: update worker js and ts templates.

* remove stackblitz commands from templates.

* remove deprecated --local from dev commands.

* update compat date and workers types package.

* Update templates/worker-typescript/wrangler.toml

Co-authored-by: MrBBot <[email protected]>

---------

Co-authored-by: MrBBot <[email protected]>
  • Loading branch information
admah and mrbbot authored Oct 25, 2023
1 parent 6fb3604 commit d1a4107
Show file tree
Hide file tree
Showing 20 changed files with 100 additions and 32 deletions.
2 changes: 1 addition & 1 deletion templates/worker-aws/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"build": "worktop build index.js",
"deploy": "wrangler deploy index.js",
"dev": "wrangler dev index.js --local"
"dev": "wrangler dev index.js"
},
"dependencies": {
"@aws-sdk/client-dynamodb": "^3.82.0",
Expand Down
3 changes: 1 addition & 2 deletions templates/worker-durable-objects/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"private": true,
"scripts": {
"deploy": "wrangler deploy index.js",
"dev": "wrangler dev index.js --local",
"start-stackblitz": "WRANGLER_SEND_METRICS=false wrangler dev index.js --local"
"dev": "wrangler dev index.js"
},
"devDependencies": {
"wrangler": "^3.0.0"
Expand Down
3 changes: 1 addition & 2 deletions templates/worker-example-request-scheduler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"private": true,
"scripts": {
"deploy": "wrangler deploy",
"start": "wrangler dev",
"start-stackblitz": "WRANGLER_SEND_METRICS=false wrangler dev --local"
"start": "wrangler dev"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20230518.0 ",
Expand Down
3 changes: 1 addition & 2 deletions templates/worker-example-wordle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"private": true,
"scripts": {
"deploy": "wrangler deploy",
"dev": "wrangler dev --local",
"start-stackblitz": "WRANGLER_SEND_METRICS=false wrangler dev --local"
"dev": "wrangler dev"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20230518.0 ",
Expand Down
2 changes: 1 addition & 1 deletion templates/worker-mysql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"build": "esbuild --bundle --sourcemap --outfile=dist/index.mjs --minify --format=esm ./src/index.js --external:*.wasm --inject:./src/deno/workers-override.ts",
"deploy": "wrangler deploy src/index.ts",
"dev": "wrangler dev src/index.ts --local"
"dev": "wrangler dev src/index.ts"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20230518.0 ",
Expand Down
2 changes: 1 addition & 1 deletion templates/worker-postgres/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"build": "esbuild --bundle --sourcemap --outfile=dist/index.mjs --minify --format=esm ./src/index.js --external:*.wasm --inject:./src/deno/workers-override.ts",
"deploy": "wrangler deploy src/index.ts",
"dev": "wrangler dev src/index.ts --local"
"dev": "wrangler dev src/index.ts"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20230518.0 ",
Expand Down
3 changes: 1 addition & 2 deletions templates/worker-r2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"private": true,
"scripts": {
"deploy": "wrangler deploy src/index.ts",
"dev": "wrangler dev src/index.ts --local",
"start-stackblitz": "WRANGLER_SEND_METRICS=false wrangler dev src/index.ts --local"
"dev": "wrangler dev src/index.ts"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20230518.0 ",
Expand Down
3 changes: 1 addition & 2 deletions templates/worker-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"private": true,
"scripts": {
"deploy": "wrangler deploy index.js",
"dev": "wrangler dev index.js --local",
"start-stackblitz": "WRANGLER_SEND_METRICS=false wrangler dev index.js --local",
"dev": "wrangler dev index.js",
"test": "vitest"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion templates/worker-sites-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"scripts": {
"deploy": "wrangler deploy",
"dev": "wrangler dev --local",
"dev": "wrangler dev",
"react:build": "react-scripts build",
"react:eject": "react-scripts eject",
"react:start": "react-scripts start",
Expand Down
2 changes: 1 addition & 1 deletion templates/worker-sites/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"scripts": {
"deploy": "wrangler deploy index.js",
"dev": "wrangler dev index.js --local"
"dev": "wrangler dev index.js"
},
"dependencies": {
"@cloudflare/kv-asset-handler": "~0.1.2"
Expand Down
2 changes: 1 addition & 1 deletion templates/worker-speedtest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"scripts": {
"deploy": "wrangler deploy src/index.js",
"dev": "wrangler dev src/index.js --local",
"dev": "wrangler dev src/index.js",
"test": "jest"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion templates/worker-turso-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"scripts": {
"deploy": "wrangler deploy",
"start": "wrangler dev --local"
"start": "wrangler dev"
},
"dependencies": {
"@libsql/client": "^0.1.1",
Expand Down
7 changes: 4 additions & 3 deletions templates/worker-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
"private": true,
"scripts": {
"deploy": "wrangler deploy src/index.ts",
"dev": "wrangler dev src/index.ts --local",
"start-stackblitz": "WRANGLER_SEND_METRICS=false wrangler dev src/index.ts --local",
"dev": "wrangler dev",
"start": "wrangler dev",
"test": "vitest run"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20230518.0 ",
"@cloudflare/workers-types": "^4.20231016.0",
"vitest": "^0.31.0",
"typescript": "^5.0.4",
"wrangler": "^3.0.0"
}
}
31 changes: 29 additions & 2 deletions templates/worker-typescript/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
/**
* Welcome to Cloudflare Workers! This is your first worker.
*
* - Run `npm run dev` in your terminal to start a development server
* - Open a browser tab at http://localhost:8787/ to see your worker in action
* - Run `npm run deploy` to publish your worker
*
* Learn more at https://developers.cloudflare.com/workers/
*/

export interface Env {
// Example binding to KV. Learn more at https://developers.cloudflare.com/workers/runtime-apis/kv/
// MY_KV_NAMESPACE: KVNamespace;
//
// Example binding to Durable Object. Learn more at https://developers.cloudflare.com/workers/runtime-apis/durable-objects/
// MY_DURABLE_OBJECT: DurableObjectNamespace;
//
// Example binding to R2. Learn more at https://developers.cloudflare.com/workers/runtime-apis/r2/
// MY_BUCKET: R2Bucket;
//
// Example binding to a Service. Learn more at https://developers.cloudflare.com/workers/runtime-apis/service-bindings/
// MY_SERVICE: Fetcher;
//
// Example binding to a Queue. Learn more at https://developers.cloudflare.com/queues/javascript-apis/
// MY_QUEUE: Queue;
}

export default {
async fetch(request: Request) {
return new Response(`request method: ${request.method}`);
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
return new Response('Hello World!');
},
};
50 changes: 49 additions & 1 deletion templates/worker-typescript/wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,51 @@
name = "" # todo
main = "./src/index.ts"
compatibility_date = "2022-05-03"
compatibility_date = "2022-10-10"

# Variable bindings. These are arbitrary, plaintext strings (similar to environment variables)
# Note: Use secrets to store sensitive data.
# Docs: https://developers.cloudflare.com/workers/platform/environment-variables
# [vars]
# MY_VARIABLE = "production_value"

# Bind a KV Namespace. Use KV as persistent storage for small key-value pairs.
# Docs: https://developers.cloudflare.com/workers/runtime-apis/kv
# [[kv_namespaces]]
# binding = "MY_KV_NAMESPACE"
# id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

# Bind an R2 Bucket. Use R2 to store arbitrarily large blobs of data, such as files.
# Docs: https://developers.cloudflare.com/r2/api/workers/workers-api-usage/
# [[r2_buckets]]
# binding = "MY_BUCKET"
# bucket_name = "my-bucket"

# Bind a Queue producer. Use this binding to schedule an arbitrary task that may be processed later by a Queue consumer.
# Docs: https://developers.cloudflare.com/queues/get-started
# [[queues.producers]]
# binding = "MY_QUEUE"
# queue = "my-queue"

# Bind a Queue consumer. Queue Consumers can retrieve tasks scheduled by Producers to act on them.
# Docs: https://developers.cloudflare.com/queues/get-started
# [[queues.consumers]]
# queue = "my-queue"

# Bind another Worker service. Use this binding to call another Worker without network overhead.
# Docs: https://developers.cloudflare.com/workers/platform/services
# [[services]]
# binding = "MY_SERVICE"
# service = "my-service"

# Bind a Durable Object. Durable objects are a scale-to-zero compute primitive based on the actor model.
# Durable Objects can live for as long as needed. Use these when you need a long-running "server", such as in realtime apps.
# Docs: https://developers.cloudflare.com/workers/runtime-apis/durable-objects
# [[durable_objects.bindings]]
# name = "MY_DURABLE_OBJECT"
# class_name = "MyDurableObject"

# Durable Object migrations.
# Docs: https://developers.cloudflare.com/workers/learning/using-durable-objects#configure-durable-object-classes-with-migrations
# [[migrations]]
# tag = "v1"
# new_classes = ["MyDurableObject"]
3 changes: 1 addition & 2 deletions templates/worker-websocket-durable-objects/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"private": true,
"scripts": {
"deploy": "wrangler deploy src/index.ts",
"start": "wrangler dev src/index.ts --local",
"start-stackblitz": "WRANGLER_SEND_METRICS=false wrangler dev src/index.ts --local"
"start": "wrangler dev src/index.ts"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20230518.0 ",
Expand Down
3 changes: 1 addition & 2 deletions templates/worker-websocket/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"private": true,
"scripts": {
"deploy": "wrangler deploy index.js",
"dev": "wrangler dev index.js --local",
"start-stackblitz": "WRANGLER_SEND_METRICS=false wrangler dev index.js --local"
"dev": "wrangler dev index.js"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20230518.0 ",
Expand Down
3 changes: 1 addition & 2 deletions templates/worker-worktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"private": true,
"scripts": {
"deploy": "wrangler deploy src/index.ts",
"dev": "wrangler dev src/index.ts --local",
"start-stackblitz": "WRANGLER_SEND_METRICS=false wrangler dev src/index.ts --local"
"dev": "wrangler dev src/index.ts"
},
"dependencies": {
"worktop": "0.8.0-next.14"
Expand Down
2 changes: 1 addition & 1 deletion templates/worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"scripts": {
"deploy": "wrangler deploy index.js",
"dev": "wrangler dev index.js --local",
"dev": "wrangler dev index.js",
"test": "vitest"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions templates/worker/wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
name = "" # todo
main = "./index.js"
compatibility_date = "2022-05-03"
main = "./index.js"
compatibility_date = "2022-10-10"

0 comments on commit d1a4107

Please sign in to comment.