create-cloudflare 2.33.1 → 2.33.3
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 +66 -70
- package/package.json +4 -4
- package/templates/angular/c3.ts +7 -9
- package/templates/angular/templates/src/server.ts +1 -1
- package/templates/hello-world/js/package.json +1 -1
- package/templates/hello-world/ts/package.json +1 -1
- package/templates/svelte/c3.ts +30 -0
- 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/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/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/dist/cli.js
CHANGED
|
@@ -73725,7 +73725,7 @@ var Yargs = YargsFactory(esm_default);
|
|
|
73725
73725
|
var yargs_default = Yargs;
|
|
73726
73726
|
|
|
73727
73727
|
// package.json
|
|
73728
|
-
var version = "2.33.
|
|
73728
|
+
var version = "2.33.3";
|
|
73729
73729
|
|
|
73730
73730
|
// src/metrics.ts
|
|
73731
73731
|
var import_node_async_hooks = require("node:async_hooks");
|
|
@@ -73817,6 +73817,13 @@ var runCommand = async (command2, opts = {}) => {
|
|
|
73817
73817
|
doneText: opts.doneText,
|
|
73818
73818
|
promise() {
|
|
73819
73819
|
const [executable, ...args] = command2;
|
|
73820
|
+
if (args[0] === "wrangler") {
|
|
73821
|
+
const metrics = readMetricsConfig();
|
|
73822
|
+
if (metrics.c3permission?.enabled === false) {
|
|
73823
|
+
opts.env ??= {};
|
|
73824
|
+
opts.env["WRANGLER_SEND_METRICS"] = "false";
|
|
73825
|
+
}
|
|
73826
|
+
}
|
|
73820
73827
|
const abortController = new AbortController();
|
|
73821
73828
|
const cmd = (0, import_cross_spawn.spawn)(executable, [...args], {
|
|
73822
73829
|
// TODO: ideally inherit stderr, but npm install uses this for warnings
|
|
@@ -74486,7 +74493,7 @@ var package_default = {
|
|
|
74486
74493
|
"create-docusaurus": "3.6.1",
|
|
74487
74494
|
"create-hono": "0.14.2",
|
|
74488
74495
|
"create-next-app": "14.2.5",
|
|
74489
|
-
"create-qwik": "1.
|
|
74496
|
+
"create-qwik": "1.11.0",
|
|
74490
74497
|
"create-vite": "5.5.5",
|
|
74491
74498
|
"create-remix": "2.14.0",
|
|
74492
74499
|
"create-solid": "0.5.13",
|
|
@@ -74526,7 +74533,11 @@ var runFrameworkGenerator = async (ctx, args) => {
|
|
|
74526
74533
|
// templates-experimental/angular/c3.ts
|
|
74527
74534
|
var { npm } = detectPackageManager();
|
|
74528
74535
|
var generate = async (ctx) => {
|
|
74529
|
-
await runFrameworkGenerator(ctx, [
|
|
74536
|
+
await runFrameworkGenerator(ctx, [
|
|
74537
|
+
ctx.project.name,
|
|
74538
|
+
"--ssr",
|
|
74539
|
+
"--server-routing"
|
|
74540
|
+
]);
|
|
74530
74541
|
logRaw("");
|
|
74531
74542
|
};
|
|
74532
74543
|
var configure = async (ctx) => {
|
|
@@ -74535,9 +74546,9 @@ var configure = async (ctx) => {
|
|
|
74535
74546
|
await installCFWorker();
|
|
74536
74547
|
};
|
|
74537
74548
|
async function installCFWorker() {
|
|
74538
|
-
await installPackages(["
|
|
74549
|
+
await installPackages(["xhr2"], {
|
|
74539
74550
|
dev: true,
|
|
74540
|
-
startText: "Installing
|
|
74551
|
+
startText: "Installing additional dependencies",
|
|
74541
74552
|
doneText: `${brandColor("installed")} ${dim(`via \`${npm} install\``)}`
|
|
74542
74553
|
});
|
|
74543
74554
|
}
|
|
@@ -74552,10 +74563,17 @@ async function updateAppCode() {
|
|
|
74552
74563
|
);
|
|
74553
74564
|
writeFile2((0, import_node_path3.resolve)(appConfigPath), newAppConfig);
|
|
74554
74565
|
s.stop(`${brandColor(`updated`)} ${dim(appConfigPath)}`);
|
|
74566
|
+
const appServerRoutesPath = "src/app/app.routes.server.ts";
|
|
74567
|
+
const appRoutes = readFile((0, import_node_path3.resolve)(appServerRoutesPath));
|
|
74568
|
+
const newAppRoutes = appRoutes.replace(
|
|
74569
|
+
"RenderMode.Prerender",
|
|
74570
|
+
"RenderMode.Server"
|
|
74571
|
+
);
|
|
74572
|
+
writeFile2((0, import_node_path3.resolve)(appServerRoutesPath), newAppRoutes);
|
|
74573
|
+
s.stop(`${brandColor(`updated`)} ${dim(appServerRoutesPath)}`);
|
|
74555
74574
|
s.start(`Updating package.json`);
|
|
74556
74575
|
const packageJsonPath = (0, import_node_path3.resolve)("package.json");
|
|
74557
74576
|
const packageManifest = readJSON(packageJsonPath);
|
|
74558
|
-
delete packageManifest["dependencies"]["@angular/ssr"];
|
|
74559
74577
|
delete packageManifest["dependencies"]["express"];
|
|
74560
74578
|
delete packageManifest["devDependencies"]["@types/express"];
|
|
74561
74579
|
writeFile2(packageJsonPath, JSON.stringify(packageManifest, null, 2));
|
|
@@ -74567,7 +74585,8 @@ function updateAngularJson(ctx) {
|
|
|
74567
74585
|
const angularJson = readJSON((0, import_node_path3.resolve)("angular.json"));
|
|
74568
74586
|
const architectSection = angularJson.projects[ctx.project.name].architect;
|
|
74569
74587
|
architectSection.build.options.outputPath = "dist";
|
|
74570
|
-
architectSection.build.options.
|
|
74588
|
+
architectSection.build.options.outputMode = "server";
|
|
74589
|
+
architectSection.build.options.ssr.experimentalPlatform = "neutral";
|
|
74571
74590
|
writeFile2((0, import_node_path3.resolve)("angular.json"), JSON.stringify(angularJson, null, 2));
|
|
74572
74591
|
s.stop(`${brandColor(`updated`)} ${dim(`\`angular.json\``)}`);
|
|
74573
74592
|
}
|
|
@@ -74583,13 +74602,13 @@ var config = {
|
|
|
74583
74602
|
path: "templates-experimental/angular",
|
|
74584
74603
|
devScript: "start",
|
|
74585
74604
|
deployScript: "deploy",
|
|
74605
|
+
previewScript: "start",
|
|
74586
74606
|
generate,
|
|
74587
74607
|
configure,
|
|
74588
74608
|
transformPackageJson: async () => ({
|
|
74589
74609
|
scripts: {
|
|
74590
74610
|
start: `${npm} run build && wrangler dev`,
|
|
74591
|
-
build: `ng build
|
|
74592
|
-
process: "node ./tools/alter-polyfills.mjs",
|
|
74611
|
+
build: `ng build`,
|
|
74593
74612
|
deploy: `${npm} run build && wrangler deploy`
|
|
74594
74613
|
}
|
|
74595
74614
|
})
|
|
@@ -75069,7 +75088,7 @@ var updateNuxtConfig = () => {
|
|
|
75069
75088
|
b2.objectExpression([
|
|
75070
75089
|
b2.objectProperty(
|
|
75071
75090
|
b2.identifier("preset"),
|
|
75072
|
-
b2.stringLiteral("
|
|
75091
|
+
b2.stringLiteral("cloudflare_module")
|
|
75073
75092
|
)
|
|
75074
75093
|
])
|
|
75075
75094
|
);
|
|
@@ -75285,6 +75304,7 @@ var configure7 = async (ctx) => {
|
|
|
75285
75304
|
});
|
|
75286
75305
|
usesTypescript(ctx);
|
|
75287
75306
|
const filePath = `app.config.${usesTypescript(ctx) ? "ts" : "js"}`;
|
|
75307
|
+
const compatDate = await getWorkerdCompatibilityDate();
|
|
75288
75308
|
updateStatus(`Updating configuration in ${blue(filePath)}`);
|
|
75289
75309
|
transformFile(filePath, {
|
|
75290
75310
|
visitCallExpression: function(n2) {
|
|
@@ -75299,60 +75319,14 @@ var configure7 = async (ctx) => {
|
|
|
75299
75319
|
b2.objectProperty(
|
|
75300
75320
|
b2.identifier("server"),
|
|
75301
75321
|
b2.objectExpression([
|
|
75302
|
-
// preset: "
|
|
75322
|
+
// preset: "cloudflare_module"
|
|
75303
75323
|
b2.objectProperty(
|
|
75304
75324
|
b2.identifier("preset"),
|
|
75305
|
-
b2.stringLiteral("
|
|
75306
|
-
),
|
|
75307
|
-
// output: {
|
|
75308
|
-
// dir: "{{ rootDir }}/dist",
|
|
75309
|
-
// publicDir: "{{ output.dir }}/public",
|
|
75310
|
-
// serverDir: "{{ output.dir }}/worker",
|
|
75311
|
-
// },
|
|
75312
|
-
b2.objectProperty(
|
|
75313
|
-
b2.identifier("output"),
|
|
75314
|
-
b2.objectExpression([
|
|
75315
|
-
b2.objectProperty(
|
|
75316
|
-
b2.identifier("dir"),
|
|
75317
|
-
b2.stringLiteral("{{ rootDir }}/dist")
|
|
75318
|
-
),
|
|
75319
|
-
b2.objectProperty(
|
|
75320
|
-
b2.identifier("publicDir"),
|
|
75321
|
-
b2.stringLiteral("{{ output.dir }}/public")
|
|
75322
|
-
),
|
|
75323
|
-
b2.objectProperty(
|
|
75324
|
-
b2.identifier("serverDir"),
|
|
75325
|
-
b2.stringLiteral("{{ output.dir }}/worker")
|
|
75326
|
-
)
|
|
75327
|
-
])
|
|
75325
|
+
b2.stringLiteral("cloudflare_module")
|
|
75328
75326
|
),
|
|
75329
|
-
// rollupConfig: {
|
|
75330
|
-
// external: ["node:async_hooks"],
|
|
75331
|
-
// },
|
|
75332
75327
|
b2.objectProperty(
|
|
75333
|
-
b2.identifier("
|
|
75334
|
-
b2.
|
|
75335
|
-
b2.objectProperty(
|
|
75336
|
-
b2.identifier("external"),
|
|
75337
|
-
b2.arrayExpression([b2.stringLiteral("node:async_hooks")])
|
|
75338
|
-
)
|
|
75339
|
-
])
|
|
75340
|
-
),
|
|
75341
|
-
// hooks: {
|
|
75342
|
-
// // Prevent the Pages preset from writing the _routes.json etc.
|
|
75343
|
-
// compiled() {},
|
|
75344
|
-
// },
|
|
75345
|
-
b2.objectProperty(
|
|
75346
|
-
b2.identifier("hooks"),
|
|
75347
|
-
b2.objectExpression([
|
|
75348
|
-
b2.objectMethod(
|
|
75349
|
-
"method",
|
|
75350
|
-
b2.identifier("compiled"),
|
|
75351
|
-
[],
|
|
75352
|
-
b2.blockStatement([]),
|
|
75353
|
-
false
|
|
75354
|
-
)
|
|
75355
|
-
])
|
|
75328
|
+
b2.identifier("compatibilityDate"),
|
|
75329
|
+
b2.stringLiteral(compatDate)
|
|
75356
75330
|
)
|
|
75357
75331
|
])
|
|
75358
75332
|
)
|
|
@@ -75609,14 +75583,11 @@ var configure10 = async (ctx) => {
|
|
|
75609
75583
|
await installCFWorker2();
|
|
75610
75584
|
};
|
|
75611
75585
|
async function installCFWorker2() {
|
|
75612
|
-
await installPackages(
|
|
75613
|
-
|
|
75614
|
-
|
|
75615
|
-
|
|
75616
|
-
|
|
75617
|
-
doneText: `${brandColor("installed")} ${dim(`via \`${npm10} install\``)}`
|
|
75618
|
-
}
|
|
75619
|
-
);
|
|
75586
|
+
await installPackages(["xhr2"], {
|
|
75587
|
+
dev: true,
|
|
75588
|
+
startText: "Installing additional dependencies",
|
|
75589
|
+
doneText: `${brandColor("installed")} ${dim(`via \`${npm10} install\``)}`
|
|
75590
|
+
});
|
|
75620
75591
|
}
|
|
75621
75592
|
async function updateAppCode2() {
|
|
75622
75593
|
const s = spinner();
|
|
@@ -75668,11 +75639,12 @@ var config14 = {
|
|
|
75668
75639
|
},
|
|
75669
75640
|
devScript: "start",
|
|
75670
75641
|
deployScript: "deploy",
|
|
75642
|
+
previewScript: "start",
|
|
75671
75643
|
generate: generate13,
|
|
75672
75644
|
configure: configure10,
|
|
75673
75645
|
transformPackageJson: async () => ({
|
|
75674
75646
|
scripts: {
|
|
75675
|
-
start: `${npm10} run build && wrangler pages dev dist/cloudflare ${await compatDateFlag()}
|
|
75647
|
+
start: `${npm10} run build && wrangler pages dev dist/cloudflare ${await compatDateFlag()}`,
|
|
75676
75648
|
build: `ng build && ${npm10} run process`,
|
|
75677
75649
|
process: "node ./tools/copy-files.mjs",
|
|
75678
75650
|
deploy: `${npm10} run build && wrangler pages deploy dist/cloudflare`
|
|
@@ -76725,6 +76697,7 @@ var config23 = {
|
|
|
76725
76697
|
var c3_default33 = config23;
|
|
76726
76698
|
|
|
76727
76699
|
// templates/svelte/c3.ts
|
|
76700
|
+
var import_node_fs3 = require("node:fs");
|
|
76728
76701
|
var import_node_os4 = require("node:os");
|
|
76729
76702
|
var recast12 = __toESM(require_main3());
|
|
76730
76703
|
var { npm: npm19 } = detectPackageManager();
|
|
@@ -76740,6 +76713,7 @@ var configure18 = async (ctx) => {
|
|
|
76740
76713
|
doneText: `${brandColor(`installed`)} ${dim(pkg)}`
|
|
76741
76714
|
});
|
|
76742
76715
|
updateSvelteConfig2();
|
|
76716
|
+
updatePlaywrightConfig(usesTypescript(ctx));
|
|
76743
76717
|
updateTypeDefinitions2(ctx);
|
|
76744
76718
|
};
|
|
76745
76719
|
var updateSvelteConfig2 = () => {
|
|
@@ -76754,6 +76728,28 @@ var updateSvelteConfig2 = () => {
|
|
|
76754
76728
|
}
|
|
76755
76729
|
});
|
|
76756
76730
|
};
|
|
76731
|
+
var updatePlaywrightConfig = (shouldUseTypescript) => {
|
|
76732
|
+
const filePath = `playwright.config.${shouldUseTypescript ? "ts" : "js"}`;
|
|
76733
|
+
if (!(0, import_node_fs3.existsSync)(filePath)) {
|
|
76734
|
+
return;
|
|
76735
|
+
}
|
|
76736
|
+
updateStatus(`Changing webServer port in ${blue(filePath)}`);
|
|
76737
|
+
transformFile(filePath, {
|
|
76738
|
+
visitObjectExpression: function(n2) {
|
|
76739
|
+
const portProp = n2.node.properties.find((prop) => {
|
|
76740
|
+
if (!("key" in prop) || !("name" in prop.key)) {
|
|
76741
|
+
return false;
|
|
76742
|
+
}
|
|
76743
|
+
return prop.key.name === "port";
|
|
76744
|
+
});
|
|
76745
|
+
if (!portProp || !("value" in portProp) || !("value" in portProp.value)) {
|
|
76746
|
+
return this.traverse(n2);
|
|
76747
|
+
}
|
|
76748
|
+
portProp.value.value = 8788;
|
|
76749
|
+
return false;
|
|
76750
|
+
}
|
|
76751
|
+
});
|
|
76752
|
+
};
|
|
76757
76753
|
var updateTypeDefinitions2 = (ctx) => {
|
|
76758
76754
|
if (!usesTypescript(ctx)) {
|
|
76759
76755
|
return;
|
|
@@ -76850,7 +76846,7 @@ var config25 = {
|
|
|
76850
76846
|
var c3_default35 = config25;
|
|
76851
76847
|
|
|
76852
76848
|
// ../wrangler/package.json
|
|
76853
|
-
var version2 = "3.
|
|
76849
|
+
var version2 = "3.93.0";
|
|
76854
76850
|
|
|
76855
76851
|
// src/git.ts
|
|
76856
76852
|
var offerGit = async (ctx) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-cloudflare",
|
|
3
|
-
"version": "2.33.
|
|
3
|
+
"version": "2.33.3",
|
|
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",
|
|
@@ -68,8 +68,8 @@
|
|
|
68
68
|
"yargs": "^17.7.2",
|
|
69
69
|
"@cloudflare/cli": "1.1.1",
|
|
70
70
|
"@cloudflare/eslint-config-worker": "1.1.0",
|
|
71
|
-
"
|
|
72
|
-
"
|
|
71
|
+
"@cloudflare/workers-tsconfig": "0.0.0",
|
|
72
|
+
"wrangler": "3.93.0"
|
|
73
73
|
},
|
|
74
74
|
"engines": {
|
|
75
75
|
"node": ">=18.14.1"
|
package/templates/angular/c3.ts
CHANGED
|
@@ -28,14 +28,11 @@ const configure = async (ctx: C3Context) => {
|
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
async function installCFWorker() {
|
|
31
|
-
await installPackages(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
doneText: `${brandColor("installed")} ${dim(`via \`${npm} install\``)}`,
|
|
37
|
-
},
|
|
38
|
-
);
|
|
31
|
+
await installPackages(["xhr2"], {
|
|
32
|
+
dev: true,
|
|
33
|
+
startText: "Installing additional dependencies",
|
|
34
|
+
doneText: `${brandColor("installed")} ${dim(`via \`${npm} install\``)}`,
|
|
35
|
+
});
|
|
39
36
|
}
|
|
40
37
|
async function updateAppCode() {
|
|
41
38
|
const s = spinner();
|
|
@@ -102,11 +99,12 @@ const config: TemplateConfig = {
|
|
|
102
99
|
},
|
|
103
100
|
devScript: "start",
|
|
104
101
|
deployScript: "deploy",
|
|
102
|
+
previewScript: "start",
|
|
105
103
|
generate,
|
|
106
104
|
configure,
|
|
107
105
|
transformPackageJson: async () => ({
|
|
108
106
|
scripts: {
|
|
109
|
-
start: `${npm} run build && wrangler pages dev dist/cloudflare ${await compatDateFlag()}
|
|
107
|
+
start: `${npm} run build && wrangler pages dev dist/cloudflare ${await compatDateFlag()}`,
|
|
110
108
|
build: `ng build && ${npm} run process`,
|
|
111
109
|
process: "node ./tools/copy-files.mjs",
|
|
112
110
|
deploy: `${npm} run build && wrangler pages deploy dist/cloudflare`,
|
|
@@ -6,7 +6,7 @@ const angularApp = new AngularAppEngine();
|
|
|
6
6
|
* This is a request handler used by the Angular CLI (dev-server and during build).
|
|
7
7
|
*/
|
|
8
8
|
export const reqHandler = createRequestHandler(async (req) => {
|
|
9
|
-
const res = await angularApp.
|
|
9
|
+
const res = await angularApp.handle(req);
|
|
10
10
|
|
|
11
11
|
return res ?? new Response('Page not found.', { status: 404 });
|
|
12
12
|
});
|
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;
|
|
@@ -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 };
|
|
@@ -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/
|
|
@@ -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("/index.html", 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
|
-
};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import { EOL } from "node:os";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
import path from "node:path";
|
|
5
|
-
import { fileURLToPath } from "node:url";
|
|
6
|
-
const dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Split by lines and comment the banner
|
|
10
|
-
* ```
|
|
11
|
-
* import { createRequire } from 'node:module';
|
|
12
|
-
* globalThis['require'] ??= createRequire(import.meta.url);
|
|
13
|
-
* ```
|
|
14
|
-
*/
|
|
15
|
-
const serverPolyfillsFile = join(
|
|
16
|
-
dirname,
|
|
17
|
-
"../dist/server/polyfills.server.mjs"
|
|
18
|
-
);
|
|
19
|
-
const serverPolyfillsData = fs
|
|
20
|
-
.readFileSync(serverPolyfillsFile, "utf8")
|
|
21
|
-
.split(/\r?\n/);
|
|
22
|
-
|
|
23
|
-
for (let index = 0; index < 2; index++) {
|
|
24
|
-
if (serverPolyfillsData[index].includes("createRequire")) {
|
|
25
|
-
serverPolyfillsData[index] = "// " + serverPolyfillsData[index];
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// Add needed polyfills
|
|
30
|
-
serverPolyfillsData.unshift(`globalThis['process'] = {};`);
|
|
31
|
-
|
|
32
|
-
fs.writeFileSync(serverPolyfillsFile, serverPolyfillsData.join(EOL));
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { type NitroPreset } from "nitropack";
|
|
2
|
-
|
|
3
|
-
export default <NitroPreset>{
|
|
4
|
-
extends: "cloudflare",
|
|
5
|
-
exportConditions: ["workerd"],
|
|
6
|
-
output: {
|
|
7
|
-
dir: "{{ rootDir }}/dist",
|
|
8
|
-
publicDir: "{{ output.dir }}/public",
|
|
9
|
-
serverDir: "{{ output.dir }}/worker",
|
|
10
|
-
},
|
|
11
|
-
commands: {
|
|
12
|
-
preview: "npx wrangler dev",
|
|
13
|
-
deploy: "npx wrangler deploy",
|
|
14
|
-
},
|
|
15
|
-
wasm: {
|
|
16
|
-
lazy: false,
|
|
17
|
-
esmImport: true,
|
|
18
|
-
},
|
|
19
|
-
rollupConfig: {
|
|
20
|
-
output: {
|
|
21
|
-
entryFileNames: "index.js",
|
|
22
|
-
format: "esm",
|
|
23
|
-
exports: "named",
|
|
24
|
-
inlineDynamicImports: false,
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
};
|