create-cloudflare 2.40.2 → 2.41.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/cli.js +817 -718
  2. package/package.json +4 -4
  3. package/templates/angular/c3.ts +5 -129
  4. package/templates/angular/pages/c3.ts +134 -0
  5. package/{templates-experimental/angular → templates/angular/workers}/c3.ts +2 -2
  6. package/templates/gatsby/c3.ts +5 -45
  7. package/templates/gatsby/pages/c3.ts +50 -0
  8. package/{templates-experimental/gatsby → templates/gatsby/workers}/c3.ts +2 -2
  9. package/templates/hello-world/js/package.json +2 -2
  10. package/templates/hello-world/ts/package.json +2 -2
  11. package/templates/nuxt/c3.ts +5 -130
  12. package/templates/nuxt/pages/c3.ts +145 -0
  13. package/templates/nuxt/{templates → pages/templates}/wrangler.jsonc +0 -3
  14. package/{templates-experimental/nuxt → templates/nuxt/workers}/c3.ts +12 -2
  15. package/templates/vue/c3.ts +5 -25
  16. package/{templates-experimental/vue → templates/vue/pages}/c3.ts +5 -8
  17. package/templates/vue/workers/c3.ts +98 -0
  18. package/templates/vue/workers/js/server/index.js +13 -0
  19. package/templates/vue/workers/js/src/App.vue +107 -0
  20. package/templates/vue/workers/js/src/components/HelloWorld.vue +47 -0
  21. package/templates/vue/workers/js/vite.config.js +21 -0
  22. package/templates/vue/workers/js/wrangler.jsonc +12 -0
  23. package/templates/vue/workers/ts/server/index.ts +13 -0
  24. package/templates/vue/workers/ts/src/App.vue +107 -0
  25. package/templates/vue/workers/ts/src/components/HelloWorld.vue +44 -0
  26. package/templates/vue/workers/ts/tsconfig.worker.json +8 -0
  27. package/templates/vue/workers/ts/vite.config.ts +21 -0
  28. package/templates/vue/workers/ts/worker-configuration.d.ts +6 -0
  29. package/templates/vue/workers/ts/wrangler.jsonc +12 -0
  30. package/templates-experimental/hello-world-with-assets/js/package.json +2 -2
  31. package/templates-experimental/hello-world-with-assets/ts/package.json +2 -2
  32. package/templates-experimental/vue/templates/wrangler.jsonc +0 -10
  33. /package/templates/angular/{templates → pages/templates}/src/_routes.json +0 -0
  34. /package/{templates-experimental/angular → templates/angular/pages}/templates/src/server.ts +0 -0
  35. /package/templates/angular/{templates → pages/templates}/tools/copy-files.mjs +0 -0
  36. /package/templates/angular/{templates → workers/templates}/src/server.ts +0 -0
  37. /package/{templates-experimental/angular → templates/angular/workers}/templates/wrangler.jsonc +0 -0
  38. /package/{templates-experimental/gatsby → templates/gatsby/workers}/templates/wrangler.jsonc +0 -0
  39. /package/{templates-experimental/nuxt → templates/nuxt/pages}/templates/env.d.ts +0 -0
  40. /package/{templates-experimental/nuxt → templates/nuxt/pages}/templates/worker-configuration.d.ts +0 -0
  41. /package/templates/nuxt/{templates → workers/templates}/env.d.ts +0 -0
  42. /package/templates/nuxt/{templates → workers/templates}/worker-configuration.d.ts +0 -0
  43. /package/{templates-experimental/nuxt → templates/nuxt/workers}/templates/wrangler.jsonc +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-cloudflare",
3
- "version": "2.40.2",
3
+ "version": "2.41.0",
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.20250224.0",
33
+ "@cloudflare/workers-types": "^4.20250310.0",
34
34
  "@iarna/toml": "^3.0.0",
35
35
  "@types/command-exists": "^1.2.0",
36
36
  "@types/cross-spawn": "^6.0.2",
@@ -72,10 +72,10 @@
72
72
  "yargs": "^17.7.2",
73
73
  "@cloudflare/cli": "1.1.1",
74
74
  "@cloudflare/mock-npm-registry": "0.0.0",
75
+ "@cloudflare/vite-plugin": "0.1.10",
75
76
  "@cloudflare/workers-tsconfig": "0.0.0",
76
77
  "@cloudflare/eslint-config-worker": "1.1.0",
77
- "wrangler": "3.113.0",
78
- "@cloudflare/vite-plugin": "0.1.9"
78
+ "wrangler": "3.114.1"
79
79
  },
80
80
  "engines": {
81
81
  "node": ">=18.14.1"
@@ -1,133 +1,9 @@
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 { runFrameworkGenerator } from "frameworks/index";
6
- import { compatDateFlag } from "helpers/compatDate";
7
- import { readFile, readJSON, writeFile } from "helpers/files";
8
- import { detectPackageManager } from "helpers/packageManagers";
9
- import { installPackages } from "helpers/packages";
10
- import type { TemplateConfig } from "../../src/templates";
11
- 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";
12
4
 
13
- const { npm } = detectPackageManager();
14
-
15
- const generate = async (ctx: C3Context) => {
16
- await runFrameworkGenerator(ctx, [
17
- ctx.project.name,
18
- "--ssr",
19
- "--server-routing" /** Dev Preview API */,
20
- ]);
21
- logRaw("");
22
- };
23
-
24
- const configure = async (ctx: C3Context) => {
25
- updateAngularJson(ctx);
26
- await updateAppCode();
27
- await installCFWorker();
28
- };
29
-
30
- async function installCFWorker() {
31
- await installPackages(["xhr2"], {
32
- dev: true,
33
- startText: "Installing additional dependencies",
34
- doneText: `${brandColor("installed")} ${dim(`via \`${npm} install\``)}`,
35
- });
36
- }
37
- async function updateAppCode() {
38
- const s = spinner();
39
- s.start(`Updating application code`);
40
-
41
- // Update an app config file to:
42
- // - add the `provideHttpClient(withFetch())` call to enable `fetch` usage in `HttpClient`
43
- const appConfigPath = "src/app/app.config.ts";
44
- const appConfig = readFile(resolve(appConfigPath));
45
- const newAppConfig =
46
- "import { provideHttpClient, withFetch } from '@angular/common/http';\n" +
47
- appConfig.replace(
48
- "providers: [",
49
- "providers: [provideHttpClient(withFetch()), ",
50
- );
51
- writeFile(resolve(appConfigPath), newAppConfig);
52
- s.stop(`${brandColor(`updated`)} ${dim(appConfigPath)}`);
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
-
64
- // Remove unwanted dependencies
65
- s.start(`Updating package.json`);
66
- const packageJsonPath = resolve("package.json");
67
- const packageManifest = readJSON(packageJsonPath) as PackageJson;
68
-
69
- delete packageManifest["dependencies"]?.["express"];
70
- delete packageManifest["devDependencies"]?.["@types/express"];
71
-
72
- writeFile(packageJsonPath, JSON.stringify(packageManifest, null, 2));
73
- s.stop(`${brandColor(`updated`)} ${dim(`\`package.json\``)}`);
74
- }
75
-
76
- function updateAngularJson(ctx: C3Context) {
77
- const s = spinner();
78
- s.start(`Updating angular.json config`);
79
- const angularJson = readJSON("angular.json") as AngularJson;
80
-
81
- // Update builder
82
- const architectSection = angularJson.projects[ctx.project.name].architect;
83
- architectSection.build.options.outputPath = "dist";
84
- architectSection.build.options.outputMode = "server";
85
- architectSection.build.options.ssr.experimentalPlatform = "neutral";
86
- architectSection.build.options.assets.push("src/_routes.json");
87
-
88
- writeFile(resolve("angular.json"), JSON.stringify(angularJson, null, 2));
89
- s.stop(`${brandColor(`updated`)} ${dim(`\`angular.json\``)}`);
90
- }
91
-
92
- const config: TemplateConfig = {
93
- configVersion: 1,
94
- id: "angular",
95
- frameworkCli: "@angular/create",
5
+ const config: MultiPlatformTemplateConfig = {
96
6
  displayName: "Angular",
97
- platform: "pages",
98
- copyFiles: {
99
- path: "./templates",
100
- },
101
- devScript: "start",
102
- deployScript: "deploy",
103
- previewScript: "start",
104
- generate,
105
- configure,
106
- transformPackageJson: async () => ({
107
- scripts: {
108
- start: `${npm} run build && wrangler pages dev dist/cloudflare ${await compatDateFlag()}`,
109
- build: `ng build && ${npm} run process`,
110
- process: "node ./tools/copy-files.mjs",
111
- deploy: `${npm} run build && wrangler pages deploy dist/cloudflare`,
112
- },
113
- }),
7
+ platformVariants: { pages, workers },
114
8
  };
115
9
  export default config;
116
-
117
- type AngularJson = {
118
- projects: Record<
119
- string,
120
- {
121
- architect: {
122
- build: {
123
- options: {
124
- outputPath: string;
125
- outputMode: string;
126
- ssr: Record<string, unknown>;
127
- assets: string[];
128
- };
129
- };
130
- };
131
- }
132
- >;
133
- };
@@ -0,0 +1,134 @@
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 { runFrameworkGenerator } from "frameworks/index";
6
+ import { compatDateFlag } from "helpers/compatDate";
7
+ import { readFile, readJSON, writeFile } from "helpers/files";
8
+ import { detectPackageManager } from "helpers/packageManagers";
9
+ import { installPackages } from "helpers/packages";
10
+ import type { TemplateConfig } from "../../../src/templates";
11
+ import type { C3Context, PackageJson } from "types";
12
+
13
+ const { npm } = detectPackageManager();
14
+
15
+ const generate = async (ctx: C3Context) => {
16
+ await runFrameworkGenerator(ctx, [
17
+ ctx.project.name,
18
+ "--ssr",
19
+ "--server-routing" /** Dev Preview API */,
20
+ ]);
21
+ logRaw("");
22
+ };
23
+
24
+ const configure = async (ctx: C3Context) => {
25
+ updateAngularJson(ctx);
26
+ await updateAppCode();
27
+ await installCFWorker();
28
+ };
29
+
30
+ async function installCFWorker() {
31
+ await installPackages(["xhr2"], {
32
+ dev: true,
33
+ startText: "Installing additional dependencies",
34
+ doneText: `${brandColor("installed")} ${dim(`via \`${npm} install\``)}`,
35
+ });
36
+ }
37
+ async function updateAppCode() {
38
+ const s = spinner();
39
+ s.start(`Updating application code`);
40
+
41
+ // Update an app config file to:
42
+ // - add the `provideHttpClient(withFetch())` call to enable `fetch` usage in `HttpClient`
43
+ const appConfigPath = "src/app/app.config.ts";
44
+ const appConfig = readFile(resolve(appConfigPath));
45
+ const newAppConfig =
46
+ "import { provideHttpClient, withFetch } from '@angular/common/http';\n" +
47
+ appConfig.replace(
48
+ "providers: [",
49
+ "providers: [provideHttpClient(withFetch()), ",
50
+ );
51
+ writeFile(resolve(appConfigPath), newAppConfig);
52
+ s.stop(`${brandColor(`updated`)} ${dim(appConfigPath)}`);
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
+
64
+ // Remove unwanted dependencies
65
+ s.start(`Updating package.json`);
66
+ const packageJsonPath = resolve("package.json");
67
+ const packageManifest = readJSON(packageJsonPath) as PackageJson;
68
+
69
+ delete packageManifest["dependencies"]?.["express"];
70
+ delete packageManifest["devDependencies"]?.["@types/express"];
71
+
72
+ writeFile(packageJsonPath, JSON.stringify(packageManifest, null, 2));
73
+ s.stop(`${brandColor(`updated`)} ${dim(`\`package.json\``)}`);
74
+ }
75
+
76
+ function updateAngularJson(ctx: C3Context) {
77
+ const s = spinner();
78
+ s.start(`Updating angular.json config`);
79
+ const angularJson = readJSON("angular.json") as AngularJson;
80
+
81
+ // Update builder
82
+ const architectSection = angularJson.projects[ctx.project.name].architect;
83
+ architectSection.build.options.outputPath = "dist";
84
+ architectSection.build.options.outputMode = "server";
85
+ architectSection.build.options.ssr.experimentalPlatform = "neutral";
86
+ architectSection.build.options.assets.push("src/_routes.json");
87
+
88
+ writeFile(resolve("angular.json"), JSON.stringify(angularJson, null, 2));
89
+ s.stop(`${brandColor(`updated`)} ${dim(`\`angular.json\``)}`);
90
+ }
91
+
92
+ const config: TemplateConfig = {
93
+ configVersion: 1,
94
+ id: "angular",
95
+ frameworkCli: "@angular/create",
96
+ displayName: "Angular",
97
+ platform: "pages",
98
+ copyFiles: {
99
+ path: "./templates",
100
+ },
101
+ path: "templates/angular/pages",
102
+ devScript: "start",
103
+ deployScript: "deploy",
104
+ previewScript: "start",
105
+ generate,
106
+ configure,
107
+ transformPackageJson: async () => ({
108
+ scripts: {
109
+ start: `${npm} run build && wrangler pages dev dist/cloudflare ${await compatDateFlag()}`,
110
+ build: `ng build && ${npm} run process`,
111
+ process: "node ./tools/copy-files.mjs",
112
+ deploy: `${npm} run build && wrangler pages deploy dist/cloudflare`,
113
+ },
114
+ }),
115
+ };
116
+ export default config;
117
+
118
+ type AngularJson = {
119
+ projects: Record<
120
+ string,
121
+ {
122
+ architect: {
123
+ build: {
124
+ options: {
125
+ outputPath: string;
126
+ outputMode: string;
127
+ ssr: Record<string, unknown>;
128
+ assets: string[];
129
+ };
130
+ };
131
+ };
132
+ }
133
+ >;
134
+ };
@@ -6,7 +6,7 @@ import { runFrameworkGenerator } from "frameworks/index";
6
6
  import { readFile, readJSON, writeFile } from "helpers/files";
7
7
  import { detectPackageManager } from "helpers/packageManagers";
8
8
  import { installPackages } from "helpers/packages";
9
- import type { TemplateConfig } from "../../src/templates";
9
+ import type { TemplateConfig } from "../../../src/templates";
10
10
  import type { C3Context, PackageJson } from "types";
11
11
 
12
12
  const { npm } = detectPackageManager();
@@ -95,7 +95,7 @@ const config: TemplateConfig = {
95
95
  copyFiles: {
96
96
  path: "./templates",
97
97
  },
98
- path: "templates-experimental/angular",
98
+ path: "templates/angular/workers",
99
99
  devScript: "start",
100
100
  deployScript: "deploy",
101
101
  previewScript: "start",
@@ -1,49 +1,9 @@
1
- import { inputPrompt } from "@cloudflare/cli/interactive";
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";
1
+ import pages from "./pages/c3";
2
+ import workers from "./workers/c3";
3
+ import type { MultiPlatformTemplateConfig } from "../../src/templates";
6
4
 
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
- frameworkCli: "gatsby",
36
- platform: "pages",
5
+ const config: MultiPlatformTemplateConfig = {
37
6
  displayName: "Gatsby",
38
- generate,
39
- transformPackageJson: async () => ({
40
- scripts: {
41
- deploy: `${npm} run build && wrangler pages deploy ./public`,
42
- preview: `${npm} run build && wrangler pages dev ./public`,
43
- },
44
- }),
45
- devScript: "develop",
46
- deployScript: "deploy",
47
- previewScript: "preview",
7
+ platformVariants: { pages, workers },
48
8
  };
49
9
  export default config;
@@ -0,0 +1,50 @@
1
+ import { inputPrompt } from "@cloudflare/cli/interactive";
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 { 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
+ frameworkCli: "gatsby",
36
+ platform: "pages",
37
+ displayName: "Gatsby",
38
+ path: "templates/gatsby/pages",
39
+ generate,
40
+ transformPackageJson: async () => ({
41
+ scripts: {
42
+ deploy: `${npm} run build && wrangler pages deploy ./public`,
43
+ preview: `${npm} run build && wrangler pages dev ./public`,
44
+ },
45
+ }),
46
+ devScript: "develop",
47
+ deployScript: "deploy",
48
+ previewScript: "preview",
49
+ };
50
+ export default config;
@@ -1,7 +1,7 @@
1
1
  import { inputPrompt } from "@cloudflare/cli/interactive";
2
2
  import { runFrameworkGenerator } from "frameworks/index";
3
3
  import { detectPackageManager } from "helpers/packageManagers";
4
- import type { TemplateConfig } from "../../src/templates";
4
+ import type { TemplateConfig } from "../../../src/templates";
5
5
  import type { C3Context } from "types";
6
6
 
7
7
  const { npm } = detectPackageManager();
@@ -38,7 +38,7 @@ const config: TemplateConfig = {
38
38
  copyFiles: {
39
39
  path: "./templates",
40
40
  },
41
- path: "templates-experimental/gatsby",
41
+ path: "templates/gatsby/workers",
42
42
  generate,
43
43
  transformPackageJson: async () => ({
44
44
  scripts: {
@@ -9,8 +9,8 @@
9
9
  "test": "vitest"
10
10
  },
11
11
  "devDependencies": {
12
- "@cloudflare/vitest-pool-workers": "^0.6.4",
12
+ "@cloudflare/vitest-pool-workers": "^0.7.5",
13
13
  "wrangler": "^3.101.0",
14
- "vitest": "~2.1.9"
14
+ "vitest": "~3.0.7"
15
15
  }
16
16
  }
@@ -10,9 +10,9 @@
10
10
  "cf-typegen": "wrangler types"
11
11
  },
12
12
  "devDependencies": {
13
- "@cloudflare/vitest-pool-workers": "^0.6.4",
13
+ "@cloudflare/vitest-pool-workers": "^0.7.5",
14
14
  "typescript": "^5.5.2",
15
- "vitest": "~2.1.9",
15
+ "vitest": "~3.0.7",
16
16
  "wrangler": "^3.101.0"
17
17
  }
18
18
  }
@@ -1,134 +1,9 @@
1
- import { logRaw } from "@cloudflare/cli";
2
- import { brandColor, dim } from "@cloudflare/cli/colors";
3
- import { spinner } from "@cloudflare/cli/interactive";
4
- import { runFrameworkGenerator } from "frameworks/index";
5
- import { mergeObjectProperties, transformFile } from "helpers/codemod";
6
- import { getLatestTypesEntrypoint } from "helpers/compatDate";
7
- import { readFile, writeFile } from "helpers/files";
8
- import { detectPackageManager } from "helpers/packageManagers";
9
- import { installPackages } from "helpers/packages";
10
- import * as recast from "recast";
11
- import type { TemplateConfig } from "../../src/templates";
12
- import type { C3Context } from "types";
1
+ import pages from "./pages/c3";
2
+ import workers from "./workers/c3";
3
+ import type { MultiPlatformTemplateConfig } from "../../src/templates";
13
4
 
14
- const { npm, name: pm } = detectPackageManager();
15
-
16
- const generate = async (ctx: C3Context) => {
17
- const gitFlag = ctx.args.git ? `--gitInit` : `--no-gitInit`;
18
-
19
- await runFrameworkGenerator(ctx, [
20
- "init",
21
- ctx.project.name,
22
- "--packageManager",
23
- npm,
24
- gitFlag,
25
- ]);
26
-
27
- writeFile("./.node-version", "18");
28
-
29
- logRaw(""); // newline
30
- };
31
-
32
- const configure = async (ctx: C3Context) => {
33
- const packages = ["nitro-cloudflare-dev"];
34
-
35
- // When using pnpm, explicitly add h3 package so the H3Event type declaration can be updated.
36
- // Package managers other than pnpm will hoist the dependency, as will pnpm with `--shamefully-hoist`
37
- if (pm === "pnpm") {
38
- packages.push("h3");
39
- }
40
-
41
- await installPackages(packages, {
42
- dev: true,
43
- startText: "Installing nitro module `nitro-cloudflare-dev`",
44
- doneText: `${brandColor("installed")} ${dim(`via \`${npm} install\``)}`,
45
- });
46
- updateNuxtConfig();
47
-
48
- updateEnvTypes(ctx);
49
- };
50
-
51
- const updateEnvTypes = (ctx: C3Context) => {
52
- const filepath = "env.d.ts";
53
-
54
- const s = spinner();
55
- s.start(`Updating ${filepath}`);
56
-
57
- let file = readFile(filepath);
58
-
59
- let typesEntrypoint = `@cloudflare/workers-types`;
60
- const latestEntrypoint = getLatestTypesEntrypoint(ctx);
61
- if (latestEntrypoint) {
62
- typesEntrypoint += `/${latestEntrypoint}`;
63
- }
64
-
65
- // Replace placeholder with actual types entrypoint
66
- file = file.replace("WORKERS_TYPES_ENTRYPOINT", typesEntrypoint);
67
- writeFile("env.d.ts", file);
68
-
69
- s.stop(`${brandColor(`updated`)} ${dim(`\`${filepath}\``)}`);
70
- };
71
-
72
- const updateNuxtConfig = () => {
73
- const s = spinner();
74
-
75
- const configFile = "nuxt.config.ts";
76
- s.start(`Updating \`${configFile}\``);
77
-
78
- const b = recast.types.builders;
79
-
80
- const presetDef = b.objectProperty(
81
- b.identifier("nitro"),
82
- b.objectExpression([
83
- b.objectProperty(
84
- b.identifier("preset"),
85
- b.stringLiteral("cloudflare-pages"),
86
- ),
87
- ]),
88
- );
89
-
90
- const moduleDef = b.objectProperty(
91
- b.identifier("modules"),
92
- b.arrayExpression([b.stringLiteral("nitro-cloudflare-dev")]),
93
- );
94
-
95
- transformFile(configFile, {
96
- visitCallExpression: function (n) {
97
- const callee = n.node.callee as recast.types.namedTypes.Identifier;
98
- if (callee.name === "defineNuxtConfig") {
99
- mergeObjectProperties(
100
- n.node.arguments[0] as recast.types.namedTypes.ObjectExpression,
101
- [presetDef, moduleDef],
102
- );
103
- }
104
-
105
- return this.traverse(n);
106
- },
107
- });
108
-
109
- s.stop(`${brandColor(`updated`)} ${dim(`\`${configFile}\``)}`);
110
- };
111
-
112
- const config: TemplateConfig = {
113
- configVersion: 1,
114
- id: "nuxt",
115
- frameworkCli: "nuxi",
116
- platform: "pages",
5
+ const config: MultiPlatformTemplateConfig = {
117
6
  displayName: "Nuxt",
118
- copyFiles: {
119
- path: "./templates",
120
- },
121
- generate,
122
- configure,
123
- transformPackageJson: async () => ({
124
- scripts: {
125
- deploy: `${npm} run build && wrangler pages deploy`,
126
- preview: `${npm} run build && wrangler pages dev`,
127
- "cf-typegen": `wrangler types`,
128
- },
129
- }),
130
- devScript: "dev",
131
- deployScript: "deploy",
132
- previewScript: "preview",
7
+ platformVariants: { pages, workers },
133
8
  };
134
9
  export default config;