create-cloudflare 2.74.15 → 2.75.1
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 +2873 -1082
- package/package.json +8 -9
- package/templates/common/ts/tsconfig.json +1 -1
- package/templates/hello-world-durable-object/ts/tsconfig.json +1 -1
- package/templates/hello-world-durable-object-with-assets/ts/tsconfig.json +1 -1
- package/templates/hello-world-workflows/ts/tsconfig.json +1 -1
- package/templates/queues/ts/tsconfig.json +1 -1
- package/templates/scheduled/ts/tsconfig.json +1 -1
- package/templates/svelte/c3.ts +129 -5
- package/templates/svelte/{workers/templates → templates}/wrangler.jsonc +1 -3
- package/templates/svelte/pages/c3.ts +0 -164
- package/templates/svelte/pages/templates/wrangler.jsonc +0 -6
- package/templates/svelte/workers/c3.ts +0 -133
- package/templates/svelte/workers/templates/static/.assetsignore +0 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-cloudflare",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.75.1",
|
|
4
4
|
"description": "A CLI for creating and deploying new applications to Cloudflare.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"@babel/types": "^7.21.4",
|
|
33
33
|
"@clack/prompts": "^1.2.0",
|
|
34
34
|
"@cloudflare/vite-plugin": "npm:@cloudflare/vite-plugin@1.63.2",
|
|
35
|
-
"@cloudflare/workers-types": "^5.
|
|
35
|
+
"@cloudflare/workers-types": "^5.20261123.1",
|
|
36
36
|
"@types/command-exists": "^1.2.0",
|
|
37
37
|
"@types/cross-spawn": "^6.0.2",
|
|
38
38
|
"@types/deepmerge": "^2.2.0",
|
|
@@ -63,20 +63,19 @@
|
|
|
63
63
|
"smol-toml": "1.9.0",
|
|
64
64
|
"tinyglobby": "0.2.16",
|
|
65
65
|
"tree-kill": "1.2.2",
|
|
66
|
-
"typescript": "
|
|
67
|
-
"undici": "7.30.
|
|
66
|
+
"typescript": "6.0.3",
|
|
67
|
+
"undici": "7.30.2",
|
|
68
68
|
"vite": "8.3.4",
|
|
69
|
-
"vite-tsconfig-paths": "^4.0.8",
|
|
70
69
|
"vitest": "5.0.4",
|
|
71
70
|
"which-pm-runs": "^1.1.0",
|
|
72
71
|
"wrap-ansi": "^9.0.0",
|
|
73
72
|
"yargs": "^17.7.2",
|
|
74
|
-
"@cloudflare/cli-shared-helpers": "0.3.11",
|
|
75
|
-
"@cloudflare/mock-npm-registry": "0.0.0",
|
|
76
73
|
"@cloudflare/shared-ast-primitives": "1.1.0",
|
|
77
|
-
"@cloudflare/
|
|
74
|
+
"@cloudflare/cli-shared-helpers": "0.3.13",
|
|
75
|
+
"@cloudflare/mock-npm-registry": "0.0.0",
|
|
78
76
|
"@cloudflare/workers-tsconfig": "0.0.0",
|
|
79
|
-
"
|
|
77
|
+
"@cloudflare/workers-utils": "0.57.0",
|
|
78
|
+
"wrangler": "4.167.0"
|
|
80
79
|
},
|
|
81
80
|
"engines": {
|
|
82
81
|
"node": ">=22.0.0"
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
/* Specify what module code is generated. */
|
|
13
13
|
"module": "es2022",
|
|
14
14
|
/* Specify how TypeScript looks up a file from a given module specifier. */
|
|
15
|
-
"moduleResolution": "
|
|
15
|
+
"moduleResolution": "Bundler",
|
|
16
16
|
/* Enable importing .json files */
|
|
17
17
|
"resolveJsonModule": true,
|
|
18
18
|
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
/* Specify what module code is generated. */
|
|
13
13
|
"module": "es2022",
|
|
14
14
|
/* Specify how TypeScript looks up a file from a given module specifier. */
|
|
15
|
-
"moduleResolution": "
|
|
15
|
+
"moduleResolution": "Bundler",
|
|
16
16
|
/* Enable importing .json files */
|
|
17
17
|
"resolveJsonModule": true,
|
|
18
18
|
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
/* Specify what module code is generated. */
|
|
13
13
|
"module": "es2022",
|
|
14
14
|
/* Specify how TypeScript looks up a file from a given module specifier. */
|
|
15
|
-
"moduleResolution": "
|
|
15
|
+
"moduleResolution": "Bundler",
|
|
16
16
|
/* Enable importing .json files */
|
|
17
17
|
"resolveJsonModule": true,
|
|
18
18
|
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
/* Specify what module code is generated. */
|
|
13
13
|
"module": "es2022",
|
|
14
14
|
/* Specify how TypeScript looks up a file from a given module specifier. */
|
|
15
|
-
"moduleResolution": "
|
|
15
|
+
"moduleResolution": "Bundler",
|
|
16
16
|
/* Enable importing .json files */
|
|
17
17
|
"resolveJsonModule": true,
|
|
18
18
|
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
/* Specify what module code is generated. */
|
|
13
13
|
"module": "es2022",
|
|
14
14
|
/* Specify how TypeScript looks up a file from a given module specifier. */
|
|
15
|
-
"moduleResolution": "
|
|
15
|
+
"moduleResolution": "Bundler",
|
|
16
16
|
/* Enable importing .json files */
|
|
17
17
|
"resolveJsonModule": true,
|
|
18
18
|
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
/* Specify what module code is generated. */
|
|
13
13
|
"module": "es2022",
|
|
14
14
|
/* Specify how TypeScript looks up a file from a given module specifier. */
|
|
15
|
-
"moduleResolution": "
|
|
15
|
+
"moduleResolution": "Bundler",
|
|
16
16
|
/* Enable importing .json files */
|
|
17
17
|
"resolveJsonModule": true,
|
|
18
18
|
|
package/templates/svelte/c3.ts
CHANGED
|
@@ -1,9 +1,133 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import { logRaw, updateStatus } from "@cloudflare/cli-shared-helpers";
|
|
2
|
+
import { blue, brandColor, dim } from "@cloudflare/cli-shared-helpers/colors";
|
|
3
|
+
import { transformFile } from "@cloudflare/shared-ast-primitives";
|
|
4
|
+
import { runFrameworkGenerator } from "frameworks/index";
|
|
5
|
+
import { usesTypescript } from "helpers/files";
|
|
6
|
+
import { detectPackageManager } from "helpers/packageManagers";
|
|
7
|
+
import { installPackages } from "helpers/packages";
|
|
8
|
+
import * as recast from "recast";
|
|
9
|
+
import type { TemplateConfig } from "../../src/templates";
|
|
10
|
+
import type { C3Context, PackageJson } from "types";
|
|
4
11
|
|
|
5
|
-
const
|
|
12
|
+
const { npm } = detectPackageManager();
|
|
13
|
+
|
|
14
|
+
const generate = async (ctx: C3Context) => {
|
|
15
|
+
await runFrameworkGenerator(ctx, ["create", ctx.project.name]);
|
|
16
|
+
|
|
17
|
+
logRaw("");
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const configure = async (ctx: C3Context) => {
|
|
21
|
+
// Install the adapter
|
|
22
|
+
const pkg = `@sveltejs/adapter-cloudflare@^9`;
|
|
23
|
+
await installPackages([pkg], {
|
|
24
|
+
dev: true,
|
|
25
|
+
startText: "Adding the Cloudflare adapter",
|
|
26
|
+
doneText: `${brandColor(`installed`)} ${dim(pkg)}`,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
updateViteConfig(ctx);
|
|
30
|
+
updateTypeDefinitions(ctx);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const updateViteConfig = (ctx: C3Context) => {
|
|
34
|
+
// As of `sv` 0.16, the adapter is configured in the Vite config rather than
|
|
35
|
+
// in `svelte.config.js`, so all we need to do is change the adapter import
|
|
36
|
+
// statement there.
|
|
37
|
+
const configFile = usesTypescript(ctx) ? "vite.config.ts" : "vite.config.js";
|
|
38
|
+
updateStatus(`Changing adapter in ${blue(configFile)}`);
|
|
39
|
+
|
|
40
|
+
transformFile(configFile, {
|
|
41
|
+
visitImportDeclaration: function (n) {
|
|
42
|
+
// importSource is the `x` in `import y from "x"`
|
|
43
|
+
const importSource = n.value.source;
|
|
44
|
+
if (importSource.value === "@sveltejs/adapter-auto") {
|
|
45
|
+
importSource.value = "@sveltejs/adapter-cloudflare";
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// stop traversing this node
|
|
49
|
+
return false;
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const updateTypeDefinitions = (ctx: C3Context) => {
|
|
55
|
+
if (!usesTypescript(ctx)) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
updateStatus(`Updating global type definitions in ${blue("app.d.ts")}`);
|
|
60
|
+
|
|
61
|
+
const b = recast.types.builders;
|
|
62
|
+
|
|
63
|
+
transformFile("src/app.d.ts", {
|
|
64
|
+
visitTSModuleDeclaration(n) {
|
|
65
|
+
if (n.value.id.name === "App" && n.node.body) {
|
|
66
|
+
const moduleBlock = n.node
|
|
67
|
+
.body as recast.types.namedTypes.TSModuleBlock;
|
|
68
|
+
|
|
69
|
+
const platformInterface = b.tsInterfaceDeclaration(
|
|
70
|
+
b.identifier("Platform"),
|
|
71
|
+
b.tsInterfaceBody([
|
|
72
|
+
b.tsPropertySignature(
|
|
73
|
+
b.identifier("env"),
|
|
74
|
+
b.tsTypeAnnotation(b.tsTypeReference(b.identifier("Env")))
|
|
75
|
+
),
|
|
76
|
+
b.tsPropertySignature(
|
|
77
|
+
b.identifier("cf"),
|
|
78
|
+
b.tsTypeAnnotation(
|
|
79
|
+
b.tsTypeReference(b.identifier("CfProperties"))
|
|
80
|
+
)
|
|
81
|
+
),
|
|
82
|
+
b.tsPropertySignature(
|
|
83
|
+
b.identifier("ctx"),
|
|
84
|
+
b.tsTypeAnnotation(
|
|
85
|
+
b.tsTypeReference(b.identifier("ExecutionContext"))
|
|
86
|
+
)
|
|
87
|
+
),
|
|
88
|
+
])
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
moduleBlock.body.unshift(platformInterface);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
this.traverse(n);
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const typesPath = "./src/worker-configuration.d.ts";
|
|
100
|
+
const config: TemplateConfig = {
|
|
101
|
+
configVersion: 1,
|
|
102
|
+
id: "svelte",
|
|
103
|
+
frameworkCli: "sv",
|
|
6
104
|
displayName: "SvelteKit",
|
|
7
|
-
|
|
105
|
+
platform: "workers",
|
|
106
|
+
languages: ["js", "ts"],
|
|
107
|
+
copyFiles: {
|
|
108
|
+
path: "./templates",
|
|
109
|
+
},
|
|
110
|
+
path: "templates/svelte",
|
|
111
|
+
generate,
|
|
112
|
+
configure,
|
|
113
|
+
transformPackageJson: async (original: PackageJson, ctx: C3Context) => {
|
|
114
|
+
let scripts: Record<string, string> = {
|
|
115
|
+
preview: `${npm} run build && wrangler dev`,
|
|
116
|
+
deploy: `${npm} run build && wrangler deploy`,
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
if (usesTypescript(ctx)) {
|
|
120
|
+
scripts = {
|
|
121
|
+
...scripts,
|
|
122
|
+
"cf-typegen": `wrangler types --include-main-module=false ${typesPath}`,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return { scripts };
|
|
127
|
+
},
|
|
128
|
+
devScript: "dev",
|
|
129
|
+
deployScript: "deploy",
|
|
130
|
+
previewScript: "preview",
|
|
131
|
+
typesPath,
|
|
8
132
|
};
|
|
9
133
|
export default config;
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "<WORKER_NAME>",
|
|
3
|
-
"main": ".svelte-kit/cloudflare/_worker.js",
|
|
4
3
|
"compatibility_date": "<COMPATIBILITY_DATE>",
|
|
5
4
|
"compatibility_flags": ["nodejs_als"],
|
|
6
5
|
"assets": {
|
|
7
|
-
"binding": "ASSETS"
|
|
8
|
-
"directory": ".svelte-kit/cloudflare"
|
|
6
|
+
"binding": "ASSETS"
|
|
9
7
|
},
|
|
10
8
|
"observability": {
|
|
11
9
|
"enabled": true
|
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import { existsSync } from "node:fs";
|
|
2
|
-
import { logRaw, updateStatus } from "@cloudflare/cli-shared-helpers";
|
|
3
|
-
import { blue, brandColor, dim } from "@cloudflare/cli-shared-helpers/colors";
|
|
4
|
-
import { transformFile } from "@cloudflare/shared-ast-primitives";
|
|
5
|
-
import { runFrameworkGenerator } from "frameworks/index";
|
|
6
|
-
import { usesTypescript } from "helpers/files";
|
|
7
|
-
import { detectPackageManager } from "helpers/packageManagers";
|
|
8
|
-
import { installPackages } from "helpers/packages";
|
|
9
|
-
import * as recast from "recast";
|
|
10
|
-
import type { TemplateConfig } from "../../../src/templates";
|
|
11
|
-
import type { C3Context, PackageJson } from "types";
|
|
12
|
-
|
|
13
|
-
const { npm } = detectPackageManager();
|
|
14
|
-
|
|
15
|
-
const generate = async (ctx: C3Context) => {
|
|
16
|
-
await runFrameworkGenerator(ctx, ["create", ctx.project.name]);
|
|
17
|
-
|
|
18
|
-
logRaw("");
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const configure = async (ctx: C3Context) => {
|
|
22
|
-
// Install the adapter
|
|
23
|
-
const pkg = `@sveltejs/adapter-cloudflare`;
|
|
24
|
-
await installPackages([pkg], {
|
|
25
|
-
dev: true,
|
|
26
|
-
startText: "Adding the Cloudflare Pages adapter",
|
|
27
|
-
doneText: `${brandColor(`installed`)} ${dim(pkg)}`,
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
updateViteConfig(ctx);
|
|
31
|
-
updatePlaywrightConfig(usesTypescript(ctx));
|
|
32
|
-
updateTypeDefinitions(ctx);
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const updateViteConfig = (ctx: C3Context) => {
|
|
36
|
-
// As of `sv` 0.16, the adapter is configured in the Vite config rather than
|
|
37
|
-
// in `svelte.config.js`, so all we need to do is change the adapter import
|
|
38
|
-
// statement there.
|
|
39
|
-
const configFile = usesTypescript(ctx) ? "vite.config.ts" : "vite.config.js";
|
|
40
|
-
updateStatus(`Changing adapter in ${blue(configFile)}`);
|
|
41
|
-
|
|
42
|
-
transformFile(configFile, {
|
|
43
|
-
visitImportDeclaration: function (n) {
|
|
44
|
-
// importSource is the `x` in `import y from "x"`
|
|
45
|
-
const importSource = n.value.source;
|
|
46
|
-
if (importSource.value === "@sveltejs/adapter-auto") {
|
|
47
|
-
importSource.value = "@sveltejs/adapter-cloudflare";
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// stop traversing this node
|
|
51
|
-
return false;
|
|
52
|
-
},
|
|
53
|
-
});
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
const updatePlaywrightConfig = (shouldUseTypescript: boolean) => {
|
|
57
|
-
const filePath = `playwright.config.${shouldUseTypescript ? "ts" : "js"}`;
|
|
58
|
-
if (!existsSync(filePath)) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
updateStatus(`Changing webServer port in ${blue(filePath)}`);
|
|
63
|
-
|
|
64
|
-
transformFile(filePath, {
|
|
65
|
-
visitObjectExpression: function (n) {
|
|
66
|
-
const portProp = n.node.properties.find((prop) => {
|
|
67
|
-
if (!("key" in prop) || !("name" in prop.key)) {
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return prop.key.name === "port";
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
if (!portProp || !("value" in portProp) || !("value" in portProp.value)) {
|
|
75
|
-
return this.traverse(n);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
portProp.value.value = 8788;
|
|
79
|
-
return false;
|
|
80
|
-
},
|
|
81
|
-
});
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const updateTypeDefinitions = (ctx: C3Context) => {
|
|
85
|
-
if (!usesTypescript(ctx)) {
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
updateStatus(`Updating global type definitions in ${blue("app.d.ts")}`);
|
|
90
|
-
|
|
91
|
-
const b = recast.types.builders;
|
|
92
|
-
|
|
93
|
-
transformFile("src/app.d.ts", {
|
|
94
|
-
visitTSModuleDeclaration(n) {
|
|
95
|
-
if (n.value.id.name === "App" && n.node.body) {
|
|
96
|
-
const moduleBlock = n.node
|
|
97
|
-
.body as recast.types.namedTypes.TSModuleBlock;
|
|
98
|
-
|
|
99
|
-
const platformInterface = b.tsInterfaceDeclaration(
|
|
100
|
-
b.identifier("Platform"),
|
|
101
|
-
b.tsInterfaceBody([
|
|
102
|
-
b.tsPropertySignature(
|
|
103
|
-
b.identifier("env"),
|
|
104
|
-
b.tsTypeAnnotation(b.tsTypeReference(b.identifier("Env")))
|
|
105
|
-
),
|
|
106
|
-
b.tsPropertySignature(
|
|
107
|
-
b.identifier("cf"),
|
|
108
|
-
b.tsTypeAnnotation(
|
|
109
|
-
b.tsTypeReference(b.identifier("CfProperties"))
|
|
110
|
-
)
|
|
111
|
-
),
|
|
112
|
-
b.tsPropertySignature(
|
|
113
|
-
b.identifier("ctx"),
|
|
114
|
-
b.tsTypeAnnotation(
|
|
115
|
-
b.tsTypeReference(b.identifier("ExecutionContext"))
|
|
116
|
-
)
|
|
117
|
-
),
|
|
118
|
-
])
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
moduleBlock.body.unshift(platformInterface);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
this.traverse(n);
|
|
125
|
-
},
|
|
126
|
-
});
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
const typesPath = "./src/worker-configuration.d.ts";
|
|
130
|
-
const config: TemplateConfig = {
|
|
131
|
-
configVersion: 1,
|
|
132
|
-
id: "svelte",
|
|
133
|
-
frameworkCli: "sv",
|
|
134
|
-
displayName: "SvelteKit",
|
|
135
|
-
platform: "pages",
|
|
136
|
-
languages: ["js", "ts"],
|
|
137
|
-
hidden: true,
|
|
138
|
-
copyFiles: {
|
|
139
|
-
path: "./templates",
|
|
140
|
-
},
|
|
141
|
-
path: "templates/svelte/pages",
|
|
142
|
-
generate,
|
|
143
|
-
configure,
|
|
144
|
-
transformPackageJson: async (original: PackageJson, ctx: C3Context) => {
|
|
145
|
-
let scripts: Record<string, string> = {
|
|
146
|
-
preview: `${npm} run build && wrangler pages dev`,
|
|
147
|
-
deploy: `${npm} run build && wrangler pages deploy`,
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
if (usesTypescript(ctx)) {
|
|
151
|
-
scripts = {
|
|
152
|
-
...scripts,
|
|
153
|
-
"cf-typegen": `wrangler types ${typesPath}`,
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
return { scripts };
|
|
158
|
-
},
|
|
159
|
-
devScript: "dev",
|
|
160
|
-
deployScript: "deploy",
|
|
161
|
-
previewScript: "preview",
|
|
162
|
-
typesPath,
|
|
163
|
-
};
|
|
164
|
-
export default config;
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { logRaw, updateStatus } from "@cloudflare/cli-shared-helpers";
|
|
2
|
-
import { blue, brandColor, dim } from "@cloudflare/cli-shared-helpers/colors";
|
|
3
|
-
import { transformFile } from "@cloudflare/shared-ast-primitives";
|
|
4
|
-
import { runFrameworkGenerator } from "frameworks/index";
|
|
5
|
-
import { usesTypescript } from "helpers/files";
|
|
6
|
-
import { detectPackageManager } from "helpers/packageManagers";
|
|
7
|
-
import { installPackages } from "helpers/packages";
|
|
8
|
-
import * as recast from "recast";
|
|
9
|
-
import type { TemplateConfig } from "../../../src/templates";
|
|
10
|
-
import type { C3Context, PackageJson } from "types";
|
|
11
|
-
|
|
12
|
-
const { npm } = detectPackageManager();
|
|
13
|
-
|
|
14
|
-
const generate = async (ctx: C3Context) => {
|
|
15
|
-
await runFrameworkGenerator(ctx, ["create", 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 adapter",
|
|
26
|
-
doneText: `${brandColor(`installed`)} ${dim(pkg)}`,
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
updateViteConfig(ctx);
|
|
30
|
-
updateTypeDefinitions(ctx);
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const updateViteConfig = (ctx: C3Context) => {
|
|
34
|
-
// As of `sv` 0.16, the adapter is configured in the Vite config rather than
|
|
35
|
-
// in `svelte.config.js`, so all we need to do is change the adapter import
|
|
36
|
-
// statement there.
|
|
37
|
-
const configFile = usesTypescript(ctx) ? "vite.config.ts" : "vite.config.js";
|
|
38
|
-
updateStatus(`Changing adapter in ${blue(configFile)}`);
|
|
39
|
-
|
|
40
|
-
transformFile(configFile, {
|
|
41
|
-
visitImportDeclaration: function (n) {
|
|
42
|
-
// importSource is the `x` in `import y from "x"`
|
|
43
|
-
const importSource = n.value.source;
|
|
44
|
-
if (importSource.value === "@sveltejs/adapter-auto") {
|
|
45
|
-
importSource.value = "@sveltejs/adapter-cloudflare";
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// stop traversing this node
|
|
49
|
-
return false;
|
|
50
|
-
},
|
|
51
|
-
});
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
const updateTypeDefinitions = (ctx: C3Context) => {
|
|
55
|
-
if (!usesTypescript(ctx)) {
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
updateStatus(`Updating global type definitions in ${blue("app.d.ts")}`);
|
|
60
|
-
|
|
61
|
-
const b = recast.types.builders;
|
|
62
|
-
|
|
63
|
-
transformFile("src/app.d.ts", {
|
|
64
|
-
visitTSModuleDeclaration(n) {
|
|
65
|
-
if (n.value.id.name === "App" && n.node.body) {
|
|
66
|
-
const moduleBlock = n.node
|
|
67
|
-
.body as recast.types.namedTypes.TSModuleBlock;
|
|
68
|
-
|
|
69
|
-
const platformInterface = b.tsInterfaceDeclaration(
|
|
70
|
-
b.identifier("Platform"),
|
|
71
|
-
b.tsInterfaceBody([
|
|
72
|
-
b.tsPropertySignature(
|
|
73
|
-
b.identifier("env"),
|
|
74
|
-
b.tsTypeAnnotation(b.tsTypeReference(b.identifier("Env")))
|
|
75
|
-
),
|
|
76
|
-
b.tsPropertySignature(
|
|
77
|
-
b.identifier("cf"),
|
|
78
|
-
b.tsTypeAnnotation(
|
|
79
|
-
b.tsTypeReference(b.identifier("CfProperties"))
|
|
80
|
-
)
|
|
81
|
-
),
|
|
82
|
-
b.tsPropertySignature(
|
|
83
|
-
b.identifier("ctx"),
|
|
84
|
-
b.tsTypeAnnotation(
|
|
85
|
-
b.tsTypeReference(b.identifier("ExecutionContext"))
|
|
86
|
-
)
|
|
87
|
-
),
|
|
88
|
-
])
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
moduleBlock.body.unshift(platformInterface);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
this.traverse(n);
|
|
95
|
-
},
|
|
96
|
-
});
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
const typesPath = "./src/worker-configuration.d.ts";
|
|
100
|
-
const config: TemplateConfig = {
|
|
101
|
-
configVersion: 1,
|
|
102
|
-
id: "svelte",
|
|
103
|
-
frameworkCli: "sv",
|
|
104
|
-
displayName: "SvelteKit",
|
|
105
|
-
platform: "workers",
|
|
106
|
-
languages: ["js", "ts"],
|
|
107
|
-
copyFiles: {
|
|
108
|
-
path: "./templates",
|
|
109
|
-
},
|
|
110
|
-
path: "templates/svelte/workers",
|
|
111
|
-
generate,
|
|
112
|
-
configure,
|
|
113
|
-
transformPackageJson: async (original: PackageJson, ctx: C3Context) => {
|
|
114
|
-
let scripts: Record<string, string> = {
|
|
115
|
-
preview: `${npm} run build && wrangler dev`,
|
|
116
|
-
deploy: `${npm} run build && wrangler deploy`,
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
if (usesTypescript(ctx)) {
|
|
120
|
-
scripts = {
|
|
121
|
-
...scripts,
|
|
122
|
-
"cf-typegen": `wrangler types --include-main-module=false ${typesPath}`,
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
return { scripts };
|
|
127
|
-
},
|
|
128
|
-
devScript: "dev",
|
|
129
|
-
deployScript: "deploy",
|
|
130
|
-
previewScript: "preview",
|
|
131
|
-
typesPath,
|
|
132
|
-
};
|
|
133
|
-
export default config;
|