Skip to content

Commit

Permalink
Merge pull request #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 authored Sep 14, 2023
2 parents 01b406b + 969e850 commit 1410061
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 1410061

Please sign in to comment.