-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #134 from zeabur/feat/bun-framework
chore: add bun framework detection
- Loading branch information
Showing
2 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters