| 11 | import { standardWatchFilePaths } from "../watchConfig"; |
| 12 | |
| 13 | export class Astro implements Framework { |
| 14 | id = "astro"; |
| 15 | name = "Astro"; |
| 16 | |
| 17 | async isMatch(path: string, packageManager: PackageManager): Promise<boolean> { |
| 18 | const configFilenames = [ |
| 19 | "astro.config.js", |
| 20 | "astro.config.mjs", |
| 21 | "astro.config.cjs", |
| 22 | "astro.config.ts", |
| 23 | ]; |
| 24 | //check for astro.config.mjs |
| 25 | const hasConfigFile = await someFileExists(path, configFilenames); |
| 26 | if (hasConfigFile) { |
| 27 | return true; |
| 28 | } |
| 29 | |
| 30 | //check for the astro package |
| 31 | const packageJsonContent = await readPackageJson(path); |
| 32 | if (packageJsonContent?.dependencies?.astro) { |
| 33 | return true; |
| 34 | } |
| 35 | |
| 36 | return false; |
| 37 | } |
| 38 | |
| 39 | async dependencies(): Promise<InstallPackage[]> { |
| 40 | return [ |
| 41 | { name: "@trigger.dev/sdk", tag: "latest" }, |
| 42 | { name: "@trigger.dev/astro", tag: "latest" }, |
| 43 | { name: "@trigger.dev/react", tag: "latest" }, |
| 44 | ]; |
| 45 | } |
| 46 | |
| 47 | possibleEnvFilenames(): string[] { |
| 48 | return [".env", ".env.development"]; |
| 49 | } |
| 50 | |
| 51 | async install(path: string, { typescript, endpointSlug }: ProjectInstallOptions): Promise<void> { |
| 52 | const pathAlias = await getPathAlias({ |
| 53 | projectPath: path, |
| 54 | isTypescriptProject: typescript, |
| 55 | extraDirectories: ["src"], |
| 56 | }); |
| 57 | const templatesDir = pathModule.join(templatesPath(), "astro"); |
| 58 | const srcFolder = pathModule.join(path, "src"); |
| 59 | const fileExtension = typescript ? ".ts" : ".js"; |
| 60 | |
| 61 | //create src/pages/api/trigger.js |
| 62 | const apiRoutePath = pathModule.join(srcFolder, "pages", "api", `trigger${fileExtension}`); |
| 63 | const apiRouteResult = await createFileFromTemplate({ |
| 64 | templatePath: pathModule.join(templatesDir, "apiRoute.js"), |
| 65 | replacements: { |
| 66 | routePathPrefix: pathAlias ? pathAlias + "/" : "../../", |
| 67 | }, |
| 68 | outputPath: apiRoutePath, |
| 69 | }); |
| 70 | if (!apiRouteResult.success) { |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…