|
| 1 | +import { updateStatus } from "@cloudflare/cli"; |
| 2 | +import { blue } from "@cloudflare/cli/colors"; |
| 3 | +import * as recast from "recast"; |
| 4 | +import { getDevCompatibilityDate } from "../../utils/compatibility-date"; |
| 5 | +import { mergeObjectProperties, transformFile } from "../c3-vendor/codemod"; |
| 6 | +import { usesTypescript } from "../uses-typescript"; |
| 7 | +import { Framework } from "."; |
| 8 | +import type { ConfigurationOptions, ConfigurationResults } from "."; |
| 9 | + |
| 10 | +export class SolidStart extends Framework { |
| 11 | + async configure({ |
| 12 | + projectPath, |
| 13 | + dryRun, |
| 14 | + }: ConfigurationOptions): Promise<ConfigurationResults> { |
| 15 | + if (!dryRun) { |
| 16 | + const filePath = `app.config.${usesTypescript(projectPath) ? "ts" : "js"}`; |
| 17 | + |
| 18 | + const compatDate = getDevCompatibilityDate(undefined); |
| 19 | + |
| 20 | + updateStatus(`Updating configuration in ${blue(filePath)}`); |
| 21 | + |
| 22 | + transformFile(filePath, { |
| 23 | + visitCallExpression: function (n) { |
| 24 | + const callee = n.node.callee as recast.types.namedTypes.Identifier; |
| 25 | + if (callee.name !== "defineConfig") { |
| 26 | + return this.traverse(n); |
| 27 | + } |
| 28 | + |
| 29 | + const b = recast.types.builders; |
| 30 | + mergeObjectProperties( |
| 31 | + n.node.arguments[0] as recast.types.namedTypes.ObjectExpression, |
| 32 | + [ |
| 33 | + b.objectProperty( |
| 34 | + b.identifier("server"), |
| 35 | + b.objectExpression([ |
| 36 | + // preset: "cloudflare_module" |
| 37 | + b.objectProperty( |
| 38 | + b.identifier("preset"), |
| 39 | + b.stringLiteral("cloudflare_module") |
| 40 | + ), |
| 41 | + b.objectProperty( |
| 42 | + b.identifier("compatibilityDate"), |
| 43 | + b.stringLiteral(compatDate) |
| 44 | + ), |
| 45 | + ]) |
| 46 | + ), |
| 47 | + ] |
| 48 | + ); |
| 49 | + |
| 50 | + return false; |
| 51 | + }, |
| 52 | + }); |
| 53 | + } |
| 54 | + |
| 55 | + return { |
| 56 | + wranglerConfig: { |
| 57 | + main: "./.output/server/index.mjs", |
| 58 | + compatibility_flags: ["nodejs_compat"], |
| 59 | + assets: { |
| 60 | + binding: "ASSETS", |
| 61 | + directory: "./.output/public", |
| 62 | + }, |
| 63 | + }, |
| 64 | + }; |
| 65 | + } |
| 66 | +} |
0 commit comments