create-cloudflare 2.0.0-next.1 → 2.0.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 (72) hide show
  1. package/README.md +9 -8
  2. package/dist/angular/templates/src/_routes.json +5 -0
  3. package/dist/angular/templates/src/main.server.ts +35 -0
  4. package/dist/angular/templates/tools/bundle.mjs +74 -0
  5. package/dist/angular/templates/tools/copy-client-files.mjs +4 -0
  6. package/dist/angular/templates/tools/copy-worker-files.mjs +10 -0
  7. package/dist/angular/templates/tools/paths.mjs +9 -0
  8. package/dist/angular/templates/tsconfig.server.json +5 -0
  9. package/dist/cli.js +6367 -17948
  10. package/dist/tsconfig.tsbuildinfo +1 -0
  11. package/package.json +51 -57
  12. package/templates/common/js/.prettierrc +5 -0
  13. package/templates/common/js/package.json +14 -0
  14. package/templates/common/js/src/ab-test.js +41 -0
  15. package/templates/common/js/src/proxy.js +23 -0
  16. package/templates/common/js/src/redirect.js +13 -0
  17. package/templates/{examples → common}/js/src/router.js +4 -8
  18. package/templates/common/js/src/worker.js +46 -0
  19. package/templates/common/js/wrangler.toml +40 -0
  20. package/templates/common/ts/.prettierrc +5 -0
  21. package/templates/common/ts/package.json +15 -0
  22. package/templates/common/ts/src/ab-test.ts +41 -0
  23. package/templates/common/ts/src/proxy.ts +23 -0
  24. package/templates/common/ts/src/redirect.ts +13 -0
  25. package/templates/{examples → common}/ts/src/router.ts +4 -8
  26. package/templates/common/ts/src/worker.ts +46 -0
  27. package/templates/{examples → common}/ts/tsconfig.json +2 -6
  28. package/templates/common/ts/worker-configuration.d.ts +16 -0
  29. package/templates/common/ts/wrangler.toml +40 -0
  30. package/templates/simple/js/.prettierrc +3 -3
  31. package/templates/simple/js/package.json +12 -12
  32. package/templates/simple/js/src/worker.js +3 -3
  33. package/templates/simple/js/wrangler.toml +37 -0
  34. package/templates/simple/ts/.prettierrc +3 -3
  35. package/templates/simple/ts/package.json +12 -12
  36. package/templates/simple/ts/src/worker.ts +17 -14
  37. package/templates/simple/ts/tsconfig.json +2 -6
  38. package/templates/simple/ts/wrangler.toml +37 -0
  39. package/dist/frameworks/astro/index.js +0 -20
  40. package/dist/frameworks/index.js +0 -26
  41. package/dist/frameworks/next/index.js +0 -37
  42. package/dist/frameworks/next/templates.js +0 -38
  43. package/dist/frameworks/nuxt/index.js +0 -19
  44. package/dist/frameworks/qwik/index.js +0 -23
  45. package/dist/frameworks/react/index.js +0 -18
  46. package/dist/frameworks/remix/index.js +0 -14
  47. package/dist/frameworks/solid/index.js +0 -33
  48. package/dist/frameworks/solid/templates.js +0 -12
  49. package/dist/frameworks/svelte/index.js +0 -50
  50. package/dist/frameworks/svelte/templates.js +0 -14
  51. package/dist/frameworks/vue/index.js +0 -16
  52. package/dist/helpers/cli.js +0 -12
  53. package/dist/helpers/codemod.js +0 -88
  54. package/dist/helpers/command.js +0 -47
  55. package/dist/helpers/files.js +0 -76
  56. package/dist/helpers/interactive.js +0 -25
  57. package/dist/types.js +0 -2
  58. package/templates/examples/js/.prettierrc +0 -5
  59. package/templates/examples/js/package.json +0 -14
  60. package/templates/examples/js/src/ab-test.js +0 -41
  61. package/templates/examples/js/src/proxy.js +0 -22
  62. package/templates/examples/js/src/redirect.js +0 -13
  63. package/templates/examples/js/src/worker.js +0 -37
  64. package/templates/examples/js/wrangler.toml +0 -7
  65. package/templates/examples/ts/.prettierrc +0 -5
  66. package/templates/examples/ts/package.json +0 -15
  67. package/templates/examples/ts/src/ab-test.ts +0 -41
  68. package/templates/examples/ts/src/proxy.ts +0 -22
  69. package/templates/examples/ts/src/redirect.ts +0 -13
  70. package/templates/examples/ts/src/worker.ts +0 -37
  71. package/templates/examples/ts/worker-configuration.d.ts +0 -13
  72. package/templates/examples/ts/wrangler.toml +0 -7
package/README.md CHANGED
@@ -1,15 +1,16 @@
1
1
  # create-cloudflare
2
2
 
3
- `create-cloudflare` is a scaffolding tool meant to help users get started with Cloudflare Pages using their framework of choice as quickly and easily as possible.
4
-
5
- Instead of having to choose from a set of pre-constructed templates, this tool allows you to run the creation commands of your desired framework directly. This means that you can configure it with all the options the
6
-
7
- To get started, run the following command:
3
+ A CLI for creating and deploying new applications to Cloudflare.
8
4
 
9
5
  ```bash
10
- npm create cloudflare
6
+ npm create cloudflare@latest
11
7
  # or
12
- yarn create cloudflare
8
+ pnpm create cloudflare@latest
13
9
  # or
14
- pnmp create cloudflare
10
+ yarn create cloudflare
15
11
  ```
12
+
13
+ ### Community
14
+
15
+ - Join us [on Discord](https://discord.gg/cloudflaredev)
16
+ - File an issue [on Github](https://github.com/cloudflare/workers-sdk/issues/new/choose)
@@ -0,0 +1,5 @@
1
+ {
2
+ "version": 1,
3
+ "include": ["/*"],
4
+ "exclude": ["/*.*"]
5
+ }
@@ -0,0 +1,35 @@
1
+ import "zone.js/dist/zone-node";
2
+ import "@angular/platform-server/init";
3
+
4
+ import { bootstrapApplication } from "@angular/platform-browser";
5
+ import { renderApplication } from "@angular/platform-server";
6
+
7
+ import { AppComponent } from "./app/app.component";
8
+ import { config } from "./app/app.config.server";
9
+
10
+ interface Env {
11
+ ASSETS: { fetch: typeof fetch };
12
+ }
13
+
14
+ // We attach the Cloudflare `fetch()` handler to the global scope
15
+ // so that we can export it when we process the Angular output.
16
+ // See tools/bundle.mjs
17
+ (globalThis as any).__workerFetchHandler = async function fetch(
18
+ request: Request,
19
+ env: Env
20
+ ) {
21
+ const url = new URL(request.url);
22
+ console.log("render SSR", url.href);
23
+
24
+ // Get the root `index.html` content.
25
+ const indexUrl = new URL("/", url);
26
+ const indexResponse = await env.ASSETS.fetch(new Request(indexUrl));
27
+ const document = await indexResponse.text();
28
+
29
+ const content = await renderApplication(
30
+ () => bootstrapApplication(AppComponent, config),
31
+ { document, url: url.pathname }
32
+ );
33
+ // console.log("rendered SSR", content);
34
+ return new Response(content, indexResponse);
35
+ };
@@ -0,0 +1,74 @@
1
+ import fs from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { worker as workerPath } from "./paths.mjs";
4
+ import * as esbuild from "esbuild";
5
+ import { NodeGlobalsPolyfillPlugin } from "@esbuild-plugins/node-globals-polyfill";
6
+ import { NodeModulesPolyfillPlugin } from "@esbuild-plugins/node-modules-polyfill";
7
+ import fg from "fast-glob";
8
+
9
+ // Process each of the JS files in the `_worker.js` directory
10
+ for (const entry of await fg("**/*.js", { cwd: workerPath, onlyFiles: true })) {
11
+ if (entry === "index.js") {
12
+ // This is the main bundle and gets special treatment
13
+ await bundleMain();
14
+ } else {
15
+ await bundleLazyModule(entry);
16
+ }
17
+ }
18
+
19
+ // Use esbuild to process the main entry-point.
20
+ // - shim Node.js APIs
21
+ // - convert `global` to `globalThis`
22
+ // - convert dynamic `require()` calls to `await import()` calls
23
+ // - ensure that the Cloudflare `fetch()` handler is exported
24
+ async function bundleMain() {
25
+ const result = await esbuild.build({
26
+ entryPoints: ["index.js"],
27
+ bundle: true,
28
+ format: "iife",
29
+ write: false,
30
+ absWorkingDir: workerPath,
31
+ define: {
32
+ global: "globalThis",
33
+ },
34
+ plugins: [
35
+ NodeGlobalsPolyfillPlugin({ buffer: true }),
36
+ NodeModulesPolyfillPlugin(),
37
+ ],
38
+ });
39
+
40
+ let main = result.outputFiles[0].text;
41
+
42
+ // Patch any dynamic imports (converting `require()` calls to `import()` calls).
43
+ main = main.replace(
44
+ 'installChunk(__require("./" + __webpack_require__.u(chunkId))',
45
+ 'promises.push(import("./" + __webpack_require__.u(chunkId)).then((mod) => installChunk(mod.default))'
46
+ );
47
+ // Export the fetch handler (grabbing it from the global).
48
+ main += "\nexport default { fetch : globalThis.__workerFetchHandler };";
49
+
50
+ await fs.writeFile(path.resolve(workerPath, "index.js"), main);
51
+ }
52
+
53
+ // Use esbuild to process the lazy load modules
54
+ // In particular we need to convert the CommonJS export syntax to ESM.
55
+ async function bundleLazyModule(filePath) {
56
+ const result = await esbuild.build({
57
+ entryPoints: [filePath],
58
+ bundle: true,
59
+ format: "cjs",
60
+ write: false,
61
+ absWorkingDir: workerPath,
62
+ define: {
63
+ global: "globalThis",
64
+ },
65
+ plugins: [NodeModulesPolyfillPlugin()],
66
+ });
67
+
68
+ let content = result.outputFiles[0].text;
69
+
70
+ // Export the fetch handler (grabbing it from the global).
71
+ content = "const exports = {};\n" + content + "\nexport default exports";
72
+
73
+ await fs.writeFile(path.resolve(workerPath, filePath), content);
74
+ }
@@ -0,0 +1,4 @@
1
+ // Copy the client-side files over so that they can be uploaded by the pages publish command.
2
+ import fs from "node:fs";
3
+ import { client, cloudflare } from "./paths.mjs";
4
+ fs.cpSync(client, cloudflare, { recursive: true });
@@ -0,0 +1,10 @@
1
+ // Copy the lazy loaded modules into the dist folder so that they can be
2
+ // uploaded along with the main Worker module.
3
+ import fs from "node:fs";
4
+ import path from "node:path";
5
+ import { ssr, worker } from "./paths.mjs";
6
+ fs.cpSync(ssr, worker, { recursive: true });
7
+ fs.renameSync(
8
+ path.resolve(worker, "main.js"),
9
+ path.resolve(worker, "index.js")
10
+ );
@@ -0,0 +1,9 @@
1
+ import path from "node:path";
2
+ import { fileURLToPath } from "node:url";
3
+
4
+ const dirname = path.dirname(fileURLToPath(import.meta.url));
5
+ export const root = path.resolve(dirname, "..");
6
+ export const client = path.resolve(root, "dist/browser");
7
+ export const ssr = path.resolve(root, "dist/server");
8
+ export const cloudflare = path.resolve(root, "dist/cloudflare");
9
+ export const worker = path.resolve(cloudflare, "_worker.js");
@@ -0,0 +1,5 @@
1
+ /* To learn more about this file see: https://angular.io/config/tsconfig. */
2
+ {
3
+ "extends": "./tsconfig.app.json",
4
+ "files": ["./src/main.server.ts"]
5
+ }