create-cloudflare 2.40.3 → 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 (38) hide show
  1. package/dist/cli.js +830 -778
  2. package/package.json +6 -6
  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/nuxt/c3.ts +5 -130
  10. package/templates/nuxt/pages/c3.ts +145 -0
  11. package/templates/nuxt/{templates → pages/templates}/wrangler.jsonc +0 -3
  12. package/{templates-experimental/nuxt → templates/nuxt/workers}/c3.ts +12 -2
  13. package/templates/vue/c3.ts +5 -25
  14. package/templates/vue/pages/c3.ts +30 -0
  15. package/{templates-experimental/vue → templates/vue/workers}/c3.ts +2 -2
  16. /package/templates/angular/{templates → pages/templates}/src/_routes.json +0 -0
  17. /package/{templates-experimental/angular → templates/angular/pages}/templates/src/server.ts +0 -0
  18. /package/templates/angular/{templates → pages/templates}/tools/copy-files.mjs +0 -0
  19. /package/templates/angular/{templates → workers/templates}/src/server.ts +0 -0
  20. /package/{templates-experimental/angular → templates/angular/workers}/templates/wrangler.jsonc +0 -0
  21. /package/{templates-experimental/gatsby → templates/gatsby/workers}/templates/wrangler.jsonc +0 -0
  22. /package/{templates-experimental/nuxt → templates/nuxt/pages}/templates/env.d.ts +0 -0
  23. /package/{templates-experimental/nuxt → templates/nuxt/pages}/templates/worker-configuration.d.ts +0 -0
  24. /package/templates/nuxt/{templates → workers/templates}/env.d.ts +0 -0
  25. /package/templates/nuxt/{templates → workers/templates}/worker-configuration.d.ts +0 -0
  26. /package/{templates-experimental/nuxt → templates/nuxt/workers}/templates/wrangler.jsonc +0 -0
  27. /package/{templates-experimental/vue → templates/vue/workers}/js/server/index.js +0 -0
  28. /package/{templates-experimental/vue → templates/vue/workers}/js/src/App.vue +0 -0
  29. /package/{templates-experimental/vue → templates/vue/workers}/js/src/components/HelloWorld.vue +0 -0
  30. /package/{templates-experimental/vue → templates/vue/workers}/js/vite.config.js +0 -0
  31. /package/{templates-experimental/vue → templates/vue/workers}/js/wrangler.jsonc +0 -0
  32. /package/{templates-experimental/vue → templates/vue/workers}/ts/server/index.ts +0 -0
  33. /package/{templates-experimental/vue → templates/vue/workers}/ts/src/App.vue +0 -0
  34. /package/{templates-experimental/vue → templates/vue/workers}/ts/src/components/HelloWorld.vue +0 -0
  35. /package/{templates-experimental/vue → templates/vue/workers}/ts/tsconfig.worker.json +0 -0
  36. /package/{templates-experimental/vue → templates/vue/workers}/ts/vite.config.ts +0 -0
  37. /package/{templates-experimental/vue → templates/vue/workers}/ts/worker-configuration.d.ts +0 -0
  38. /package/{templates-experimental/vue → templates/vue/workers}/ts/wrangler.jsonc +0 -0
@@ -0,0 +1,145 @@
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";
13
+
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
+ b.objectProperty(
88
+ b.identifier("cloudflare"),
89
+ b.objectExpression([
90
+ b.objectProperty(
91
+ b.identifier("deployConfig"),
92
+ b.booleanLiteral(true),
93
+ ),
94
+ b.objectProperty(b.identifier("nodeCompat"), b.booleanLiteral(true)),
95
+ ]),
96
+ ),
97
+ ]),
98
+ );
99
+
100
+ const moduleDef = b.objectProperty(
101
+ b.identifier("modules"),
102
+ b.arrayExpression([b.stringLiteral("nitro-cloudflare-dev")]),
103
+ );
104
+
105
+ transformFile(configFile, {
106
+ visitCallExpression: function (n) {
107
+ const callee = n.node.callee as recast.types.namedTypes.Identifier;
108
+ if (callee.name === "defineNuxtConfig") {
109
+ mergeObjectProperties(
110
+ n.node.arguments[0] as recast.types.namedTypes.ObjectExpression,
111
+ [presetDef, moduleDef],
112
+ );
113
+ }
114
+
115
+ return this.traverse(n);
116
+ },
117
+ });
118
+
119
+ s.stop(`${brandColor(`updated`)} ${dim(`\`${configFile}\``)}`);
120
+ };
121
+
122
+ const config: TemplateConfig = {
123
+ configVersion: 1,
124
+ id: "nuxt",
125
+ frameworkCli: "nuxi",
126
+ platform: "pages",
127
+ displayName: "Nuxt",
128
+ copyFiles: {
129
+ path: "./templates",
130
+ },
131
+ path: "templates/nuxt/pages",
132
+ generate,
133
+ configure,
134
+ transformPackageJson: async () => ({
135
+ scripts: {
136
+ deploy: `${npm} run build && wrangler pages deploy`,
137
+ preview: `${npm} run build && wrangler pages dev`,
138
+ "cf-typegen": `wrangler types`,
139
+ },
140
+ }),
141
+ devScript: "dev",
142
+ deployScript: "deploy",
143
+ previewScript: "preview",
144
+ };
145
+ export default config;
@@ -1,8 +1,5 @@
1
1
  {
2
2
  "name": "<TBD>",
3
3
  "compatibility_date": "<TBD>",
4
- "compatibility_flags": [
5
- "nodejs_compat"
6
- ],
7
4
  "pages_build_output_dir": "./dist"
8
5
  }
@@ -8,7 +8,7 @@ import { readFile, writeFile } from "helpers/files";
8
8
  import { detectPackageManager } from "helpers/packageManagers";
9
9
  import { installPackages } from "helpers/packages";
10
10
  import * as recast from "recast";
11
- import type { TemplateConfig } from "../../src/templates";
11
+ import type { TemplateConfig } from "../../../src/templates";
12
12
  import type { C3Context } from "types";
13
13
 
14
14
  const { npm, name: pm } = detectPackageManager();
@@ -84,6 +84,16 @@ const updateNuxtConfig = () => {
84
84
  b.identifier("preset"),
85
85
  b.stringLiteral("cloudflare_module"),
86
86
  ),
87
+ b.objectProperty(
88
+ b.identifier("cloudflare"),
89
+ b.objectExpression([
90
+ b.objectProperty(
91
+ b.identifier("deployConfig"),
92
+ b.booleanLiteral(true),
93
+ ),
94
+ b.objectProperty(b.identifier("nodeCompat"), b.booleanLiteral(true)),
95
+ ]),
96
+ ),
87
97
  ]),
88
98
  );
89
99
 
@@ -118,7 +128,7 @@ const config: TemplateConfig = {
118
128
  copyFiles: {
119
129
  path: "./templates",
120
130
  },
121
- path: "templates-experimental/nuxt",
131
+ path: "templates/nuxt/workers",
122
132
  generate,
123
133
  configure,
124
134
  transformPackageJson: async () => ({
@@ -1,29 +1,9 @@
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";
1
+ import pages from "./pages/c3";
2
+ import workers from "./workers/c3";
3
+ import type { MultiPlatformTemplateConfig } from "../../src/templates";
5
4
 
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",
5
+ const config: MultiPlatformTemplateConfig = {
16
6
  displayName: "Vue",
17
- platform: "pages",
18
- generate,
19
- transformPackageJson: async () => ({
20
- scripts: {
21
- deploy: `${npm} run build && wrangler pages deploy ./dist`,
22
- preview: `${npm} run build && wrangler pages dev ./dist`,
23
- },
24
- }),
25
- devScript: "dev",
26
- deployScript: "deploy",
27
- previewScript: "preview",
7
+ platformVariants: { pages, workers },
28
8
  };
29
9
  export default config;
@@ -0,0 +1,30 @@
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
+ displayName: "Vue",
17
+ platform: "pages",
18
+ path: "templates/pages/vue",
19
+ generate,
20
+ transformPackageJson: async () => ({
21
+ scripts: {
22
+ deploy: `${npm} run build && wrangler pages deploy ./dist`,
23
+ preview: `${npm} run build && wrangler pages dev ./dist`,
24
+ },
25
+ }),
26
+ devScript: "dev",
27
+ deployScript: "deploy",
28
+ previewScript: "preview",
29
+ };
30
+ export default config;
@@ -5,7 +5,7 @@ import { runFrameworkGenerator } from "frameworks/index";
5
5
  import { readJSON, usesTypescript, writeJSON } from "helpers/files";
6
6
  import { detectPackageManager } from "helpers/packageManagers";
7
7
  import { installPackages } from "helpers/packages";
8
- import type { TemplateConfig } from "../../src/templates";
8
+ import type { TemplateConfig } from "../../../src/templates";
9
9
  import type { C3Context } from "types";
10
10
 
11
11
  const { npm } = detectPackageManager();
@@ -64,7 +64,7 @@ const config: TemplateConfig = {
64
64
  frameworkCli: "create-vue",
65
65
  platform: "workers",
66
66
  displayName: "Vue",
67
- path: "templates-experimental/vue",
67
+ path: "templates/vue/workers",
68
68
  copyFiles: {
69
69
  async selectVariant(ctx) {
70
70
  // Note: this `selectVariant` function should not be needed