create-cloudflare 0.0.0-e94b46ff7 → 0.0.0-e981d0be5
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 +876 -861
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -8
- package/templates/astro/c3.ts +5 -93
- package/templates/astro/pages/c3.ts +98 -0
- package/{templates-experimental/astro → templates/astro/workers}/c3.ts +2 -2
- package/templates/astro/workers/templates/js/public/.assetsignore +2 -0
- package/templates/astro/workers/templates/ts/public/.assetsignore +2 -0
- package/templates/hello-world-durable-object/js/src/index.js +10 -9
- package/templates/hello-world-durable-object/js/wrangler.jsonc +1 -1
- package/templates/hello-world-durable-object/ts/src/index.ts +10 -9
- package/templates/hello-world-durable-object/ts/wrangler.jsonc +1 -1
- package/templates/hono/c3.ts +5 -66
- package/templates/hono/pages/c3.ts +42 -0
- package/templates/hono/pages/templates/src/index.tsx +12 -0
- package/templates/hono/{templates → pages/templates}/wrangler.jsonc +2 -1
- package/{templates-experimental/hono → templates/hono/workers}/c3.ts +2 -4
- package/templates/qwik/c3.ts +5 -144
- package/templates/qwik/pages/c3.ts +149 -0
- package/{templates-experimental/qwik → templates/qwik/workers}/c3.ts +2 -2
- package/templates/remix/c3.ts +5 -63
- package/templates/remix/pages/c3.ts +68 -0
- package/{templates-experimental/remix → templates/remix/workers}/c3.ts +2 -2
- package/templates/svelte/c3.ts +5 -154
- package/templates/svelte/pages/c3.ts +159 -0
- package/{templates-experimental/svelte → templates/svelte/workers}/c3.ts +3 -3
- package/templates/svelte/workers/templates/static/.assetsignore +2 -0
- package/templates/hono/snippets/appDeclaration.ts +0 -1
- package/templates-experimental/astro/templates/ts/public/.assetsignore +0 -4
- package/templates-experimental/qwik/templates/public/.assetsignore +0 -4
- package/templates-experimental/svelte/templates/static/.assetsignore +0 -4
- /package/templates/astro/{templates → pages/templates}/js/wrangler.jsonc +0 -0
- /package/{templates-experimental/astro → templates/astro/pages}/templates/ts/src/env.d.ts +0 -0
- /package/{templates-experimental/astro → templates/astro/pages}/templates/ts/worker-configuration.d.ts +0 -0
- /package/templates/astro/{templates → pages/templates}/ts/wrangler.jsonc +0 -0
- /package/{templates-experimental/astro → templates/astro/workers}/templates/js/wrangler.jsonc +0 -0
- /package/templates/astro/{templates → workers/templates}/ts/src/env.d.ts +0 -0
- /package/{templates-experimental/qwik/templates → templates/astro/workers/templates/ts}/worker-configuration.d.ts +0 -0
- /package/{templates-experimental/astro → templates/astro/workers}/templates/ts/wrangler.jsonc +0 -0
- /package/{templates-experimental/hono → templates/hono/pages}/templates/worker-configuration.d.ts +0 -0
- /package/{templates-experimental/hono → templates/hono/workers}/templates/public/index.html +0 -0
- /package/{templates-experimental/hono → templates/hono/workers}/templates/src/index.ts +0 -0
- /package/templates/hono/{templates → workers/templates}/worker-configuration.d.ts +0 -0
- /package/{templates-experimental/hono → templates/hono/workers}/templates/wrangler.jsonc +0 -0
- /package/{templates-experimental/qwik → templates/qwik/pages}/snippets/getPlatformProxy.ts +0 -0
- /package/templates/{astro/templates/ts → qwik/pages/templates}/worker-configuration.d.ts +0 -0
- /package/templates/qwik/{templates → pages/templates}/wrangler.jsonc +0 -0
- /package/templates/qwik/{snippets → workers/snippets}/getPlatformProxy.ts +0 -0
- /package/{templates-experimental/astro/templates/js → templates/qwik/workers/templates}/public/.assetsignore +0 -0
- /package/templates/qwik/{templates → workers/templates}/worker-configuration.d.ts +0 -0
- /package/{templates-experimental/qwik → templates/qwik/workers}/templates/wrangler.jsonc +0 -0
- /package/templates/remix/{templates → pages/templates}/worker-configuration.d.ts +0 -0
- /package/templates/remix/{templates → pages/templates}/wrangler.jsonc +0 -0
- /package/{templates-experimental/remix → templates/remix/workers}/templates/public/.assetsignore +0 -0
- /package/{templates-experimental/remix → templates/remix/workers}/templates/worker-configuration.d.ts +0 -0
- /package/{templates-experimental/remix → templates/remix/workers}/templates/wrangler.toml +0 -0
- /package/templates/svelte/{templates → pages/templates}/wrangler.jsonc +0 -0
- /package/{templates-experimental/svelte → templates/svelte/workers}/templates/wrangler.jsonc +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-e981d0be5",
|
|
4
4
|
"description": "A CLI for creating and deploying new applications to Cloudflare.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"@babel/parser": "^7.21.3",
|
|
31
31
|
"@babel/types": "^7.21.4",
|
|
32
32
|
"@clack/prompts": "^0.6.3",
|
|
33
|
-
"@cloudflare/workers-types": "^4.
|
|
33
|
+
"@cloudflare/workers-types": "^4.20250320.0",
|
|
34
34
|
"@iarna/toml": "^3.0.0",
|
|
35
35
|
"@types/command-exists": "^1.2.0",
|
|
36
36
|
"@types/cross-spawn": "^6.0.2",
|
|
@@ -65,17 +65,17 @@
|
|
|
65
65
|
"undici": "^5.28.5",
|
|
66
66
|
"vite": "^5.4.14",
|
|
67
67
|
"vite-tsconfig-paths": "^4.0.8",
|
|
68
|
-
"vitest": "~3.0.
|
|
68
|
+
"vitest": "~3.0.8",
|
|
69
69
|
"which-pm-runs": "^1.1.0",
|
|
70
70
|
"wrap-ansi": "^9.0.0",
|
|
71
71
|
"xdg-app-paths": "^8.3.0",
|
|
72
72
|
"yargs": "^17.7.2",
|
|
73
|
-
"@cloudflare/mock-npm-registry": "0.0.0",
|
|
74
|
-
"@cloudflare/eslint-config-worker": "1.1.0",
|
|
75
73
|
"@cloudflare/cli": "1.1.1",
|
|
76
|
-
"@cloudflare/
|
|
77
|
-
"
|
|
78
|
-
"@cloudflare/workers-tsconfig": "0.0.0"
|
|
74
|
+
"@cloudflare/eslint-config-worker": "1.1.0",
|
|
75
|
+
"@cloudflare/mock-npm-registry": "0.0.0",
|
|
76
|
+
"@cloudflare/workers-tsconfig": "0.0.0",
|
|
77
|
+
"@cloudflare/vite-plugin": "0.0.0-e981d0be5",
|
|
78
|
+
"wrangler": "0.0.0-e981d0be5"
|
|
79
79
|
},
|
|
80
80
|
"engines": {
|
|
81
81
|
"node": ">=18.14.1"
|
package/templates/astro/c3.ts
CHANGED
|
@@ -1,97 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import { transformFile } from "helpers/codemod";
|
|
5
|
-
import { runCommand } from "helpers/command";
|
|
6
|
-
import { usesTypescript } from "helpers/files";
|
|
7
|
-
import { detectPackageManager } from "helpers/packageManagers";
|
|
8
|
-
import * as recast from "recast";
|
|
9
|
-
import type { TemplateConfig } from "../../src/templates";
|
|
10
|
-
import type { C3Context, PackageJson } from "types";
|
|
1
|
+
import pages from "./pages/c3";
|
|
2
|
+
import workers from "./workers/c3";
|
|
3
|
+
import type { MultiPlatformTemplateConfig } from "../../src/templates";
|
|
11
4
|
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
const generate = async (ctx: C3Context) => {
|
|
15
|
-
await runFrameworkGenerator(ctx, [ctx.project.name, "--no-install"]);
|
|
16
|
-
|
|
17
|
-
logRaw(""); // newline
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const configure = async () => {
|
|
21
|
-
await runCommand([npx, "astro", "add", "cloudflare", "-y"], {
|
|
22
|
-
silent: true,
|
|
23
|
-
startText: "Installing adapter",
|
|
24
|
-
doneText: `${brandColor("installed")} ${dim(
|
|
25
|
-
`via \`${npx} astro add cloudflare\``,
|
|
26
|
-
)}`,
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
updateAstroConfig();
|
|
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("platformProxy"),
|
|
49
|
-
b.objectExpression([
|
|
50
|
-
b.objectProperty(b.identifier("enabled"), b.booleanLiteral(true)),
|
|
51
|
-
]),
|
|
52
|
-
),
|
|
53
|
-
]),
|
|
54
|
-
];
|
|
55
|
-
|
|
56
|
-
return false;
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const config: TemplateConfig = {
|
|
62
|
-
configVersion: 1,
|
|
63
|
-
id: "astro",
|
|
64
|
-
frameworkCli: "create-astro",
|
|
65
|
-
platform: "pages",
|
|
5
|
+
const config: MultiPlatformTemplateConfig = {
|
|
66
6
|
displayName: "Astro",
|
|
67
|
-
|
|
68
|
-
async selectVariant(ctx) {
|
|
69
|
-
// Note: this `selectVariant` function should not be needed
|
|
70
|
-
// this is just a quick workaround until
|
|
71
|
-
// https://github.com/cloudflare/workers-sdk/issues/7495
|
|
72
|
-
// is resolved
|
|
73
|
-
return usesTypescript(ctx) ? "ts" : "js";
|
|
74
|
-
},
|
|
75
|
-
variants: {
|
|
76
|
-
js: {
|
|
77
|
-
path: "./templates/js",
|
|
78
|
-
},
|
|
79
|
-
ts: {
|
|
80
|
-
path: "./templates/ts",
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
|
-
},
|
|
84
|
-
devScript: "dev",
|
|
85
|
-
deployScript: "deploy",
|
|
86
|
-
previewScript: "preview",
|
|
87
|
-
generate,
|
|
88
|
-
configure,
|
|
89
|
-
transformPackageJson: async (pkgJson: PackageJson, ctx: C3Context) => ({
|
|
90
|
-
scripts: {
|
|
91
|
-
deploy: `astro build && wrangler pages deploy`,
|
|
92
|
-
preview: `astro build && wrangler pages dev`,
|
|
93
|
-
...(usesTypescript(ctx) && { "cf-typegen": `wrangler types` }),
|
|
94
|
-
},
|
|
95
|
-
}),
|
|
7
|
+
platformVariants: { pages, workers },
|
|
96
8
|
};
|
|
97
9
|
export default config;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { logRaw, updateStatus } from "@cloudflare/cli";
|
|
2
|
+
import { blue, brandColor, dim } from "@cloudflare/cli/colors";
|
|
3
|
+
import { runFrameworkGenerator } from "frameworks/index";
|
|
4
|
+
import { transformFile } from "helpers/codemod";
|
|
5
|
+
import { runCommand } from "helpers/command";
|
|
6
|
+
import { usesTypescript } from "helpers/files";
|
|
7
|
+
import { detectPackageManager } from "helpers/packageManagers";
|
|
8
|
+
import * as recast from "recast";
|
|
9
|
+
import type { TemplateConfig } from "../../../src/templates";
|
|
10
|
+
import type { C3Context, PackageJson } from "types";
|
|
11
|
+
|
|
12
|
+
const { npx } = detectPackageManager();
|
|
13
|
+
|
|
14
|
+
const generate = async (ctx: C3Context) => {
|
|
15
|
+
await runFrameworkGenerator(ctx, [ctx.project.name, "--no-install"]);
|
|
16
|
+
|
|
17
|
+
logRaw(""); // newline
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const configure = async () => {
|
|
21
|
+
await runCommand([npx, "astro", "add", "cloudflare", "-y"], {
|
|
22
|
+
silent: true,
|
|
23
|
+
startText: "Installing adapter",
|
|
24
|
+
doneText: `${brandColor("installed")} ${dim(
|
|
25
|
+
`via \`${npx} astro add cloudflare\``,
|
|
26
|
+
)}`,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
updateAstroConfig();
|
|
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("platformProxy"),
|
|
49
|
+
b.objectExpression([
|
|
50
|
+
b.objectProperty(b.identifier("enabled"), b.booleanLiteral(true)),
|
|
51
|
+
]),
|
|
52
|
+
),
|
|
53
|
+
]),
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
return false;
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const config: TemplateConfig = {
|
|
62
|
+
configVersion: 1,
|
|
63
|
+
id: "astro",
|
|
64
|
+
frameworkCli: "create-astro",
|
|
65
|
+
platform: "pages",
|
|
66
|
+
displayName: "Astro",
|
|
67
|
+
path: "templates/astro/pages",
|
|
68
|
+
copyFiles: {
|
|
69
|
+
async selectVariant(ctx) {
|
|
70
|
+
// Note: this `selectVariant` function should not be needed
|
|
71
|
+
// this is just a quick workaround until
|
|
72
|
+
// https://github.com/cloudflare/workers-sdk/issues/7495
|
|
73
|
+
// is resolved
|
|
74
|
+
return usesTypescript(ctx) ? "ts" : "js";
|
|
75
|
+
},
|
|
76
|
+
variants: {
|
|
77
|
+
js: {
|
|
78
|
+
path: "./templates/js",
|
|
79
|
+
},
|
|
80
|
+
ts: {
|
|
81
|
+
path: "./templates/ts",
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
devScript: "dev",
|
|
86
|
+
deployScript: "deploy",
|
|
87
|
+
previewScript: "preview",
|
|
88
|
+
generate,
|
|
89
|
+
configure,
|
|
90
|
+
transformPackageJson: async (pkgJson: PackageJson, ctx: C3Context) => ({
|
|
91
|
+
scripts: {
|
|
92
|
+
deploy: `astro build && wrangler pages deploy`,
|
|
93
|
+
preview: `astro build && wrangler pages dev`,
|
|
94
|
+
...(usesTypescript(ctx) && { "cf-typegen": `wrangler types` }),
|
|
95
|
+
},
|
|
96
|
+
}),
|
|
97
|
+
};
|
|
98
|
+
export default config;
|
|
@@ -6,7 +6,7 @@ import { runCommand } from "helpers/command";
|
|
|
6
6
|
import { usesTypescript } from "helpers/files";
|
|
7
7
|
import { detectPackageManager } from "helpers/packageManagers";
|
|
8
8
|
import * as recast from "recast";
|
|
9
|
-
import type { TemplateConfig } from "
|
|
9
|
+
import type { TemplateConfig } from "../../../src/templates";
|
|
10
10
|
import type { C3Context, PackageJson } from "types";
|
|
11
11
|
|
|
12
12
|
const { npx } = detectPackageManager();
|
|
@@ -84,7 +84,7 @@ const config: TemplateConfig = {
|
|
|
84
84
|
devScript: "dev",
|
|
85
85
|
deployScript: "deploy",
|
|
86
86
|
previewScript: "preview",
|
|
87
|
-
path: "templates
|
|
87
|
+
path: "templates/astro/workers",
|
|
88
88
|
generate,
|
|
89
89
|
configure,
|
|
90
90
|
transformPackageJson: async (pkgJson: PackageJson, ctx: C3Context) => ({
|
|
@@ -52,17 +52,18 @@ export default {
|
|
|
52
52
|
* @returns {Promise<Response>} The response to be sent back to the client
|
|
53
53
|
*/
|
|
54
54
|
async fetch(request, env, ctx) {
|
|
55
|
-
//
|
|
56
|
-
//
|
|
57
|
-
|
|
55
|
+
// Create a `DurableObjectId` for an instance of the `MyDurableObject`
|
|
56
|
+
// class named "foo". Requests from all Workers to the instance named
|
|
57
|
+
// "foo" will go to a single globally unique Durable Object instance.
|
|
58
|
+
const id = env.MY_DURABLE_OBJECT.idFromName("foo");
|
|
58
59
|
|
|
59
|
-
//
|
|
60
|
-
//
|
|
61
|
-
|
|
60
|
+
// Create a stub to open a communication channel with the Durable
|
|
61
|
+
// Object instance.
|
|
62
|
+
const stub = env.MY_DURABLE_OBJECT.get(id);
|
|
62
63
|
|
|
63
|
-
//
|
|
64
|
-
// Durable Object instance
|
|
65
|
-
|
|
64
|
+
// Call the `sayHello()` RPC method on the stub to invoke the method on
|
|
65
|
+
// the remote Durable Object instance
|
|
66
|
+
const greeting = await stub.sayHello("world");
|
|
66
67
|
|
|
67
68
|
return new Response(greeting);
|
|
68
69
|
},
|
|
@@ -48,17 +48,18 @@ export default {
|
|
|
48
48
|
* @returns The response to be sent back to the client
|
|
49
49
|
*/
|
|
50
50
|
async fetch(request, env, ctx): Promise<Response> {
|
|
51
|
-
//
|
|
52
|
-
//
|
|
53
|
-
|
|
51
|
+
// Create a `DurableObjectId` for an instance of the `MyDurableObject`
|
|
52
|
+
// class named "foo". Requests from all Workers to the instance named
|
|
53
|
+
// "foo" will go to a single globally unique Durable Object instance.
|
|
54
|
+
const id: DurableObjectId = env.MY_DURABLE_OBJECT.idFromName("foo");
|
|
54
55
|
|
|
55
|
-
//
|
|
56
|
-
//
|
|
57
|
-
|
|
56
|
+
// Create a stub to open a communication channel with the Durable
|
|
57
|
+
// Object instance.
|
|
58
|
+
const stub = env.MY_DURABLE_OBJECT.get(id);
|
|
58
59
|
|
|
59
|
-
//
|
|
60
|
-
// Durable Object instance
|
|
61
|
-
|
|
60
|
+
// Call the `sayHello()` RPC method on the stub to invoke the method on
|
|
61
|
+
// the remote Durable Object instance
|
|
62
|
+
const greeting = await stub.sayHello("world");
|
|
62
63
|
|
|
63
64
|
return new Response(greeting);
|
|
64
65
|
},
|
package/templates/hono/c3.ts
CHANGED
|
@@ -1,70 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import { runFrameworkGenerator } from "frameworks/index";
|
|
5
|
-
import { loadTemplateSnippets, transformFile } from "helpers/codemod";
|
|
6
|
-
import { detectPackageManager } from "helpers/packageManagers";
|
|
7
|
-
import type { TemplateConfig } from "../../src/templates";
|
|
8
|
-
import type * as recast from "recast";
|
|
9
|
-
import type { C3Context } from "types";
|
|
1
|
+
import pages from "./pages/c3";
|
|
2
|
+
import workers from "./workers/c3";
|
|
3
|
+
import type { MultiPlatformTemplateConfig } from "../../src/templates";
|
|
10
4
|
|
|
11
|
-
const
|
|
12
|
-
const { name: pm } = detectPackageManager();
|
|
13
|
-
|
|
14
|
-
await runFrameworkGenerator(ctx, [
|
|
15
|
-
ctx.project.name,
|
|
16
|
-
"--template",
|
|
17
|
-
"cloudflare-workers",
|
|
18
|
-
"--install",
|
|
19
|
-
"--pm",
|
|
20
|
-
pm,
|
|
21
|
-
]);
|
|
22
|
-
|
|
23
|
-
logRaw(""); // newline
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const configure = async (ctx: C3Context) => {
|
|
27
|
-
const indexFile = "src/index.ts";
|
|
28
|
-
|
|
29
|
-
const s = spinner();
|
|
30
|
-
s.start(`Updating \`${indexFile}\``);
|
|
31
|
-
|
|
32
|
-
const snippets = loadTemplateSnippets(ctx);
|
|
33
|
-
|
|
34
|
-
transformFile(indexFile, {
|
|
35
|
-
visitVariableDeclarator(n) {
|
|
36
|
-
if (n.node.id.type === "Identifier" && n.node.id.name === "app") {
|
|
37
|
-
n.node.init = snippets
|
|
38
|
-
.appDeclarationTs[0] as recast.types.namedTypes.NewExpression;
|
|
39
|
-
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
s.stop(`${brandColor("updated")} \`${dim(indexFile)}\``);
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const config: TemplateConfig = {
|
|
49
|
-
configVersion: 1,
|
|
50
|
-
id: "hono",
|
|
51
|
-
frameworkCli: "create-hono",
|
|
5
|
+
const config: MultiPlatformTemplateConfig = {
|
|
52
6
|
displayName: "Hono",
|
|
53
|
-
|
|
54
|
-
path: "./templates",
|
|
55
|
-
},
|
|
56
|
-
platform: "workers",
|
|
57
|
-
generate,
|
|
58
|
-
configure,
|
|
59
|
-
transformPackageJson: async () => ({
|
|
60
|
-
scripts: {
|
|
61
|
-
dev: "wrangler dev",
|
|
62
|
-
deploy: "wrangler deploy --minify",
|
|
63
|
-
"cf-typegen": "wrangler types --env-interface CloudflareBindings",
|
|
64
|
-
},
|
|
65
|
-
}),
|
|
66
|
-
devScript: "dev",
|
|
67
|
-
deployScript: "deploy",
|
|
68
|
-
previewScript: "dev",
|
|
7
|
+
platformVariants: { pages, workers },
|
|
69
8
|
};
|
|
70
9
|
export default config;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { logRaw } from "@cloudflare/cli";
|
|
2
|
+
import { runFrameworkGenerator } from "frameworks/index";
|
|
3
|
+
import { detectPackageManager } from "helpers/packageManagers";
|
|
4
|
+
import type { TemplateConfig } from "../../../src/templates";
|
|
5
|
+
import type { C3Context } from "types";
|
|
6
|
+
|
|
7
|
+
const generate = async (ctx: C3Context) => {
|
|
8
|
+
const { name: pm } = detectPackageManager();
|
|
9
|
+
|
|
10
|
+
await runFrameworkGenerator(ctx, [
|
|
11
|
+
ctx.project.name,
|
|
12
|
+
"--template",
|
|
13
|
+
"cloudflare-pages",
|
|
14
|
+
"--install",
|
|
15
|
+
"--pm",
|
|
16
|
+
pm,
|
|
17
|
+
]);
|
|
18
|
+
|
|
19
|
+
logRaw(""); // newline
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const config: TemplateConfig = {
|
|
23
|
+
configVersion: 1,
|
|
24
|
+
id: "hono",
|
|
25
|
+
frameworkCli: "create-hono",
|
|
26
|
+
displayName: "Hono",
|
|
27
|
+
copyFiles: {
|
|
28
|
+
path: "./templates",
|
|
29
|
+
},
|
|
30
|
+
path: "templates/hono/pages",
|
|
31
|
+
platform: "pages",
|
|
32
|
+
generate,
|
|
33
|
+
transformPackageJson: async () => ({
|
|
34
|
+
scripts: {
|
|
35
|
+
"cf-typegen": "wrangler types --env-interface CloudflareBindings",
|
|
36
|
+
},
|
|
37
|
+
}),
|
|
38
|
+
devScript: "dev",
|
|
39
|
+
deployScript: "deploy",
|
|
40
|
+
previewScript: "dev",
|
|
41
|
+
};
|
|
42
|
+
export default config;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { logRaw } from "@cloudflare/cli";
|
|
2
2
|
import { runFrameworkGenerator } from "frameworks/index";
|
|
3
3
|
import { detectPackageManager } from "helpers/packageManagers";
|
|
4
|
-
import type { TemplateConfig } from "
|
|
4
|
+
import type { TemplateConfig } from "../../../src/templates";
|
|
5
5
|
import type { C3Context } from "types";
|
|
6
6
|
|
|
7
7
|
const generate = async (ctx: C3Context) => {
|
|
@@ -28,12 +28,10 @@ const config: TemplateConfig = {
|
|
|
28
28
|
path: "./templates",
|
|
29
29
|
},
|
|
30
30
|
platform: "workers",
|
|
31
|
-
path: "templates
|
|
31
|
+
path: "templates/hono/workers",
|
|
32
32
|
generate,
|
|
33
33
|
transformPackageJson: async () => ({
|
|
34
34
|
scripts: {
|
|
35
|
-
dev: "wrangler dev",
|
|
36
|
-
deploy: "wrangler deploy --minify",
|
|
37
35
|
"cf-typegen": "wrangler types --env-interface CloudflareBindings",
|
|
38
36
|
},
|
|
39
37
|
}),
|
package/templates/qwik/c3.ts
CHANGED
|
@@ -1,148 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import { runFrameworkGenerator } from "frameworks/index";
|
|
5
|
-
import { loadTemplateSnippets, transformFile } from "helpers/codemod";
|
|
6
|
-
import { quoteShellArgs, runCommand } from "helpers/command";
|
|
7
|
-
import { usesTypescript } from "helpers/files";
|
|
8
|
-
import { detectPackageManager } from "helpers/packageManagers";
|
|
9
|
-
import * as recast from "recast";
|
|
10
|
-
import type { TemplateConfig } from "../../src/templates";
|
|
11
|
-
import type { C3Context } from "types";
|
|
1
|
+
import pages from "./pages/c3";
|
|
2
|
+
import workers from "./workers/c3";
|
|
3
|
+
import type { MultiPlatformTemplateConfig } from "../../src/templates";
|
|
12
4
|
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
const generate = async (ctx: C3Context) => {
|
|
16
|
-
await runFrameworkGenerator(ctx, ["playground", ctx.project.name]);
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const configure = async (ctx: C3Context) => {
|
|
20
|
-
// Add the pages integration
|
|
21
|
-
// For some reason `pnpx qwik add` fails for qwik so we use `pnpm qwik add` instead.
|
|
22
|
-
const cmd = [name === "pnpm" ? npm : npx, "qwik", "add", "cloudflare-pages"];
|
|
23
|
-
endSection(`Running ${quoteShellArgs(cmd)}`);
|
|
24
|
-
await runCommand(cmd);
|
|
25
|
-
|
|
26
|
-
addBindingsProxy(ctx);
|
|
27
|
-
populateCloudflareEnv();
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const addBindingsProxy = (ctx: C3Context) => {
|
|
31
|
-
// Qwik only has a typescript template atm.
|
|
32
|
-
// This check is an extra precaution
|
|
33
|
-
if (!usesTypescript(ctx)) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const s = spinner();
|
|
38
|
-
s.start("Updating `vite.config.ts`");
|
|
39
|
-
|
|
40
|
-
const snippets = loadTemplateSnippets(ctx);
|
|
41
|
-
const b = recast.types.builders;
|
|
42
|
-
|
|
43
|
-
transformFile("vite.config.ts", {
|
|
44
|
-
// Insert the env declaration after the last import (but before the rest of the body)
|
|
45
|
-
visitProgram: function (n) {
|
|
46
|
-
const lastImportIndex = n.node.body.findLastIndex(
|
|
47
|
-
(t) => t.type === "ImportDeclaration",
|
|
48
|
-
);
|
|
49
|
-
const lastImport = n.get("body", lastImportIndex);
|
|
50
|
-
lastImport.insertAfter(...snippets.getPlatformProxyTs);
|
|
51
|
-
|
|
52
|
-
return this.traverse(n);
|
|
53
|
-
},
|
|
54
|
-
// Pass the `platform` object from the declaration to the `qwikCity` plugin
|
|
55
|
-
visitCallExpression: function (n) {
|
|
56
|
-
const callee = n.node.callee as recast.types.namedTypes.Identifier;
|
|
57
|
-
if (callee.name !== "qwikCity") {
|
|
58
|
-
return this.traverse(n);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// The config object passed to `qwikCity`
|
|
62
|
-
const configArgument = n.node.arguments[0] as
|
|
63
|
-
| recast.types.namedTypes.ObjectExpression
|
|
64
|
-
| undefined;
|
|
65
|
-
|
|
66
|
-
const platformPropery = b.objectProperty.from({
|
|
67
|
-
key: b.identifier("platform"),
|
|
68
|
-
value: b.identifier("platform"),
|
|
69
|
-
shorthand: true,
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
if (!configArgument) {
|
|
73
|
-
n.node.arguments = [b.objectExpression([platformPropery])];
|
|
74
|
-
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (configArgument.type !== "ObjectExpression") {
|
|
79
|
-
throw new Error("Failed to update `vite.config.ts`");
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// Add the `platform` object to the object
|
|
83
|
-
configArgument.properties.push(platformPropery);
|
|
84
|
-
|
|
85
|
-
return false;
|
|
86
|
-
},
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
s.stop(`${brandColor("updated")} \`vite.config.ts\``);
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
const populateCloudflareEnv = () => {
|
|
93
|
-
const entrypointPath = "src/entry.cloudflare-pages.tsx";
|
|
94
|
-
|
|
95
|
-
const s = spinner();
|
|
96
|
-
s.start(`Updating \`${entrypointPath}\``);
|
|
97
|
-
|
|
98
|
-
transformFile(entrypointPath, {
|
|
99
|
-
visitTSInterfaceDeclaration: function (n) {
|
|
100
|
-
const b = recast.types.builders;
|
|
101
|
-
const id = n.node.id as recast.types.namedTypes.Identifier;
|
|
102
|
-
if (id.name !== "QwikCityPlatform") {
|
|
103
|
-
this.traverse(n);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const newBody = [
|
|
107
|
-
["env", "Env"],
|
|
108
|
-
// Qwik doesn't supply `cf` to the platform object. Should they do so, uncomment this
|
|
109
|
-
// ["cf", "CfProperties"],
|
|
110
|
-
].map(([varName, type]) =>
|
|
111
|
-
b.tsPropertySignature(
|
|
112
|
-
b.identifier(varName),
|
|
113
|
-
b.tsTypeAnnotation(b.tsTypeReference(b.identifier(type))),
|
|
114
|
-
),
|
|
115
|
-
);
|
|
116
|
-
|
|
117
|
-
n.node.body.body = newBody;
|
|
118
|
-
|
|
119
|
-
return false;
|
|
120
|
-
},
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
s.stop(`${brandColor("updated")} \`${entrypointPath}\``);
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
const config: TemplateConfig = {
|
|
127
|
-
configVersion: 1,
|
|
128
|
-
id: "qwik",
|
|
129
|
-
frameworkCli: "create-qwik",
|
|
5
|
+
const config: MultiPlatformTemplateConfig = {
|
|
130
6
|
displayName: "Qwik",
|
|
131
|
-
|
|
132
|
-
copyFiles: {
|
|
133
|
-
path: "./templates",
|
|
134
|
-
},
|
|
135
|
-
generate,
|
|
136
|
-
configure,
|
|
137
|
-
transformPackageJson: async () => ({
|
|
138
|
-
scripts: {
|
|
139
|
-
deploy: `${npm} run build && wrangler pages deploy`,
|
|
140
|
-
preview: `${npm} run build && wrangler pages dev`,
|
|
141
|
-
"cf-typegen": `wrangler types`,
|
|
142
|
-
},
|
|
143
|
-
}),
|
|
144
|
-
devScript: "dev",
|
|
145
|
-
deployScript: "deploy",
|
|
146
|
-
previewScript: "preview",
|
|
7
|
+
platformVariants: { pages, workers },
|
|
147
8
|
};
|
|
148
9
|
export default config;
|