create-cloudflare 0.0.0-9c15b6ea2 → 0.0.0-9c30aecaa
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 +283 -246
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -8
- package/templates/analog/c3.ts +0 -24
- package/templates/analog/templates/env.d.ts +1 -1
- package/templates/angular/pages/c3.ts +3 -3
- package/templates/angular/pages/templates/wrangler.jsonc +5 -0
- package/templates/angular/workers/c3.ts +1 -0
- package/templates/astro/workers/templates/js/wrangler.jsonc +2 -1
- package/templates/astro/workers/templates/ts/wrangler.jsonc +2 -1
- package/templates/common/ts/tsconfig.json +0 -3
- package/templates/docusaurus/pages/c3.ts +1 -0
- package/templates/docusaurus/workers/c3.ts +1 -0
- package/templates/gatsby/pages/c3.ts +1 -0
- package/templates/gatsby/workers/c3.ts +1 -0
- package/templates/hello-world/ts/test/index.spec.ts +0 -1
- package/templates/hello-world/ts/test/tsconfig.json +1 -1
- package/templates/hello-world/ts/tsconfig.json +0 -2
- package/templates/hello-world-assets-only/templates/public/index.html +1 -0
- package/templates/hello-world-assets-only/templates/wrangler.jsonc +1 -0
- package/templates/hello-world-durable-object/ts/tsconfig.json +0 -2
- package/templates/hello-world-durable-object-with-assets/js/public/index.html +1 -0
- package/templates/hello-world-durable-object-with-assets/js/wrangler.jsonc +1 -1
- package/templates/hello-world-durable-object-with-assets/py/public/index.html +1 -0
- package/templates/hello-world-durable-object-with-assets/py/wrangler.jsonc +1 -1
- package/templates/hello-world-durable-object-with-assets/ts/public/index.html +1 -0
- package/templates/hello-world-durable-object-with-assets/ts/tsconfig.json +0 -2
- package/templates/hello-world-durable-object-with-assets/ts/wrangler.jsonc +1 -1
- package/templates/hello-world-with-assets/js/public/index.html +1 -0
- package/templates/hello-world-with-assets/js/wrangler.jsonc +3 -2
- package/templates/hello-world-with-assets/py/public/index.html +1 -0
- package/templates/hello-world-with-assets/py/wrangler.jsonc +1 -1
- package/templates/hello-world-with-assets/ts/public/index.html +1 -0
- package/templates/hello-world-with-assets/ts/test/tsconfig.json +1 -1
- package/templates/hello-world-with-assets/ts/tsconfig.json +0 -2
- package/templates/hello-world-with-assets/ts/wrangler.jsonc +2 -2
- package/templates/hello-world-workflows/c3.ts +20 -0
- package/templates/hello-world-workflows/js/package.json +13 -0
- package/templates/hello-world-workflows/js/src/index.js +129 -0
- package/templates/hello-world-workflows/js/wrangler.jsonc +17 -0
- package/templates/hello-world-workflows/ts/package.json +15 -0
- package/templates/hello-world-workflows/ts/src/index.ts +111 -0
- package/templates/hello-world-workflows/ts/tsconfig.json +40 -0
- package/templates/hello-world-workflows/ts/wrangler.jsonc +17 -0
- package/templates/hono/pages/c3.ts +4 -1
- package/templates/hono/workers/c3.ts +3 -1
- package/templates/next/pages/c3.ts +6 -10
- package/templates/next/workers/c3.ts +7 -5
- package/templates/next/workers/templates/public/_headers +3 -0
- package/templates/nuxt/pages/c3.ts +2 -26
- package/templates/nuxt/pages/templates/env.d.ts +1 -1
- package/templates/nuxt/workers/c3.ts +2 -26
- package/templates/nuxt/workers/templates/env.d.ts +1 -1
- package/templates/openapi/ts/tsconfig.json +0 -1
- package/templates/queues/ts/tsconfig.json +0 -2
- package/templates/qwik/pages/c3.ts +1 -0
- package/templates/qwik/workers/c3.ts +1 -0
- package/templates/qwik/workers/templates/wrangler.jsonc +2 -1
- package/templates/react/pages/c3.ts +4 -2
- package/templates/react/pages/templates/wrangler.jsonc +5 -0
- package/templates/react/workers/ts/tsconfig.worker.json +1 -1
- package/templates/react-router/c3.ts +0 -12
- package/templates/remix/pages/c3.ts +1 -0
- package/templates/remix/pages/templates/worker-configuration.d.ts +1 -1
- package/templates/remix/workers/c3.ts +1 -0
- package/templates/scheduled/ts/tsconfig.json +0 -2
- package/templates/solid/c3.ts +1 -0
- package/templates/svelte/pages/c3.ts +3 -3
- package/templates/svelte/workers/c3.ts +3 -3
- package/templates/vue/pages/c3.ts +5 -3
- package/templates/vue/pages/templates/wrangler.jsonc +5 -0
- package/templates/vue/workers/ts/tsconfig.worker.json +1 -1
- package/templates-experimental/solid/c3.ts +1 -1
- package/templates/analog/templates/worker-configuration.d.ts +0 -4
- package/templates/astro/workers/templates/ts/worker-configuration.d.ts +0 -4
- package/templates/common/ts/worker-configuration.d.ts +0 -4
- package/templates/hello-world/ts/worker-configuration.d.ts +0 -8
- package/templates/hello-world-durable-object/ts/worker-configuration.d.ts +0 -7
- package/templates/hello-world-durable-object-with-assets/ts/worker-configuration.d.ts +0 -8
- package/templates/hello-world-with-assets/ts/worker-configuration.d.ts +0 -7
- package/templates/hono/pages/templates/worker-configuration.d.ts +0 -4
- package/templates/hono/workers/templates/worker-configuration.d.ts +0 -4
- package/templates/next/pages/env.d.ts +0 -5
- package/templates/next/workers/templates/cloudflare-env.d.ts +0 -5
- package/templates/nuxt/pages/templates/worker-configuration.d.ts +0 -4
- package/templates/nuxt/workers/templates/worker-configuration.d.ts +0 -4
- package/templates/openapi/ts/worker-configuration.d.ts +0 -4
- package/templates/queues/ts/worker-configuration.d.ts +0 -5
- package/templates/react/workers/ts/worker-configuration.d.ts +0 -5
- package/templates/react-router/templates/worker-configuration.d.ts +0 -8
- package/templates/scheduled/ts/worker-configuration.d.ts +0 -4
- package/templates/vue/workers/ts/worker-configuration.d.ts +0 -6
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import {
|
|
2
|
+
WorkflowEntrypoint,
|
|
3
|
+
WorkflowEvent,
|
|
4
|
+
WorkflowStep,
|
|
5
|
+
} from "cloudflare:workers";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Welcome to Cloudflare Workers! This is your first Workflows application.
|
|
9
|
+
*
|
|
10
|
+
* - Run `npm run dev` in your terminal to start a development server
|
|
11
|
+
* - Open a browser tab at http://localhost:8787/ to see your Workflow in action
|
|
12
|
+
* - Run `npm run deploy` to publish your application
|
|
13
|
+
*
|
|
14
|
+
* Learn more at https://developers.cloudflare.com/workflows
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
// User-defined params passed to your Workflow
|
|
18
|
+
type Params = {
|
|
19
|
+
email: string;
|
|
20
|
+
metadata: Record<string, string>;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export class MyWorkflow extends WorkflowEntrypoint<Env, Params> {
|
|
24
|
+
async run(event: WorkflowEvent<Params>, step: WorkflowStep) {
|
|
25
|
+
// Can access bindings on `this.env`
|
|
26
|
+
// Can access params on `event.payload`
|
|
27
|
+
|
|
28
|
+
const files = await step.do("my first step", async () => {
|
|
29
|
+
// Fetch a list of files from $SOME_SERVICE
|
|
30
|
+
return {
|
|
31
|
+
inputParams: event,
|
|
32
|
+
files: [
|
|
33
|
+
"doc_7392_rev3.pdf",
|
|
34
|
+
"report_x29_final.pdf",
|
|
35
|
+
"memo_2024_05_12.pdf",
|
|
36
|
+
"file_089_update.pdf",
|
|
37
|
+
"proj_alpha_v2.pdf",
|
|
38
|
+
"data_analysis_q2.pdf",
|
|
39
|
+
"notes_meeting_52.pdf",
|
|
40
|
+
"summary_fy24_draft.pdf",
|
|
41
|
+
],
|
|
42
|
+
};
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// You can optionally have a Workflow wait for additional data,
|
|
46
|
+
// human approval or an external webhook or HTTP request, before progressing.
|
|
47
|
+
// You can submit data via HTTP POST to /accounts/{account_id}/workflows/{workflow_name}/instances/{instance_id}/events/{eventName}
|
|
48
|
+
const waitForApproval = await step.waitForEvent("request-approval", {
|
|
49
|
+
type: "approval", // define an optional key to switch on
|
|
50
|
+
timeout: "1 minute", // keep it short for the example!
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const apiResponse = await step.do("some other step", async () => {
|
|
54
|
+
let resp = await fetch("https://api.cloudflare.com/client/v4/ips");
|
|
55
|
+
return await resp.json<any>();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
await step.sleep("wait on something", "1 minute");
|
|
59
|
+
|
|
60
|
+
await step.do(
|
|
61
|
+
"make a call to write that could maybe, just might, fail",
|
|
62
|
+
// Define a retry strategy
|
|
63
|
+
{
|
|
64
|
+
retries: {
|
|
65
|
+
limit: 5,
|
|
66
|
+
delay: "5 second",
|
|
67
|
+
backoff: "exponential",
|
|
68
|
+
},
|
|
69
|
+
timeout: "15 minutes",
|
|
70
|
+
},
|
|
71
|
+
async () => {
|
|
72
|
+
// Do stuff here, with access to the state from our previous steps
|
|
73
|
+
if (Math.random() > 0.5) {
|
|
74
|
+
throw new Error("API call to $STORAGE_SYSTEM failed");
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
export default {
|
|
81
|
+
async fetch(req: Request, env: Env): Promise<Response> {
|
|
82
|
+
let url = new URL(req.url);
|
|
83
|
+
|
|
84
|
+
if (url.pathname.startsWith("/favicon")) {
|
|
85
|
+
return Response.json({}, { status: 404 });
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Get the status of an existing instance, if provided
|
|
89
|
+
// GET /?instanceId=<id here>
|
|
90
|
+
let id = url.searchParams.get("instanceId");
|
|
91
|
+
if (id) {
|
|
92
|
+
let instance = await env.MY_WORKFLOW.get(id);
|
|
93
|
+
return Response.json({
|
|
94
|
+
status: await instance.status(),
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Spawn a new instance and return the ID and status
|
|
99
|
+
let instance = await env.MY_WORKFLOW.create();
|
|
100
|
+
// You can also set the ID to match an ID in your own system
|
|
101
|
+
// and pass an optional payload to the Workflow
|
|
102
|
+
// let instance = await env.MY_WORKFLOW.create({
|
|
103
|
+
// id: 'id-from-your-system',
|
|
104
|
+
// params: { payload: 'to send' },
|
|
105
|
+
// });
|
|
106
|
+
return Response.json({
|
|
107
|
+
id: instance.id,
|
|
108
|
+
details: await instance.status(),
|
|
109
|
+
});
|
|
110
|
+
},
|
|
111
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
|
4
|
+
|
|
5
|
+
/* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
|
6
|
+
"target": "es2021",
|
|
7
|
+
/* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
|
8
|
+
"lib": ["es2021"],
|
|
9
|
+
/* Specify what JSX code is generated. */
|
|
10
|
+
"jsx": "react-jsx",
|
|
11
|
+
|
|
12
|
+
/* Specify what module code is generated. */
|
|
13
|
+
"module": "es2022",
|
|
14
|
+
/* Specify how TypeScript looks up a file from a given module specifier. */
|
|
15
|
+
"moduleResolution": "node",
|
|
16
|
+
/* Enable importing .json files */
|
|
17
|
+
"resolveJsonModule": true,
|
|
18
|
+
|
|
19
|
+
/* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */
|
|
20
|
+
"allowJs": true,
|
|
21
|
+
/* Enable error reporting in type-checked JavaScript files. */
|
|
22
|
+
"checkJs": false,
|
|
23
|
+
|
|
24
|
+
/* Disable emitting files from a compilation. */
|
|
25
|
+
"noEmit": true,
|
|
26
|
+
|
|
27
|
+
/* Ensure that each file can be safely transpiled without relying on other imports. */
|
|
28
|
+
"isolatedModules": true,
|
|
29
|
+
/* Allow 'import x from y' when a module doesn't have a default export. */
|
|
30
|
+
"allowSyntheticDefaultImports": true,
|
|
31
|
+
/* Ensure that casing is correct in imports. */
|
|
32
|
+
"forceConsistentCasingInFileNames": true,
|
|
33
|
+
|
|
34
|
+
/* Enable all strict type-checking options. */
|
|
35
|
+
"strict": true,
|
|
36
|
+
|
|
37
|
+
/* Skip type checking all .d.ts files. */
|
|
38
|
+
"skipLibCheck": true
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "<TBD>",
|
|
3
|
+
"main": "src/index.ts",
|
|
4
|
+
"compatibility_date": "<TBD>",
|
|
5
|
+
|
|
6
|
+
"observability": {
|
|
7
|
+
"enabled": true,
|
|
8
|
+
"head_sampling_rate": 1,
|
|
9
|
+
},
|
|
10
|
+
"workflows": [
|
|
11
|
+
{
|
|
12
|
+
"name": "<TBD>",
|
|
13
|
+
"binding": "MY_WORKFLOW",
|
|
14
|
+
"class_name": "MyWorkflow",
|
|
15
|
+
},
|
|
16
|
+
],
|
|
17
|
+
}
|
|
@@ -19,6 +19,8 @@ const generate = async (ctx: C3Context) => {
|
|
|
19
19
|
logRaw(""); // newline
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
+
const envInterfaceName = "CloudflareBindings";
|
|
23
|
+
|
|
22
24
|
const config: TemplateConfig = {
|
|
23
25
|
configVersion: 1,
|
|
24
26
|
id: "hono",
|
|
@@ -33,12 +35,13 @@ const config: TemplateConfig = {
|
|
|
33
35
|
generate,
|
|
34
36
|
transformPackageJson: async () => ({
|
|
35
37
|
scripts: {
|
|
36
|
-
"cf-typegen":
|
|
38
|
+
"cf-typegen": `wrangler types --env-interface ${envInterfaceName}`,
|
|
37
39
|
preview: "vite build && wrangler pages dev",
|
|
38
40
|
},
|
|
39
41
|
}),
|
|
40
42
|
devScript: "dev",
|
|
41
43
|
deployScript: "deploy",
|
|
42
44
|
previewScript: "preview",
|
|
45
|
+
envInterfaceName,
|
|
43
46
|
};
|
|
44
47
|
export default config;
|
|
@@ -19,6 +19,7 @@ const generate = async (ctx: C3Context) => {
|
|
|
19
19
|
logRaw(""); // newline
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
+
const envInterfaceName = "CloudflareBindings";
|
|
22
23
|
const config: TemplateConfig = {
|
|
23
24
|
configVersion: 1,
|
|
24
25
|
id: "hono",
|
|
@@ -32,11 +33,12 @@ const config: TemplateConfig = {
|
|
|
32
33
|
generate,
|
|
33
34
|
transformPackageJson: async () => ({
|
|
34
35
|
scripts: {
|
|
35
|
-
"cf-typegen":
|
|
36
|
+
"cf-typegen": `wrangler types --env-interface ${envInterfaceName}`,
|
|
36
37
|
},
|
|
37
38
|
}),
|
|
38
39
|
devScript: "dev",
|
|
39
40
|
deployScript: "deploy",
|
|
40
41
|
previewScript: "dev",
|
|
42
|
+
envInterfaceName,
|
|
41
43
|
};
|
|
42
44
|
export default config;
|
|
@@ -75,14 +75,6 @@ const configure = async (ctx: C3Context) => {
|
|
|
75
75
|
|
|
76
76
|
const usesTs = usesTypescript(ctx);
|
|
77
77
|
|
|
78
|
-
if (usesTs) {
|
|
79
|
-
copyFile(
|
|
80
|
-
join(getTemplatePath(ctx), "env.d.ts"),
|
|
81
|
-
join(projectPath, "env.d.ts"),
|
|
82
|
-
);
|
|
83
|
-
updateStatus("Created an env.d.ts file");
|
|
84
|
-
}
|
|
85
|
-
|
|
86
78
|
const installEslintPlugin = await shouldInstallNextOnPagesEslintPlugin(ctx);
|
|
87
79
|
|
|
88
80
|
if (installEslintPlugin) {
|
|
@@ -145,7 +137,6 @@ export const writeEslintrc = async (ctx: C3Context): Promise<void> => {
|
|
|
145
137
|
const addDevDependencies = async (installEslintPlugin: boolean) => {
|
|
146
138
|
const packages = [
|
|
147
139
|
"@cloudflare/next-on-pages@1",
|
|
148
|
-
"@cloudflare/workers-types",
|
|
149
140
|
"vercel",
|
|
150
141
|
...(installEslintPlugin ? ["eslint-plugin-next-on-pages"] : []),
|
|
151
142
|
];
|
|
@@ -156,6 +147,9 @@ const addDevDependencies = async (installEslintPlugin: boolean) => {
|
|
|
156
147
|
});
|
|
157
148
|
};
|
|
158
149
|
|
|
150
|
+
const envInterfaceName = "CloudflareEnv";
|
|
151
|
+
const typesPath = "./env.d.ts";
|
|
152
|
+
|
|
159
153
|
export default {
|
|
160
154
|
configVersion: 1,
|
|
161
155
|
id: "next",
|
|
@@ -213,7 +207,7 @@ export default {
|
|
|
213
207
|
preview: `${pagesBuildRunCommand} && wrangler pages dev`,
|
|
214
208
|
deploy: `${pagesBuildRunCommand} && wrangler pages deploy`,
|
|
215
209
|
...(usesTypescript(ctx) && {
|
|
216
|
-
"cf-typegen": `wrangler types --env-interface
|
|
210
|
+
"cf-typegen": `wrangler types --env-interface ${envInterfaceName} ${typesPath}`,
|
|
217
211
|
}),
|
|
218
212
|
},
|
|
219
213
|
};
|
|
@@ -222,4 +216,6 @@ export default {
|
|
|
222
216
|
previewScript: "preview",
|
|
223
217
|
deployScript: "deploy",
|
|
224
218
|
compatibilityFlags: ["nodejs_compat"],
|
|
219
|
+
typesPath,
|
|
220
|
+
envInterfaceName,
|
|
225
221
|
} as TemplateConfig;
|
|
@@ -11,7 +11,7 @@ const generate = async (ctx: C3Context) => {
|
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
const configure = async (ctx: C3Context) => {
|
|
14
|
-
await installPackages(["@opennextjs/cloudflare
|
|
14
|
+
await installPackages(["@opennextjs/cloudflare@^1.0.2"], {
|
|
15
15
|
startText: "Adding the Cloudflare adapter",
|
|
16
16
|
doneText: `${brandColor(`installed`)} @opennextjs/cloudflare)}`,
|
|
17
17
|
});
|
|
@@ -42,13 +42,14 @@ const updateNextConfig = (usesTs: boolean) => {
|
|
|
42
42
|
s.stop(`${brandColor(`updated`)} ${dim(`\`${configFile}\``)}`);
|
|
43
43
|
};
|
|
44
44
|
|
|
45
|
+
const envInterfaceName = "CloudflareEnv";
|
|
46
|
+
const typesPath = "./cloudflare-env.d.ts";
|
|
45
47
|
export default {
|
|
46
48
|
configVersion: 1,
|
|
47
49
|
id: "next",
|
|
48
50
|
frameworkCli: "create-next-app",
|
|
49
|
-
frameworkCliPinnedVersion: "~15.3.0",
|
|
50
51
|
platform: "workers",
|
|
51
|
-
displayName: "Next.js
|
|
52
|
+
displayName: "Next.js",
|
|
52
53
|
path: "templates/next/workers",
|
|
53
54
|
copyFiles: {
|
|
54
55
|
path: "./templates",
|
|
@@ -59,11 +60,12 @@ export default {
|
|
|
59
60
|
scripts: {
|
|
60
61
|
deploy: `opennextjs-cloudflare build && opennextjs-cloudflare deploy`,
|
|
61
62
|
preview: `opennextjs-cloudflare build && opennextjs-cloudflare preview`,
|
|
62
|
-
"cf-typegen": `wrangler types --env-interface
|
|
63
|
+
"cf-typegen": `wrangler types --env-interface ${envInterfaceName} ${typesPath}`,
|
|
63
64
|
},
|
|
64
65
|
}),
|
|
65
66
|
devScript: "dev",
|
|
66
67
|
previewScript: "preview",
|
|
67
68
|
deployScript: "deploy",
|
|
68
|
-
|
|
69
|
+
typesPath,
|
|
70
|
+
envInterfaceName,
|
|
69
71
|
} as TemplateConfig;
|
|
@@ -3,8 +3,7 @@ import { brandColor, dim } from "@cloudflare/cli/colors";
|
|
|
3
3
|
import { spinner } from "@cloudflare/cli/interactive";
|
|
4
4
|
import { runFrameworkGenerator } from "frameworks/index";
|
|
5
5
|
import { mergeObjectProperties, transformFile } from "helpers/codemod";
|
|
6
|
-
import {
|
|
7
|
-
import { readFile, writeFile } from "helpers/files";
|
|
6
|
+
import { writeFile } from "helpers/files";
|
|
8
7
|
import { detectPackageManager } from "helpers/packageManagers";
|
|
9
8
|
import { installPackages } from "helpers/packages";
|
|
10
9
|
import * as recast from "recast";
|
|
@@ -30,7 +29,7 @@ const generate = async (ctx: C3Context) => {
|
|
|
30
29
|
logRaw(""); // newline
|
|
31
30
|
};
|
|
32
31
|
|
|
33
|
-
const configure = async (
|
|
32
|
+
const configure = async () => {
|
|
34
33
|
const packages = ["nitro-cloudflare-dev"];
|
|
35
34
|
|
|
36
35
|
// When using pnpm, explicitly add h3 package so the H3Event type declaration can be updated.
|
|
@@ -45,29 +44,6 @@ const configure = async (ctx: C3Context) => {
|
|
|
45
44
|
doneText: `${brandColor("installed")} ${dim(`via \`${npm} install\``)}`,
|
|
46
45
|
});
|
|
47
46
|
updateNuxtConfig();
|
|
48
|
-
|
|
49
|
-
updateEnvTypes(ctx);
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
const updateEnvTypes = (ctx: C3Context) => {
|
|
53
|
-
const filepath = "env.d.ts";
|
|
54
|
-
|
|
55
|
-
const s = spinner();
|
|
56
|
-
s.start(`Updating ${filepath}`);
|
|
57
|
-
|
|
58
|
-
let file = readFile(filepath);
|
|
59
|
-
|
|
60
|
-
let typesEntrypoint = `@cloudflare/workers-types`;
|
|
61
|
-
const latestEntrypoint = getLatestTypesEntrypoint(ctx);
|
|
62
|
-
if (latestEntrypoint) {
|
|
63
|
-
typesEntrypoint += `/${latestEntrypoint}`;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Replace placeholder with actual types entrypoint
|
|
67
|
-
file = file.replace("WORKERS_TYPES_ENTRYPOINT", typesEntrypoint);
|
|
68
|
-
writeFile("env.d.ts", file);
|
|
69
|
-
|
|
70
|
-
s.stop(`${brandColor(`updated`)} ${dim(`\`${filepath}\``)}`);
|
|
71
47
|
};
|
|
72
48
|
|
|
73
49
|
const updateNuxtConfig = () => {
|
|
@@ -3,8 +3,7 @@ import { brandColor, dim } from "@cloudflare/cli/colors";
|
|
|
3
3
|
import { spinner } from "@cloudflare/cli/interactive";
|
|
4
4
|
import { runFrameworkGenerator } from "frameworks/index";
|
|
5
5
|
import { mergeObjectProperties, transformFile } from "helpers/codemod";
|
|
6
|
-
import {
|
|
7
|
-
import { readFile, writeFile } from "helpers/files";
|
|
6
|
+
import { writeFile } from "helpers/files";
|
|
8
7
|
import { detectPackageManager } from "helpers/packageManagers";
|
|
9
8
|
import { installPackages } from "helpers/packages";
|
|
10
9
|
import * as recast from "recast";
|
|
@@ -30,7 +29,7 @@ const generate = async (ctx: C3Context) => {
|
|
|
30
29
|
logRaw(""); // newline
|
|
31
30
|
};
|
|
32
31
|
|
|
33
|
-
const configure = async (
|
|
32
|
+
const configure = async () => {
|
|
34
33
|
const packages = ["nitro-cloudflare-dev", "nitropack"];
|
|
35
34
|
|
|
36
35
|
// When using pnpm, explicitly add h3 package so the H3Event type declaration can be updated.
|
|
@@ -45,29 +44,6 @@ const configure = async (ctx: C3Context) => {
|
|
|
45
44
|
doneText: `${brandColor("installed")} ${dim(`via \`${npm} install\``)}`,
|
|
46
45
|
});
|
|
47
46
|
updateNuxtConfig();
|
|
48
|
-
|
|
49
|
-
updateEnvTypes(ctx);
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
const updateEnvTypes = (ctx: C3Context) => {
|
|
53
|
-
const filepath = "env.d.ts";
|
|
54
|
-
|
|
55
|
-
const s = spinner();
|
|
56
|
-
s.start(`Updating ${filepath}`);
|
|
57
|
-
|
|
58
|
-
let file = readFile(filepath);
|
|
59
|
-
|
|
60
|
-
let typesEntrypoint = `@cloudflare/workers-types`;
|
|
61
|
-
const latestEntrypoint = getLatestTypesEntrypoint(ctx);
|
|
62
|
-
if (latestEntrypoint) {
|
|
63
|
-
typesEntrypoint += `/${latestEntrypoint}`;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Replace placeholder with actual types entrypoint
|
|
67
|
-
file = file.replace("WORKERS_TYPES_ENTRYPOINT", typesEntrypoint);
|
|
68
|
-
writeFile("env.d.ts", file);
|
|
69
|
-
|
|
70
|
-
s.stop(`${brandColor(`updated`)} ${dim(`\`${filepath}\``)}`);
|
|
71
47
|
};
|
|
72
48
|
|
|
73
49
|
const updateNuxtConfig = () => {
|
|
@@ -13,8 +13,6 @@
|
|
|
13
13
|
"module": "es2022",
|
|
14
14
|
/* Specify how TypeScript looks up a file from a given module specifier. */
|
|
15
15
|
"moduleResolution": "node",
|
|
16
|
-
/* Specify type package names to be included without being referenced in a source file. */
|
|
17
|
-
"types": ["@cloudflare/workers-types"],
|
|
18
16
|
/* Enable importing .json files */
|
|
19
17
|
"resolveJsonModule": true,
|
|
20
18
|
|
|
@@ -49,11 +49,13 @@ const config: TemplateConfig = {
|
|
|
49
49
|
platform: "pages",
|
|
50
50
|
hidden: true,
|
|
51
51
|
path: "templates/react/pages",
|
|
52
|
+
copyFiles: { path: "./templates" },
|
|
52
53
|
generate,
|
|
53
54
|
transformPackageJson: async () => ({
|
|
54
55
|
scripts: {
|
|
55
|
-
deploy: `${npm} run build && wrangler pages deploy
|
|
56
|
-
preview: `${npm} run build && wrangler pages dev
|
|
56
|
+
deploy: `${npm} run build && wrangler pages deploy`,
|
|
57
|
+
preview: `${npm} run build && wrangler pages dev`,
|
|
58
|
+
"cf-typegen": `wrangler types`,
|
|
57
59
|
},
|
|
58
60
|
}),
|
|
59
61
|
devScript: "dev",
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"extends": "./tsconfig.node.json",
|
|
3
3
|
"compilerOptions": {
|
|
4
4
|
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.worker.tsbuildinfo",
|
|
5
|
-
"types": ["
|
|
5
|
+
"types": ["./worker-configuration.d.ts", "vite/client"],
|
|
6
6
|
},
|
|
7
7
|
"include": ["./worker-configuration.d.ts", "./worker"]
|
|
8
8
|
}
|
|
@@ -19,24 +19,12 @@ const generate = async (ctx: C3Context) => {
|
|
|
19
19
|
logRaw(""); // newline
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
-
// TODO: Uncomment this once @react-router/dev updates its peer dependency to Wrangler v4
|
|
23
|
-
// const configure = async () => {
|
|
24
|
-
// await installPackages(["wrangler@latest"], {
|
|
25
|
-
// dev: true,
|
|
26
|
-
// startText: "Updating the Wrangler version",
|
|
27
|
-
// doneText: `${brandColor(`updated`)} ${dim("wrangler@latest")}`,
|
|
28
|
-
// });
|
|
29
|
-
// };
|
|
30
|
-
|
|
31
22
|
const config: TemplateConfig = {
|
|
32
23
|
configVersion: 1,
|
|
33
24
|
id: "react-router",
|
|
34
25
|
platform: "workers",
|
|
35
26
|
frameworkCli: "create-react-router",
|
|
36
27
|
displayName: "React Router (formerly Remix)",
|
|
37
|
-
copyFiles: {
|
|
38
|
-
path: "./templates",
|
|
39
|
-
},
|
|
40
28
|
generate,
|
|
41
29
|
// configure,
|
|
42
30
|
transformPackageJson: async () => ({
|
|
@@ -13,8 +13,6 @@
|
|
|
13
13
|
"module": "es2022",
|
|
14
14
|
/* Specify how TypeScript looks up a file from a given module specifier. */
|
|
15
15
|
"moduleResolution": "node",
|
|
16
|
-
/* Specify type package names to be included without being referenced in a source file. */
|
|
17
|
-
"types": ["@cloudflare/workers-types"],
|
|
18
16
|
/* Enable importing .json files */
|
|
19
17
|
"resolveJsonModule": true,
|
|
20
18
|
|
package/templates/solid/c3.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
|
-
import { platform } from "node:os";
|
|
3
2
|
import { logRaw, updateStatus } from "@cloudflare/cli";
|
|
4
3
|
import { blue, brandColor, dim } from "@cloudflare/cli/colors";
|
|
5
4
|
import { runFrameworkGenerator } from "frameworks/index";
|
|
@@ -124,6 +123,7 @@ const updateTypeDefinitions = (ctx: C3Context) => {
|
|
|
124
123
|
});
|
|
125
124
|
};
|
|
126
125
|
|
|
126
|
+
const typesPath = "src/worker-configuration.d.ts";
|
|
127
127
|
const config: TemplateConfig = {
|
|
128
128
|
configVersion: 1,
|
|
129
129
|
id: "svelte",
|
|
@@ -144,10 +144,9 @@ const config: TemplateConfig = {
|
|
|
144
144
|
};
|
|
145
145
|
|
|
146
146
|
if (usesTypescript(ctx)) {
|
|
147
|
-
const mv = platform() === "win32" ? "move" : "mv";
|
|
148
147
|
scripts = {
|
|
149
148
|
...scripts,
|
|
150
|
-
"cf-typegen": `wrangler types
|
|
149
|
+
"cf-typegen": `wrangler types ${typesPath}`,
|
|
151
150
|
};
|
|
152
151
|
}
|
|
153
152
|
|
|
@@ -156,5 +155,6 @@ const config: TemplateConfig = {
|
|
|
156
155
|
devScript: "dev",
|
|
157
156
|
deployScript: "deploy",
|
|
158
157
|
previewScript: "preview",
|
|
158
|
+
typesPath,
|
|
159
159
|
};
|
|
160
160
|
export default config;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { platform } from "node:os";
|
|
2
1
|
import { logRaw, updateStatus } from "@cloudflare/cli";
|
|
3
2
|
import { blue, brandColor, dim } from "@cloudflare/cli/colors";
|
|
4
3
|
import { runFrameworkGenerator } from "frameworks/index";
|
|
@@ -94,6 +93,7 @@ const updateTypeDefinitions = (ctx: C3Context) => {
|
|
|
94
93
|
});
|
|
95
94
|
};
|
|
96
95
|
|
|
96
|
+
const typesPath = "./src/worker-configuration.d.ts";
|
|
97
97
|
const config: TemplateConfig = {
|
|
98
98
|
configVersion: 1,
|
|
99
99
|
id: "svelte",
|
|
@@ -113,10 +113,9 @@ const config: TemplateConfig = {
|
|
|
113
113
|
};
|
|
114
114
|
|
|
115
115
|
if (usesTypescript(ctx)) {
|
|
116
|
-
const mv = platform() === "win32" ? "move" : "mv";
|
|
117
116
|
scripts = {
|
|
118
117
|
...scripts,
|
|
119
|
-
"cf-typegen": `wrangler types
|
|
118
|
+
"cf-typegen": `wrangler types ${typesPath}`,
|
|
120
119
|
};
|
|
121
120
|
}
|
|
122
121
|
|
|
@@ -125,5 +124,6 @@ const config: TemplateConfig = {
|
|
|
125
124
|
devScript: "dev",
|
|
126
125
|
deployScript: "deploy",
|
|
127
126
|
previewScript: "preview",
|
|
127
|
+
typesPath,
|
|
128
128
|
};
|
|
129
129
|
export default config;
|
|
@@ -16,12 +16,14 @@ const config: TemplateConfig = {
|
|
|
16
16
|
displayName: "Vue",
|
|
17
17
|
platform: "pages",
|
|
18
18
|
hidden: true,
|
|
19
|
-
path: "templates/pages
|
|
19
|
+
path: "templates/vue/pages",
|
|
20
|
+
copyFiles: { path: "./templates" },
|
|
20
21
|
generate,
|
|
21
22
|
transformPackageJson: async () => ({
|
|
22
23
|
scripts: {
|
|
23
|
-
deploy: `${npm} run build && wrangler pages deploy
|
|
24
|
-
preview: `${npm} run build && wrangler pages dev
|
|
24
|
+
deploy: `${npm} run build && wrangler pages deploy`,
|
|
25
|
+
preview: `${npm} run build && wrangler pages dev`,
|
|
26
|
+
"cf-typegen": `wrangler types`,
|
|
25
27
|
},
|
|
26
28
|
}),
|
|
27
29
|
devScript: "dev",
|