create-cloudflare 2.9.2 → 2.10.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.
- package/dist/cli.js +71506 -58729
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +13 -7
- package/templates/angular/c3.ts +100 -0
- package/{dist → templates}/angular/templates/tools/copy-files.mjs +1 -1
- package/templates/astro/c3.ts +50 -0
- package/templates/common/c3.ts +14 -0
- package/templates/docusaurus/c3.ts +27 -0
- package/templates/gatsby/c3.ts +46 -0
- package/templates/hello-world/c3.ts +14 -0
- package/templates/hello-world-durable-object/c3.ts +14 -0
- package/templates/hello-world-durable-object/js/.editorconfig +13 -0
- package/templates/hello-world-durable-object/js/.prettierrc +6 -0
- package/templates/{chatgptPlugin/ts → hello-world-durable-object/js}/__dot__gitignore +1 -0
- package/templates/{chatgptPlugin/ts → hello-world-durable-object/js}/package.json +2 -5
- package/templates/hello-world-durable-object/js/src/index.js +65 -0
- package/templates/hello-world-durable-object/js/wrangler.toml +51 -0
- package/templates/hello-world-durable-object/ts/.editorconfig +13 -0
- package/templates/hello-world-durable-object/ts/.prettierrc +6 -0
- package/templates/hello-world-durable-object/ts/__dot__gitignore +172 -0
- package/templates/hello-world-durable-object/ts/package.json +15 -0
- package/templates/hello-world-durable-object/ts/src/index.ts +78 -0
- package/templates/hello-world-durable-object/ts/tsconfig.json +101 -0
- package/templates/hello-world-durable-object/ts/wrangler.toml +51 -0
- package/templates/hono/c3.ts +25 -0
- package/templates/next/c3.ts +212 -0
- package/templates/next/templates.ts +281 -0
- package/templates/nuxt/c3.ts +59 -0
- package/templates/openapi/c3.ts +9 -0
- package/templates/openapi/ts/src/endpoints/taskList.ts +1 -1
- package/templates/openapi/ts/src/index.ts +2 -2
- package/templates/pre-existing/c3.ts +84 -0
- package/templates/pre-existing/js/.editorconfig +13 -0
- package/templates/pre-existing/js/.prettierrc +6 -0
- package/templates/pre-existing/js/__dot__gitignore +172 -0
- package/templates/pre-existing/js/package.json +13 -0
- package/templates/pre-existing/js/wrangler.toml +3 -0
- package/templates/queues/c3.ts +24 -0
- package/templates/qwik/c3.ts +36 -0
- package/templates/react/c3.ts +29 -0
- package/templates/remix/c3.ts +33 -0
- package/templates/scheduled/c3.ts +14 -0
- package/templates/solid/c3.ts +37 -0
- package/templates/solid/js/vite.config.js +12 -0
- package/templates/solid/ts/vite.config.ts +12 -0
- package/templates/svelte/c3.ts +75 -0
- package/templates/svelte/templates.ts +13 -0
- package/templates/vue/c3.ts +27 -0
- package/templates/chatgptPlugin/ts/.assets/example.png +0 -0
- package/templates/chatgptPlugin/ts/README.md +0 -25
- package/templates/chatgptPlugin/ts/src/index.ts +0 -33
- package/templates/chatgptPlugin/ts/src/search.ts +0 -59
- package/templates/chatgptPlugin/ts/wrangler.toml +0 -3
- package/{dist → templates}/angular/templates/server.ts +0 -0
- package/{dist → templates}/angular/templates/src/_routes.json +0 -0
- package/{dist → templates}/angular/templates/tools/alter-polyfills.mjs +1 -1
- /package/{dist → templates}/angular/templates/tools/paths.mjs +0 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { logRaw } from "@cloudflare/cli";
|
|
4
|
+
import { brandColor, dim } from "@cloudflare/cli/colors";
|
|
5
|
+
import { spinner } from "@cloudflare/cli/interactive";
|
|
6
|
+
import { runFrameworkGenerator } from "helpers/command";
|
|
7
|
+
import { compatDateFlag, writeFile } from "helpers/files";
|
|
8
|
+
import { detectPackageManager } from "helpers/packages";
|
|
9
|
+
import type { TemplateConfig } from "../../src/templates";
|
|
10
|
+
import type { C3Context } from "types";
|
|
11
|
+
|
|
12
|
+
const { npm } = detectPackageManager();
|
|
13
|
+
|
|
14
|
+
const generate = async (ctx: C3Context) => {
|
|
15
|
+
const gitFlag = ctx.args.git ? `--gitInit` : `--no-gitInit`;
|
|
16
|
+
|
|
17
|
+
await runFrameworkGenerator(ctx, [
|
|
18
|
+
"init",
|
|
19
|
+
ctx.project.name,
|
|
20
|
+
"--packageManager",
|
|
21
|
+
npm,
|
|
22
|
+
gitFlag,
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
writeFile("./.node-version", "17");
|
|
26
|
+
|
|
27
|
+
logRaw(""); // newline
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const configure = async (ctx: C3Context) => {
|
|
31
|
+
const configFileName = "nuxt.config.ts";
|
|
32
|
+
const configFilePath = resolve(configFileName);
|
|
33
|
+
const s = spinner();
|
|
34
|
+
s.start(`Updating \`${configFileName}\``);
|
|
35
|
+
// Add the cloudflare preset into the configuration file.
|
|
36
|
+
const originalConfigFile = readFileSync(configFilePath, "utf8");
|
|
37
|
+
const updatedConfigFile = originalConfigFile.replace(
|
|
38
|
+
"defineNuxtConfig({",
|
|
39
|
+
"defineNuxtConfig({\n nitro: {\n preset: 'cloudflare-pages'\n },"
|
|
40
|
+
);
|
|
41
|
+
writeFile(configFilePath, updatedConfigFile);
|
|
42
|
+
s.stop(`${brandColor(`updated`)} ${dim(`\`${configFileName}\``)}`);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const config: TemplateConfig = {
|
|
46
|
+
configVersion: 1,
|
|
47
|
+
id: "nuxt",
|
|
48
|
+
platform: "pages",
|
|
49
|
+
displayName: "Nuxt",
|
|
50
|
+
generate,
|
|
51
|
+
configure,
|
|
52
|
+
transformPackageJson: async () => ({
|
|
53
|
+
scripts: {
|
|
54
|
+
"pages:dev": `wrangler pages dev ${await compatDateFlag()} --proxy 3000 -- ${npm} run dev`,
|
|
55
|
+
"pages:deploy": `${npm} run build && wrangler pages deploy ./dist`,
|
|
56
|
+
},
|
|
57
|
+
}),
|
|
58
|
+
};
|
|
59
|
+
export default config;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { OpenAPIRouter } from "@cloudflare/itty-router-openapi";
|
|
2
|
-
import { TaskList } from "./endpoints/taskList";
|
|
3
2
|
import { TaskCreate } from "./endpoints/taskCreate";
|
|
4
|
-
import { TaskFetch } from "./endpoints/taskFetch";
|
|
5
3
|
import { TaskDelete } from "./endpoints/taskDelete";
|
|
4
|
+
import { TaskFetch } from "./endpoints/taskFetch";
|
|
5
|
+
import { TaskList } from "./endpoints/taskList";
|
|
6
6
|
|
|
7
7
|
export const router = OpenAPIRouter({
|
|
8
8
|
docs_url: "/",
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { cp, mkdtemp, readdir, rm } from "fs/promises";
|
|
2
|
+
import { tmpdir } from "os";
|
|
3
|
+
import { join } from "path";
|
|
4
|
+
import { crash } from "@cloudflare/cli";
|
|
5
|
+
import { processArgument } from "@cloudflare/cli/args";
|
|
6
|
+
import { brandColor, dim } from "@cloudflare/cli/colors";
|
|
7
|
+
import { runCommand } from "helpers/command";
|
|
8
|
+
import { detectPackageManager } from "helpers/packages";
|
|
9
|
+
import { chooseAccount } from "../../src/common";
|
|
10
|
+
import type { C3Context } from "types";
|
|
11
|
+
|
|
12
|
+
export async function copyExistingWorkerFiles(ctx: C3Context) {
|
|
13
|
+
const { dlx, npm } = detectPackageManager();
|
|
14
|
+
|
|
15
|
+
await chooseAccount(ctx);
|
|
16
|
+
|
|
17
|
+
if (ctx.args.existingScript === undefined) {
|
|
18
|
+
ctx.args.existingScript = await processArgument<string>(
|
|
19
|
+
ctx.args,
|
|
20
|
+
"existingScript",
|
|
21
|
+
{
|
|
22
|
+
type: "text",
|
|
23
|
+
question:
|
|
24
|
+
"Please specify the name of the existing worker in this account?",
|
|
25
|
+
label: "worker",
|
|
26
|
+
defaultValue: ctx.project.name,
|
|
27
|
+
}
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// `wrangler init --from-dash` bails if you opt-out of creating a package.json
|
|
32
|
+
// so run it (with -y) in a tempdir and copy the src files after
|
|
33
|
+
const tempdir = await mkdtemp(join(tmpdir(), "c3-wrangler-init--from-dash-"));
|
|
34
|
+
await runCommand(
|
|
35
|
+
[
|
|
36
|
+
...dlx,
|
|
37
|
+
"wrangler@3",
|
|
38
|
+
"init",
|
|
39
|
+
"--from-dash",
|
|
40
|
+
ctx.args.existingScript,
|
|
41
|
+
"-y",
|
|
42
|
+
"--no-delegate-c3",
|
|
43
|
+
],
|
|
44
|
+
{
|
|
45
|
+
silent: true,
|
|
46
|
+
cwd: tempdir, // use a tempdir because we don't want all the files
|
|
47
|
+
env: { CLOUDFLARE_ACCOUNT_ID: ctx.account?.id },
|
|
48
|
+
startText: "Downloading existing worker files",
|
|
49
|
+
doneText: `${brandColor("downloaded")} ${dim(
|
|
50
|
+
`existing "${ctx.args.existingScript}" worker files`
|
|
51
|
+
)}`,
|
|
52
|
+
}
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
// copy src/* files from the downloaded worker
|
|
56
|
+
await cp(
|
|
57
|
+
join(tempdir, ctx.args.existingScript, "src"),
|
|
58
|
+
join(ctx.project.path, "src"),
|
|
59
|
+
{ recursive: true }
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
// copy wrangler.toml from the downloaded worker
|
|
63
|
+
await cp(
|
|
64
|
+
join(tempdir, ctx.args.existingScript, "wrangler.toml"),
|
|
65
|
+
join(ctx.project.path, "wrangler.toml")
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export default {
|
|
70
|
+
configVersion: 1,
|
|
71
|
+
id: "pre-existing",
|
|
72
|
+
displayName: "Pre-existing Worker (from Dashboard)",
|
|
73
|
+
platform: "workers",
|
|
74
|
+
hidden: true,
|
|
75
|
+
copyFiles: {
|
|
76
|
+
path: "./js",
|
|
77
|
+
},
|
|
78
|
+
configure: async (ctx: C3Context) => {
|
|
79
|
+
await copyExistingWorkerFiles(ctx);
|
|
80
|
+
|
|
81
|
+
// Force no-deploy since the worker is already deployed
|
|
82
|
+
ctx.args.deploy = false;
|
|
83
|
+
},
|
|
84
|
+
};
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# Logs
|
|
2
|
+
|
|
3
|
+
logs
|
|
4
|
+
_.log
|
|
5
|
+
npm-debug.log_
|
|
6
|
+
yarn-debug.log*
|
|
7
|
+
yarn-error.log*
|
|
8
|
+
lerna-debug.log*
|
|
9
|
+
.pnpm-debug.log*
|
|
10
|
+
|
|
11
|
+
# Diagnostic reports (https://nodejs.org/api/report.html)
|
|
12
|
+
|
|
13
|
+
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
|
|
14
|
+
|
|
15
|
+
# Runtime data
|
|
16
|
+
|
|
17
|
+
pids
|
|
18
|
+
_.pid
|
|
19
|
+
_.seed
|
|
20
|
+
\*.pid.lock
|
|
21
|
+
|
|
22
|
+
# Directory for instrumented libs generated by jscoverage/JSCover
|
|
23
|
+
|
|
24
|
+
lib-cov
|
|
25
|
+
|
|
26
|
+
# Coverage directory used by tools like istanbul
|
|
27
|
+
|
|
28
|
+
coverage
|
|
29
|
+
\*.lcov
|
|
30
|
+
|
|
31
|
+
# nyc test coverage
|
|
32
|
+
|
|
33
|
+
.nyc_output
|
|
34
|
+
|
|
35
|
+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
|
36
|
+
|
|
37
|
+
.grunt
|
|
38
|
+
|
|
39
|
+
# Bower dependency directory (https://bower.io/)
|
|
40
|
+
|
|
41
|
+
bower_components
|
|
42
|
+
|
|
43
|
+
# node-waf configuration
|
|
44
|
+
|
|
45
|
+
.lock-wscript
|
|
46
|
+
|
|
47
|
+
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
|
48
|
+
|
|
49
|
+
build/Release
|
|
50
|
+
|
|
51
|
+
# Dependency directories
|
|
52
|
+
|
|
53
|
+
node_modules/
|
|
54
|
+
jspm_packages/
|
|
55
|
+
|
|
56
|
+
# Snowpack dependency directory (https://snowpack.dev/)
|
|
57
|
+
|
|
58
|
+
web_modules/
|
|
59
|
+
|
|
60
|
+
# TypeScript cache
|
|
61
|
+
|
|
62
|
+
\*.tsbuildinfo
|
|
63
|
+
|
|
64
|
+
# Optional npm cache directory
|
|
65
|
+
|
|
66
|
+
.npm
|
|
67
|
+
|
|
68
|
+
# Optional eslint cache
|
|
69
|
+
|
|
70
|
+
.eslintcache
|
|
71
|
+
|
|
72
|
+
# Optional stylelint cache
|
|
73
|
+
|
|
74
|
+
.stylelintcache
|
|
75
|
+
|
|
76
|
+
# Microbundle cache
|
|
77
|
+
|
|
78
|
+
.rpt2_cache/
|
|
79
|
+
.rts2_cache_cjs/
|
|
80
|
+
.rts2_cache_es/
|
|
81
|
+
.rts2_cache_umd/
|
|
82
|
+
|
|
83
|
+
# Optional REPL history
|
|
84
|
+
|
|
85
|
+
.node_repl_history
|
|
86
|
+
|
|
87
|
+
# Output of 'npm pack'
|
|
88
|
+
|
|
89
|
+
\*.tgz
|
|
90
|
+
|
|
91
|
+
# Yarn Integrity file
|
|
92
|
+
|
|
93
|
+
.yarn-integrity
|
|
94
|
+
|
|
95
|
+
# dotenv environment variable files
|
|
96
|
+
|
|
97
|
+
.env
|
|
98
|
+
.env.development.local
|
|
99
|
+
.env.test.local
|
|
100
|
+
.env.production.local
|
|
101
|
+
.env.local
|
|
102
|
+
|
|
103
|
+
# parcel-bundler cache (https://parceljs.org/)
|
|
104
|
+
|
|
105
|
+
.cache
|
|
106
|
+
.parcel-cache
|
|
107
|
+
|
|
108
|
+
# Next.js build output
|
|
109
|
+
|
|
110
|
+
.next
|
|
111
|
+
out
|
|
112
|
+
|
|
113
|
+
# Nuxt.js build / generate output
|
|
114
|
+
|
|
115
|
+
.nuxt
|
|
116
|
+
dist
|
|
117
|
+
|
|
118
|
+
# Gatsby files
|
|
119
|
+
|
|
120
|
+
.cache/
|
|
121
|
+
|
|
122
|
+
# Comment in the public line in if your project uses Gatsby and not Next.js
|
|
123
|
+
|
|
124
|
+
# https://nextjs.org/blog/next-9-1#public-directory-support
|
|
125
|
+
|
|
126
|
+
# public
|
|
127
|
+
|
|
128
|
+
# vuepress build output
|
|
129
|
+
|
|
130
|
+
.vuepress/dist
|
|
131
|
+
|
|
132
|
+
# vuepress v2.x temp and cache directory
|
|
133
|
+
|
|
134
|
+
.temp
|
|
135
|
+
.cache
|
|
136
|
+
|
|
137
|
+
# Docusaurus cache and generated files
|
|
138
|
+
|
|
139
|
+
.docusaurus
|
|
140
|
+
|
|
141
|
+
# Serverless directories
|
|
142
|
+
|
|
143
|
+
.serverless/
|
|
144
|
+
|
|
145
|
+
# FuseBox cache
|
|
146
|
+
|
|
147
|
+
.fusebox/
|
|
148
|
+
|
|
149
|
+
# DynamoDB Local files
|
|
150
|
+
|
|
151
|
+
.dynamodb/
|
|
152
|
+
|
|
153
|
+
# TernJS port file
|
|
154
|
+
|
|
155
|
+
.tern-port
|
|
156
|
+
|
|
157
|
+
# Stores VSCode versions used for testing VSCode extensions
|
|
158
|
+
|
|
159
|
+
.vscode-test
|
|
160
|
+
|
|
161
|
+
# yarn v2
|
|
162
|
+
|
|
163
|
+
.yarn/cache
|
|
164
|
+
.yarn/unplugged
|
|
165
|
+
.yarn/build-state.yml
|
|
166
|
+
.yarn/install-state.gz
|
|
167
|
+
.pnp.\*
|
|
168
|
+
|
|
169
|
+
# wrangler project
|
|
170
|
+
|
|
171
|
+
.dev.vars
|
|
172
|
+
.wrangler/
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
configVersion: 1,
|
|
3
|
+
id: "queues",
|
|
4
|
+
displayName: "Queue consumer & producer Worker",
|
|
5
|
+
platform: "workers",
|
|
6
|
+
copyFiles: {
|
|
7
|
+
js: {
|
|
8
|
+
path: "./js",
|
|
9
|
+
},
|
|
10
|
+
ts: {
|
|
11
|
+
path: "./ts",
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
bindings: {
|
|
15
|
+
queues: [
|
|
16
|
+
{
|
|
17
|
+
boundVariable: "MY_QUEUE",
|
|
18
|
+
defaultValue: "my-queue",
|
|
19
|
+
producer: true,
|
|
20
|
+
consumer: true,
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { endSection } from "@cloudflare/cli";
|
|
2
|
+
import { runCommand, runFrameworkGenerator } from "helpers/command";
|
|
3
|
+
import { compatDateFlag } from "helpers/files";
|
|
4
|
+
import { detectPackageManager } from "helpers/packages";
|
|
5
|
+
import { quoteShellArgs } from "../../src/common";
|
|
6
|
+
import type { TemplateConfig } from "../../src/templates";
|
|
7
|
+
import type { C3Context } from "types";
|
|
8
|
+
|
|
9
|
+
const { npm, npx } = detectPackageManager();
|
|
10
|
+
|
|
11
|
+
const generate = async (ctx: C3Context) => {
|
|
12
|
+
await runFrameworkGenerator(ctx, ["basic", ctx.project.name]);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const configure = async (ctx: C3Context) => {
|
|
16
|
+
// Add the pages integration
|
|
17
|
+
const cmd = [npx, "qwik", "add", "cloudflare-pages"];
|
|
18
|
+
endSection(`Running ${quoteShellArgs(cmd)}`);
|
|
19
|
+
await runCommand(cmd);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const config: TemplateConfig = {
|
|
23
|
+
configVersion: 1,
|
|
24
|
+
id: "qwik",
|
|
25
|
+
displayName: "Qwik",
|
|
26
|
+
platform: "pages",
|
|
27
|
+
generate,
|
|
28
|
+
configure,
|
|
29
|
+
transformPackageJson: async () => ({
|
|
30
|
+
scripts: {
|
|
31
|
+
"pages:dev": `wrangler pages dev ${await compatDateFlag()} -- ${npm} run dev`,
|
|
32
|
+
"pages:deploy": `${npm} run build && wrangler pages deploy ./dist`,
|
|
33
|
+
},
|
|
34
|
+
}),
|
|
35
|
+
};
|
|
36
|
+
export default config;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { logRaw } from "@cloudflare/cli";
|
|
2
|
+
import { runFrameworkGenerator } from "helpers/command";
|
|
3
|
+
import { compatDateFlag } from "helpers/files";
|
|
4
|
+
import { detectPackageManager } from "helpers/packages";
|
|
5
|
+
import type { TemplateConfig } from "../../src/templates";
|
|
6
|
+
import type { C3Context } from "types";
|
|
7
|
+
|
|
8
|
+
const { npm } = detectPackageManager();
|
|
9
|
+
|
|
10
|
+
const generate = async (ctx: C3Context) => {
|
|
11
|
+
await runFrameworkGenerator(ctx, [ctx.project.name]);
|
|
12
|
+
|
|
13
|
+
logRaw("");
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const config: TemplateConfig = {
|
|
17
|
+
configVersion: 1,
|
|
18
|
+
id: "react",
|
|
19
|
+
displayName: "React",
|
|
20
|
+
platform: "pages",
|
|
21
|
+
generate,
|
|
22
|
+
transformPackageJson: async () => ({
|
|
23
|
+
scripts: {
|
|
24
|
+
"pages:dev": `wrangler pages dev ${await compatDateFlag()} --port 3000 -- ${npm} start`,
|
|
25
|
+
"pages:deploy": `${npm} run build && wrangler pages deploy ./build`,
|
|
26
|
+
},
|
|
27
|
+
}),
|
|
28
|
+
};
|
|
29
|
+
export default config;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { logRaw } from "@cloudflare/cli";
|
|
2
|
+
import { runFrameworkGenerator } from "helpers/command.js";
|
|
3
|
+
import { detectPackageManager } from "helpers/packages";
|
|
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
|
+
await runFrameworkGenerator(ctx, [
|
|
11
|
+
ctx.project.name,
|
|
12
|
+
"--template",
|
|
13
|
+
"https://github.com/remix-run/remix/tree/main/templates/cloudflare-pages",
|
|
14
|
+
]);
|
|
15
|
+
|
|
16
|
+
logRaw(""); // newline
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const config: TemplateConfig = {
|
|
20
|
+
configVersion: 1,
|
|
21
|
+
id: "remix",
|
|
22
|
+
displayName: "Remix",
|
|
23
|
+
platform: "pages",
|
|
24
|
+
generate,
|
|
25
|
+
transformPackageJson: async () => ({
|
|
26
|
+
scripts: {
|
|
27
|
+
"pages:deploy": `${npm} run build && wrangler pages deploy ./public`,
|
|
28
|
+
},
|
|
29
|
+
}),
|
|
30
|
+
devScript: "dev",
|
|
31
|
+
testFlags: ["--typescript", "--no-install", "--no-git-init"],
|
|
32
|
+
};
|
|
33
|
+
export default config;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { logRaw, updateStatus } from "@cloudflare/cli";
|
|
2
|
+
import { blue, brandColor, dim } from "@cloudflare/cli/colors";
|
|
3
|
+
import { installPackages, runFrameworkGenerator } from "helpers/command";
|
|
4
|
+
import { compatDateFlag } from "helpers/files";
|
|
5
|
+
import { detectPackageManager } from "helpers/packages";
|
|
6
|
+
import type { TemplateConfig } from "../../src/templates";
|
|
7
|
+
import type { C3Context } from "types";
|
|
8
|
+
|
|
9
|
+
const { npm } = detectPackageManager();
|
|
10
|
+
|
|
11
|
+
const generate = async (ctx: C3Context) => {
|
|
12
|
+
// Run the create-solid command
|
|
13
|
+
await runFrameworkGenerator(ctx, [ctx.project.name]);
|
|
14
|
+
|
|
15
|
+
logRaw("");
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const config: TemplateConfig = {
|
|
19
|
+
configVersion: 1,
|
|
20
|
+
id: "solid",
|
|
21
|
+
displayName: "Solid",
|
|
22
|
+
platform: "pages",
|
|
23
|
+
copyFiles: {
|
|
24
|
+
js: { path: "./js" },
|
|
25
|
+
ts: { path: "./ts" },
|
|
26
|
+
},
|
|
27
|
+
generate,
|
|
28
|
+
transformPackageJson: async () => ({
|
|
29
|
+
scripts: {
|
|
30
|
+
"pages:preview": `${npm} run build && npx wrangler pages dev dist ${await compatDateFlag()} --compatibility-flag nodejs_compat`,
|
|
31
|
+
"pages:deploy": `${npm} run build && wrangler pages deploy ./dist`,
|
|
32
|
+
},
|
|
33
|
+
}),
|
|
34
|
+
devScript: "dev",
|
|
35
|
+
compatibilityFlags: ["nodejs_compat"],
|
|
36
|
+
};
|
|
37
|
+
export default config;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { logRaw, updateStatus } from "@cloudflare/cli";
|
|
2
|
+
import { blue, brandColor, dim } from "@cloudflare/cli/colors";
|
|
3
|
+
import { parseTs, transformFile } from "helpers/codemod";
|
|
4
|
+
import { installPackages, runFrameworkGenerator } from "helpers/command";
|
|
5
|
+
import { compatDateFlag, usesTypescript } from "helpers/files";
|
|
6
|
+
import { detectPackageManager } from "helpers/packages";
|
|
7
|
+
import { platformInterface } from "./templates";
|
|
8
|
+
import type { TemplateConfig } from "../../src/templates";
|
|
9
|
+
import type * as recast from "recast";
|
|
10
|
+
import type { C3Context } from "types";
|
|
11
|
+
|
|
12
|
+
const { npm } = detectPackageManager();
|
|
13
|
+
|
|
14
|
+
const generate = async (ctx: C3Context) => {
|
|
15
|
+
await runFrameworkGenerator(ctx, [ctx.project.name]);
|
|
16
|
+
|
|
17
|
+
logRaw("");
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const configure = async (ctx: C3Context) => {
|
|
21
|
+
// Install the adapter
|
|
22
|
+
const pkg = `@sveltejs/adapter-cloudflare`;
|
|
23
|
+
await installPackages([pkg], {
|
|
24
|
+
dev: true,
|
|
25
|
+
startText: "Adding the Cloudflare Pages adapter",
|
|
26
|
+
doneText: `${brandColor(`installed`)} ${dim(pkg)}`,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// Change the import statement in svelte.config.js
|
|
30
|
+
transformFile("svelte.config.js", {
|
|
31
|
+
visitImportDeclaration: function (n) {
|
|
32
|
+
// importSource is the `x` in `import y from "x"`
|
|
33
|
+
const importSource = n.value.source;
|
|
34
|
+
if (importSource.value === "@sveltejs/adapter-auto") {
|
|
35
|
+
importSource.value = "@sveltejs/adapter-cloudflare";
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// stop traversing this node
|
|
39
|
+
return false;
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
updateStatus(`Changing adapter in ${blue("svelte.config.js")}`);
|
|
43
|
+
|
|
44
|
+
// If using typescript, add the platform interface to the `App` interface
|
|
45
|
+
if (usesTypescript(ctx)) {
|
|
46
|
+
transformFile("src/app.d.ts", {
|
|
47
|
+
visitTSModuleDeclaration(n) {
|
|
48
|
+
if (n.value.id.name === "App") {
|
|
49
|
+
const patchAst = parseTs(platformInterface);
|
|
50
|
+
const body = n.node.body as recast.types.namedTypes.TSModuleBlock;
|
|
51
|
+
body.body.push(patchAst.program.body[0]);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
this.traverse(n);
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
updateStatus(`Updating global type definitions in ${blue("app.d.ts")}`);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const config: TemplateConfig = {
|
|
62
|
+
configVersion: 1,
|
|
63
|
+
id: "svelte",
|
|
64
|
+
displayName: "Svelte",
|
|
65
|
+
platform: "pages",
|
|
66
|
+
generate,
|
|
67
|
+
configure,
|
|
68
|
+
transformPackageJson: async () => ({
|
|
69
|
+
scripts: {
|
|
70
|
+
"pages:dev": `wrangler pages dev ${await compatDateFlag()} --proxy 5173 -- ${npm} run dev`,
|
|
71
|
+
"pages:deploy": `${npm} run build && wrangler pages deploy .svelte-kit/cloudflare`,
|
|
72
|
+
},
|
|
73
|
+
}),
|
|
74
|
+
};
|
|
75
|
+
export default config;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const platformInterface = `
|
|
2
|
+
interface Platform {
|
|
3
|
+
env: {
|
|
4
|
+
COUNTER: DurableObjectNamespace;
|
|
5
|
+
};
|
|
6
|
+
context: {
|
|
7
|
+
waitUntil(promise: Promise<any>): void;
|
|
8
|
+
};
|
|
9
|
+
caches: CacheStorage & { default: Cache }
|
|
10
|
+
}
|
|
11
|
+
`;
|
|
12
|
+
|
|
13
|
+
// interface["Platform"] #context #waitUntil:nth(2)
|