| 
1 |  | -import { brandColor, dim } from "@cloudflare/cli/colors";  | 
2 |  | -import { spinner } from "@cloudflare/cli/interactive";  | 
 | 1 | +import { brandColor } from "@cloudflare/cli/colors";  | 
3 | 2 | import { runFrameworkGenerator } from "frameworks/index";  | 
4 |  | -import { readFile, usesTypescript, writeFile } from "helpers/files";  | 
5 | 3 | import { installPackages } from "helpers/packages";  | 
6 | 4 | import type { TemplateConfig } from "../../src/templates";  | 
7 | 5 | import type { C3Context } from "types";  | 
8 | 6 | 
 
  | 
9 | 7 | const generate = async (ctx: C3Context) => {  | 
10 |  | -	await runFrameworkGenerator(ctx, [ctx.project.name]);  | 
 | 8 | +	await runFrameworkGenerator(ctx, [  | 
 | 9 | +		ctx.project.name,  | 
 | 10 | +		// We are using the Cloudflare template for Next.js projects  | 
 | 11 | +		// This is a template maintained by Cloudflare that based on a standard Next.js starter project,  | 
 | 12 | +		// and has already been configured to work with Cloudflare Workers  | 
 | 13 | +		"--example",  | 
 | 14 | +		"https://github.com/cloudflare/templates/tree/main/next-starter-template",  | 
 | 15 | +	]);  | 
11 | 16 | };  | 
12 | 17 | 
 
  | 
13 |  | -const configure = async (ctx: C3Context) => {  | 
 | 18 | +const configure = async () => {  | 
 | 19 | +	// Although the template is pre-configured for Cloudflare Workers,  | 
 | 20 | +	// we still need to install the latest minor of the OpenNext Cloudflare adapter package.  | 
14 | 21 | 	await installPackages(["@opennextjs/cloudflare@^1.3.0"], {  | 
15 | 22 | 		startText: "Adding the Cloudflare adapter",  | 
16 | 23 | 		doneText: `${brandColor(`installed`)} @opennextjs/cloudflare)}`,  | 
17 | 24 | 	});  | 
18 |  | - | 
19 |  | -	const usesTs = usesTypescript(ctx);  | 
20 |  | - | 
21 |  | -	updateNextConfig(usesTs);  | 
22 |  | -};  | 
23 |  | - | 
24 |  | -const updateNextConfig = (usesTs: boolean) => {  | 
25 |  | -	const s = spinner();  | 
26 |  | - | 
27 |  | -	const configFile = `next.config.${usesTs ? "ts" : "mjs"}`;  | 
28 |  | -	s.start(`Updating \`${configFile}\``);  | 
29 |  | - | 
30 |  | -	const configContent = readFile(configFile);  | 
31 |  | - | 
32 |  | -	const updatedConfigFile =  | 
33 |  | -		configContent +  | 
34 |  | -		`  | 
35 |  | -		// added by create cloudflare to enable calling \`getCloudflareContext()\` in \`next dev\`  | 
36 |  | -		import { initOpenNextCloudflareForDev } from '@opennextjs/cloudflare';  | 
37 |  | -		initOpenNextCloudflareForDev();  | 
38 |  | -		`.replace(/\n\t*/g, "\n");  | 
39 |  | - | 
40 |  | -	writeFile(configFile, updatedConfigFile);  | 
41 |  | - | 
42 |  | -	s.stop(`${brandColor(`updated`)} ${dim(`\`${configFile}\``)}`);  | 
43 | 25 | };  | 
44 | 26 | 
 
  | 
45 | 27 | const envInterfaceName = "CloudflareEnv";  | 
 | 
0 commit comments