core/providers/node/astro.go
core/providers/node/astro.goBrowse 1970 files
561 tokens
2,147 bytes
Token encoding: o200k_base
Snapshot 21a254f
← Back to SKILL.md
1package node2 3import (4 "regexp"5 "strings"6 7 "github.com/railwayapp/railpack/core/generate"8)9 10const (11 DefaultAstroOutputDirectory = "dist"12)13 14func (p *NodeProvider) isAstroPackage(pkg *WorkspacePackage, ctx *generate.GenerateContext) bool {15 astroConfigMjs := "astro.config.mjs"16 astroConfigTs := "astro.config.ts"17 if pkg.Path != "" {18 astroConfigMjs = pkg.Path + "/astro.config.mjs"19 astroConfigTs = pkg.Path + "/astro.config.ts"20 }21 22 hasAstroConfig := ctx.App.HasFile(astroConfigMjs) || ctx.App.HasFile(astroConfigTs)23 hasAstroBuildCommand := strings.Contains(strings.ToLower(pkg.PackageJson.GetScript("build")), "astro build")24 25 return hasAstroConfig && hasAstroBuildCommand26}27 28func (p *NodeProvider) isAstro(ctx *generate.GenerateContext) bool {29 return p.isAstroPackage(p.workspace.Root, ctx)30}31 32func (p *NodeProvider) isAstroSPA(ctx *generate.GenerateContext) bool {33 if !p.isAstro(ctx) {34 return false35 }36 37 configFileContents := p.getAstroConfigFileContents(ctx)38 hasServerOutput := strings.Contains(configFileContents, "output: 'server'")39 hasAdapter := p.hasDependency("@astrojs/node") || p.hasDependency("@astrojs/vercel") || p.hasDependency("@astrojs/cloudflare") || p.hasDependency("@astrojs/netlify")40 41 return !hasServerOutput && !hasAdapter42}43 44func (p *NodeProvider) getAstroOutputDirectory(ctx *generate.GenerateContext) string {45 configFileContents := p.getAstroConfigFileContents(ctx)46 if configFileContents != "" {47 // Look for outDir in config48 outDirRegex := regexp.MustCompile(`outDir:\s*['"](.+?)['"]`)49 matches := outDirRegex.FindStringSubmatch(configFileContents)50 if len(matches) > 1 {51 return matches[1]52 }53 }54 55 return DefaultAstroOutputDirectory56}57 58func (p *NodeProvider) getAstroConfigFileContents(ctx *generate.GenerateContext) string {59 _, contents, _ := ctx.App.ReadFirstFileOf("astro.config.mjs", "astro.config.ts")60 return contents61}62 63// TODO feels like we should be able to specify this in the start command and avoid injecting additional vars into the container?64func (p *NodeProvider) getAstroEnvVars() map[string]string {65 envVars := map[string]string{66 "HOST": "0.0.0.0",67 }68 69 return envVars70}71