mirror of
https://github.com/hanzoai/pack.git
synced 2026-09-30 23:43:13 +00:00
- Migrate module path to github.com/hanzoai/pack across all Go packages - Remove legacy upstream docs and competitor brand references - Modernize LLM.md and mise.toml for pristine Hanzo Pack builder
71 lines
2.1 KiB
Go
71 lines
2.1 KiB
Go
package node
|
|
|
|
import (
|
|
"regexp"
|
|
"strings"
|
|
|
|
"github.com/hanzoai/pack/core/generate"
|
|
)
|
|
|
|
const (
|
|
DefaultAstroOutputDirectory = "dist"
|
|
)
|
|
|
|
func (p *NodeProvider) isAstroPackage(pkg *WorkspacePackage, ctx *generate.GenerateContext) bool {
|
|
astroConfigMjs := "astro.config.mjs"
|
|
astroConfigTs := "astro.config.ts"
|
|
if pkg.Path != "" {
|
|
astroConfigMjs = pkg.Path + "/astro.config.mjs"
|
|
astroConfigTs = pkg.Path + "/astro.config.ts"
|
|
}
|
|
|
|
hasAstroConfig := ctx.App.HasFile(astroConfigMjs) || ctx.App.HasFile(astroConfigTs)
|
|
hasAstroBuildCommand := strings.Contains(strings.ToLower(pkg.PackageJson.GetScript("build")), "astro build")
|
|
|
|
return hasAstroConfig && hasAstroBuildCommand
|
|
}
|
|
|
|
func (p *NodeProvider) isAstro(ctx *generate.GenerateContext) bool {
|
|
return p.isAstroPackage(p.workspace.Root, ctx)
|
|
}
|
|
|
|
func (p *NodeProvider) isAstroSPA(ctx *generate.GenerateContext) bool {
|
|
if !p.isAstro(ctx) {
|
|
return false
|
|
}
|
|
|
|
configFileContents := p.getAstroConfigFileContents(ctx)
|
|
hasServerOutput := strings.Contains(configFileContents, "output: 'server'")
|
|
hasAdapter := p.hasDependency("@astrojs/node") || p.hasDependency("@astrojs/vercel") || p.hasDependency("@astrojs/cloudflare") || p.hasDependency("@astrojs/netlify")
|
|
|
|
return !hasServerOutput && !hasAdapter
|
|
}
|
|
|
|
func (p *NodeProvider) getAstroOutputDirectory(ctx *generate.GenerateContext) string {
|
|
configFileContents := p.getAstroConfigFileContents(ctx)
|
|
if configFileContents != "" {
|
|
// Look for outDir in config
|
|
outDirRegex := regexp.MustCompile(`outDir:\s*['"](.+?)['"]`)
|
|
matches := outDirRegex.FindStringSubmatch(configFileContents)
|
|
if len(matches) > 1 {
|
|
return matches[1]
|
|
}
|
|
}
|
|
|
|
return DefaultAstroOutputDirectory
|
|
}
|
|
|
|
func (p *NodeProvider) getAstroConfigFileContents(ctx *generate.GenerateContext) string {
|
|
_, contents, _ := ctx.App.ReadFirstFileOf("astro.config.mjs", "astro.config.ts")
|
|
return contents
|
|
}
|
|
|
|
// TODO feels like we should be able to specify this in the start command and avoid injecting additional vars into the container?
|
|
func (p *NodeProvider) getAstroEnvVars() map[string]string {
|
|
envVars := map[string]string{
|
|
"HOST": "0.0.0.0",
|
|
}
|
|
|
|
return envVars
|
|
}
|