create-cloudflare 0.0.0-ee305dd67 → 0.0.0-ee3ef6414
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 +3308 -3218
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -5
- package/templates/angular/c3.ts +25 -13
- package/templates/angular/templates/src/server.ts +15 -0
- package/templates/angular/templates/tools/copy-files.mjs +8 -2
- package/templates/hello-world/js/package.json +1 -1
- package/templates/hello-world/ts/package.json +1 -1
- package/templates/hello-world/ts/test/tsconfig.json +1 -1
- package/templates/next/README.md +1 -1
- package/templates/next/app/js/app/api/hello/route.js +4 -4
- package/templates/next/app/ts/app/api/hello/route.ts +4 -5
- package/templates/next/c3.ts +3 -3
- package/templates/svelte/c3.ts +31 -4
- package/templates-experimental/angular/c3.ts +21 -7
- package/templates-experimental/angular/templates/src/server.ts +15 -0
- package/templates-experimental/hello-world-with-assets/js/package.json +1 -1
- package/templates-experimental/hello-world-with-assets/ts/package.json +1 -1
- package/templates-experimental/next/c3.ts +4 -0
- package/templates-experimental/nuxt/c3.ts +1 -1
- package/templates-experimental/nuxt/templates/wrangler.toml +2 -2
- package/templates-experimental/solid/c3.ts +7 -50
- package/templates-experimental/solid/templates/wrangler.toml +2 -2
- package/templates-experimental/svelte/c3.ts +1 -4
- package/templates-experimental/vue/c3.ts +33 -0
- package/templates-experimental/{svelte/ts → vue/templates}/wrangler.toml +1 -2
- package/templates/angular/templates/server.ts +0 -34
- package/templates/angular/templates/tools/alter-polyfills.mjs +0 -27
- package/templates/angular/templates/tools/paths.mjs +0 -9
- package/templates/svelte/ts/wrangler.toml +0 -85
- package/templates-experimental/angular/templates/server.ts +0 -34
- package/templates-experimental/angular/templates/tools/alter-polyfills.mjs +0 -32
- package/templates-experimental/nuxt/templates/cloudflare-preset/nitro.config.ts +0 -27
- package/templates-experimental/svelte/ts/static/.assetsignore +0 -4
- /package/templates/svelte/{js → templates}/wrangler.toml +0 -0
- /package/templates-experimental/svelte/{js → templates}/static/.assetsignore +0 -0
- /package/templates-experimental/svelte/{js → templates}/wrangler.toml +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-ee3ef6414",
|
|
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.20241205.0",
|
|
34
34
|
"@iarna/toml": "^3.0.0",
|
|
35
35
|
"@types/command-exists": "^1.2.0",
|
|
36
36
|
"@types/cross-spawn": "^6.0.2",
|
|
@@ -66,16 +66,17 @@
|
|
|
66
66
|
"wrap-ansi": "^9.0.0",
|
|
67
67
|
"xdg-app-paths": "^8.3.0",
|
|
68
68
|
"yargs": "^17.7.2",
|
|
69
|
+
"@cloudflare/cli": "1.1.1",
|
|
69
70
|
"@cloudflare/eslint-config-worker": "1.1.0",
|
|
70
71
|
"@cloudflare/workers-tsconfig": "0.0.0",
|
|
71
|
-
"
|
|
72
|
-
"wrangler": "0.0.0-ee305dd67"
|
|
72
|
+
"wrangler": "0.0.0-ee3ef6414"
|
|
73
73
|
},
|
|
74
74
|
"engines": {
|
|
75
75
|
"node": ">=18.14.1"
|
|
76
76
|
},
|
|
77
77
|
"workers-sdk": {
|
|
78
|
-
"prerelease": true
|
|
78
|
+
"prerelease": true,
|
|
79
|
+
"type": "cli"
|
|
79
80
|
},
|
|
80
81
|
"volta": {
|
|
81
82
|
"extends": "../../package.json"
|
package/templates/angular/c3.ts
CHANGED
|
@@ -13,7 +13,11 @@ import type { C3Context } from "types";
|
|
|
13
13
|
const { npm } = detectPackageManager();
|
|
14
14
|
|
|
15
15
|
const generate = async (ctx: C3Context) => {
|
|
16
|
-
await runFrameworkGenerator(ctx, [
|
|
16
|
+
await runFrameworkGenerator(ctx, [
|
|
17
|
+
ctx.project.name,
|
|
18
|
+
"--ssr",
|
|
19
|
+
"--server-routing" /** Dev Preview API */,
|
|
20
|
+
]);
|
|
17
21
|
logRaw("");
|
|
18
22
|
};
|
|
19
23
|
|
|
@@ -24,14 +28,11 @@ const configure = async (ctx: C3Context) => {
|
|
|
24
28
|
};
|
|
25
29
|
|
|
26
30
|
async function installCFWorker() {
|
|
27
|
-
await installPackages(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
doneText: `${brandColor("installed")} ${dim(`via \`${npm} install\``)}`,
|
|
33
|
-
},
|
|
34
|
-
);
|
|
31
|
+
await installPackages(["xhr2"], {
|
|
32
|
+
dev: true,
|
|
33
|
+
startText: "Installing additional dependencies",
|
|
34
|
+
doneText: `${brandColor("installed")} ${dim(`via \`${npm} install\``)}`,
|
|
35
|
+
});
|
|
35
36
|
}
|
|
36
37
|
async function updateAppCode() {
|
|
37
38
|
const s = spinner();
|
|
@@ -50,12 +51,21 @@ async function updateAppCode() {
|
|
|
50
51
|
writeFile(resolve(appConfigPath), newAppConfig);
|
|
51
52
|
s.stop(`${brandColor(`updated`)} ${dim(appConfigPath)}`);
|
|
52
53
|
|
|
54
|
+
// Update an app server routes file to:
|
|
55
|
+
const appServerRoutesPath = "src/app/app.routes.server.ts";
|
|
56
|
+
const appRoutes = readFile(resolve(appServerRoutesPath));
|
|
57
|
+
const newAppRoutes = appRoutes.replace(
|
|
58
|
+
"RenderMode.Prerender",
|
|
59
|
+
"RenderMode.Server",
|
|
60
|
+
);
|
|
61
|
+
writeFile(resolve(appServerRoutesPath), newAppRoutes);
|
|
62
|
+
s.stop(`${brandColor(`updated`)} ${dim(appServerRoutesPath)}`);
|
|
63
|
+
|
|
53
64
|
// Remove unwanted dependencies
|
|
54
65
|
s.start(`Updating package.json`);
|
|
55
66
|
const packageJsonPath = resolve("package.json");
|
|
56
67
|
const packageManifest = readJSON(packageJsonPath);
|
|
57
68
|
|
|
58
|
-
delete packageManifest["dependencies"]["@angular/ssr"];
|
|
59
69
|
delete packageManifest["dependencies"]["express"];
|
|
60
70
|
delete packageManifest["devDependencies"]["@types/express"];
|
|
61
71
|
|
|
@@ -70,6 +80,8 @@ function updateAngularJson(ctx: C3Context) {
|
|
|
70
80
|
// Update builder
|
|
71
81
|
const architectSection = angularJson.projects[ctx.project.name].architect;
|
|
72
82
|
architectSection.build.options.outputPath = "dist";
|
|
83
|
+
architectSection.build.options.outputMode = "server";
|
|
84
|
+
architectSection.build.options.ssr.experimentalPlatform = "neutral";
|
|
73
85
|
architectSection.build.options.assets.push("src/_routes.json");
|
|
74
86
|
|
|
75
87
|
writeFile(resolve("angular.json"), JSON.stringify(angularJson, null, 2));
|
|
@@ -87,14 +99,14 @@ const config: TemplateConfig = {
|
|
|
87
99
|
},
|
|
88
100
|
devScript: "start",
|
|
89
101
|
deployScript: "deploy",
|
|
102
|
+
previewScript: "start",
|
|
90
103
|
generate,
|
|
91
104
|
configure,
|
|
92
105
|
transformPackageJson: async () => ({
|
|
93
106
|
scripts: {
|
|
94
|
-
start: `${npm} run build && wrangler pages dev dist/cloudflare ${await compatDateFlag()}
|
|
107
|
+
start: `${npm} run build && wrangler pages dev dist/cloudflare ${await compatDateFlag()}`,
|
|
95
108
|
build: `ng build && ${npm} run process`,
|
|
96
|
-
process:
|
|
97
|
-
"node ./tools/copy-files.mjs && node ./tools/alter-polyfills.mjs",
|
|
109
|
+
process: "node ./tools/copy-files.mjs",
|
|
98
110
|
deploy: `${npm} run build && wrangler pages deploy dist/cloudflare`,
|
|
99
111
|
},
|
|
100
112
|
}),
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AngularAppEngine, createRequestHandler } from '@angular/ssr';
|
|
2
|
+
|
|
3
|
+
const angularApp = new AngularAppEngine();
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* This is a request handler used by the Angular CLI (dev-server and during build).
|
|
7
|
+
*/
|
|
8
|
+
export const reqHandler = createRequestHandler(async (req) => {
|
|
9
|
+
const res = await angularApp.handle(req);
|
|
10
|
+
|
|
11
|
+
return res ?? new Response('Page not found.', { status: 404 });
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
export default { fetch: reqHandler };
|
|
@@ -1,7 +1,13 @@
|
|
|
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
|
-
import { join } from "node:path";
|
|
4
|
-
import {
|
|
3
|
+
import { join, resolve } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
|
|
6
|
+
const root = resolve(fileURLToPath(import.meta.url), "../../");
|
|
7
|
+
const client = resolve(root, "dist/browser");
|
|
8
|
+
const ssr = resolve(root, "dist/server");
|
|
9
|
+
const cloudflare = resolve(root, "dist/cloudflare");
|
|
10
|
+
const worker = resolve(cloudflare, "_worker.js");
|
|
5
11
|
|
|
6
12
|
fs.cpSync(client, cloudflare, { recursive: true });
|
|
7
13
|
fs.cpSync(ssr, worker, { recursive: true });
|
package/templates/next/README.md
CHANGED
|
@@ -46,7 +46,7 @@ In order to enable the example:
|
|
|
46
46
|
```ts
|
|
47
47
|
// KV Example:
|
|
48
48
|
```
|
|
49
|
-
and uncomment the commented lines below it.
|
|
49
|
+
and uncomment the commented lines below it (also uncomment the relevant imports).
|
|
50
50
|
- Do the same in the `wrangler.toml` file, where
|
|
51
51
|
the comment is:
|
|
52
52
|
```
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { getRequestContext } from '@cloudflare/next-on-pages'
|
|
1
|
+
// import { getRequestContext } from '@cloudflare/next-on-pages'
|
|
2
2
|
|
|
3
3
|
export const runtime = 'edge'
|
|
4
4
|
|
|
5
|
-
export async function GET(
|
|
6
|
-
|
|
5
|
+
export async function GET() {
|
|
6
|
+
const responseText = 'Hello World'
|
|
7
7
|
|
|
8
8
|
// In the edge runtime you can use Bindings that are available in your application
|
|
9
9
|
// (for more details see:
|
|
@@ -15,7 +15,7 @@ export async function GET(request) {
|
|
|
15
15
|
// const myKv = getRequestContext().env.MY_KV_NAMESPACE
|
|
16
16
|
// await myKv.put('suffix', ' from a KV store!')
|
|
17
17
|
// const suffix = await myKv.get('suffix')
|
|
18
|
-
// responseText
|
|
18
|
+
// return new Response(responseText + suffix)
|
|
19
19
|
|
|
20
20
|
return new Response(responseText)
|
|
21
21
|
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { getRequestContext } from '@cloudflare/next-on-pages'
|
|
1
|
+
// import { getRequestContext } from '@cloudflare/next-on-pages'
|
|
3
2
|
|
|
4
3
|
export const runtime = 'edge'
|
|
5
4
|
|
|
6
|
-
export async function GET(
|
|
7
|
-
|
|
5
|
+
export async function GET() {
|
|
6
|
+
const responseText = 'Hello World'
|
|
8
7
|
|
|
9
8
|
// In the edge runtime you can use Bindings that are available in your application
|
|
10
9
|
// (for more details see:
|
|
@@ -16,7 +15,7 @@ export async function GET(request: NextRequest) {
|
|
|
16
15
|
// const myKv = getRequestContext().env.MY_KV_NAMESPACE
|
|
17
16
|
// await myKv.put('suffix', ' from a KV store!')
|
|
18
17
|
// const suffix = await myKv.get('suffix')
|
|
19
|
-
// responseText
|
|
18
|
+
// return new Response(responseText + suffix)
|
|
20
19
|
|
|
21
20
|
return new Response(responseText)
|
|
22
21
|
}
|
package/templates/next/c3.ts
CHANGED
|
@@ -49,10 +49,10 @@ const generate = async (ctx: C3Context) => {
|
|
|
49
49
|
updateStatus("Created wrangler.toml file");
|
|
50
50
|
};
|
|
51
51
|
|
|
52
|
-
const updateNextConfig = () => {
|
|
52
|
+
const updateNextConfig = (usesTs: boolean) => {
|
|
53
53
|
const s = spinner();
|
|
54
54
|
|
|
55
|
-
const configFile =
|
|
55
|
+
const configFile = `next.config.${usesTs ? "ts" : "mjs"}`;
|
|
56
56
|
s.start(`Updating \`${configFile}\``);
|
|
57
57
|
|
|
58
58
|
const configContent = readFile(configFile);
|
|
@@ -107,7 +107,7 @@ const configure = async (ctx: C3Context) => {
|
|
|
107
107
|
await writeEslintrc(ctx);
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
updateNextConfig();
|
|
110
|
+
updateNextConfig(usesTs);
|
|
111
111
|
|
|
112
112
|
copyFile(
|
|
113
113
|
join(getTemplatePath(ctx), "README.md"),
|
package/templates/svelte/c3.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
1
2
|
import { platform } from "node:os";
|
|
2
3
|
import { logRaw, updateStatus } from "@cloudflare/cli";
|
|
3
4
|
import { blue, brandColor, dim } from "@cloudflare/cli/colors";
|
|
@@ -28,6 +29,7 @@ const configure = async (ctx: C3Context) => {
|
|
|
28
29
|
});
|
|
29
30
|
|
|
30
31
|
updateSvelteConfig();
|
|
32
|
+
updatePlaywrightConfig(usesTypescript(ctx));
|
|
31
33
|
updateTypeDefinitions(ctx);
|
|
32
34
|
};
|
|
33
35
|
|
|
@@ -49,6 +51,34 @@ const updateSvelteConfig = () => {
|
|
|
49
51
|
});
|
|
50
52
|
};
|
|
51
53
|
|
|
54
|
+
const updatePlaywrightConfig = (shouldUseTypescript: boolean) => {
|
|
55
|
+
const filePath = `playwright.config.${shouldUseTypescript ? "ts" : "js"}`;
|
|
56
|
+
if (!existsSync(filePath)) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
updateStatus(`Changing webServer port in ${blue(filePath)}`);
|
|
61
|
+
|
|
62
|
+
transformFile(filePath, {
|
|
63
|
+
visitObjectExpression: function (n) {
|
|
64
|
+
const portProp = n.node.properties.find((prop) => {
|
|
65
|
+
if (!("key" in prop) || !("name" in prop.key)) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return prop.key.name === "port";
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
if (!portProp || !("value" in portProp) || !("value" in portProp.value)) {
|
|
73
|
+
return this.traverse(n);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
portProp.value.value = 8788;
|
|
77
|
+
return false;
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
|
|
52
82
|
const updateTypeDefinitions = (ctx: C3Context) => {
|
|
53
83
|
if (!usesTypescript(ctx)) {
|
|
54
84
|
return;
|
|
@@ -101,10 +131,7 @@ const config: TemplateConfig = {
|
|
|
101
131
|
displayName: "SvelteKit",
|
|
102
132
|
platform: "pages",
|
|
103
133
|
copyFiles: {
|
|
104
|
-
|
|
105
|
-
js: { path: "./js" },
|
|
106
|
-
ts: { path: "./ts" },
|
|
107
|
-
},
|
|
134
|
+
path: "./templates",
|
|
108
135
|
},
|
|
109
136
|
generate,
|
|
110
137
|
configure,
|
|
@@ -12,7 +12,11 @@ import type { C3Context } from "types";
|
|
|
12
12
|
const { npm } = detectPackageManager();
|
|
13
13
|
|
|
14
14
|
const generate = async (ctx: C3Context) => {
|
|
15
|
-
await runFrameworkGenerator(ctx, [
|
|
15
|
+
await runFrameworkGenerator(ctx, [
|
|
16
|
+
ctx.project.name,
|
|
17
|
+
"--ssr",
|
|
18
|
+
"--server-routing" /** Dev Preview API */,
|
|
19
|
+
]);
|
|
16
20
|
logRaw("");
|
|
17
21
|
};
|
|
18
22
|
|
|
@@ -23,9 +27,9 @@ const configure = async (ctx: C3Context) => {
|
|
|
23
27
|
};
|
|
24
28
|
|
|
25
29
|
async function installCFWorker() {
|
|
26
|
-
await installPackages(["
|
|
30
|
+
await installPackages(["xhr2"], {
|
|
27
31
|
dev: true,
|
|
28
|
-
startText: "Installing
|
|
32
|
+
startText: "Installing additional dependencies",
|
|
29
33
|
doneText: `${brandColor("installed")} ${dim(`via \`${npm} install\``)}`,
|
|
30
34
|
});
|
|
31
35
|
}
|
|
@@ -46,12 +50,21 @@ async function updateAppCode() {
|
|
|
46
50
|
writeFile(resolve(appConfigPath), newAppConfig);
|
|
47
51
|
s.stop(`${brandColor(`updated`)} ${dim(appConfigPath)}`);
|
|
48
52
|
|
|
53
|
+
// Update an app server routes file to:
|
|
54
|
+
const appServerRoutesPath = "src/app/app.routes.server.ts";
|
|
55
|
+
const appRoutes = readFile(resolve(appServerRoutesPath));
|
|
56
|
+
const newAppRoutes = appRoutes.replace(
|
|
57
|
+
"RenderMode.Prerender",
|
|
58
|
+
"RenderMode.Server",
|
|
59
|
+
);
|
|
60
|
+
writeFile(resolve(appServerRoutesPath), newAppRoutes);
|
|
61
|
+
s.stop(`${brandColor(`updated`)} ${dim(appServerRoutesPath)}`);
|
|
62
|
+
|
|
49
63
|
// Remove unwanted dependencies
|
|
50
64
|
s.start(`Updating package.json`);
|
|
51
65
|
const packageJsonPath = resolve("package.json");
|
|
52
66
|
const packageManifest = readJSON(packageJsonPath);
|
|
53
67
|
|
|
54
|
-
delete packageManifest["dependencies"]["@angular/ssr"];
|
|
55
68
|
delete packageManifest["dependencies"]["express"];
|
|
56
69
|
delete packageManifest["devDependencies"]["@types/express"];
|
|
57
70
|
|
|
@@ -66,7 +79,8 @@ function updateAngularJson(ctx: C3Context) {
|
|
|
66
79
|
// Update builder
|
|
67
80
|
const architectSection = angularJson.projects[ctx.project.name].architect;
|
|
68
81
|
architectSection.build.options.outputPath = "dist";
|
|
69
|
-
architectSection.build.options.
|
|
82
|
+
architectSection.build.options.outputMode = "server";
|
|
83
|
+
architectSection.build.options.ssr.experimentalPlatform = "neutral";
|
|
70
84
|
|
|
71
85
|
writeFile(resolve("angular.json"), JSON.stringify(angularJson, null, 2));
|
|
72
86
|
s.stop(`${brandColor(`updated`)} ${dim(`\`angular.json\``)}`);
|
|
@@ -84,13 +98,13 @@ const config: TemplateConfig = {
|
|
|
84
98
|
path: "templates-experimental/angular",
|
|
85
99
|
devScript: "start",
|
|
86
100
|
deployScript: "deploy",
|
|
101
|
+
previewScript: "start",
|
|
87
102
|
generate,
|
|
88
103
|
configure,
|
|
89
104
|
transformPackageJson: async () => ({
|
|
90
105
|
scripts: {
|
|
91
106
|
start: `${npm} run build && wrangler dev`,
|
|
92
|
-
build: `ng build
|
|
93
|
-
process: "node ./tools/alter-polyfills.mjs",
|
|
107
|
+
build: `ng build`,
|
|
94
108
|
deploy: `${npm} run build && wrangler deploy`,
|
|
95
109
|
},
|
|
96
110
|
}),
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AngularAppEngine, createRequestHandler } from '@angular/ssr';
|
|
2
|
+
|
|
3
|
+
const angularApp = new AngularAppEngine();
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* This is a request handler used by the Angular CLI (dev-server and during build).
|
|
7
|
+
*/
|
|
8
|
+
export const reqHandler = createRequestHandler(async (req) => {
|
|
9
|
+
const res = await angularApp.handle(req);
|
|
10
|
+
|
|
11
|
+
return res ?? new Response('Page not found.', { status: 404 });
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
export default { fetch: reqHandler };
|
|
@@ -30,6 +30,10 @@ export default {
|
|
|
30
30
|
configVersion: 1,
|
|
31
31
|
id: "next",
|
|
32
32
|
frameworkCli: "create-next-app",
|
|
33
|
+
// TODO: here we need to specify a version of create-next-app which is different from the
|
|
34
|
+
// standard one used in the stable Next.js template, that's because our open-next adapter
|
|
35
|
+
// is not yet fully ready for Next.js 15, once it is we should remove the following
|
|
36
|
+
frameworkCliPinnedVersion: "14.2.5",
|
|
33
37
|
platform: "workers",
|
|
34
38
|
displayName: "Next (using Node.js compat + Workers Assets)",
|
|
35
39
|
path: "templates-experimental/next",
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#:schema node_modules/wrangler/config-schema.json
|
|
2
2
|
name = "<TBD>"
|
|
3
3
|
compatibility_date = "<TBD>"
|
|
4
|
-
main = "
|
|
5
|
-
assets = { directory = "
|
|
4
|
+
main = "./.output/server/index.mjs"
|
|
5
|
+
assets = { directory = "./.output/public/", binding = "ASSETS" }
|
|
6
6
|
|
|
7
7
|
# Workers Logs
|
|
8
8
|
# Docs: https://developers.cloudflare.com/workers/observability/logs/workers-logs/
|
|
@@ -2,6 +2,7 @@ import { logRaw, updateStatus } from "@cloudflare/cli";
|
|
|
2
2
|
import { blue, brandColor, dim } from "@cloudflare/cli/colors";
|
|
3
3
|
import { runFrameworkGenerator } from "frameworks/index";
|
|
4
4
|
import { mergeObjectProperties, transformFile } from "helpers/codemod";
|
|
5
|
+
import { getWorkerdCompatibilityDate } from "helpers/compatDate";
|
|
5
6
|
import { usesTypescript } from "helpers/files";
|
|
6
7
|
import { detectPackageManager } from "helpers/packageManagers";
|
|
7
8
|
import { installPackages } from "helpers/packages";
|
|
@@ -30,6 +31,8 @@ const configure = async (ctx: C3Context) => {
|
|
|
30
31
|
usesTypescript(ctx);
|
|
31
32
|
const filePath = `app.config.${usesTypescript(ctx) ? "ts" : "js"}`;
|
|
32
33
|
|
|
34
|
+
const compatDate = await getWorkerdCompatibilityDate();
|
|
35
|
+
|
|
33
36
|
updateStatus(`Updating configuration in ${blue(filePath)}`);
|
|
34
37
|
|
|
35
38
|
transformFile(filePath, {
|
|
@@ -46,60 +49,14 @@ const configure = async (ctx: C3Context) => {
|
|
|
46
49
|
b.objectProperty(
|
|
47
50
|
b.identifier("server"),
|
|
48
51
|
b.objectExpression([
|
|
49
|
-
// preset: "
|
|
52
|
+
// preset: "cloudflare_module"
|
|
50
53
|
b.objectProperty(
|
|
51
54
|
b.identifier("preset"),
|
|
52
|
-
b.stringLiteral("
|
|
53
|
-
),
|
|
54
|
-
// output: {
|
|
55
|
-
// dir: "{{ rootDir }}/dist",
|
|
56
|
-
// publicDir: "{{ output.dir }}/public",
|
|
57
|
-
// serverDir: "{{ output.dir }}/worker",
|
|
58
|
-
// },
|
|
59
|
-
b.objectProperty(
|
|
60
|
-
b.identifier("output"),
|
|
61
|
-
b.objectExpression([
|
|
62
|
-
b.objectProperty(
|
|
63
|
-
b.identifier("dir"),
|
|
64
|
-
b.stringLiteral("{{ rootDir }}/dist"),
|
|
65
|
-
),
|
|
66
|
-
b.objectProperty(
|
|
67
|
-
b.identifier("publicDir"),
|
|
68
|
-
b.stringLiteral("{{ output.dir }}/public"),
|
|
69
|
-
),
|
|
70
|
-
b.objectProperty(
|
|
71
|
-
b.identifier("serverDir"),
|
|
72
|
-
b.stringLiteral("{{ output.dir }}/worker"),
|
|
73
|
-
),
|
|
74
|
-
]),
|
|
75
|
-
),
|
|
76
|
-
// rollupConfig: {
|
|
77
|
-
// external: ["node:async_hooks"],
|
|
78
|
-
// },
|
|
79
|
-
b.objectProperty(
|
|
80
|
-
b.identifier("rollupConfig"),
|
|
81
|
-
b.objectExpression([
|
|
82
|
-
b.objectProperty(
|
|
83
|
-
b.identifier("external"),
|
|
84
|
-
b.arrayExpression([b.stringLiteral("node:async_hooks")]),
|
|
85
|
-
),
|
|
86
|
-
]),
|
|
55
|
+
b.stringLiteral("cloudflare_module"),
|
|
87
56
|
),
|
|
88
|
-
// hooks: {
|
|
89
|
-
// // Prevent the Pages preset from writing the _routes.json etc.
|
|
90
|
-
// compiled() {},
|
|
91
|
-
// },
|
|
92
57
|
b.objectProperty(
|
|
93
|
-
b.identifier("
|
|
94
|
-
b.
|
|
95
|
-
b.objectMethod(
|
|
96
|
-
"method",
|
|
97
|
-
b.identifier("compiled"),
|
|
98
|
-
[],
|
|
99
|
-
b.blockStatement([]),
|
|
100
|
-
false,
|
|
101
|
-
),
|
|
102
|
-
]),
|
|
58
|
+
b.identifier("compatibilityDate"),
|
|
59
|
+
b.stringLiteral(compatDate),
|
|
103
60
|
),
|
|
104
61
|
]),
|
|
105
62
|
),
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
name = "<TBD>"
|
|
3
3
|
compatibility_date = "<TBD>"
|
|
4
4
|
compatibility_flags = ["nodejs_compat"]
|
|
5
|
-
main = "
|
|
6
|
-
assets = { directory = "
|
|
5
|
+
main = "./.output/server/index.mjs"
|
|
6
|
+
assets = { directory = "./.output/public", binding = "ASSETS" }
|
|
7
7
|
|
|
8
8
|
# Workers Logs
|
|
9
9
|
# Docs: https://developers.cloudflare.com/workers/observability/logs/workers-logs/
|
|
@@ -101,10 +101,7 @@ const config: TemplateConfig = {
|
|
|
101
101
|
displayName: "SvelteKit",
|
|
102
102
|
platform: "workers",
|
|
103
103
|
copyFiles: {
|
|
104
|
-
|
|
105
|
-
js: { path: "./js" },
|
|
106
|
-
ts: { path: "./ts" },
|
|
107
|
-
},
|
|
104
|
+
path: "./templates",
|
|
108
105
|
},
|
|
109
106
|
path: "templates-experimental/svelte",
|
|
110
107
|
generate,
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { runFrameworkGenerator } from "frameworks/index";
|
|
2
|
+
import { detectPackageManager } from "helpers/packageManagers";
|
|
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]);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const config: TemplateConfig = {
|
|
13
|
+
configVersion: 1,
|
|
14
|
+
id: "vue",
|
|
15
|
+
frameworkCli: "create-vue",
|
|
16
|
+
platform: "workers",
|
|
17
|
+
displayName: "Vue",
|
|
18
|
+
copyFiles: {
|
|
19
|
+
path: "./templates",
|
|
20
|
+
},
|
|
21
|
+
path: "templates-experimental/vue",
|
|
22
|
+
generate,
|
|
23
|
+
transformPackageJson: async () => ({
|
|
24
|
+
scripts: {
|
|
25
|
+
deploy: `${npm} run build && wrangler deploy`,
|
|
26
|
+
preview: `${npm} run build && wrangler dev`,
|
|
27
|
+
},
|
|
28
|
+
}),
|
|
29
|
+
devScript: "dev",
|
|
30
|
+
deployScript: "deploy",
|
|
31
|
+
previewScript: "preview",
|
|
32
|
+
};
|
|
33
|
+
export default config;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
#:schema node_modules/wrangler/config-schema.json
|
|
2
2
|
name = "<TBD>"
|
|
3
3
|
compatibility_date = "<TBD>"
|
|
4
|
-
|
|
5
|
-
assets = { directory = ".svelte-kit/cloudflare", binding = "ASSETS" }
|
|
4
|
+
assets = { directory = "./dist" }
|
|
6
5
|
|
|
7
6
|
# Workers Logs
|
|
8
7
|
# Docs: https://developers.cloudflare.com/workers/observability/logs/workers-logs/
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { renderApplication } from "@angular/platform-server";
|
|
2
|
-
import bootstrap from "./src/main.server";
|
|
3
|
-
|
|
4
|
-
interface Env {
|
|
5
|
-
ASSETS: { fetch: typeof fetch };
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
// We attach the Cloudflare `fetch()` handler to the global scope
|
|
9
|
-
// so that we can export it when we process the Angular output.
|
|
10
|
-
// See tools/bundle.mjs
|
|
11
|
-
async function workerFetchHandler(request: Request, env: Env) {
|
|
12
|
-
const url = new URL(request.url);
|
|
13
|
-
console.log("render SSR", url.href);
|
|
14
|
-
|
|
15
|
-
// Get the root `index.html` content.
|
|
16
|
-
const indexUrl = new URL("/", url);
|
|
17
|
-
const indexResponse = await env.ASSETS.fetch(new Request(indexUrl));
|
|
18
|
-
const document = await indexResponse.text();
|
|
19
|
-
|
|
20
|
-
const content = await renderApplication(bootstrap, {
|
|
21
|
-
document,
|
|
22
|
-
url: url.pathname,
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
// console.log("rendered SSR", content);
|
|
26
|
-
return new Response(content, indexResponse);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export default {
|
|
30
|
-
fetch: (request: Request, env: Env) =>
|
|
31
|
-
(globalThis as any)["__zone_symbol__Promise"].resolve(
|
|
32
|
-
workerFetchHandler(request, env)
|
|
33
|
-
),
|
|
34
|
-
};
|