Skip to content

Commit

Permalink
Merge pull request zeabur#134 from zeabur/feat/bun-framework
Browse files Browse the repository at this point in the history
chore: add bun framework detection
  • Loading branch information
MichaelYuhe committed Sep 14, 2023
2 parents 720d69e + d1abd4b commit 27912f7
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
47 changes: 46 additions & 1 deletion internal/bun/plan.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,59 @@
package bun

import (
"log"

"github.com/moznion/go-optional"
"github.com/spf13/afero"
"github.com/zeabur/zbpack/internal/nodejs"
"github.com/zeabur/zbpack/pkg/types"
)

type bunPlanContext struct {
PackageJSON nodejs.PackageJSON
Src afero.Fs

Framework optional.Option[types.BunFramework]
}

// GetMetaOptions is the options for GetMeta.
type GetMetaOptions nodejs.GetMetaOptions

// GetMeta gets the metadata of the Node.js project.
func GetMeta(opt GetMetaOptions) types.PlanMeta {
return nodejs.GetMeta(nodejs.GetMetaOptions(opt))
packageJSON, err := nodejs.DeserializePackageJSON(opt.Src)
if err != nil {
log.Printf("Failed to read package.json: %v", err)
// not fatal
}

ctx := &bunPlanContext{
PackageJSON: packageJSON,
Src: opt.Src,
}

meta := nodejs.GetMeta(nodejs.GetMetaOptions(opt))

framework := DetermineFramework(ctx)
meta["framework"] = string(framework)

return meta
}

// DetermineFramework determines the framework of the Bun project.
func DetermineFramework(ctx *bunPlanContext) types.BunFramework {
fw := &ctx.Framework
packageJSON := ctx.PackageJSON

if framework, err := fw.Take(); err == nil {
return framework
}

if _, isElysia := packageJSON.Dependencies["elysia"]; isElysia {
*fw = optional.Some(types.BunFrameworkElysia)
return fw.Unwrap()
}

*fw = optional.Some(types.BunFrameworkNone)
return fw.Unwrap()
}
9 changes: 9 additions & 0 deletions pkg/types/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,12 @@ const (
)

//revive:enable:exported

// BunFramework represents the framework of a Bun project.
type BunFramework string

//revive:enable:exported
const (
BunFrameworkElysia BunFramework = "elysia"
BunFrameworkNone BunFramework = "none"
)

0 comments on commit 27912f7

Please sign in to comment.