Skip to content

Commit 03ec951

Browse files
authored
graduate astro + workers template (#8402)
* add test for astro workers template * graduate astro * changeset * remove headers and redirects from assets ignore
1 parent a7bd79b commit 03ec951

File tree

18 files changed

+146
-106
lines changed

18 files changed

+146
-106
lines changed

.changeset/pink-crews-throw.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"create-cloudflare": patch
3+
---
4+
5+
graduate Astro Workers + Assets template from experimental
6+
7+
You no longer need to pass in --experimental to access the Workers + Assets version of the template.

packages/create-cloudflare/e2e-tests/frameworks/framework-test-config.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,36 @@ import { keys, LONG_TIMEOUT } from "../helpers";
33
// These are ordered based on speed and reliability for ease of debugging
44
export default function getFrameworkTestConfig(pm: string) {
55
return {
6-
astro: {
6+
"astro:pages": {
7+
argv: ["--platform", "pages"],
8+
testCommitMessage: true,
9+
unsupportedOSs: ["win32"],
10+
verifyDeploy: {
11+
route: "/",
12+
expectedText: "Hello, Astronaut!",
13+
},
14+
verifyPreview: {
15+
route: "/test",
16+
expectedText: "C3_TEST",
17+
},
18+
verifyBuild: {
19+
outputDir: "./dist",
20+
script: "build",
21+
route: "/test",
22+
expectedText: "C3_TEST",
23+
},
24+
flags: [
25+
"--skip-houston",
26+
"--no-install",
27+
"--no-git",
28+
"--template",
29+
"blog",
30+
"--typescript",
31+
"strict",
32+
],
33+
},
34+
"astro:workers": {
35+
argv: ["--platform", "workers"],
736
testCommitMessage: true,
837
unsupportedOSs: ["win32"],
938
verifyDeploy: {

packages/create-cloudflare/src/templates.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {
1818
writeFile,
1919
writeJSON,
2020
} from "helpers/files";
21-
import astroTemplateExperimental from "templates-experimental/astro/c3";
2221
import honoTemplateExperimental from "templates-experimental/hono/c3";
2322
import nextTemplateExperimental from "templates-experimental/next/c3";
2423
import qwikTemplateExperimental from "templates-experimental/qwik/c3";
@@ -176,7 +175,6 @@ export type TemplateMap = Record<
176175
export function getFrameworkMap({ experimental = false }): TemplateMap {
177176
if (experimental) {
178177
return {
179-
astro: astroTemplateExperimental,
180178
hono: honoTemplateExperimental,
181179
next: nextTemplateExperimental,
182180
qwik: qwikTemplateExperimental,

packages/create-cloudflare/templates-experimental/astro/templates/js/public/.assetsignore

Lines changed: 0 additions & 4 deletions
This file was deleted.

packages/create-cloudflare/templates-experimental/astro/templates/ts/public/.assetsignore

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 5 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,9 @@
1-
import { logRaw, updateStatus } from "@cloudflare/cli";
2-
import { blue, brandColor, dim } from "@cloudflare/cli/colors";
3-
import { runFrameworkGenerator } from "frameworks/index";
4-
import { transformFile } from "helpers/codemod";
5-
import { runCommand } from "helpers/command";
6-
import { usesTypescript } from "helpers/files";
7-
import { detectPackageManager } from "helpers/packageManagers";
8-
import * as recast from "recast";
9-
import type { TemplateConfig } from "../../src/templates";
10-
import type { C3Context, PackageJson } from "types";
1+
import pages from "./pages/c3";
2+
import workers from "./workers/c3";
3+
import type { MultiPlatformTemplateConfig } from "../../src/templates";
114

12-
const { npx } = detectPackageManager();
13-
14-
const generate = async (ctx: C3Context) => {
15-
await runFrameworkGenerator(ctx, [ctx.project.name, "--no-install"]);
16-
17-
logRaw(""); // newline
18-
};
19-
20-
const configure = async () => {
21-
await runCommand([npx, "astro", "add", "cloudflare", "-y"], {
22-
silent: true,
23-
startText: "Installing adapter",
24-
doneText: `${brandColor("installed")} ${dim(
25-
`via \`${npx} astro add cloudflare\``,
26-
)}`,
27-
});
28-
29-
updateAstroConfig();
30-
};
31-
32-
const updateAstroConfig = () => {
33-
const filePath = "astro.config.mjs";
34-
35-
updateStatus(`Updating configuration in ${blue(filePath)}`);
36-
37-
transformFile(filePath, {
38-
visitCallExpression: function (n) {
39-
const callee = n.node.callee as recast.types.namedTypes.Identifier;
40-
if (callee.name !== "cloudflare") {
41-
return this.traverse(n);
42-
}
43-
44-
const b = recast.types.builders;
45-
n.node.arguments = [
46-
b.objectExpression([
47-
b.objectProperty(
48-
b.identifier("platformProxy"),
49-
b.objectExpression([
50-
b.objectProperty(b.identifier("enabled"), b.booleanLiteral(true)),
51-
]),
52-
),
53-
]),
54-
];
55-
56-
return false;
57-
},
58-
});
59-
};
60-
61-
const config: TemplateConfig = {
62-
configVersion: 1,
63-
id: "astro",
64-
frameworkCli: "create-astro",
65-
platform: "pages",
5+
const config: MultiPlatformTemplateConfig = {
666
displayName: "Astro",
67-
copyFiles: {
68-
async selectVariant(ctx) {
69-
// Note: this `selectVariant` function should not be needed
70-
// this is just a quick workaround until
71-
// https://github.com/cloudflare/workers-sdk/issues/7495
72-
// is resolved
73-
return usesTypescript(ctx) ? "ts" : "js";
74-
},
75-
variants: {
76-
js: {
77-
path: "./templates/js",
78-
},
79-
ts: {
80-
path: "./templates/ts",
81-
},
82-
},
83-
},
84-
devScript: "dev",
85-
deployScript: "deploy",
86-
previewScript: "preview",
87-
generate,
88-
configure,
89-
transformPackageJson: async (pkgJson: PackageJson, ctx: C3Context) => ({
90-
scripts: {
91-
deploy: `astro build && wrangler pages deploy`,
92-
preview: `astro build && wrangler pages dev`,
93-
...(usesTypescript(ctx) && { "cf-typegen": `wrangler types` }),
94-
},
95-
}),
7+
platformVariants: { pages, workers },
968
};
979
export default config;
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import { logRaw, updateStatus } from "@cloudflare/cli";
2+
import { blue, brandColor, dim } from "@cloudflare/cli/colors";
3+
import { runFrameworkGenerator } from "frameworks/index";
4+
import { transformFile } from "helpers/codemod";
5+
import { runCommand } from "helpers/command";
6+
import { usesTypescript } from "helpers/files";
7+
import { detectPackageManager } from "helpers/packageManagers";
8+
import * as recast from "recast";
9+
import type { TemplateConfig } from "../../../src/templates";
10+
import type { C3Context, PackageJson } from "types";
11+
12+
const { npx } = detectPackageManager();
13+
14+
const generate = async (ctx: C3Context) => {
15+
await runFrameworkGenerator(ctx, [ctx.project.name, "--no-install"]);
16+
17+
logRaw(""); // newline
18+
};
19+
20+
const configure = async () => {
21+
await runCommand([npx, "astro", "add", "cloudflare", "-y"], {
22+
silent: true,
23+
startText: "Installing adapter",
24+
doneText: `${brandColor("installed")} ${dim(
25+
`via \`${npx} astro add cloudflare\``,
26+
)}`,
27+
});
28+
29+
updateAstroConfig();
30+
};
31+
32+
const updateAstroConfig = () => {
33+
const filePath = "astro.config.mjs";
34+
35+
updateStatus(`Updating configuration in ${blue(filePath)}`);
36+
37+
transformFile(filePath, {
38+
visitCallExpression: function (n) {
39+
const callee = n.node.callee as recast.types.namedTypes.Identifier;
40+
if (callee.name !== "cloudflare") {
41+
return this.traverse(n);
42+
}
43+
44+
const b = recast.types.builders;
45+
n.node.arguments = [
46+
b.objectExpression([
47+
b.objectProperty(
48+
b.identifier("platformProxy"),
49+
b.objectExpression([
50+
b.objectProperty(b.identifier("enabled"), b.booleanLiteral(true)),
51+
]),
52+
),
53+
]),
54+
];
55+
56+
return false;
57+
},
58+
});
59+
};
60+
61+
const config: TemplateConfig = {
62+
configVersion: 1,
63+
id: "astro",
64+
frameworkCli: "create-astro",
65+
platform: "pages",
66+
displayName: "Astro",
67+
path: "templates/astro/pages",
68+
copyFiles: {
69+
async selectVariant(ctx) {
70+
// Note: this `selectVariant` function should not be needed
71+
// this is just a quick workaround until
72+
// https://github.com/cloudflare/workers-sdk/issues/7495
73+
// is resolved
74+
return usesTypescript(ctx) ? "ts" : "js";
75+
},
76+
variants: {
77+
js: {
78+
path: "./templates/js",
79+
},
80+
ts: {
81+
path: "./templates/ts",
82+
},
83+
},
84+
},
85+
devScript: "dev",
86+
deployScript: "deploy",
87+
previewScript: "preview",
88+
generate,
89+
configure,
90+
transformPackageJson: async (pkgJson: PackageJson, ctx: C3Context) => ({
91+
scripts: {
92+
deploy: `astro build && wrangler pages deploy`,
93+
preview: `astro build && wrangler pages dev`,
94+
...(usesTypescript(ctx) && { "cf-typegen": `wrangler types` }),
95+
},
96+
}),
97+
};
98+
export default config;
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)