70bf21e064
Deploy (to testing) and Test Playground Preview Worker / Deploy Playground Preview Worker (testing) (push) Has been skipped
Deploy Workers Shared Staging / Deploy Workers Shared Staging (push) Failing after 0s
Prerelease / build (push) Has been skipped
Handle Changesets / Handle Changesets (push) Has been cancelled
Semgrep OSS scan / semgrep-oss (push) Has been cancelled
85 lines
1.9 KiB
TypeScript
85 lines
1.9 KiB
TypeScript
import { logRaw } from "@cloudflare/cli-shared-helpers";
|
|
import { inputPrompt } from "@cloudflare/cli-shared-helpers/interactive";
|
|
import { runFrameworkGenerator } from "frameworks/index";
|
|
import { detectPackageManager } from "helpers/packageManagers";
|
|
import type { TemplateConfig } from "../../../src/templates";
|
|
import type { C3Context } from "types";
|
|
|
|
const { npm } = detectPackageManager();
|
|
|
|
const generate = async (ctx: C3Context) => {
|
|
const variant = await getVariant(ctx);
|
|
|
|
await runFrameworkGenerator(ctx, [
|
|
ctx.project.name,
|
|
"--template",
|
|
variant,
|
|
"--no-immediate",
|
|
]);
|
|
|
|
logRaw("");
|
|
};
|
|
|
|
const variantsOptions = [
|
|
{
|
|
value: "react-ts",
|
|
label: "TypeScript",
|
|
},
|
|
{
|
|
value: "react-swc-ts",
|
|
label: "TypeScript + SWC",
|
|
},
|
|
{
|
|
value: "react",
|
|
label: "JavaScript",
|
|
},
|
|
{
|
|
value: "react-swc",
|
|
label: "JavaScript + SWC",
|
|
},
|
|
];
|
|
|
|
async function getVariant(ctx: C3Context) {
|
|
if (ctx.args.variant) {
|
|
const selected = variantsOptions.find((v) => v.value === ctx.args.variant);
|
|
if (!selected) {
|
|
throw new Error(
|
|
`Unknown variant "${ctx.args.variant}". Valid variants are: ${variantsOptions.map((v) => v.value).join(", ")}`
|
|
);
|
|
}
|
|
return selected.value;
|
|
}
|
|
|
|
return await inputPrompt({
|
|
type: "select",
|
|
question: "Select a variant:",
|
|
label: "variant",
|
|
options: variantsOptions,
|
|
defaultValue: variantsOptions[0].value,
|
|
});
|
|
}
|
|
|
|
const config: TemplateConfig = {
|
|
configVersion: 1,
|
|
id: "react",
|
|
// React's documentation now recommends using create-vite.
|
|
frameworkCli: "create-vite",
|
|
displayName: "React",
|
|
platform: "pages",
|
|
hidden: true,
|
|
path: "templates/react/pages",
|
|
copyFiles: { path: "./templates" },
|
|
generate,
|
|
transformPackageJson: async () => ({
|
|
scripts: {
|
|
deploy: `${npm} run build && wrangler pages deploy`,
|
|
preview: `${npm} run build && wrangler pages dev`,
|
|
"cf-typegen": `wrangler types`,
|
|
},
|
|
}),
|
|
devScript: "dev",
|
|
deployScript: "deploy",
|
|
previewScript: "preview",
|
|
};
|
|
export default config;
|