create-cloudflare 2.18.0 → 2.19.0
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 +809 -682
- package/package.json +2 -2
- package/templates/analog/c3.ts +134 -0
- package/templates/analog/snippets/devBindingsModule.ts +7 -0
- package/templates/analog/templates/env.d.ts +13 -0
- package/templates/analog/templates/src/dev-bindings.ts +18 -0
- package/templates/analog/templates/worker-configuration.d.ts +4 -0
- package/templates/analog/templates/wrangler.toml +78 -0
- package/templates/hello-world-python/py/wrangler.toml +94 -0
- package/templates/nuxt/c3.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-cloudflare",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.19.0",
|
|
4
4
|
"description": "A CLI for creating and deploying new applications to Cloudflare.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"yarn": "^1.22.19",
|
|
71
71
|
"@cloudflare/cli": "1.1.1",
|
|
72
72
|
"@cloudflare/workers-tsconfig": "0.0.0",
|
|
73
|
-
"wrangler": "3.
|
|
73
|
+
"wrangler": "3.51.0"
|
|
74
74
|
},
|
|
75
75
|
"engines": {
|
|
76
76
|
"node": ">=18.14.1"
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { logRaw } from "@cloudflare/cli";
|
|
2
|
+
import { brandColor, dim } from "@cloudflare/cli/colors";
|
|
3
|
+
import { spinner } from "@cloudflare/cli/interactive";
|
|
4
|
+
import { runFrameworkGenerator } from "frameworks/index";
|
|
5
|
+
import { loadTemplateSnippets, transformFile } from "helpers/codemod";
|
|
6
|
+
import { getLatestTypesEntrypoint } from "helpers/compatDate";
|
|
7
|
+
import { readFile, writeFile } from "helpers/files";
|
|
8
|
+
import { detectPackageManager } from "helpers/packageManagers";
|
|
9
|
+
import { installPackages } from "helpers/packages";
|
|
10
|
+
import * as recast from "recast";
|
|
11
|
+
import type { TemplateConfig } from "../../src/templates";
|
|
12
|
+
import type { C3Context } from "types";
|
|
13
|
+
|
|
14
|
+
const { npm, name: pm } = detectPackageManager();
|
|
15
|
+
|
|
16
|
+
const generate = async (ctx: C3Context) => {
|
|
17
|
+
await runFrameworkGenerator(ctx, [
|
|
18
|
+
ctx.project.name,
|
|
19
|
+
"--template",
|
|
20
|
+
"angular-v17",
|
|
21
|
+
]);
|
|
22
|
+
|
|
23
|
+
logRaw(""); // newline
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const configure = async (ctx: C3Context) => {
|
|
27
|
+
// Fix hoisting issues with pnpm, yarn and bun
|
|
28
|
+
if (pm === "pnpm" || pm === "yarn" || pm === "bun") {
|
|
29
|
+
const packages = [];
|
|
30
|
+
packages.push("nitropack");
|
|
31
|
+
packages.push("h3");
|
|
32
|
+
packages.push("@ngtools/webpack");
|
|
33
|
+
packages.push("@angular-devkit/build-angular");
|
|
34
|
+
|
|
35
|
+
await installPackages(packages, {
|
|
36
|
+
dev: true,
|
|
37
|
+
startText: `Installing ${packages.join(", ")}`,
|
|
38
|
+
doneText: `${brandColor("installed")} ${dim(`via \`${npm} install\``)}`,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
updateViteConfig(ctx);
|
|
43
|
+
updateEnvTypes(ctx);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const updateEnvTypes = (ctx: C3Context) => {
|
|
47
|
+
const filepath = "env.d.ts";
|
|
48
|
+
|
|
49
|
+
const s = spinner();
|
|
50
|
+
s.start(`Updating ${filepath}`);
|
|
51
|
+
|
|
52
|
+
let file = readFile(filepath);
|
|
53
|
+
|
|
54
|
+
let typesEntrypoint = `@cloudflare/workers-types`;
|
|
55
|
+
const latestEntrypoint = getLatestTypesEntrypoint(ctx);
|
|
56
|
+
if (latestEntrypoint) {
|
|
57
|
+
typesEntrypoint += `/${latestEntrypoint}`;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Replace placeholder with actual types entrypoint
|
|
61
|
+
file = file.replace("WORKERS_TYPES_ENTRYPOINT", typesEntrypoint);
|
|
62
|
+
writeFile("env.d.ts", file);
|
|
63
|
+
|
|
64
|
+
s.stop(`${brandColor(`updated`)} ${dim(`\`${filepath}\``)}`);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const updateViteConfig = (ctx: C3Context) => {
|
|
68
|
+
const b = recast.types.builders;
|
|
69
|
+
const s = spinner();
|
|
70
|
+
|
|
71
|
+
const configFile = "vite.config.ts";
|
|
72
|
+
s.start(`Updating \`${configFile}\``);
|
|
73
|
+
|
|
74
|
+
const snippets = loadTemplateSnippets(ctx);
|
|
75
|
+
|
|
76
|
+
transformFile(configFile, {
|
|
77
|
+
visitProgram(n) {
|
|
78
|
+
const lastImportIndex = n.node.body.findLastIndex(
|
|
79
|
+
(t) => t.type === "ImportDeclaration"
|
|
80
|
+
);
|
|
81
|
+
const lastImport = n.get("body", lastImportIndex);
|
|
82
|
+
lastImport.insertAfter(...snippets.devBindingsModuleTs);
|
|
83
|
+
|
|
84
|
+
return this.traverse(n);
|
|
85
|
+
},
|
|
86
|
+
visitCallExpression(n) {
|
|
87
|
+
const callee = n.node.callee as recast.types.namedTypes.Identifier;
|
|
88
|
+
if (callee.name === "analog") {
|
|
89
|
+
const pluginArguments = b.objectProperty(
|
|
90
|
+
b.identifier("nitro"),
|
|
91
|
+
b.objectExpression([
|
|
92
|
+
b.objectProperty(
|
|
93
|
+
b.identifier("preset"),
|
|
94
|
+
b.stringLiteral("cloudflare-pages")
|
|
95
|
+
),
|
|
96
|
+
b.objectProperty(
|
|
97
|
+
b.identifier("modules"),
|
|
98
|
+
b.arrayExpression([b.identifier("devBindingsModule")])
|
|
99
|
+
),
|
|
100
|
+
])
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
n.node.arguments = [b.objectExpression([pluginArguments])];
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return this.traverse(n);
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
s.stop(`${brandColor(`updated`)} ${dim(`\`${configFile}\``)}`);
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const config: TemplateConfig = {
|
|
114
|
+
configVersion: 1,
|
|
115
|
+
id: "analog",
|
|
116
|
+
platform: "pages",
|
|
117
|
+
displayName: "Analog",
|
|
118
|
+
copyFiles: {
|
|
119
|
+
path: "./templates",
|
|
120
|
+
},
|
|
121
|
+
generate,
|
|
122
|
+
configure,
|
|
123
|
+
transformPackageJson: async () => ({
|
|
124
|
+
scripts: {
|
|
125
|
+
preview: `${npm} run build && wrangler pages dev`,
|
|
126
|
+
deploy: `${npm} run build && wrangler pages deploy`,
|
|
127
|
+
"build-cf-types": `wrangler types`,
|
|
128
|
+
},
|
|
129
|
+
}),
|
|
130
|
+
devScript: "dev",
|
|
131
|
+
deployScript: "deploy",
|
|
132
|
+
previewScript: "preview",
|
|
133
|
+
};
|
|
134
|
+
export default config;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { NitroApp } from 'nitropack';
|
|
2
|
+
import { defineNitroPlugin } from 'nitropack/dist/runtime/plugin';
|
|
3
|
+
|
|
4
|
+
export default defineNitroPlugin((nitroApp: NitroApp) => {
|
|
5
|
+
nitroApp.hooks.hook('request', async (event) => {
|
|
6
|
+
const _pkg = 'wrangler'; // Bypass bundling!
|
|
7
|
+
const { getPlatformProxy } = (await import(
|
|
8
|
+
_pkg
|
|
9
|
+
)) as typeof import('wrangler');
|
|
10
|
+
const platform = await getPlatformProxy();
|
|
11
|
+
|
|
12
|
+
event.context.cf = platform['cf'];
|
|
13
|
+
event.context.cloudflare = {
|
|
14
|
+
env: platform['env'] as unknown as Env,
|
|
15
|
+
context: platform['ctx'],
|
|
16
|
+
};
|
|
17
|
+
});
|
|
18
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
#:schema node_modules/wrangler/config-schema.json
|
|
2
|
+
name = "<TBD>"
|
|
3
|
+
compatibility_date = "<TBD>"
|
|
4
|
+
pages_build_output_dir = "./dist/analog/public"
|
|
5
|
+
|
|
6
|
+
# Variable bindings. These are arbitrary, plaintext strings (similar to environment variables)
|
|
7
|
+
# Note: Use secrets to store sensitive data.
|
|
8
|
+
# Docs:
|
|
9
|
+
# - https://developers.cloudflare.com/pages/functions/bindings/#environment-variables
|
|
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>"
|
|
@@ -3,3 +3,97 @@ name = "<TBD>"
|
|
|
3
3
|
main = "src/entry.py"
|
|
4
4
|
compatibility_flags = ["python_workers"]
|
|
5
5
|
compatibility_date = "<TBD>"
|
|
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/workers/wrangler/configuration/#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/workers/wrangler/configuration/#workers-ai
|
|
15
|
+
# [ai]
|
|
16
|
+
# binding = "AI"
|
|
17
|
+
|
|
18
|
+
# Bind an Analytics Engine dataset. Use Analytics Engine to write analytics within your Pages Function.
|
|
19
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#analytics-engine-datasets
|
|
20
|
+
# [[analytics_engine_datasets]]
|
|
21
|
+
# binding = "MY_DATASET"
|
|
22
|
+
|
|
23
|
+
# Bind a headless browser instance running on Cloudflare's global network.
|
|
24
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#browser-rendering
|
|
25
|
+
# [browser]
|
|
26
|
+
# binding = "MY_BROWSER"
|
|
27
|
+
|
|
28
|
+
# Bind a D1 database. D1 is Cloudflare’s native serverless SQL database.
|
|
29
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#d1-databases
|
|
30
|
+
# [[d1_databases]]
|
|
31
|
+
# binding = "MY_DB"
|
|
32
|
+
# database_name = "my-database"
|
|
33
|
+
# database_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
34
|
+
|
|
35
|
+
# Bind a dispatch namespace. Use Workers for Platforms to deploy serverless functions programmatically on behalf of your customers.
|
|
36
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#dispatch-namespace-bindings-workers-for-platforms
|
|
37
|
+
# [[dispatch_namespaces]]
|
|
38
|
+
# binding = "MY_DISPATCHER"
|
|
39
|
+
# namespace = "my-namespace"
|
|
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/wrangler/configuration/#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/wrangler/configuration/#migrations
|
|
50
|
+
# [[migrations]]
|
|
51
|
+
# tag = "v1"
|
|
52
|
+
# new_classes = ["MyDurableObject"]
|
|
53
|
+
|
|
54
|
+
# Bind a Hyperdrive configuration. Use to accelerate access to your existing databases from Cloudflare Workers.
|
|
55
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#hyperdrive
|
|
56
|
+
# [[hyperdrive]]
|
|
57
|
+
# binding = "MY_HYPERDRIVE"
|
|
58
|
+
# id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
|
59
|
+
|
|
60
|
+
# Bind a KV Namespace. Use KV as persistent storage for small key-value pairs.
|
|
61
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#kv-namespaces
|
|
62
|
+
# [[kv_namespaces]]
|
|
63
|
+
# binding = "MY_KV_NAMESPACE"
|
|
64
|
+
# id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
|
65
|
+
|
|
66
|
+
# Bind an mTLS certificate. Use to present a client certificate when communicating with another service.
|
|
67
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#mtls-certificates
|
|
68
|
+
# [[mtls_certificates]]
|
|
69
|
+
# binding = "MY_CERTIFICATE"
|
|
70
|
+
# certificate_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
71
|
+
|
|
72
|
+
# Bind a Queue producer. Use this binding to schedule an arbitrary task that may be processed later by a Queue consumer.
|
|
73
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#queues
|
|
74
|
+
# [[queues.producers]]
|
|
75
|
+
# binding = "MY_QUEUE"
|
|
76
|
+
# queue = "my-queue"
|
|
77
|
+
|
|
78
|
+
# Bind a Queue consumer. Queue Consumers can retrieve tasks scheduled by Producers to act on them.
|
|
79
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#queues
|
|
80
|
+
# [[queues.consumers]]
|
|
81
|
+
# queue = "my-queue"
|
|
82
|
+
|
|
83
|
+
# Bind an R2 Bucket. Use R2 to store arbitrarily large blobs of data, such as files.
|
|
84
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#r2-buckets
|
|
85
|
+
# [[r2_buckets]]
|
|
86
|
+
# binding = "MY_BUCKET"
|
|
87
|
+
# bucket_name = "my-bucket"
|
|
88
|
+
|
|
89
|
+
# Bind another Worker service. Use this binding to call another Worker without network overhead.
|
|
90
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#service-bindings
|
|
91
|
+
# [[services]]
|
|
92
|
+
# binding = "MY_SERVICE"
|
|
93
|
+
# service = "my-service"
|
|
94
|
+
|
|
95
|
+
# Bind a Vectorize index. Use to store and query vector embeddings for semantic search, classification and other vector search use-cases.
|
|
96
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#vectorize-indexes
|
|
97
|
+
# [[vectorize]]
|
|
98
|
+
# binding = "MY_INDEX"
|
|
99
|
+
# index_name = "my-index"
|
package/templates/nuxt/c3.ts
CHANGED
|
@@ -56,7 +56,7 @@ const updateEnvTypes = (ctx: C3Context) => {
|
|
|
56
56
|
|
|
57
57
|
let file = readFile(filepath);
|
|
58
58
|
|
|
59
|
-
let typesEntrypoint = `@cloudflare/workers-types
|
|
59
|
+
let typesEntrypoint = `@cloudflare/workers-types`;
|
|
60
60
|
const latestEntrypoint = getLatestTypesEntrypoint(ctx);
|
|
61
61
|
if (latestEntrypoint) {
|
|
62
62
|
typesEntrypoint += `/${latestEntrypoint}`;
|