create-cloudflare 0.0.0-e5cdd7fa → 0.0.0-e60a675d

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 (105) hide show
  1. package/dist/cli.js +39716 -37539
  2. package/package.json +8 -4
  3. package/templates/analog/c3.ts +134 -0
  4. package/templates/analog/snippets/devBindingsModule.ts +7 -0
  5. package/templates/analog/templates/env.d.ts +13 -0
  6. package/templates/analog/templates/src/dev-bindings.ts +18 -0
  7. package/templates/analog/templates/worker-configuration.d.ts +4 -0
  8. package/templates/analog/templates/wrangler.toml +78 -0
  9. package/templates/angular/c3.ts +10 -9
  10. package/templates/astro/c3.ts +81 -19
  11. package/templates/astro/snippets/runtimeDeclaration.ts +5 -0
  12. package/templates/astro/templates/wrangler.toml +78 -0
  13. package/templates/common/c3.ts +7 -5
  14. package/templates/common/js/.editorconfig +0 -1
  15. package/templates/common/js/wrangler.toml +71 -22
  16. package/templates/common/ts/.editorconfig +0 -1
  17. package/templates/common/ts/package.json +2 -1
  18. package/templates/common/ts/src/index.ts +3 -0
  19. package/templates/common/ts/worker-configuration.d.ts +2 -14
  20. package/templates/common/ts/wrangler.toml +71 -22
  21. package/templates/docusaurus/c3.ts +5 -6
  22. package/templates/gatsby/c3.ts +7 -5
  23. package/templates/hello-world/c3.ts +7 -5
  24. package/templates/hello-world/js/.editorconfig +0 -1
  25. package/templates/hello-world/js/package.json +5 -2
  26. package/templates/hello-world/js/test/index.spec.js +20 -0
  27. package/templates/hello-world/js/vitest.config.js +11 -0
  28. package/templates/hello-world/js/wrangler.toml +72 -22
  29. package/templates/hello-world/ts/.editorconfig +0 -1
  30. package/templates/hello-world/ts/package.json +6 -2
  31. package/templates/hello-world/ts/src/index.ts +3 -17
  32. package/templates/hello-world/ts/test/index.spec.ts +25 -0
  33. package/templates/hello-world/ts/test/tsconfig.json +11 -0
  34. package/templates/hello-world/ts/tsconfig.json +3 -2
  35. package/templates/hello-world/ts/vitest.config.ts +11 -0
  36. package/templates/hello-world/ts/worker-configuration.d.ts +4 -0
  37. package/templates/hello-world/ts/wrangler.toml +72 -22
  38. package/templates/hello-world-durable-object/c3.ts +7 -5
  39. package/templates/hello-world-durable-object/js/.editorconfig +0 -1
  40. package/templates/hello-world-durable-object/js/wrangler.toml +72 -23
  41. package/templates/hello-world-durable-object/ts/.editorconfig +0 -1
  42. package/templates/hello-world-durable-object/ts/package.json +2 -1
  43. package/templates/hello-world-durable-object/ts/src/index.ts +3 -20
  44. package/templates/hello-world-durable-object/ts/worker-configuration.d.ts +6 -0
  45. package/templates/hello-world-durable-object/ts/wrangler.toml +71 -22
  46. package/templates/hello-world-python/c3.ts +9 -0
  47. package/templates/hello-world-python/py/__dot__gitignore +68 -0
  48. package/templates/hello-world-python/py/package.json +13 -0
  49. package/templates/hello-world-python/py/src/entry.py +4 -0
  50. package/templates/hello-world-python/py/wrangler.toml +101 -0
  51. package/templates/hono/c3.ts +1 -1
  52. package/templates/next/README.md +68 -0
  53. package/templates/next/app/js/app/api/hello/route.js +21 -0
  54. package/templates/next/app/js/app/not-found.js +58 -0
  55. package/templates/next/app/ts/app/api/hello/route.ts +22 -0
  56. package/templates/next/app/ts/app/not-found.tsx +58 -0
  57. package/templates/next/c3.ts +99 -76
  58. package/templates/next/env.d.ts +5 -0
  59. package/templates/next/pages/js/pages/api/hello.js +23 -0
  60. package/templates/next/pages/ts/pages/api/hello.ts +24 -0
  61. package/templates/next/wrangler.toml +79 -0
  62. package/templates/nuxt/c3.ts +94 -19
  63. package/templates/nuxt/templates/env.d.ts +14 -0
  64. package/templates/nuxt/templates/worker-configuration.d.ts +4 -0
  65. package/templates/nuxt/templates/wrangler.toml +78 -0
  66. package/templates/openapi/ts/package.json +2 -1
  67. package/templates/openapi/ts/worker-configuration.d.ts +4 -0
  68. package/templates/openapi/ts/wrangler.toml +97 -0
  69. package/templates/pre-existing/c3.ts +2 -2
  70. package/templates/pre-existing/js/.editorconfig +0 -1
  71. package/templates/pre-existing/js/wrangler.toml +1 -0
  72. package/templates/queues/c3.ts +7 -5
  73. package/templates/queues/js/.editorconfig +0 -1
  74. package/templates/queues/js/wrangler.toml +88 -2
  75. package/templates/queues/ts/.editorconfig +0 -1
  76. package/templates/queues/ts/package.json +2 -1
  77. package/templates/queues/ts/src/index.ts +3 -5
  78. package/templates/queues/ts/worker-configuration.d.ts +5 -0
  79. package/templates/queues/ts/wrangler.toml +88 -2
  80. package/templates/qwik/c3.ts +83 -29
  81. package/templates/qwik/snippets/getPlatformProxy.ts +6 -0
  82. package/templates/qwik/templates/worker-configuration.d.ts +4 -0
  83. package/templates/qwik/templates/wrangler.toml +78 -0
  84. package/templates/react/c3.ts +7 -5
  85. package/templates/remix/c3.ts +39 -6
  86. package/templates/remix/templates/worker-configuration.d.ts +4 -0
  87. package/templates/remix/templates/wrangler.toml +78 -0
  88. package/templates/scheduled/c3.ts +7 -5
  89. package/templates/scheduled/js/.editorconfig +0 -1
  90. package/templates/scheduled/js/wrangler.toml +97 -0
  91. package/templates/scheduled/ts/.editorconfig +0 -1
  92. package/templates/scheduled/ts/package.json +2 -1
  93. package/templates/scheduled/ts/src/index.ts +3 -20
  94. package/templates/scheduled/ts/worker-configuration.d.ts +4 -0
  95. package/templates/scheduled/ts/wrangler.toml +97 -0
  96. package/templates/solid/c3.ts +58 -11
  97. package/templates/solid/templates/wrangler.toml +77 -0
  98. package/templates/svelte/c3.ts +83 -30
  99. package/templates/svelte/js/wrangler.toml +78 -0
  100. package/templates/svelte/ts/wrangler.toml +78 -0
  101. package/templates/vue/c3.ts +7 -6
  102. package/templates/next/templates.ts +0 -281
  103. package/templates/solid/js/vite.config.js +0 -12
  104. package/templates/solid/ts/vite.config.ts +0 -12
  105. package/templates/svelte/templates.ts +0 -13
@@ -1,3 +1,4 @@
1
+ #:schema node_modules/wrangler/config-schema.json
1
2
  name = "<TBD>"
2
3
  main = "src/index.js"
3
4
  compatibility_date = "<TBD>"
@@ -7,3 +8,99 @@ compatibility_date = "<TBD>"
7
8
  # Configuration: https://developers.cloudflare.com/workers/wrangler/configuration/#triggers
8
9
  [triggers]
9
10
  crons = ["* * * * *"] # * * * * * = run every minute
11
+
12
+ # Variable bindings. These are arbitrary, plaintext strings (similar to environment variables)
13
+ # Docs:
14
+ # - https://developers.cloudflare.com/workers/wrangler/configuration/#environment-variables
15
+ # Note: Use secrets to store sensitive data.
16
+ # - https://developers.cloudflare.com/workers/configuration/secrets/
17
+ # [vars]
18
+ # MY_VARIABLE = "production_value"
19
+
20
+ # Bind the Workers AI model catalog. Run machine learning models, powered by serverless GPUs, on Cloudflare’s global network
21
+ # Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#workers-ai
22
+ # [ai]
23
+ # binding = "AI"
24
+
25
+ # Bind an Analytics Engine dataset. Use Analytics Engine to write analytics within your Pages Function.
26
+ # Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#analytics-engine-datasets
27
+ # [[analytics_engine_datasets]]
28
+ # binding = "MY_DATASET"
29
+
30
+ # Bind a headless browser instance running on Cloudflare's global network.
31
+ # Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#browser-rendering
32
+ # [browser]
33
+ # binding = "MY_BROWSER"
34
+
35
+ # Bind a D1 database. D1 is Cloudflare’s native serverless SQL database.
36
+ # Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#d1-databases
37
+ # [[d1_databases]]
38
+ # binding = "MY_DB"
39
+ # database_name = "my-database"
40
+ # database_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
41
+
42
+ # Bind a dispatch namespace. Use Workers for Platforms to deploy serverless functions programmatically on behalf of your customers.
43
+ # Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#dispatch-namespace-bindings-workers-for-platforms
44
+ # [[dispatch_namespaces]]
45
+ # binding = "MY_DISPATCHER"
46
+ # namespace = "my-namespace"
47
+
48
+ # Bind a Durable Object. Durable objects are a scale-to-zero compute primitive based on the actor model.
49
+ # Durable Objects can live for as long as needed. Use these when you need a long-running "server", such as in realtime apps.
50
+ # Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#durable-objects
51
+ # [[durable_objects.bindings]]
52
+ # name = "MY_DURABLE_OBJECT"
53
+ # class_name = "MyDurableObject"
54
+
55
+ # Durable Object migrations.
56
+ # Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#migrations
57
+ # [[migrations]]
58
+ # tag = "v1"
59
+ # new_classes = ["MyDurableObject"]
60
+
61
+ # Bind a Hyperdrive configuration. Use to accelerate access to your existing databases from Cloudflare Workers.
62
+ # Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#hyperdrive
63
+ # [[hyperdrive]]
64
+ # binding = "MY_HYPERDRIVE"
65
+ # id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
66
+
67
+ # Bind a KV Namespace. Use KV as persistent storage for small key-value pairs.
68
+ # Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#kv-namespaces
69
+ # [[kv_namespaces]]
70
+ # binding = "MY_KV_NAMESPACE"
71
+ # id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
72
+
73
+ # Bind an mTLS certificate. Use to present a client certificate when communicating with another service.
74
+ # Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#mtls-certificates
75
+ # [[mtls_certificates]]
76
+ # binding = "MY_CERTIFICATE"
77
+ # certificate_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
78
+
79
+ # Bind a Queue producer. Use this binding to schedule an arbitrary task that may be processed later by a Queue consumer.
80
+ # Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#queues
81
+ # [[queues.producers]]
82
+ # binding = "MY_QUEUE"
83
+ # queue = "my-queue"
84
+
85
+ # Bind a Queue consumer. Queue Consumers can retrieve tasks scheduled by Producers to act on them.
86
+ # Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#queues
87
+ # [[queues.consumers]]
88
+ # queue = "my-queue"
89
+
90
+ # Bind an R2 Bucket. Use R2 to store arbitrarily large blobs of data, such as files.
91
+ # Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#r2-buckets
92
+ # [[r2_buckets]]
93
+ # binding = "MY_BUCKET"
94
+ # bucket_name = "my-bucket"
95
+
96
+ # Bind another Worker service. Use this binding to call another Worker without network overhead.
97
+ # Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#service-bindings
98
+ # [[services]]
99
+ # binding = "MY_SERVICE"
100
+ # service = "my-service"
101
+
102
+ # Bind a Vectorize index. Use to store and query vector embeddings for semantic search, classification and other vector search use-cases.
103
+ # Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#vectorize-indexes
104
+ # [[vectorize]]
105
+ # binding = "MY_INDEX"
106
+ # index_name = "my-index"
@@ -3,7 +3,6 @@ root = true
3
3
 
4
4
  [*]
5
5
  indent_style = tab
6
- tab_width = 2
7
6
  end_of_line = lf
8
7
  charset = utf-8
9
8
  trim_trailing_whitespace = true
@@ -5,7 +5,8 @@
5
5
  "scripts": {
6
6
  "deploy": "wrangler deploy",
7
7
  "dev": "wrangler dev",
8
- "start": "wrangler dev"
8
+ "start": "wrangler dev",
9
+ "cf-typegen": "wrangler types"
9
10
  },
10
11
  "devDependencies": {
11
12
  "typescript": "^5.0.4",
@@ -9,29 +9,12 @@
9
9
  * - Open a browser tab at http://localhost:8787/ to see your worker in action
10
10
  * - Run `npm run deploy` to publish your worker
11
11
  *
12
+ * Bind resources to your worker in `wrangler.toml`. After adding bindings, a type definition for the
13
+ * `Env` object can be regenerated with `npm run cf-typegen`.
14
+ *
12
15
  * Learn more at https://developers.cloudflare.com/workers/
13
16
  */
14
17
 
15
- export interface Env {
16
- // Example binding to KV. Learn more at https://developers.cloudflare.com/workers/runtime-apis/kv/
17
- // MY_KV_NAMESPACE: KVNamespace;
18
- //
19
- // Example binding to Durable Object. Learn more at https://developers.cloudflare.com/workers/runtime-apis/durable-objects/
20
- // MY_DURABLE_OBJECT: DurableObjectNamespace;
21
- //
22
- // Example binding to R2. Learn more at https://developers.cloudflare.com/workers/runtime-apis/r2/
23
- // MY_BUCKET: R2Bucket;
24
- //
25
- // Example binding to a Service. Learn more at https://developers.cloudflare.com/workers/runtime-apis/service-bindings/
26
- // MY_SERVICE: Fetcher;
27
- //
28
- // Example binding to a Queue. Learn more at https://developers.cloudflare.com/queues/javascript-apis/
29
- // MY_QUEUE: Queue;
30
- //
31
- // Example binding to a D1 Database. Learn more at https://developers.cloudflare.com/workers/platform/bindings/#d1-database-bindings
32
- // DB: D1Database
33
- }
34
-
35
18
  export default {
36
19
  // The scheduled handler is invoked at the interval set in our wrangler.toml's
37
20
  // [[triggers]] configuration.
@@ -0,0 +1,4 @@
1
+ // Generated by Wrangler
2
+ // After adding bindings to `wrangler.toml`, regenerate this interface via `npm run cf-typegen`
3
+ interface Env {
4
+ }
@@ -1,3 +1,4 @@
1
+ #:schema node_modules/wrangler/config-schema.json
1
2
  name = "<TBD>"
2
3
  main = "src/index.ts"
3
4
  compatibility_date = "<TBD>"
@@ -7,3 +8,99 @@ compatibility_date = "<TBD>"
7
8
  # Configuration: https://developers.cloudflare.com/workers/wrangler/configuration/#triggers
8
9
  [triggers]
9
10
  crons = ["* * * * *"] # * * * * * = run every minute
11
+
12
+ # Variable bindings. These are arbitrary, plaintext strings (similar to environment variables)
13
+ # Docs:
14
+ # - https://developers.cloudflare.com/workers/wrangler/configuration/#environment-variables
15
+ # Note: Use secrets to store sensitive data.
16
+ # - https://developers.cloudflare.com/workers/configuration/secrets/
17
+ # [vars]
18
+ # MY_VARIABLE = "production_value"
19
+
20
+ # Bind the Workers AI model catalog. Run machine learning models, powered by serverless GPUs, on Cloudflare’s global network
21
+ # Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#workers-ai
22
+ # [ai]
23
+ # binding = "AI"
24
+
25
+ # Bind an Analytics Engine dataset. Use Analytics Engine to write analytics within your Pages Function.
26
+ # Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#analytics-engine-datasets
27
+ # [[analytics_engine_datasets]]
28
+ # binding = "MY_DATASET"
29
+
30
+ # Bind a headless browser instance running on Cloudflare's global network.
31
+ # Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#browser-rendering
32
+ # [browser]
33
+ # binding = "MY_BROWSER"
34
+
35
+ # Bind a D1 database. D1 is Cloudflare’s native serverless SQL database.
36
+ # Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#d1-databases
37
+ # [[d1_databases]]
38
+ # binding = "MY_DB"
39
+ # database_name = "my-database"
40
+ # database_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
41
+
42
+ # Bind a dispatch namespace. Use Workers for Platforms to deploy serverless functions programmatically on behalf of your customers.
43
+ # Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#dispatch-namespace-bindings-workers-for-platforms
44
+ # [[dispatch_namespaces]]
45
+ # binding = "MY_DISPATCHER"
46
+ # namespace = "my-namespace"
47
+
48
+ # Bind a Durable Object. Durable objects are a scale-to-zero compute primitive based on the actor model.
49
+ # Durable Objects can live for as long as needed. Use these when you need a long-running "server", such as in realtime apps.
50
+ # Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#durable-objects
51
+ # [[durable_objects.bindings]]
52
+ # name = "MY_DURABLE_OBJECT"
53
+ # class_name = "MyDurableObject"
54
+
55
+ # Durable Object migrations.
56
+ # Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#migrations
57
+ # [[migrations]]
58
+ # tag = "v1"
59
+ # new_classes = ["MyDurableObject"]
60
+
61
+ # Bind a Hyperdrive configuration. Use to accelerate access to your existing databases from Cloudflare Workers.
62
+ # Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#hyperdrive
63
+ # [[hyperdrive]]
64
+ # binding = "MY_HYPERDRIVE"
65
+ # id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
66
+
67
+ # Bind a KV Namespace. Use KV as persistent storage for small key-value pairs.
68
+ # Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#kv-namespaces
69
+ # [[kv_namespaces]]
70
+ # binding = "MY_KV_NAMESPACE"
71
+ # id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
72
+
73
+ # Bind an mTLS certificate. Use to present a client certificate when communicating with another service.
74
+ # Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#mtls-certificates
75
+ # [[mtls_certificates]]
76
+ # binding = "MY_CERTIFICATE"
77
+ # certificate_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
78
+
79
+ # Bind a Queue producer. Use this binding to schedule an arbitrary task that may be processed later by a Queue consumer.
80
+ # Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#queues
81
+ # [[queues.producers]]
82
+ # binding = "MY_QUEUE"
83
+ # queue = "my-queue"
84
+
85
+ # Bind a Queue consumer. Queue Consumers can retrieve tasks scheduled by Producers to act on them.
86
+ # Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#queues
87
+ # [[queues.consumers]]
88
+ # queue = "my-queue"
89
+
90
+ # Bind an R2 Bucket. Use R2 to store arbitrarily large blobs of data, such as files.
91
+ # Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#r2-buckets
92
+ # [[r2_buckets]]
93
+ # binding = "MY_BUCKET"
94
+ # bucket_name = "my-bucket"
95
+
96
+ # Bind another Worker service. Use this binding to call another Worker without network overhead.
97
+ # Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#service-bindings
98
+ # [[services]]
99
+ # binding = "MY_SERVICE"
100
+ # service = "my-service"
101
+
102
+ # Bind a Vectorize index. Use to store and query vector embeddings for semantic search, classification and other vector search use-cases.
103
+ # Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#vectorize-indexes
104
+ # [[vectorize]]
105
+ # binding = "MY_INDEX"
106
+ # index_name = "my-index"
@@ -1,7 +1,10 @@
1
- import { logRaw } from "@cloudflare/cli";
2
- import { runFrameworkGenerator } from "helpers/command";
3
- import { compatDateFlag } from "helpers/files";
4
- import { detectPackageManager } from "helpers/packages";
1
+ import { logRaw, updateStatus } from "@cloudflare/cli";
2
+ import { blue } from "@cloudflare/cli/colors";
3
+ import { runFrameworkGenerator } from "frameworks/index";
4
+ import { transformFile } from "helpers/codemod";
5
+ import { usesTypescript } from "helpers/files";
6
+ import { detectPackageManager } from "helpers/packageManagers";
7
+ import * as recast from "recast";
5
8
  import type { TemplateConfig } from "../../src/templates";
6
9
  import type { C3Context } from "types";
7
10
 
@@ -9,29 +12,73 @@ const { npm } = detectPackageManager();
9
12
 
10
13
  const generate = async (ctx: C3Context) => {
11
14
  // Run the create-solid command
12
- await runFrameworkGenerator(ctx, [ctx.project.name]);
15
+ // -s flag forces solid-start
16
+ await runFrameworkGenerator(ctx, ["-p", ctx.project.name, "-s"]);
13
17
 
14
18
  logRaw("");
15
19
  };
16
20
 
21
+ const configure = async (ctx: C3Context) => {
22
+ usesTypescript(ctx);
23
+ const filePath = `app.config.${usesTypescript(ctx) ? "ts" : "js"}`;
24
+
25
+ updateStatus(`Updating configuration in ${blue(filePath)}`);
26
+
27
+ transformFile(filePath, {
28
+ visitCallExpression: function (n) {
29
+ const callee = n.node.callee as recast.types.namedTypes.Identifier;
30
+ if (callee.name !== "defineConfig") {
31
+ return this.traverse(n);
32
+ }
33
+
34
+ const b = recast.types.builders;
35
+ n.node.arguments = [
36
+ b.objectExpression([
37
+ b.objectProperty(
38
+ b.identifier("server"),
39
+ b.objectExpression([
40
+ b.objectProperty(
41
+ b.identifier("preset"),
42
+ b.stringLiteral("cloudflare-pages")
43
+ ),
44
+ b.objectProperty(
45
+ b.identifier("rollupConfig"),
46
+ b.objectExpression([
47
+ b.objectProperty(
48
+ b.identifier("external"),
49
+ b.arrayExpression([b.stringLiteral("node:async_hooks")])
50
+ ),
51
+ ])
52
+ ),
53
+ ])
54
+ ),
55
+ ]),
56
+ ];
57
+
58
+ return false;
59
+ },
60
+ });
61
+ };
62
+
17
63
  const config: TemplateConfig = {
18
64
  configVersion: 1,
19
65
  id: "solid",
20
66
  displayName: "Solid",
21
67
  platform: "pages",
22
68
  copyFiles: {
23
- js: { path: "./js" },
24
- ts: { path: "./ts" },
69
+ path: "./templates",
25
70
  },
26
71
  generate,
72
+ configure,
27
73
  transformPackageJson: async () => ({
28
74
  scripts: {
29
- "pages:preview": `${npm} run build && npx wrangler pages dev dist ${await compatDateFlag()} --compatibility-flag nodejs_compat`,
30
- "pages:deploy": `${npm} run build && wrangler pages deploy ./dist`,
75
+ preview: `${npm} run build && npx wrangler pages dev`,
76
+ deploy: `${npm} run build && wrangler pages deploy`,
31
77
  },
32
78
  }),
33
- devScript: "dev",
34
- previewScript: "pages:preview",
35
79
  compatibilityFlags: ["nodejs_compat"],
80
+ devScript: "dev",
81
+ deployScript: "deploy",
82
+ previewScript: "preview",
36
83
  };
37
84
  export default config;
@@ -0,0 +1,77 @@
1
+ #:schema node_modules/wrangler/config-schema.json
2
+ name = "<TBD>"
3
+ compatibility_date = "<TBD>"
4
+ compatibility_flags = ["nodejs_compat"]
5
+ pages_build_output_dir = "./dist"
6
+
7
+ # Variable bindings. These are arbitrary, plaintext strings (similar to environment variables)
8
+ # Note: Use secrets to store sensitive data.
9
+ # Docs: https://developers.cloudflare.com/pages/functions/bindings/#environment-variables
10
+ # [vars]
11
+ # MY_VARIABLE = "production_value"
12
+
13
+ # Bind the Workers AI model catalog. Run machine learning models, powered by serverless GPUs, on Cloudflare’s global network
14
+ # Docs: https://developers.cloudflare.com/pages/functions/bindings/#workers-ai
15
+ # [ai]
16
+ # binding = "AI"
17
+
18
+ # Bind a D1 database. D1 is Cloudflare’s native serverless SQL database.
19
+ # Docs: https://developers.cloudflare.com/pages/functions/bindings/#d1-databases
20
+ # [[d1_databases]]
21
+ # binding = "MY_DB"
22
+ # database_name = "my-database"
23
+ # database_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
24
+
25
+ # Bind a Durable Object. Durable objects are a scale-to-zero compute primitive based on the actor model.
26
+ # Durable Objects can live for as long as needed. Use these when you need a long-running "server", such as in realtime apps.
27
+ # Docs: https://developers.cloudflare.com/workers/runtime-apis/durable-objects
28
+ # [[durable_objects.bindings]]
29
+ # name = "MY_DURABLE_OBJECT"
30
+ # class_name = "MyDurableObject"
31
+ # script_name = 'my-durable-object'
32
+
33
+ # Bind a KV Namespace. Use KV as persistent storage for small key-value pairs.
34
+ # Docs: https://developers.cloudflare.com/pages/functions/bindings/#kv-namespaces
35
+ # [[kv_namespaces]]
36
+ # binding = "MY_KV_NAMESPACE"
37
+ # id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
38
+
39
+ # Bind a Queue producer. Use this binding to schedule an arbitrary task that may be processed later by a Queue consumer.
40
+ # Docs: https://developers.cloudflare.com/pages/functions/bindings/#queue-producers
41
+ # [[queues.producers]]
42
+ # binding = "MY_QUEUE"
43
+ # queue = "my-queue"
44
+
45
+ # Bind an R2 Bucket. Use R2 to store arbitrarily large blobs of data, such as files.
46
+ # Docs: https://developers.cloudflare.com/pages/functions/bindings/#r2-buckets
47
+ # [[r2_buckets]]
48
+ # binding = "MY_BUCKET"
49
+ # bucket_name = "my-bucket"
50
+
51
+ # Bind another Worker service. Use this binding to call another Worker without network overhead.
52
+ # Docs: https://developers.cloudflare.com/pages/functions/bindings/#service-bindings
53
+ # [[services]]
54
+ # binding = "MY_SERVICE"
55
+ # service = "my-service"
56
+
57
+ # To use different bindings for preview and production environments, follow the examples below.
58
+ # When using environment-specific overrides for bindings, ALL bindings must be specified on a per-environment basis.
59
+ # Docs: https://developers.cloudflare.com/pages/functions/wrangler-configuration#environment-specific-overrides
60
+
61
+ ######## PREVIEW environment config ########
62
+
63
+ # [env.preview.vars]
64
+ # API_KEY = "xyz789"
65
+
66
+ # [[env.preview.kv_namespaces]]
67
+ # binding = "MY_KV_NAMESPACE"
68
+ # id = "<PREVIEW_NAMESPACE_ID>"
69
+
70
+ ######## PRODUCTION environment config ########
71
+
72
+ # [env.production.vars]
73
+ # API_KEY = "abc123"
74
+
75
+ # [[env.production.kv_namespaces]]
76
+ # binding = "MY_KV_NAMESPACE"
77
+ # id = "<PRODUCTION_NAMESPACE_ID>"
@@ -1,13 +1,14 @@
1
+ import { platform } from "node:os";
1
2
  import { logRaw, updateStatus } from "@cloudflare/cli";
2
3
  import { blue, brandColor, dim } from "@cloudflare/cli/colors";
3
- import { parseTs, transformFile } from "helpers/codemod";
4
- import { installPackages, runFrameworkGenerator } from "helpers/command";
5
- import { compatDateFlag, usesTypescript } from "helpers/files";
6
- import { detectPackageManager } from "helpers/packages";
7
- import { platformInterface } from "./templates";
4
+ import { runFrameworkGenerator } from "frameworks/index";
5
+ import { transformFile } from "helpers/codemod";
6
+ import { usesTypescript } from "helpers/files";
7
+ import { detectPackageManager } from "helpers/packageManagers";
8
+ import { installPackages } from "helpers/packages";
9
+ import * as recast from "recast";
8
10
  import type { TemplateConfig } from "../../src/templates";
9
- import type * as recast from "recast";
10
- import type { C3Context } from "types";
11
+ import type { C3Context, PackageJson } from "types";
11
12
 
12
13
  const { npm } = detectPackageManager();
13
14
 
@@ -26,7 +27,14 @@ const configure = async (ctx: C3Context) => {
26
27
  doneText: `${brandColor(`installed`)} ${dim(pkg)}`,
27
28
  });
28
29
 
29
- // Change the import statement in svelte.config.js
30
+ updateSvelteConfig();
31
+ updateTypeDefinitions(ctx);
32
+ };
33
+
34
+ const updateSvelteConfig = () => {
35
+ // All we need to do is change the import statement in svelte.config.js
36
+ updateStatus(`Changing adapter in ${blue("svelte.config.js")}`);
37
+
30
38
  transformFile("svelte.config.js", {
31
39
  visitImportDeclaration: function (n) {
32
40
  // importSource is the `x` in `import y from "x"`
@@ -39,23 +47,51 @@ const configure = async (ctx: C3Context) => {
39
47
  return false;
40
48
  },
41
49
  });
42
- updateStatus(`Changing adapter in ${blue("svelte.config.js")}`);
50
+ };
43
51
 
44
- // If using typescript, add the platform interface to the `App` interface
45
- if (usesTypescript(ctx)) {
46
- transformFile("src/app.d.ts", {
47
- visitTSModuleDeclaration(n) {
48
- if (n.value.id.name === "App") {
49
- const patchAst = parseTs(platformInterface);
50
- const body = n.node.body as recast.types.namedTypes.TSModuleBlock;
51
- body.body.push(patchAst.program.body[0]);
52
- }
53
-
54
- this.traverse(n);
55
- },
56
- });
57
- updateStatus(`Updating global type definitions in ${blue("app.d.ts")}`);
52
+ const updateTypeDefinitions = (ctx: C3Context) => {
53
+ if (!usesTypescript(ctx)) {
54
+ return;
58
55
  }
56
+
57
+ updateStatus(`Updating global type definitions in ${blue("app.d.ts")}`);
58
+
59
+ const b = recast.types.builders;
60
+
61
+ transformFile("src/app.d.ts", {
62
+ visitTSModuleDeclaration(n) {
63
+ if (n.value.id.name === "App" && n.node.body) {
64
+ const moduleBlock = n.node
65
+ .body as recast.types.namedTypes.TSModuleBlock;
66
+
67
+ const platformInterface = b.tsInterfaceDeclaration(
68
+ b.identifier("Platform"),
69
+ b.tsInterfaceBody([
70
+ b.tsPropertySignature(
71
+ b.identifier("env"),
72
+ b.tsTypeAnnotation(b.tsTypeReference(b.identifier("Env")))
73
+ ),
74
+ b.tsPropertySignature(
75
+ b.identifier("cf"),
76
+ b.tsTypeAnnotation(
77
+ b.tsTypeReference(b.identifier("CfProperties"))
78
+ )
79
+ ),
80
+ b.tsPropertySignature(
81
+ b.identifier("ctx"),
82
+ b.tsTypeAnnotation(
83
+ b.tsTypeReference(b.identifier("ExecutionContext"))
84
+ )
85
+ ),
86
+ ])
87
+ );
88
+
89
+ moduleBlock.body.unshift(platformInterface);
90
+ }
91
+
92
+ this.traverse(n);
93
+ },
94
+ });
59
95
  };
60
96
 
61
97
  const config: TemplateConfig = {
@@ -63,15 +99,32 @@ const config: TemplateConfig = {
63
99
  id: "svelte",
64
100
  displayName: "Svelte",
65
101
  platform: "pages",
102
+ copyFiles: {
103
+ variants: {
104
+ js: { path: "./js" },
105
+ ts: { path: "./ts" },
106
+ },
107
+ },
66
108
  generate,
67
109
  configure,
68
- transformPackageJson: async () => ({
69
- scripts: {
70
- "pages:preview": `${npm} run build && wrangler pages dev ${await compatDateFlag()} .svelte-kit/cloudflare`,
71
- "pages:deploy": `${npm} run build && wrangler pages deploy .svelte-kit/cloudflare`,
72
- },
73
- }),
110
+ transformPackageJson: async (original: PackageJson, ctx: C3Context) => {
111
+ let scripts: Record<string, string> = {
112
+ preview: `${npm} run build && wrangler pages dev`,
113
+ deploy: `${npm} run build && wrangler pages deploy`,
114
+ };
115
+
116
+ if (usesTypescript(ctx)) {
117
+ const mv = platform() === "win32" ? "move" : "mv";
118
+ scripts = {
119
+ ...scripts,
120
+ "cf-typegen": `wrangler types && ${mv} worker-configuration.d.ts src/`,
121
+ };
122
+ }
123
+
124
+ return { scripts };
125
+ },
74
126
  devScript: "dev",
75
- previewScript: "pages:preview",
127
+ deployScript: "deploy",
128
+ previewScript: "preview",
76
129
  };
77
130
  export default config;
@@ -0,0 +1,78 @@
1
+ #:schema node_modules/wrangler/config-schema.json
2
+ name = "<TBD>"
3
+ compatibility_date = "<TBD>"
4
+ pages_build_output_dir = ".svelte-kit/cloudflare"
5
+
6
+ # Variable bindings. These are arbitrary, plaintext strings (similar to environment variables)
7
+ # Docs:
8
+ # - https://developers.cloudflare.com/pages/functions/bindings/#environment-variables
9
+ # Note: Use secrets to store sensitive data.
10
+ # - https://developers.cloudflare.com/pages/functions/bindings/#secrets
11
+ # [vars]
12
+ # MY_VARIABLE = "production_value"
13
+
14
+ # Bind the Workers AI model catalog. Run machine learning models, powered by serverless GPUs, on Cloudflare’s global network
15
+ # Docs: https://developers.cloudflare.com/pages/functions/bindings/#workers-ai
16
+ # [ai]
17
+ # binding = "AI"
18
+
19
+ # Bind a D1 database. D1 is Cloudflare’s native serverless SQL database.
20
+ # Docs: https://developers.cloudflare.com/pages/functions/bindings/#d1-databases
21
+ # [[d1_databases]]
22
+ # binding = "MY_DB"
23
+ # database_name = "my-database"
24
+ # database_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
25
+
26
+ # Bind a Durable Object. Durable objects are a scale-to-zero compute primitive based on the actor model.
27
+ # Durable Objects can live for as long as needed. Use these when you need a long-running "server", such as in realtime apps.
28
+ # Docs: https://developers.cloudflare.com/workers/runtime-apis/durable-objects
29
+ # [[durable_objects.bindings]]
30
+ # name = "MY_DURABLE_OBJECT"
31
+ # class_name = "MyDurableObject"
32
+ # script_name = 'my-durable-object'
33
+
34
+ # Bind a KV Namespace. Use KV as persistent storage for small key-value pairs.
35
+ # Docs: https://developers.cloudflare.com/pages/functions/bindings/#kv-namespaces
36
+ # [[kv_namespaces]]
37
+ # binding = "MY_KV_NAMESPACE"
38
+ # id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
39
+
40
+ # Bind a Queue producer. Use this binding to schedule an arbitrary task that may be processed later by a Queue consumer.
41
+ # Docs: https://developers.cloudflare.com/pages/functions/bindings/#queue-producers
42
+ # [[queues.producers]]
43
+ # binding = "MY_QUEUE"
44
+ # queue = "my-queue"
45
+
46
+ # Bind an R2 Bucket. Use R2 to store arbitrarily large blobs of data, such as files.
47
+ # Docs: https://developers.cloudflare.com/pages/functions/bindings/#r2-buckets
48
+ # [[r2_buckets]]
49
+ # binding = "MY_BUCKET"
50
+ # bucket_name = "my-bucket"
51
+
52
+ # Bind another Worker service. Use this binding to call another Worker without network overhead.
53
+ # Docs: https://developers.cloudflare.com/pages/functions/bindings/#service-bindings
54
+ # [[services]]
55
+ # binding = "MY_SERVICE"
56
+ # service = "my-service"
57
+
58
+ # To use different bindings for preview and production environments, follow the examples below.
59
+ # When using environment-specific overrides for bindings, ALL bindings must be specified on a per-environment basis.
60
+ # Docs: https://developers.cloudflare.com/pages/functions/wrangler-configuration#environment-specific-overrides
61
+
62
+ ######## PREVIEW environment config ########
63
+
64
+ # [env.preview.vars]
65
+ # API_KEY = "xyz789"
66
+
67
+ # [[env.preview.kv_namespaces]]
68
+ # binding = "MY_KV_NAMESPACE"
69
+ # id = "<PREVIEW_NAMESPACE_ID>"
70
+
71
+ ######## PRODUCTION environment config ########
72
+
73
+ # [env.production.vars]
74
+ # API_KEY = "abc123"
75
+
76
+ # [[env.production.kv_namespaces]]
77
+ # binding = "MY_KV_NAMESPACE"
78
+ # id = "<PRODUCTION_NAMESPACE_ID>"