create-cloudflare 0.0.0-d031e75a → 0.0.0-d0fb7b81

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 (45) hide show
  1. package/dist/cli.js +20217 -19197
  2. package/package.json +3 -5
  3. package/templates/angular/c3.ts +4 -5
  4. package/templates/astro/c3.ts +1 -1
  5. package/templates/common/c3.ts +7 -6
  6. package/templates/hello-world/c3.ts +7 -6
  7. package/templates/hello-world-durable-object/c3.ts +7 -6
  8. package/templates/hono/c3.ts +2 -2
  9. package/templates/next/README.md +58 -0
  10. package/templates/next/app/js/app/api/hello/route.js +21 -0
  11. package/templates/next/app/js/app/not-found.js +58 -0
  12. package/templates/next/app/ts/app/api/hello/route.ts +22 -0
  13. package/templates/next/app/ts/app/not-found.tsx +58 -0
  14. package/templates/next/c3.ts +76 -61
  15. package/templates/next/env.d.ts +7 -0
  16. package/templates/next/pages/js/pages/api/hello.js +23 -0
  17. package/templates/next/pages/ts/pages/api/hello.ts +24 -0
  18. package/templates/next/wrangler.toml +57 -0
  19. package/templates/nuxt/c3.ts +57 -17
  20. package/templates/nuxt/templates/wrangler.toml +50 -0
  21. package/templates/openapi/c3.ts +0 -1
  22. package/templates/pre-existing/c3.ts +2 -4
  23. package/templates/queues/c3.ts +7 -6
  24. package/templates/qwik/c3.ts +62 -3
  25. package/templates/qwik/templates/wrangler.toml +50 -0
  26. package/templates/remix/c3.ts +1 -1
  27. package/templates/scheduled/c3.ts +7 -6
  28. package/templates/solid/c3.ts +11 -20
  29. package/templates/solid/js/vite.config.js +9 -4
  30. package/templates/solid/ts/vite.config.ts +9 -4
  31. package/templates/svelte/c3.ts +81 -27
  32. package/templates/svelte/js/src/hooks.server.js +25 -0
  33. package/templates/svelte/js/wrangler.toml +50 -0
  34. package/templates/svelte/ts/src/hooks.server.ts +24 -0
  35. package/templates/svelte/ts/wrangler.toml +50 -0
  36. package/templates/chatgptPlugin/c3.ts +0 -10
  37. package/templates/chatgptPlugin/ts/.assets/example.png +0 -0
  38. package/templates/chatgptPlugin/ts/README.md +0 -25
  39. package/templates/chatgptPlugin/ts/__dot__gitignore +0 -171
  40. package/templates/chatgptPlugin/ts/package.json +0 -16
  41. package/templates/chatgptPlugin/ts/src/index.ts +0 -33
  42. package/templates/chatgptPlugin/ts/src/search.ts +0 -59
  43. package/templates/chatgptPlugin/ts/wrangler.toml +0 -3
  44. package/templates/next/templates.ts +0 -281
  45. package/templates/svelte/templates.ts +0 -13
@@ -0,0 +1,57 @@
1
+ name = "<TBD>"
2
+ compatibility_date = "<TBD>"
3
+
4
+ compatibility_flags = ["nodejs_compat"]
5
+
6
+ # Variable bindings. These are arbitrary, plaintext strings (similar to environment variables)
7
+ # Note: Use secrets to store sensitive data.
8
+ # Docs: https://developers.cloudflare.com/workers/platform/environment-variables
9
+ # [vars]
10
+ # MY_VARIABLE = "production_value"
11
+
12
+ # Bind a KV Namespace. Use KV as persistent storage for small key-value pairs.
13
+ # Docs: https://developers.cloudflare.com/workers/runtime-apis/kv
14
+ # [[kv_namespaces]]
15
+ # binding = "MY_KV_NAMESPACE"
16
+ # id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
17
+
18
+ # Bind an R2 Bucket. Use R2 to store arbitrarily large blobs of data, such as files.
19
+ # Docs: https://developers.cloudflare.com/r2/api/workers/workers-api-usage/
20
+ # [[r2_buckets]]
21
+ # binding = "MY_BUCKET"
22
+ # bucket_name = "my-bucket"
23
+
24
+ # Bind a Queue producer. Use this binding to schedule an arbitrary task that may be processed later by a Queue consumer.
25
+ # Docs: https://developers.cloudflare.com/queues/get-started
26
+ # [[queues.producers]]
27
+ # binding = "MY_QUEUE"
28
+ # queue = "my-queue"
29
+
30
+ # Bind a Queue consumer. Queue Consumers can retrieve tasks scheduled by Producers to act on them.
31
+ # Docs: https://developers.cloudflare.com/queues/get-started
32
+ # [[queues.consumers]]
33
+ # queue = "my-queue"
34
+
35
+ # Bind another Worker service. Use this binding to call another Worker without network overhead.
36
+ # Docs: https://developers.cloudflare.com/workers/platform/services
37
+ # [[services]]
38
+ # binding = "MY_SERVICE"
39
+ # service = "my-service"
40
+
41
+ # Bind a Durable Object. Durable objects are a scale-to-zero compute primitive based on the actor model.
42
+ # Durable Objects can live for as long as needed. Use these when you need a long-running "server", such as in realtime apps.
43
+ # Docs: https://developers.cloudflare.com/workers/runtime-apis/durable-objects
44
+ # [[durable_objects.bindings]]
45
+ # name = "MY_DURABLE_OBJECT"
46
+ # class_name = "MyDurableObject"
47
+
48
+ # Durable Object migrations.
49
+ # Docs: https://developers.cloudflare.com/workers/learning/using-durable-objects#configure-durable-object-classes-with-migrations
50
+ # [[migrations]]
51
+ # tag = "v1"
52
+ # new_classes = ["MyDurableObject"]
53
+
54
+ # KV Example:
55
+ # [[kv_namespaces]]
56
+ # binding = "MY_KV"
57
+ # id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
@@ -1,11 +1,11 @@
1
- import { readFileSync } from "node:fs";
2
- import { resolve } from "node:path";
3
1
  import { logRaw } from "@cloudflare/cli";
4
2
  import { brandColor, dim } from "@cloudflare/cli/colors";
5
3
  import { spinner } from "@cloudflare/cli/interactive";
6
- import { runFrameworkGenerator } from "helpers/command";
7
- import { compatDateFlag, writeFile } from "helpers/files";
4
+ import { transformFile } from "helpers/codemod";
5
+ import { installPackages, runFrameworkGenerator } from "helpers/command";
6
+ import { writeFile } from "helpers/files";
8
7
  import { detectPackageManager } from "helpers/packages";
8
+ import * as recast from "recast";
9
9
  import type { TemplateConfig } from "../../src/templates";
10
10
  import type { C3Context } from "types";
11
11
 
@@ -27,32 +27,72 @@ const generate = async (ctx: C3Context) => {
27
27
  logRaw(""); // newline
28
28
  };
29
29
 
30
- const configure = async (ctx: C3Context) => {
31
- const configFileName = "nuxt.config.ts";
32
- const configFilePath = resolve(configFileName);
30
+ const configure = async () => {
31
+ await installPackages(["nitro-cloudflare-dev"], {
32
+ dev: true,
33
+ startText: "Installing nitro module `nitro-cloudflare-dev`",
34
+ doneText: `${brandColor("installed")} ${dim(`via \`${npm} install\``)}`,
35
+ });
36
+ updateNuxtConfig();
37
+ };
38
+
39
+ const updateNuxtConfig = () => {
33
40
  const s = spinner();
34
- s.start(`Updating \`${configFileName}\``);
35
- // Add the cloudflare preset into the configuration file.
36
- const originalConfigFile = readFileSync(configFilePath, "utf8");
37
- const updatedConfigFile = originalConfigFile.replace(
38
- "defineNuxtConfig({",
39
- "defineNuxtConfig({\n nitro: {\n preset: 'cloudflare-pages'\n },"
41
+
42
+ const configFile = "nuxt.config.ts";
43
+ s.start(`Updating \`${configFile}\``);
44
+
45
+ const b = recast.types.builders;
46
+
47
+ const presetDef = b.objectProperty(
48
+ b.identifier("nitro"),
49
+ b.objectExpression([
50
+ b.objectProperty(
51
+ b.identifier("preset"),
52
+ b.stringLiteral("cloudflare-pages")
53
+ ),
54
+ ])
55
+ );
56
+
57
+ const moduleDef = b.objectProperty(
58
+ b.identifier("modules"),
59
+ b.arrayExpression([b.stringLiteral("nitro-cloudflare-dev")])
40
60
  );
41
- writeFile(configFilePath, updatedConfigFile);
42
- s.stop(`${brandColor(`updated`)} ${dim(`\`${configFileName}\``)}`);
61
+
62
+ transformFile(configFile, {
63
+ visitCallExpression: function (n) {
64
+ const callee = n.node.callee as recast.types.namedTypes.Identifier;
65
+ if (callee.name === "defineNuxtConfig") {
66
+ const obj = n.node
67
+ .arguments[0] as recast.types.namedTypes.ObjectExpression;
68
+
69
+ obj.properties.push(presetDef);
70
+ obj.properties.push(moduleDef);
71
+ }
72
+
73
+ return this.traverse(n);
74
+ },
75
+ });
76
+
77
+ s.stop(`${brandColor(`updated`)} ${dim(`\`${configFile}\``)}`);
43
78
  };
44
79
 
45
80
  const config: TemplateConfig = {
46
81
  configVersion: 1,
47
82
  id: "nuxt",
48
83
  platform: "pages",
84
+ copyFiles: {
85
+ path: "./templates",
86
+ },
49
87
  displayName: "Nuxt",
88
+ devScript: "dev",
89
+ deployScript: "deploy",
50
90
  generate,
51
91
  configure,
52
92
  transformPackageJson: async () => ({
53
93
  scripts: {
54
- "pages:dev": `wrangler pages dev ${await compatDateFlag()} --proxy 3000 -- ${npm} run dev`,
55
- "pages:deploy": `${npm} run build && wrangler pages deploy ./dist`,
94
+ deploy: `${npm} run build && wrangler pages deploy ./dist`,
95
+ preview: `${npm} run build && wrangler pages dev ./dist`,
56
96
  },
57
97
  }),
58
98
  };
@@ -0,0 +1,50 @@
1
+ name = "<TBD>"
2
+ compatibility_date = "<TBD>"
3
+
4
+ # Variable bindings. These are arbitrary, plaintext strings (similar to environment variables)
5
+ # Note: Use secrets to store sensitive data.
6
+ # Docs: https://developers.cloudflare.com/workers/platform/environment-variables
7
+ # [vars]
8
+ # MY_VARIABLE = "production_value"
9
+
10
+ # Bind a KV Namespace. Use KV as persistent storage for small key-value pairs.
11
+ # Docs: https://developers.cloudflare.com/workers/runtime-apis/kv
12
+ # [[kv_namespaces]]
13
+ # binding = "MY_KV_NAMESPACE"
14
+ # id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
15
+
16
+ # Bind an R2 Bucket. Use R2 to store arbitrarily large blobs of data, such as files.
17
+ # Docs: https://developers.cloudflare.com/r2/api/workers/workers-api-usage/
18
+ # [[r2_buckets]]
19
+ # binding = "MY_BUCKET"
20
+ # bucket_name = "my-bucket"
21
+
22
+ # Bind a Queue producer. Use this binding to schedule an arbitrary task that may be processed later by a Queue consumer.
23
+ # Docs: https://developers.cloudflare.com/queues/get-started
24
+ # [[queues.producers]]
25
+ # binding = "MY_QUEUE"
26
+ # queue = "my-queue"
27
+
28
+ # Bind a Queue consumer. Queue Consumers can retrieve tasks scheduled by Producers to act on them.
29
+ # Docs: https://developers.cloudflare.com/queues/get-started
30
+ # [[queues.consumers]]
31
+ # queue = "my-queue"
32
+
33
+ # Bind another Worker service. Use this binding to call another Worker without network overhead.
34
+ # Docs: https://developers.cloudflare.com/workers/platform/services
35
+ # [[services]]
36
+ # binding = "MY_SERVICE"
37
+ # service = "my-service"
38
+
39
+ # Bind a Durable Object. Durable objects are a scale-to-zero compute primitive based on the actor model.
40
+ # Durable Objects can live for as long as needed. Use these when you need a long-running "server", such as in realtime apps.
41
+ # Docs: https://developers.cloudflare.com/workers/runtime-apis/durable-objects
42
+ # [[durable_objects.bindings]]
43
+ # name = "MY_DURABLE_OBJECT"
44
+ # class_name = "MyDurableObject"
45
+
46
+ # Durable Object migrations.
47
+ # Docs: https://developers.cloudflare.com/workers/learning/using-durable-objects#configure-durable-object-classes-with-migrations
48
+ # [[migrations]]
49
+ # tag = "v1"
50
+ # new_classes = ["MyDurableObject"]
@@ -3,7 +3,6 @@ export default {
3
3
  id: "openapi",
4
4
  displayName: "API starter (OpenAPI compliant)",
5
5
  platform: "workers",
6
- languages: ["ts"],
7
6
  copyFiles: {
8
7
  path: "./ts",
9
8
  },
@@ -1,7 +1,6 @@
1
- import { cp, mkdtemp, readdir, rm } from "fs/promises";
1
+ import { cp, mkdtemp } from "fs/promises";
2
2
  import { tmpdir } from "os";
3
3
  import { join } from "path";
4
- import { crash } from "@cloudflare/cli";
5
4
  import { processArgument } from "@cloudflare/cli/args";
6
5
  import { brandColor, dim } from "@cloudflare/cli/colors";
7
6
  import { runCommand } from "helpers/command";
@@ -10,7 +9,7 @@ import { chooseAccount } from "../../src/common";
10
9
  import type { C3Context } from "types";
11
10
 
12
11
  export async function copyExistingWorkerFiles(ctx: C3Context) {
13
- const { dlx, npm } = detectPackageManager();
12
+ const { dlx } = detectPackageManager();
14
13
 
15
14
  await chooseAccount(ctx);
16
15
 
@@ -72,7 +71,6 @@ export default {
72
71
  displayName: "Pre-existing Worker (from Dashboard)",
73
72
  platform: "workers",
74
73
  hidden: true,
75
- languages: ["js"],
76
74
  copyFiles: {
77
75
  path: "./js",
78
76
  },
@@ -3,13 +3,14 @@ export default {
3
3
  id: "queues",
4
4
  displayName: "Queue consumer & producer Worker",
5
5
  platform: "workers",
6
- languages: ["js", "ts"],
7
6
  copyFiles: {
8
- js: {
9
- path: "./js",
10
- },
11
- ts: {
12
- path: "./ts",
7
+ variants: {
8
+ js: {
9
+ path: "./js",
10
+ },
11
+ ts: {
12
+ path: "./ts",
13
+ },
13
14
  },
14
15
  },
15
16
  bindings: {
@@ -1,9 +1,13 @@
1
1
  import { endSection } from "@cloudflare/cli";
2
+ import { brandColor } from "@cloudflare/cli/colors";
3
+ import { spinner } from "@cloudflare/cli/interactive";
4
+ import { parseTs, transformFile } from "helpers/codemod";
2
5
  import { runCommand, runFrameworkGenerator } from "helpers/command";
3
- import { compatDateFlag } from "helpers/files";
6
+ import { usesTypescript } from "helpers/files";
4
7
  import { detectPackageManager } from "helpers/packages";
5
8
  import { quoteShellArgs } from "../../src/common";
6
9
  import type { TemplateConfig } from "../../src/templates";
10
+ import type * as recast from "recast";
7
11
  import type { C3Context } from "types";
8
12
 
9
13
  const { npm, npx } = detectPackageManager();
@@ -17,6 +21,57 @@ const configure = async (ctx: C3Context) => {
17
21
  const cmd = [npx, "qwik", "add", "cloudflare-pages"];
18
22
  endSection(`Running ${quoteShellArgs(cmd)}`);
19
23
  await runCommand(cmd);
24
+
25
+ addBindingsProxy(ctx);
26
+ };
27
+
28
+ const addBindingsProxy = (ctx: C3Context) => {
29
+ // Qwik only has a typescript template atm.
30
+ // This check is an extra precaution
31
+ if (!usesTypescript(ctx)) {
32
+ return;
33
+ }
34
+
35
+ const s = spinner();
36
+ s.start("Updating `vite.config.ts`");
37
+
38
+ // Insert the env declaration after the last import (but before the rest of the body)
39
+ const envDeclaration = `
40
+ let env = {};
41
+
42
+ if(process.env.NODE_ENV === 'development') {
43
+ const { getPlatformProxy } = await import('wrangler');
44
+ const platformProxy = await getPlatformProxy();
45
+ env = platformProxy.env;
46
+ }
47
+ `;
48
+
49
+ transformFile("vite.config.ts", {
50
+ visitProgram: function (n) {
51
+ const lastImportIndex = n.node.body.findLastIndex(
52
+ (t) => t.type === "ImportDeclaration"
53
+ );
54
+ n.get("body").insertAt(lastImportIndex + 1, envDeclaration);
55
+
56
+ return false;
57
+ },
58
+ });
59
+
60
+ // Populate the `qwikCity` plugin with the platform object containing the `env` defined above.
61
+ const platformObject = parseTs(`{ platform: { env } }`);
62
+
63
+ transformFile("vite.config.ts", {
64
+ visitCallExpression: function (n) {
65
+ const callee = n.node.callee as recast.types.namedTypes.Identifier;
66
+ if (callee.name === "qwikCity") {
67
+ n.node.arguments = [platformObject];
68
+ }
69
+
70
+ this.traverse(n);
71
+ },
72
+ });
73
+
74
+ s.stop(`${brandColor("updated")} \`vite.config.ts\``);
20
75
  };
21
76
 
22
77
  const config: TemplateConfig = {
@@ -24,12 +79,16 @@ const config: TemplateConfig = {
24
79
  id: "qwik",
25
80
  displayName: "Qwik",
26
81
  platform: "pages",
82
+ copyFiles: {
83
+ path: "./templates",
84
+ },
85
+ devScript: "dev",
86
+ deployScript: "deploy",
27
87
  generate,
28
88
  configure,
29
89
  transformPackageJson: async () => ({
30
90
  scripts: {
31
- "pages:dev": `wrangler pages dev ${await compatDateFlag()} -- ${npm} run dev`,
32
- "pages:deploy": `${npm} run build && wrangler pages deploy ./dist`,
91
+ deploy: `${npm} run build && wrangler pages deploy ./dist`,
33
92
  },
34
93
  }),
35
94
  };
@@ -0,0 +1,50 @@
1
+ name = "<TBD>"
2
+ compatibility_date = "<TBD>"
3
+
4
+ # Variable bindings. These are arbitrary, plaintext strings (similar to environment variables)
5
+ # Note: Use secrets to store sensitive data.
6
+ # Docs: https://developers.cloudflare.com/workers/platform/environment-variables
7
+ # [vars]
8
+ # MY_VARIABLE = "production_value"
9
+
10
+ # Bind a KV Namespace. Use KV as persistent storage for small key-value pairs.
11
+ # Docs: https://developers.cloudflare.com/workers/runtime-apis/kv
12
+ # [[kv_namespaces]]
13
+ # binding = "MY_KV_NAMESPACE"
14
+ # id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
15
+
16
+ # Bind an R2 Bucket. Use R2 to store arbitrarily large blobs of data, such as files.
17
+ # Docs: https://developers.cloudflare.com/r2/api/workers/workers-api-usage/
18
+ # [[r2_buckets]]
19
+ # binding = "MY_BUCKET"
20
+ # bucket_name = "my-bucket"
21
+
22
+ # Bind a Queue producer. Use this binding to schedule an arbitrary task that may be processed later by a Queue consumer.
23
+ # Docs: https://developers.cloudflare.com/queues/get-started
24
+ # [[queues.producers]]
25
+ # binding = "MY_QUEUE"
26
+ # queue = "my-queue"
27
+
28
+ # Bind a Queue consumer. Queue Consumers can retrieve tasks scheduled by Producers to act on them.
29
+ # Docs: https://developers.cloudflare.com/queues/get-started
30
+ # [[queues.consumers]]
31
+ # queue = "my-queue"
32
+
33
+ # Bind another Worker service. Use this binding to call another Worker without network overhead.
34
+ # Docs: https://developers.cloudflare.com/workers/platform/services
35
+ # [[services]]
36
+ # binding = "MY_SERVICE"
37
+ # service = "my-service"
38
+
39
+ # Bind a Durable Object. Durable objects are a scale-to-zero compute primitive based on the actor model.
40
+ # Durable Objects can live for as long as needed. Use these when you need a long-running "server", such as in realtime apps.
41
+ # Docs: https://developers.cloudflare.com/workers/runtime-apis/durable-objects
42
+ # [[durable_objects.bindings]]
43
+ # name = "MY_DURABLE_OBJECT"
44
+ # class_name = "MyDurableObject"
45
+
46
+ # Durable Object migrations.
47
+ # Docs: https://developers.cloudflare.com/workers/learning/using-durable-objects#configure-durable-object-classes-with-migrations
48
+ # [[migrations]]
49
+ # tag = "v1"
50
+ # new_classes = ["MyDurableObject"]
@@ -27,7 +27,7 @@ const config: TemplateConfig = {
27
27
  "pages:deploy": `${npm} run build && wrangler pages deploy ./public`,
28
28
  },
29
29
  }),
30
- devCommand: ["dev"],
30
+ devScript: "dev",
31
31
  testFlags: ["--typescript", "--no-install", "--no-git-init"],
32
32
  };
33
33
  export default config;
@@ -3,13 +3,14 @@ export default {
3
3
  id: "scheduled",
4
4
  displayName: "Scheduled Worker (Cron Trigger)",
5
5
  platform: "workers",
6
- languages: ["js", "ts"],
7
6
  copyFiles: {
8
- js: {
9
- path: "./js",
10
- },
11
- ts: {
12
- path: "./ts",
7
+ variants: {
8
+ js: {
9
+ path: "./js",
10
+ },
11
+ ts: {
12
+ path: "./ts",
13
+ },
13
14
  },
14
15
  },
15
16
  };
@@ -1,6 +1,5 @@
1
- import { logRaw, updateStatus } from "@cloudflare/cli";
2
- import { blue, brandColor, dim } from "@cloudflare/cli/colors";
3
- import { installPackages, runFrameworkGenerator } from "helpers/command";
1
+ import { logRaw } from "@cloudflare/cli";
2
+ import { runFrameworkGenerator } from "helpers/command";
4
3
  import { compatDateFlag } from "helpers/files";
5
4
  import { detectPackageManager } from "helpers/packages";
6
5
  import type { TemplateConfig } from "../../src/templates";
@@ -15,34 +14,26 @@ const generate = async (ctx: C3Context) => {
15
14
  logRaw("");
16
15
  };
17
16
 
18
- const configure = async (ctx: C3Context) => {
19
- // Install the pages adapter
20
- const pkg = "solid-start-cloudflare-pages";
21
- await installPackages([pkg], {
22
- dev: true,
23
- startText: "Adding the Cloudflare Pages adapter",
24
- doneText: `${brandColor(`installed`)} ${dim(pkg)}`,
25
- });
26
-
27
- updateStatus(`Adding the Cloudflare Pages adapter to vite config`);
28
- };
29
-
30
17
  const config: TemplateConfig = {
31
18
  configVersion: 1,
32
19
  id: "solid",
33
20
  displayName: "Solid",
34
21
  platform: "pages",
35
22
  copyFiles: {
36
- js: { path: "./js" },
37
- ts: { path: "./ts" },
23
+ variants: {
24
+ js: { path: "./js" },
25
+ ts: { path: "./ts" },
26
+ },
38
27
  },
39
28
  generate,
40
- configure,
41
29
  transformPackageJson: async () => ({
42
30
  scripts: {
43
- "pages:dev": `wrangler pages dev ${await compatDateFlag()} --proxy 3000 -- ${npm} run dev`,
44
- "pages:deploy": `${npm} run build && wrangler pages deploy ./dist/public`,
31
+ "pages:preview": `${npm} run build && npx wrangler pages dev dist ${await compatDateFlag()} --compatibility-flag nodejs_compat`,
32
+ "pages:deploy": `${npm} run build && wrangler pages deploy ./dist`,
45
33
  },
46
34
  }),
35
+ devScript: "dev",
36
+ previewScript: "pages:preview",
37
+ compatibilityFlags: ["nodejs_compat"],
47
38
  };
48
39
  export default config;
@@ -1,7 +1,12 @@
1
- import cloudflare from "solid-start-cloudflare-pages";
2
- import solid from "solid-start/vite";
3
- import { defineConfig } from "vite";
1
+ import { defineConfig } from "@solidjs/start/config";
4
2
 
5
3
  export default defineConfig({
6
- plugins: [solid({ adapter: cloudflare({}) })],
4
+ start: {
5
+ server: {
6
+ preset: "cloudflare-pages",
7
+ rollupConfig: {
8
+ external: ["node:async_hooks"]
9
+ },
10
+ }
11
+ }
7
12
  });
@@ -1,7 +1,12 @@
1
- import cloudflare from "solid-start-cloudflare-pages";
2
- import solid from "solid-start/vite";
3
- import { defineConfig } from "vite";
1
+ import { defineConfig } from "@solidjs/start/config";
4
2
 
5
3
  export default defineConfig({
6
- plugins: [solid({ adapter: cloudflare({}) })],
4
+ start: {
5
+ server: {
6
+ preset: "cloudflare-pages",
7
+ rollupConfig: {
8
+ external: ["node:async_hooks"]
9
+ },
10
+ }
11
+ }
7
12
  });
@@ -1,13 +1,13 @@
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 { transformFile } from "helpers/codemod";
4
5
  import { installPackages, runFrameworkGenerator } from "helpers/command";
5
- import { compatDateFlag, usesTypescript } from "helpers/files";
6
+ import { usesTypescript } from "helpers/files";
6
7
  import { detectPackageManager } from "helpers/packages";
7
- import { platformInterface } from "./templates";
8
+ import * as recast from "recast";
8
9
  import type { TemplateConfig } from "../../src/templates";
9
- import type * as recast from "recast";
10
- import type { C3Context } from "types";
10
+ import type { C3Context, PackageJson } from "types";
11
11
 
12
12
  const { npm } = detectPackageManager();
13
13
 
@@ -26,7 +26,14 @@ const configure = async (ctx: C3Context) => {
26
26
  doneText: `${brandColor(`installed`)} ${dim(pkg)}`,
27
27
  });
28
28
 
29
- // Change the import statement in svelte.config.js
29
+ updateSvelteConfig();
30
+ updateTypeDefinitions(ctx);
31
+ };
32
+
33
+ const updateSvelteConfig = () => {
34
+ // All we need to do is change the import statement in svelte.config.js
35
+ updateStatus(`Changing adapter in ${blue("svelte.config.js")}`);
36
+
30
37
  transformFile("svelte.config.js", {
31
38
  visitImportDeclaration: function (n) {
32
39
  // importSource is the `x` in `import y from "x"`
@@ -39,23 +46,51 @@ const configure = async (ctx: C3Context) => {
39
46
  return false;
40
47
  },
41
48
  });
42
- updateStatus(`Changing adapter in ${blue("svelte.config.js")}`);
49
+ };
43
50
 
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")}`);
51
+ const updateTypeDefinitions = (ctx: C3Context) => {
52
+ if (!usesTypescript(ctx)) {
53
+ return;
58
54
  }
55
+
56
+ updateStatus(`Updating global type definitions in ${blue("app.d.ts")}`);
57
+
58
+ const b = recast.types.builders;
59
+
60
+ transformFile("src/app.d.ts", {
61
+ visitTSModuleDeclaration(n) {
62
+ if (n.value.id.name === "App" && n.node.body) {
63
+ const moduleBlock = n.node
64
+ .body as recast.types.namedTypes.TSModuleBlock;
65
+
66
+ const platformInterface = b.tsInterfaceDeclaration(
67
+ b.identifier("Platform"),
68
+ b.tsInterfaceBody([
69
+ b.tsPropertySignature(
70
+ b.identifier("env"),
71
+ b.tsTypeAnnotation(b.tsTypeReference(b.identifier("Env")))
72
+ ),
73
+ b.tsPropertySignature(
74
+ b.identifier("cf"),
75
+ b.tsTypeAnnotation(
76
+ b.tsTypeReference(b.identifier("CfProperties"))
77
+ )
78
+ ),
79
+ b.tsPropertySignature(
80
+ b.identifier("ctx"),
81
+ b.tsTypeAnnotation(
82
+ b.tsTypeReference(b.identifier("ExecutionContext"))
83
+ )
84
+ ),
85
+ ])
86
+ );
87
+
88
+ moduleBlock.body.unshift(platformInterface);
89
+ }
90
+
91
+ this.traverse(n);
92
+ },
93
+ });
59
94
  };
60
95
 
61
96
  const config: TemplateConfig = {
@@ -63,13 +98,32 @@ const config: TemplateConfig = {
63
98
  id: "svelte",
64
99
  displayName: "Svelte",
65
100
  platform: "pages",
101
+ copyFiles: {
102
+ variants: {
103
+ js: { path: "./js" },
104
+ ts: { path: "./ts" },
105
+ },
106
+ },
66
107
  generate,
67
108
  configure,
68
- transformPackageJson: async () => ({
69
- scripts: {
70
- "pages:dev": `wrangler pages dev ${await compatDateFlag()} --proxy 5173 -- ${npm} run dev`,
71
- "pages:deploy": `${npm} run build && wrangler pages deploy .svelte-kit/cloudflare`,
72
- },
73
- }),
109
+ transformPackageJson: async (original: PackageJson, ctx: C3Context) => {
110
+ let scripts: Record<string, string> = {
111
+ preview: `${npm} run build && wrangler pages dev .svelte-kit/cloudflare`,
112
+ deploy: `${npm} run build && wrangler pages deploy .svelte-kit/cloudflare`,
113
+ };
114
+
115
+ if (usesTypescript(ctx)) {
116
+ const mv = platform() === "win32" ? "move" : "mv";
117
+ scripts = {
118
+ ...scripts,
119
+ "build-cf-types": `wrangler types && ${mv} worker-configuration.d.ts src/`,
120
+ };
121
+ }
122
+
123
+ return { scripts };
124
+ },
125
+ devScript: "dev",
126
+ deployScript: "deploy",
127
+ previewScript: "preview",
74
128
  };
75
129
  export default config;