create-cloudflare 0.0.0-fd084bc0 → 0.0.0-fd0fb230
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.
- package/dist/cli.js +2553 -1291
- package/package.json +3 -3
- package/templates/common/c3.ts +7 -5
- package/templates/hello-world/c3.ts +7 -5
- package/templates/hello-world-durable-object/c3.ts +7 -5
- package/templates/next/README.md +58 -0
- package/templates/next/app/js/app/api/hello/route.js +21 -0
- package/templates/next/app/js/app/not-found.js +58 -0
- package/templates/next/app/ts/app/api/hello/route.ts +22 -0
- package/templates/next/app/ts/app/not-found.tsx +58 -0
- package/templates/next/c3.ts +75 -62
- package/templates/next/env.d.ts +7 -0
- package/templates/next/pages/js/pages/api/hello.js +23 -0
- package/templates/next/pages/ts/pages/api/hello.ts +24 -0
- package/templates/next/wrangler.toml +57 -0
- package/templates/nuxt/c3.ts +56 -16
- package/templates/nuxt/templates/wrangler.toml +50 -0
- package/templates/queues/c3.ts +7 -5
- package/templates/qwik/c3.ts +63 -4
- package/templates/qwik/templates/wrangler.toml +50 -0
- package/templates/scheduled/c3.ts +7 -5
- package/templates/solid/c3.ts +4 -2
- package/templates/svelte/c3.ts +80 -28
- package/templates/svelte/js/src/hooks.server.js +25 -0
- package/templates/svelte/js/wrangler.toml +50 -0
- package/templates/svelte/ts/src/hooks.server.ts +24 -0
- package/templates/svelte/ts/wrangler.toml +50 -0
- package/templates/next/templates.ts +0 -281
- package/templates/svelte/templates.ts +0 -13
package/templates/nuxt/c3.ts
CHANGED
|
@@ -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 {
|
|
7
|
-
import {
|
|
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
|
|
|
@@ -28,31 +28,71 @@ const generate = async (ctx: C3Context) => {
|
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
const configure = async () => {
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
42
|
-
|
|
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
|
-
|
|
55
|
-
|
|
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"]
|
package/templates/queues/c3.ts
CHANGED
|
@@ -4,11 +4,13 @@ export default {
|
|
|
4
4
|
displayName: "Queue consumer & producer Worker",
|
|
5
5
|
platform: "workers",
|
|
6
6
|
copyFiles: {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
variants: {
|
|
8
|
+
js: {
|
|
9
|
+
path: "./js",
|
|
10
|
+
},
|
|
11
|
+
ts: {
|
|
12
|
+
path: "./ts",
|
|
13
|
+
},
|
|
12
14
|
},
|
|
13
15
|
},
|
|
14
16
|
bindings: {
|
package/templates/qwik/c3.ts
CHANGED
|
@@ -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 {
|
|
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();
|
|
@@ -12,11 +16,62 @@ const generate = async (ctx: C3Context) => {
|
|
|
12
16
|
await runFrameworkGenerator(ctx, ["basic", ctx.project.name]);
|
|
13
17
|
};
|
|
14
18
|
|
|
15
|
-
const configure = async () => {
|
|
19
|
+
const configure = async (ctx: C3Context) => {
|
|
16
20
|
// Add the pages integration
|
|
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
|
-
|
|
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"]
|
|
@@ -4,11 +4,13 @@ export default {
|
|
|
4
4
|
displayName: "Scheduled Worker (Cron Trigger)",
|
|
5
5
|
platform: "workers",
|
|
6
6
|
copyFiles: {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
variants: {
|
|
8
|
+
js: {
|
|
9
|
+
path: "./js",
|
|
10
|
+
},
|
|
11
|
+
ts: {
|
|
12
|
+
path: "./ts",
|
|
13
|
+
},
|
|
12
14
|
},
|
|
13
15
|
},
|
|
14
16
|
};
|
package/templates/solid/c3.ts
CHANGED
|
@@ -20,8 +20,10 @@ const config: TemplateConfig = {
|
|
|
20
20
|
displayName: "Solid",
|
|
21
21
|
platform: "pages",
|
|
22
22
|
copyFiles: {
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
variants: {
|
|
24
|
+
js: { path: "./js" },
|
|
25
|
+
ts: { path: "./ts" },
|
|
26
|
+
},
|
|
25
27
|
},
|
|
26
28
|
generate,
|
|
27
29
|
transformPackageJson: async () => ({
|
package/templates/svelte/c3.ts
CHANGED
|
@@ -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 {
|
|
4
|
+
import { transformFile } from "helpers/codemod";
|
|
4
5
|
import { installPackages, runFrameworkGenerator } from "helpers/command";
|
|
5
|
-
import {
|
|
6
|
+
import { usesTypescript } from "helpers/files";
|
|
6
7
|
import { detectPackageManager } from "helpers/packages";
|
|
7
|
-
import
|
|
8
|
+
import * as recast from "recast";
|
|
8
9
|
import type { TemplateConfig } from "../../src/templates";
|
|
9
|
-
import type
|
|
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
|
-
|
|
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
|
-
|
|
49
|
+
};
|
|
43
50
|
|
|
44
|
-
|
|
45
|
-
if (usesTypescript(ctx)) {
|
|
46
|
-
|
|
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,15 +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
|
-
|
|
71
|
-
|
|
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
|
+
},
|
|
74
125
|
devScript: "dev",
|
|
75
|
-
|
|
126
|
+
deployScript: "deploy",
|
|
127
|
+
previewScript: "preview",
|
|
76
128
|
};
|
|
77
129
|
export default config;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { dev } from '$app/environment';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
When developing, this hook will add proxy objects to the `platform` object which
|
|
5
|
+
will emulate any bindings defined in `wrangler.toml`.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
let platform;
|
|
9
|
+
|
|
10
|
+
if (dev) {
|
|
11
|
+
const { getPlatformProxy } = await import('wrangler');
|
|
12
|
+
platform = await getPlatformProxy();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const handle = async ({ event, resolve }) => {
|
|
16
|
+
if (platform) {
|
|
17
|
+
event.platform = {
|
|
18
|
+
...event.platform,
|
|
19
|
+
...platform
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return resolve(event);
|
|
24
|
+
};
|
|
25
|
+
|
|
@@ -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"]
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { dev } from '$app/environment';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
When developing, this hook will add proxy objects to the `platform` object which
|
|
5
|
+
will emulate any bindings defined in `wrangler.toml`.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
let platform: App.Platform;
|
|
9
|
+
|
|
10
|
+
if (dev) {
|
|
11
|
+
const { getPlatformProxy } = await import('wrangler');
|
|
12
|
+
platform = await getPlatformProxy();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const handle = async ({ event, resolve }) => {
|
|
16
|
+
if (platform) {
|
|
17
|
+
event.platform = {
|
|
18
|
+
...event.platform,
|
|
19
|
+
...platform
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return resolve(event);
|
|
24
|
+
};
|
|
@@ -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"]
|