create-cloudflare 0.0.0-fa09f4a2 → 0.0.0-fa42550d
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 +73215 -58937
- package/package.json +12 -7
- package/templates/angular/c3.ts +98 -0
- package/{dist → templates}/angular/templates/tools/copy-files.mjs +1 -1
- package/templates/astro/c3.ts +111 -0
- package/templates/astro/snippets/runtimeDeclaration.ts +4 -0
- package/templates/astro/templates/wrangler.toml +50 -0
- package/templates/common/c3.ts +16 -0
- package/templates/docusaurus/c3.ts +26 -0
- package/templates/gatsby/c3.ts +48 -0
- package/templates/hello-world/c3.ts +16 -0
- package/templates/hello-world-durable-object/c3.ts +16 -0
- package/templates/hono/c3.ts +25 -0
- 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 +216 -0
- 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 +133 -0
- package/templates/nuxt/templates/env.d.ts +14 -0
- package/templates/nuxt/templates/worker-configuration.d.ts +3 -0
- package/templates/nuxt/templates/wrangler.toml +50 -0
- package/templates/openapi/c3.ts +9 -0
- package/templates/openapi/ts/src/endpoints/taskList.ts +1 -1
- package/templates/openapi/ts/src/index.ts +2 -2
- package/templates/pre-existing/c3.ts +83 -0
- package/templates/pre-existing/js/.editorconfig +13 -0
- package/templates/pre-existing/js/.prettierrc +6 -0
- package/templates/{chatgptPlugin/ts → pre-existing/js}/__dot__gitignore +1 -0
- package/templates/{chatgptPlugin/ts → pre-existing/js}/package.json +2 -5
- package/templates/pre-existing/js/wrangler.toml +3 -0
- package/templates/queues/c3.ts +26 -0
- package/templates/qwik/c3.ts +146 -0
- package/templates/qwik/snippets/getPlatformProxy.ts +6 -0
- package/templates/qwik/templates/worker-configuration.d.ts +3 -0
- package/templates/qwik/templates/wrangler.toml +50 -0
- package/templates/react/c3.ts +31 -0
- package/templates/remix/c3.ts +66 -0
- package/templates/remix/templates/worker-configuration.d.ts +3 -0
- package/templates/remix/templates/wrangler.toml +50 -0
- package/templates/scheduled/c3.ts +16 -0
- package/templates/solid/c3.ts +81 -0
- package/templates/svelte/c3.ts +129 -0
- 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/vue/c3.ts +28 -0
- package/templates/chatgptPlugin/ts/.assets/example.png +0 -0
- package/templates/chatgptPlugin/ts/README.md +0 -25
- package/templates/chatgptPlugin/ts/src/index.ts +0 -33
- package/templates/chatgptPlugin/ts/src/search.ts +0 -59
- package/templates/chatgptPlugin/ts/wrangler.toml +0 -3
- package/{dist → templates}/angular/templates/server.ts +0 -0
- package/{dist → templates}/angular/templates/src/_routes.json +0 -0
- package/{dist → templates}/angular/templates/tools/alter-polyfills.mjs +1 -1
- /package/{dist → templates}/angular/templates/tools/paths.mjs +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-cloudflare",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-fa42550d",
|
|
4
4
|
"description": "A CLI for creating and deploying new applications to Cloudflare.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -34,11 +34,12 @@
|
|
|
34
34
|
"@iarna/toml": "^3.0.0",
|
|
35
35
|
"@types/command-exists": "^1.2.0",
|
|
36
36
|
"@types/cross-spawn": "^6.0.2",
|
|
37
|
+
"@types/deepmerge": "^2.2.0",
|
|
38
|
+
"@types/degit": "^2.8.6",
|
|
37
39
|
"@types/dns2": "^2.0.3",
|
|
38
40
|
"@types/esprima": "^4.0.3",
|
|
39
41
|
"@types/node": "^18.15.3",
|
|
40
42
|
"@types/semver": "^7.5.1",
|
|
41
|
-
"@types/shell-quote": "^1.7.2",
|
|
42
43
|
"@types/which-pm-runs": "^1.0.0",
|
|
43
44
|
"@types/yargs": "^17.0.22",
|
|
44
45
|
"@typescript-eslint/eslint-plugin": "^5.55.0",
|
|
@@ -46,25 +47,28 @@
|
|
|
46
47
|
"chalk": "^5.2.0",
|
|
47
48
|
"command-exists": "^1.2.9",
|
|
48
49
|
"cross-spawn": "^7.0.3",
|
|
50
|
+
"deepmerge": "^4.3.1",
|
|
51
|
+
"degit": "^2.8.4",
|
|
49
52
|
"dns2": "^2.1.0",
|
|
53
|
+
"dotenv": "^16.0.0",
|
|
50
54
|
"esbuild": "^0.17.12",
|
|
51
55
|
"execa": "^7.1.1",
|
|
52
56
|
"glob": "^10.3.3",
|
|
53
57
|
"haikunator": "^2.1.2",
|
|
58
|
+
"magic-string": "^0.30.5",
|
|
54
59
|
"open": "^8.4.0",
|
|
55
60
|
"pnpm": "^8.10.0",
|
|
56
61
|
"recast": "^0.22.0",
|
|
57
62
|
"semver": "^7.5.1",
|
|
58
|
-
"shell-quote": "^1.8.1",
|
|
59
63
|
"typescript": "^5.0.2",
|
|
60
|
-
"undici": "5.
|
|
64
|
+
"undici": "5.28.3",
|
|
61
65
|
"vite-tsconfig-paths": "^4.0.8",
|
|
62
66
|
"which-pm-runs": "^1.1.0",
|
|
63
67
|
"yargs": "^17.7.1",
|
|
64
68
|
"yarn": "^1.22.19",
|
|
65
|
-
"
|
|
66
|
-
"@cloudflare/
|
|
67
|
-
"
|
|
69
|
+
"@cloudflare/cli": "1.1.1",
|
|
70
|
+
"@cloudflare/workers-tsconfig": "0.0.0",
|
|
71
|
+
"wrangler": "3.33.0"
|
|
68
72
|
},
|
|
69
73
|
"engines": {
|
|
70
74
|
"node": ">=18.14.1"
|
|
@@ -74,6 +78,7 @@
|
|
|
74
78
|
},
|
|
75
79
|
"scripts": {
|
|
76
80
|
"build": "node -r esbuild-register scripts/build.ts",
|
|
81
|
+
"dev:codemod": "node -r esbuild-register scripts/codemodDev.ts",
|
|
77
82
|
"check:lint": "eslint .",
|
|
78
83
|
"check:type": "tsc",
|
|
79
84
|
"lint": "eslint",
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import { logRaw } from "@cloudflare/cli";
|
|
3
|
+
import { brandColor, dim } from "@cloudflare/cli/colors";
|
|
4
|
+
import { spinner } from "@cloudflare/cli/interactive";
|
|
5
|
+
import { installPackages, runFrameworkGenerator } from "helpers/command";
|
|
6
|
+
import { compatDateFlag, readFile, readJSON, writeFile } from "helpers/files";
|
|
7
|
+
import { detectPackageManager } from "helpers/packages";
|
|
8
|
+
import type { TemplateConfig } from "../../src/templates";
|
|
9
|
+
import type { C3Context } from "types";
|
|
10
|
+
|
|
11
|
+
const { npm } = detectPackageManager();
|
|
12
|
+
|
|
13
|
+
const generate = async (ctx: C3Context) => {
|
|
14
|
+
await runFrameworkGenerator(ctx, [ctx.project.name, "--ssr"]);
|
|
15
|
+
logRaw("");
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const configure = async (ctx: C3Context) => {
|
|
19
|
+
updateAngularJson(ctx);
|
|
20
|
+
await updateAppCode();
|
|
21
|
+
await installCFWorker();
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
async function installCFWorker() {
|
|
25
|
+
await installPackages(
|
|
26
|
+
["@cloudflare/workers-types", "@miniflare/tre@next", "wrangler@beta"],
|
|
27
|
+
{
|
|
28
|
+
dev: true,
|
|
29
|
+
startText: "Installing adapter dependencies",
|
|
30
|
+
doneText: `${brandColor("installed")} ${dim(`via \`${npm} install\``)}`,
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
async function updateAppCode() {
|
|
35
|
+
const s = spinner();
|
|
36
|
+
s.start(`Updating application code`);
|
|
37
|
+
|
|
38
|
+
// Update an app config file to:
|
|
39
|
+
// - add the `provideHttpClient(withFetch())` call to enable `fetch` usage in `HttpClient`
|
|
40
|
+
const appConfigPath = "src/app/app.config.ts";
|
|
41
|
+
const appConfig = readFile(resolve(appConfigPath));
|
|
42
|
+
const newAppConfig =
|
|
43
|
+
"import { provideHttpClient, withFetch } from '@angular/common/http';\n" +
|
|
44
|
+
appConfig.replace(
|
|
45
|
+
"providers: [",
|
|
46
|
+
"providers: [provideHttpClient(withFetch()), "
|
|
47
|
+
);
|
|
48
|
+
writeFile(resolve(appConfigPath), newAppConfig);
|
|
49
|
+
s.stop(`${brandColor(`updated`)} ${dim(appConfigPath)}`);
|
|
50
|
+
|
|
51
|
+
// Remove unwanted dependencies
|
|
52
|
+
s.start(`Updating package.json`);
|
|
53
|
+
const packageJsonPath = resolve("package.json");
|
|
54
|
+
const packageManifest = readJSON(packageJsonPath);
|
|
55
|
+
|
|
56
|
+
delete packageManifest["dependencies"]["@angular/ssr"];
|
|
57
|
+
delete packageManifest["dependencies"]["express"];
|
|
58
|
+
|
|
59
|
+
writeFile(packageJsonPath, JSON.stringify(packageManifest, null, 2));
|
|
60
|
+
s.stop(`${brandColor(`updated`)} ${dim(`\`package.json\``)}`);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function updateAngularJson(ctx: C3Context) {
|
|
64
|
+
const s = spinner();
|
|
65
|
+
s.start(`Updating angular.json config`);
|
|
66
|
+
const angularJson = readJSON(resolve("angular.json"));
|
|
67
|
+
// Update builder
|
|
68
|
+
const architectSection = angularJson.projects[ctx.project.name].architect;
|
|
69
|
+
architectSection.build.options.outputPath = "dist";
|
|
70
|
+
architectSection.build.options.assets.push("src/_routes.json");
|
|
71
|
+
|
|
72
|
+
writeFile(resolve("angular.json"), JSON.stringify(angularJson, null, 2));
|
|
73
|
+
s.stop(`${brandColor(`updated`)} ${dim(`\`angular.json\``)}`);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const config: TemplateConfig = {
|
|
77
|
+
configVersion: 1,
|
|
78
|
+
id: "angular",
|
|
79
|
+
displayName: "Angular",
|
|
80
|
+
platform: "pages",
|
|
81
|
+
copyFiles: {
|
|
82
|
+
path: "./templates",
|
|
83
|
+
},
|
|
84
|
+
devScript: "start",
|
|
85
|
+
deployScript: "deploy",
|
|
86
|
+
generate,
|
|
87
|
+
configure,
|
|
88
|
+
transformPackageJson: async () => ({
|
|
89
|
+
scripts: {
|
|
90
|
+
start: `${npm} run build && wrangler pages dev dist/cloudflare ${await compatDateFlag()} --experimental-local`,
|
|
91
|
+
build: `ng build && ${npm} run process`,
|
|
92
|
+
process:
|
|
93
|
+
"node ./tools/copy-files.mjs && node ./tools/alter-polyfills.mjs",
|
|
94
|
+
deploy: `${npm} run build && wrangler pages deploy dist/cloudflare`,
|
|
95
|
+
},
|
|
96
|
+
}),
|
|
97
|
+
};
|
|
98
|
+
export default config;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copy the files over so that they can be uploaded by the pages publish command.
|
|
2
2
|
import fs from "node:fs";
|
|
3
3
|
import { join } from "node:path";
|
|
4
|
-
import { client, cloudflare,
|
|
4
|
+
import { client, cloudflare, ssr, worker } from "./paths.mjs";
|
|
5
5
|
|
|
6
6
|
fs.cpSync(client, cloudflare, { recursive: true });
|
|
7
7
|
fs.cpSync(ssr, worker, { recursive: true });
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { logRaw, updateStatus } from "@cloudflare/cli";
|
|
2
|
+
import { blue, brandColor, dim } from "@cloudflare/cli/colors";
|
|
3
|
+
import { loadTemplateSnippets, transformFile } from "helpers/codemod";
|
|
4
|
+
import { runCommand, runFrameworkGenerator } from "helpers/command";
|
|
5
|
+
import { usesTypescript } from "helpers/files";
|
|
6
|
+
import { detectPackageManager } from "helpers/packages";
|
|
7
|
+
import * as recast from "recast";
|
|
8
|
+
import type { TemplateConfig } from "../../src/templates";
|
|
9
|
+
import type { C3Context, PackageJson } from "types";
|
|
10
|
+
|
|
11
|
+
const { npx } = detectPackageManager();
|
|
12
|
+
|
|
13
|
+
const generate = async (ctx: C3Context) => {
|
|
14
|
+
await runFrameworkGenerator(ctx, [ctx.project.name, "--no-install"]);
|
|
15
|
+
|
|
16
|
+
logRaw(""); // newline
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const configure = async (ctx: C3Context) => {
|
|
20
|
+
await runCommand([npx, "astro", "add", "cloudflare", "-y"], {
|
|
21
|
+
silent: true,
|
|
22
|
+
startText: "Installing adapter",
|
|
23
|
+
doneText: `${brandColor("installed")} ${dim(
|
|
24
|
+
`via \`${npx} astro add cloudflare\``
|
|
25
|
+
)}`,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
updateAstroConfig();
|
|
29
|
+
updateEnvDeclaration(ctx);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const updateAstroConfig = () => {
|
|
33
|
+
const filePath = "astro.config.mjs";
|
|
34
|
+
|
|
35
|
+
updateStatus(`Updating configuration in ${blue(filePath)}`);
|
|
36
|
+
|
|
37
|
+
transformFile(filePath, {
|
|
38
|
+
visitCallExpression: function (n) {
|
|
39
|
+
const callee = n.node.callee as recast.types.namedTypes.Identifier;
|
|
40
|
+
if (callee.name !== "cloudflare") {
|
|
41
|
+
return this.traverse(n);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const b = recast.types.builders;
|
|
45
|
+
n.node.arguments = [
|
|
46
|
+
b.objectExpression([
|
|
47
|
+
b.objectProperty(
|
|
48
|
+
b.identifier("runtime"),
|
|
49
|
+
b.objectExpression([
|
|
50
|
+
b.objectProperty(b.identifier("mode"), b.stringLiteral("local")),
|
|
51
|
+
])
|
|
52
|
+
),
|
|
53
|
+
]),
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
return false;
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const updateEnvDeclaration = (ctx: C3Context) => {
|
|
62
|
+
if (!usesTypescript(ctx)) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const filePath = "src/env.d.ts";
|
|
67
|
+
|
|
68
|
+
updateStatus(`Adding type declarations in ${blue(filePath)}`);
|
|
69
|
+
|
|
70
|
+
transformFile(filePath, {
|
|
71
|
+
visitProgram: function (n) {
|
|
72
|
+
const snippets = loadTemplateSnippets(ctx);
|
|
73
|
+
const patch = snippets.runtimeDeclarationTs;
|
|
74
|
+
const b = recast.types.builders;
|
|
75
|
+
|
|
76
|
+
// Preserve comments with the new body
|
|
77
|
+
const comments = n.get("comments").value;
|
|
78
|
+
n.node.comments = comments.map((c: recast.types.namedTypes.CommentLine) =>
|
|
79
|
+
b.commentLine(c.value)
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
// Add the patch
|
|
83
|
+
n.get("body").push(...patch);
|
|
84
|
+
|
|
85
|
+
return false;
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const config: TemplateConfig = {
|
|
91
|
+
configVersion: 1,
|
|
92
|
+
id: "astro",
|
|
93
|
+
platform: "pages",
|
|
94
|
+
displayName: "Astro",
|
|
95
|
+
copyFiles: {
|
|
96
|
+
path: "./templates",
|
|
97
|
+
},
|
|
98
|
+
devScript: "dev",
|
|
99
|
+
deployScript: "deploy",
|
|
100
|
+
previewScript: "preview",
|
|
101
|
+
generate,
|
|
102
|
+
configure,
|
|
103
|
+
transformPackageJson: async (pkgJson: PackageJson, ctx: C3Context) => ({
|
|
104
|
+
scripts: {
|
|
105
|
+
deploy: `astro build && wrangler pages deploy ./dist`,
|
|
106
|
+
preview: `astro build && wrangler pages dev ./dist`,
|
|
107
|
+
...(usesTypescript(ctx) && { "build-cf-types": `wrangler types` }),
|
|
108
|
+
},
|
|
109
|
+
}),
|
|
110
|
+
};
|
|
111
|
+
export default config;
|
|
@@ -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,26 @@
|
|
|
1
|
+
import { runFrameworkGenerator } from "helpers/command";
|
|
2
|
+
import { detectPackageManager } from "helpers/packages";
|
|
3
|
+
import type { TemplateConfig } from "../../src/templates";
|
|
4
|
+
import type { C3Context } from "types";
|
|
5
|
+
|
|
6
|
+
const { npm } = detectPackageManager();
|
|
7
|
+
|
|
8
|
+
const generate = async (ctx: C3Context) => {
|
|
9
|
+
await runFrameworkGenerator(ctx, [ctx.project.name, "classic"]);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const config: TemplateConfig = {
|
|
13
|
+
configVersion: 1,
|
|
14
|
+
id: "docusaurus",
|
|
15
|
+
platform: "pages",
|
|
16
|
+
displayName: "Docusaurus",
|
|
17
|
+
generate,
|
|
18
|
+
transformPackageJson: async () => ({
|
|
19
|
+
scripts: {
|
|
20
|
+
deploy: `${npm} run build && wrangler pages deploy ./build`,
|
|
21
|
+
},
|
|
22
|
+
}),
|
|
23
|
+
devScript: "start",
|
|
24
|
+
deployScript: "deploy",
|
|
25
|
+
};
|
|
26
|
+
export default config;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { inputPrompt } from "@cloudflare/cli/interactive";
|
|
2
|
+
import { runFrameworkGenerator } from "helpers/command";
|
|
3
|
+
import { detectPackageManager } from "helpers/packages";
|
|
4
|
+
import type { TemplateConfig } from "../../src/templates";
|
|
5
|
+
import type { C3Context } from "types";
|
|
6
|
+
|
|
7
|
+
const { npm } = detectPackageManager();
|
|
8
|
+
|
|
9
|
+
const generate = async (ctx: C3Context) => {
|
|
10
|
+
const defaultTemplate = "https://github.com/gatsbyjs/gatsby-starter-blog";
|
|
11
|
+
|
|
12
|
+
const useTemplate = await inputPrompt({
|
|
13
|
+
type: "confirm",
|
|
14
|
+
question: "Would you like to use a template?",
|
|
15
|
+
label: "template",
|
|
16
|
+
defaultValue: true,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
let templateUrl = "";
|
|
20
|
+
if (useTemplate) {
|
|
21
|
+
templateUrl = await inputPrompt({
|
|
22
|
+
type: "text",
|
|
23
|
+
question: `Please specify the url of the template you'd like to use`,
|
|
24
|
+
label: "template",
|
|
25
|
+
defaultValue: defaultTemplate,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
await runFrameworkGenerator(ctx, ["new", ctx.project.name, templateUrl]);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const config: TemplateConfig = {
|
|
33
|
+
configVersion: 1,
|
|
34
|
+
id: "gatsby",
|
|
35
|
+
platform: "pages",
|
|
36
|
+
displayName: "Gatsby",
|
|
37
|
+
generate,
|
|
38
|
+
transformPackageJson: async () => ({
|
|
39
|
+
scripts: {
|
|
40
|
+
deploy: `${npm} run build && wrangler pages deploy ./public`,
|
|
41
|
+
preview: `${npm} run build && wrangler pages dev ./public`,
|
|
42
|
+
},
|
|
43
|
+
}),
|
|
44
|
+
devScript: "develop",
|
|
45
|
+
deployScript: "deploy",
|
|
46
|
+
previewScript: "preview",
|
|
47
|
+
};
|
|
48
|
+
export default config;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
configVersion: 1,
|
|
3
|
+
id: "hello-world-durable-object",
|
|
4
|
+
displayName: '"Hello World" Durable Object',
|
|
5
|
+
platform: "workers",
|
|
6
|
+
copyFiles: {
|
|
7
|
+
variants: {
|
|
8
|
+
js: {
|
|
9
|
+
path: "./js",
|
|
10
|
+
},
|
|
11
|
+
ts: {
|
|
12
|
+
path: "./ts",
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { logRaw } from "@cloudflare/cli";
|
|
2
|
+
import { runFrameworkGenerator } from "helpers/command";
|
|
3
|
+
import type { TemplateConfig } from "../../src/templates";
|
|
4
|
+
import type { C3Context } from "types";
|
|
5
|
+
|
|
6
|
+
const generate = async (ctx: C3Context) => {
|
|
7
|
+
await runFrameworkGenerator(ctx, [
|
|
8
|
+
ctx.project.name,
|
|
9
|
+
"--template",
|
|
10
|
+
"cloudflare-workers",
|
|
11
|
+
]);
|
|
12
|
+
|
|
13
|
+
logRaw(""); // newline
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const config: TemplateConfig = {
|
|
17
|
+
configVersion: 1,
|
|
18
|
+
id: "hono",
|
|
19
|
+
displayName: "Hono",
|
|
20
|
+
platform: "workers",
|
|
21
|
+
generate,
|
|
22
|
+
devScript: "dev",
|
|
23
|
+
deployScript: "deploy",
|
|
24
|
+
};
|
|
25
|
+
export default config;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`c3`](https://developers.cloudflare.com/pages/get-started/c3).
|
|
2
|
+
|
|
3
|
+
## Getting Started
|
|
4
|
+
|
|
5
|
+
First, run the development server:
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm run dev
|
|
9
|
+
# or
|
|
10
|
+
yarn dev
|
|
11
|
+
# or
|
|
12
|
+
pnpm dev
|
|
13
|
+
# or
|
|
14
|
+
bun dev
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
|
|
18
|
+
|
|
19
|
+
## Cloudflare integration
|
|
20
|
+
|
|
21
|
+
Besides the `dev` script mentioned above `c3` has added a few extra scripts that allow you to integrate the application with the [Cloudflare Pages](https://pages.cloudflare.com/) environment, these are:
|
|
22
|
+
- `pages:build` to build the application for Pages using the [`@cloudflare/next-on-pages`](https://github.com/cloudflare/next-on-pages) CLI
|
|
23
|
+
- `preview` to locally preview your Pages application using the [Wrangler](https://developers.cloudflare.com/workers/wrangler/) CLI
|
|
24
|
+
- `deploy` to deploy your Pages application using the [Wrangler](https://developers.cloudflare.com/workers/wrangler/) CLI
|
|
25
|
+
|
|
26
|
+
> __Note:__ while the `dev` script is optimal for local development you should preview your Pages application as well (periodically or before deployments) in order to make sure that it can properly work in the Pages environment (for more details see the [`@cloudflare/next-on-pages` recommended workflow](https://github.com/cloudflare/next-on-pages/blob/05b6256/internal-packages/next-dev/README.md#recommended-workflow))
|
|
27
|
+
|
|
28
|
+
### Bindings
|
|
29
|
+
|
|
30
|
+
Cloudflare [Bindings](https://developers.cloudflare.com/pages/functions/bindings/) are what allows you to interact with resources available in the Cloudflare Platform.
|
|
31
|
+
|
|
32
|
+
You can use bindings during development, when previewing locally your application and of course in the deployed application:
|
|
33
|
+
|
|
34
|
+
- To use bindings in dev mode you need to define them in the `next.config.js` file under `setupDevBindings`, this mode uses the `next-dev` `@cloudflare/next-on-pages` submodule. For more details see its [documentation](https://github.com/cloudflare/next-on-pages/blob/05b6256/internal-packages/next-dev/README.md).
|
|
35
|
+
|
|
36
|
+
- To use bindings in the preview mode you need to add them to the `pages:preview` script accordingly to the `wrangler pages dev` command. For more details see its [documentation](https://developers.cloudflare.com/workers/wrangler/commands/#dev-1) or the [Pages Bindings documentation](https://developers.cloudflare.com/pages/functions/bindings/).
|
|
37
|
+
|
|
38
|
+
- To use bindings in the deployed application you will need to configure them in the Cloudflare [dashboard](https://dash.cloudflare.com/). For more details see the [Pages Bindings documentation](https://developers.cloudflare.com/pages/functions/bindings/).
|
|
39
|
+
|
|
40
|
+
#### KV Example
|
|
41
|
+
|
|
42
|
+
`c3` has added for you an example showing how you can use a KV binding.
|
|
43
|
+
|
|
44
|
+
In order to enable the example:
|
|
45
|
+
- Search for javascript/typescript lines containing the following comment:
|
|
46
|
+
```ts
|
|
47
|
+
// KV Example:
|
|
48
|
+
```
|
|
49
|
+
and uncomment the commented lines below it.
|
|
50
|
+
- Do the same in the `wrangler.toml` file, where
|
|
51
|
+
the comment is:
|
|
52
|
+
```
|
|
53
|
+
# KV Example:
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
After doing this you can run the `dev` or `preview` script and visit the `/api/hello` route to see the example in action.
|
|
57
|
+
|
|
58
|
+
Finally, if you also want to see the example work in the deployed application make sure to add a `MY_KV` binding to your Pages application in its [dashboard kv bindings settings section](https://dash.cloudflare.com/?to=/:account/pages/view/:pages-project/settings/functions#kv_namespace_bindings_section). After having configured it make sure to re-deploy your application.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { getRequestContext } from '@cloudflare/next-on-pages'
|
|
2
|
+
|
|
3
|
+
export const runtime = 'edge'
|
|
4
|
+
|
|
5
|
+
export async function GET(request) {
|
|
6
|
+
let responseText = 'Hello World'
|
|
7
|
+
|
|
8
|
+
// In the edge runtime you can use Bindings that are available in your application
|
|
9
|
+
// (for more details see:
|
|
10
|
+
// - https://developers.cloudflare.com/pages/framework-guides/deploy-a-nextjs-site/#use-bindings-in-your-nextjs-application
|
|
11
|
+
// - https://developers.cloudflare.com/pages/functions/bindings/
|
|
12
|
+
// )
|
|
13
|
+
//
|
|
14
|
+
// KV Example:
|
|
15
|
+
// const myKv = getRequestContext().env.MY_KV
|
|
16
|
+
// await myKv.put('suffix', ' from a KV store!')
|
|
17
|
+
// const suffix = await myKv.get('suffix')
|
|
18
|
+
// responseText += suffix
|
|
19
|
+
|
|
20
|
+
return new Response(responseText)
|
|
21
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export const runtime = "edge";
|
|
2
|
+
|
|
3
|
+
export default function NotFound() {
|
|
4
|
+
return (
|
|
5
|
+
<>
|
|
6
|
+
<title>404: This page could not be found.</title>
|
|
7
|
+
<div style={styles.error}>
|
|
8
|
+
<div>
|
|
9
|
+
<style
|
|
10
|
+
dangerouslySetInnerHTML={{
|
|
11
|
+
__html: `body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}`,
|
|
12
|
+
}}
|
|
13
|
+
/>
|
|
14
|
+
<h1 className="next-error-h1" style={styles.h1}>
|
|
15
|
+
404
|
|
16
|
+
</h1>
|
|
17
|
+
<div style={styles.desc}>
|
|
18
|
+
<h2 style={styles.h2}>This page could not be found.</h2>
|
|
19
|
+
</div>
|
|
20
|
+
</div>
|
|
21
|
+
</div>
|
|
22
|
+
</>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const styles = {
|
|
27
|
+
error: {
|
|
28
|
+
fontFamily:
|
|
29
|
+
'system-ui,"Segoe UI",Roboto,Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji"',
|
|
30
|
+
height: "100vh",
|
|
31
|
+
textAlign: "center",
|
|
32
|
+
display: "flex",
|
|
33
|
+
flexDirection: "column",
|
|
34
|
+
alignItems: "center",
|
|
35
|
+
justifyContent: "center",
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
desc: {
|
|
39
|
+
display: "inline-block",
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
h1: {
|
|
43
|
+
display: "inline-block",
|
|
44
|
+
margin: "0 20px 0 0",
|
|
45
|
+
padding: "0 23px 0 0",
|
|
46
|
+
fontSize: 24,
|
|
47
|
+
fontWeight: 500,
|
|
48
|
+
verticalAlign: "top",
|
|
49
|
+
lineHeight: "49px",
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
h2: {
|
|
53
|
+
fontSize: 14,
|
|
54
|
+
fontWeight: 400,
|
|
55
|
+
lineHeight: "49px",
|
|
56
|
+
margin: 0,
|
|
57
|
+
},
|
|
58
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { NextRequest } from 'next/server'
|
|
2
|
+
import { getRequestContext } from '@cloudflare/next-on-pages'
|
|
3
|
+
|
|
4
|
+
export const runtime = 'edge'
|
|
5
|
+
|
|
6
|
+
export async function GET(request: NextRequest) {
|
|
7
|
+
let responseText = 'Hello World'
|
|
8
|
+
|
|
9
|
+
// In the edge runtime you can use Bindings that are available in your application
|
|
10
|
+
// (for more details see:
|
|
11
|
+
// - https://developers.cloudflare.com/pages/framework-guides/deploy-a-nextjs-site/#use-bindings-in-your-nextjs-application
|
|
12
|
+
// - https://developers.cloudflare.com/pages/functions/bindings/
|
|
13
|
+
// )
|
|
14
|
+
//
|
|
15
|
+
// KV Example:
|
|
16
|
+
// const myKv = getRequestContext().env.MY_KV
|
|
17
|
+
// await myKv.put('suffix', ' from a KV store!')
|
|
18
|
+
// const suffix = await myKv.get('suffix')
|
|
19
|
+
// responseText += suffix
|
|
20
|
+
|
|
21
|
+
return new Response(responseText)
|
|
22
|
+
}
|