Skip to content

Commit

Permalink
Add more comments
Browse files Browse the repository at this point in the history
  • Loading branch information
penalosa committed Jan 9, 2025
1 parent 9172193 commit a9fe2e1
Show file tree
Hide file tree
Showing 2 changed files with 283 additions and 4 deletions.
190 changes: 188 additions & 2 deletions packages/create-cloudflare/src/wrangler/__tests__/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,41 @@ describe("update wrangler config", () => {
name = "test"
main = "src/index.ts"
compatibility_date = "2024-01-17"
[observability]
enabled = true
# Smart Placement
# Docs: https://developers.cloudflare.com/workers/configuration/smart-placement/#smart-placement
# [placement]
# mode = "smart"
###
# Bindings
# Bindings allow your Worker to interact with resources on the Cloudflare Developer Platform, including
# databases, object storage, AI inference, real-time communication and more.
# https://developers.cloudflare.com/workers/runtime-apis/bindings/
###
# Environment Variables
# https://developers.cloudflare.com/workers/wrangler/configuration/#environment-variables
# [vars]
# MY_VARIABLE = "production_value"
# Note: Use secrets to store sensitive data.
# https://developers.cloudflare.com/workers/configuration/secrets/
# Static Assets
# https://developers.cloudflare.com/workers/static-assets/binding/
# [assets]
# directory = "./public/"
# binding = "ASSETS"
# Service Bindings (communicate between multiple Workers)
# https://developers.cloudflare.com/workers/wrangler/configuration/#service-bindings
# [[services]]
# binding = "MY_SERVICE"
# service = "my-service"
"
`);
});
Expand All @@ -73,8 +108,54 @@ describe("update wrangler config", () => {
"name": "test",
"main": "src/index.ts",
"compatibility_date": "2024-01-17",
"$schema": "node_modules/wrangler/config-schema.json"
}"
"$schema": "node_modules/wrangler/config-schema.json",
"observability": {
"enabled": true
}
/**
* Smart Placement
* Docs: https://developers.cloudflare.com/workers/configuration/smart-placement/#smart-placement
*/
// "placement": { "mode": "smart" },
/**
* Bindings
* Bindings allow your Worker to interact with resources on the Cloudflare Developer Platform, including
* databases, object storage, AI inference, real-time communication and more.
* https://developers.cloudflare.com/workers/runtime-apis/bindings/
*/
/**
* Environment Variables
* https://developers.cloudflare.com/workers/wrangler/configuration/#environment-variables
*/
// "vars": {
// "MY_VARIABLE": "production_value"
// },
/**
* Note: Use secrets to store sensitive data.
* https://developers.cloudflare.com/workers/configuration/secrets/
*/
/**
* Static Assets
* https://developers.cloudflare.com/workers/static-assets/binding/
*/
// "assets": {
// "directory": "./public/",
// "binding": "ASSETS"
// },
/**
* Service Bindings (communicate between multiple Workers)
* https://developers.cloudflare.com/workers/wrangler/configuration/#service-bindings
*/
// "services": [{
// "binding": "MY_SERVICE",
// "service": "my-service"
// }]
}
"
`);
});

Expand All @@ -94,6 +175,41 @@ describe("update wrangler config", () => {
name = "test"
main = "src/index.ts"
compatibility_date = "2024-01-17"
[observability]
enabled = true
# Smart Placement
# Docs: https://developers.cloudflare.com/workers/configuration/smart-placement/#smart-placement
# [placement]
# mode = "smart"
###
# Bindings
# Bindings allow your Worker to interact with resources on the Cloudflare Developer Platform, including
# databases, object storage, AI inference, real-time communication and more.
# https://developers.cloudflare.com/workers/runtime-apis/bindings/
###
# Environment Variables
# https://developers.cloudflare.com/workers/wrangler/configuration/#environment-variables
# [vars]
# MY_VARIABLE = "production_value"
# Note: Use secrets to store sensitive data.
# https://developers.cloudflare.com/workers/configuration/secrets/
# Static Assets
# https://developers.cloudflare.com/workers/static-assets/binding/
# [assets]
# directory = "./public/"
# binding = "ASSETS"
# Service Bindings (communicate between multiple Workers)
# https://developers.cloudflare.com/workers/wrangler/configuration/#service-bindings
# [[services]]
# binding = "MY_SERVICE"
# service = "my-service"
"
`);
});
Expand All @@ -112,6 +228,41 @@ describe("update wrangler config", () => {
main = "src/index.ts"
name = "test"
compatibility_date = "2024-01-17"
[observability]
enabled = true
# Smart Placement
# Docs: https://developers.cloudflare.com/workers/configuration/smart-placement/#smart-placement
# [placement]
# mode = "smart"
###
# Bindings
# Bindings allow your Worker to interact with resources on the Cloudflare Developer Platform, including
# databases, object storage, AI inference, real-time communication and more.
# https://developers.cloudflare.com/workers/runtime-apis/bindings/
###
# Environment Variables
# https://developers.cloudflare.com/workers/wrangler/configuration/#environment-variables
# [vars]
# MY_VARIABLE = "production_value"
# Note: Use secrets to store sensitive data.
# https://developers.cloudflare.com/workers/configuration/secrets/
# Static Assets
# https://developers.cloudflare.com/workers/static-assets/binding/
# [assets]
# directory = "./public/"
# binding = "ASSETS"
# Service Bindings (communicate between multiple Workers)
# https://developers.cloudflare.com/workers/wrangler/configuration/#service-bindings
# [[services]]
# binding = "MY_SERVICE"
# service = "my-service"
"
`);
});
Expand All @@ -132,6 +283,41 @@ describe("update wrangler config", () => {
# https://developers.cloudflare.com/workers/wrangler/configuration/
name = "test"
compatibility_date = "2001-10-12"
[observability]
enabled = true
# Smart Placement
# Docs: https://developers.cloudflare.com/workers/configuration/smart-placement/#smart-placement
# [placement]
# mode = "smart"
###
# Bindings
# Bindings allow your Worker to interact with resources on the Cloudflare Developer Platform, including
# databases, object storage, AI inference, real-time communication and more.
# https://developers.cloudflare.com/workers/runtime-apis/bindings/
###
# Environment Variables
# https://developers.cloudflare.com/workers/wrangler/configuration/#environment-variables
# [vars]
# MY_VARIABLE = "production_value"
# Note: Use secrets to store sensitive data.
# https://developers.cloudflare.com/workers/configuration/secrets/
# Static Assets
# https://developers.cloudflare.com/workers/static-assets/binding/
# [assets]
# directory = "./public/"
# binding = "ASSETS"
# Service Bindings (communicate between multiple Workers)
# https://developers.cloudflare.com/workers/wrangler/configuration/#service-bindings
# [[services]]
# binding = "MY_SERVICE"
# service = "my-service"
"
`);
});
Expand Down
97 changes: 95 additions & 2 deletions packages/create-cloudflare/src/wrangler/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,110 @@ export const updateWranglerConfig = async (ctx: C3Context) => {
const comment = `// For more details on how to configure Wrangler, refer to:\n// https://developers.cloudflare.com/workers/wrangler/configuration/\n`;

modified["$schema"] = "node_modules/wrangler/config-schema.json";
writeWranglerJson(ctx, comment + JSON.stringify(modified, null, 2));
if (!modified["observability"]) {
modified["observability"] = { enabled: true };
}
const stringified = comment + JSON.stringify(modified, null, 2);

writeWranglerJson(
ctx,
stringified.slice(0, -1) +
` /**
* Smart Placement
* Docs: https://developers.cloudflare.com/workers/configuration/smart-placement/#smart-placement
*/
// "placement": { "mode": "smart" },
/**
* Bindings
* Bindings allow your Worker to interact with resources on the Cloudflare Developer Platform, including
* databases, object storage, AI inference, real-time communication and more.
* https://developers.cloudflare.com/workers/runtime-apis/bindings/
*/
/**
* Environment Variables
* https://developers.cloudflare.com/workers/wrangler/configuration/#environment-variables
*/
// "vars": {
// "MY_VARIABLE": "production_value"
// },
/**
* Note: Use secrets to store sensitive data.
* https://developers.cloudflare.com/workers/configuration/secrets/
*/
/**
* Static Assets
* https://developers.cloudflare.com/workers/static-assets/binding/
*/
// "assets": {
// "directory": "./public/",
// "binding": "ASSETS"
// },
/**
* Service Bindings (communicate between multiple Workers)
* https://developers.cloudflare.com/workers/wrangler/configuration/#service-bindings
*/
// "services": [{
// "binding": "MY_SERVICE",
// "service": "my-service"
// }]
}
`,
);
} else if (wranglerTomlExists(ctx)) {
const wranglerTomlStr = readWranglerToml(ctx);
const parsed = TOML.parse(wranglerTomlStr);
const modified = await ensureCompatDateExists(
ensureNameExists(parsed, ctx.project.name),
);
if (!modified["observability"]) {
modified["observability"] = { enabled: true };
}

const comment = `#:schema node_modules/wrangler/config-schema.json\n# For more details on how to configure Wrangler, refer to:\n# https://developers.cloudflare.com/workers/wrangler/configuration/\n`;

writeWranglerToml(ctx, comment + TOML.stringify(modified as JsonMap));
const stringified = comment + TOML.stringify(modified as JsonMap);

writeWranglerToml(
ctx,
stringified +
`
# Smart Placement
# Docs: https://developers.cloudflare.com/workers/configuration/smart-placement/#smart-placement
# [placement]
# mode = "smart"
###
# Bindings
# Bindings allow your Worker to interact with resources on the Cloudflare Developer Platform, including
# databases, object storage, AI inference, real-time communication and more.
# https://developers.cloudflare.com/workers/runtime-apis/bindings/
###
# Environment Variables
# https://developers.cloudflare.com/workers/wrangler/configuration/#environment-variables
# [vars]
# MY_VARIABLE = "production_value"
# Note: Use secrets to store sensitive data.
# https://developers.cloudflare.com/workers/configuration/secrets/
# Static Assets
# https://developers.cloudflare.com/workers/static-assets/binding/
# [assets]
# directory = "./public/"
# binding = "ASSETS"
# Service Bindings (communicate between multiple Workers)
# https://developers.cloudflare.com/workers/wrangler/configuration/#service-bindings
# [[services]]
# binding = "MY_SERVICE"
# service = "my-service"
`,
);
}
};

Expand Down

0 comments on commit a9fe2e1

Please sign in to comment.