Skip to content

Commit

Permalink
refactor!: Remove deprecated Custom*Command and OutputDir (#364)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuaanlin authored Oct 19, 2024
2 parents 86c5d5c + 761ebcc commit aa8f872
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 279 deletions.
3 changes: 0 additions & 3 deletions internal/bun/identify.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ func (i *identify) PlanMeta(options plan.NewPlannerOptions) types.PlanMeta {
GetMetaOptions{
Src: options.Source,
Config: options.Config,
CustomBuildCmd: options.CustomBuildCommand,
CustomStartCmd: options.CustomStartCommand,
OutputDir: options.OutputDir,
Bun: true,
},
)
Expand Down
7 changes: 2 additions & 5 deletions internal/nodejs/identify.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@ func (i *identify) Match(fs afero.Fs) bool {
func (i *identify) PlanMeta(options plan.NewPlannerOptions) types.PlanMeta {
return GetMeta(
GetMetaOptions{
Src: options.Source,
Config: options.Config,
CustomBuildCmd: options.CustomBuildCommand,
CustomStartCmd: options.CustomStartCommand,
OutputDir: options.OutputDir,
Src: options.Source,
Config: options.Config,
},
)
}
Expand Down
23 changes: 1 addition & 22 deletions internal/nodejs/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -947,10 +947,6 @@ type GetMetaOptions struct {
Src afero.Fs
Config plan.ImmutableProjectConfiguration

CustomBuildCmd *string
CustomStartCmd *string
OutputDir *string

Bun bool
}

Expand Down Expand Up @@ -989,9 +985,6 @@ func GetMeta(opt GetMetaOptions) types.PlanMeta {
meta["installCmd"] = installCmd

buildCmd := GetBuildCmd(ctx)
if opt.CustomBuildCmd != nil && *opt.CustomBuildCmd != "" {
buildCmd = *opt.CustomBuildCmd
}
meta["buildCmd"] = buildCmd

serverless := getServerless(ctx)
Expand All @@ -1000,29 +993,15 @@ func GetMeta(opt GetMetaOptions) types.PlanMeta {
}

// only set outputDir if there is no custom start command (because if there is, it shouldn't be a static project)
if opt.CustomStartCmd == nil || *opt.CustomStartCmd == "" {

if opt.OutputDir != nil && *opt.OutputDir != "" {
if strings.HasPrefix(*opt.OutputDir, "/") {
meta["outputDir"] = strings.TrimPrefix(*opt.OutputDir, "/")
} else {
meta["outputDir"] = *opt.OutputDir
}
return meta
}

if buildCmd == "" {
staticOutputDir := GetStaticOutputDir(ctx)
if staticOutputDir != "" {
meta["outputDir"] = staticOutputDir
return meta
}

}

startCmd := GetStartCmd(ctx)
if opt.CustomStartCmd != nil && *opt.CustomStartCmd != "" {
startCmd = *opt.CustomStartCmd
}
meta["startCmd"] = startCmd

return meta
Expand Down
4 changes: 2 additions & 2 deletions internal/php/identify.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ func (i *identify) PlanMeta(options plan.NewPlannerOptions) types.PlanMeta {
deps := DetermineAptDependencies(options.Source, server)
exts := DeterminePHPExtensions(options.Source)
app, property := DetermineApplication(options.Source)
buildCommand := DetermineBuildCommand(options.Source, options.Config, options.CustomBuildCommand)
startCommand := DetermineStartCommand(options.Config, options.CustomStartCommand)
buildCommand := DetermineBuildCommand(options.Source, options.Config)
startCommand := DetermineStartCommand(options.Config)

// Some meta will be added to the plan dynamically later.
meta := types.PlanMeta{
Expand Down
11 changes: 3 additions & 8 deletions internal/php/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,10 @@ func determineStartupFunction(config plan.ImmutableProjectConfiguration) string
}

// DetermineStartCommand determines the start command of the project.
func DetermineStartCommand(config plan.ImmutableProjectConfiguration, startCommand *string) string {
func DetermineStartCommand(config plan.ImmutableProjectConfiguration) string {
completeStartCommand := determineStartupFunction(config)

if startCommand != nil {
completeStartCommand += *startCommand
} else if startCommand, err := plan.Cast(config.Get(plan.ConfigStartCommand), cast.ToStringE).Take(); err == nil {
if startCommand, err := plan.Cast(config.Get(plan.ConfigStartCommand), cast.ToStringE).Take(); err == nil {
completeStartCommand += startCommand
} else {
completeStartCommand += "_startup"
Expand All @@ -201,10 +199,7 @@ func DetermineStartCommand(config plan.ImmutableProjectConfiguration, startComma
}

// DetermineBuildCommand determines the build command of the project.
func DetermineBuildCommand(source afero.Fs, config plan.ImmutableProjectConfiguration, buildCommand *string) string {
if buildCommand != nil {
return *buildCommand
}
func DetermineBuildCommand(source afero.Fs, config plan.ImmutableProjectConfiguration) string {
if buildCommand, err := plan.Cast(config.Get(plan.ConfigBuildCommand), cast.ToStringE).Take(); err == nil {
return buildCommand
}
Expand Down
36 changes: 8 additions & 28 deletions internal/php/plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package php_test
import (
"testing"

"github.com/samber/lo"
"github.com/spf13/afero"
"github.com/stretchr/testify/assert"
"github.com/zeabur/zbpack/internal/php"
Expand Down Expand Up @@ -136,15 +135,15 @@ func TestDetermineApplication_AcgFaka(t *testing.T) {

func TestDetermineStartCommand_Default(t *testing.T) {
config := plan.NewProjectConfigurationFromFs(afero.NewMemMapFs(), "")
command := php.DetermineStartCommand(config, nil)
command := php.DetermineStartCommand(config)

assert.Contains(t, command, "nginx; php-fpm")
}

func TestDetermineStartCommand_Swoole(t *testing.T) {
config := plan.NewProjectConfigurationFromFs(afero.NewMemMapFs(), "")
config.Set(php.ConfigLaravelOctaneServer, php.OctaneServerSwoole)
command := php.DetermineStartCommand(config, nil)
command := php.DetermineStartCommand(config)

assert.Contains(t, command, "php artisan octane:start --server=swoole --host=0.0.0.0 --port=8080")
}
Expand All @@ -154,15 +153,15 @@ func TestDetermineStartCommand_Roadrunner(t *testing.T) {

config := plan.NewProjectConfigurationFromFs(afero.NewMemMapFs(), "")
config.Set(php.ConfigLaravelOctaneServer, php.OctaneServerRoadrunner)
command := php.DetermineStartCommand(config, nil)
command := php.DetermineStartCommand(config)

assert.Contains(t, command, "nginx; php-fpm")
}

func TestDetermineStartCommand_UnknownOctane(t *testing.T) {
config := plan.NewProjectConfigurationFromFs(afero.NewMemMapFs(), "")
config.Set(php.ConfigLaravelOctaneServer, "unknown")
command := php.DetermineStartCommand(config, nil)
command := php.DetermineStartCommand(config)

assert.Contains(t, command, "nginx; php-fpm")
}
Expand All @@ -173,24 +172,15 @@ func TestDetermineStartCommand_CustomInConfig(t *testing.T) {
config := plan.NewProjectConfigurationFromFs(afero.NewMemMapFs(), "")
config.Set(plan.ConfigStartCommand, expectedCommand)

actualCommand := php.DetermineStartCommand(config, nil)

assert.Contains(t, actualCommand, expectedCommand)
}

func TestDetermineStartCommand_CustomInOptions(t *testing.T) {
const expectedCommand = "php artisan serve; _startup"

config := plan.NewProjectConfigurationFromFs(afero.NewMemMapFs(), "")
actualCommand := php.DetermineStartCommand(config, lo.ToPtr(expectedCommand))
actualCommand := php.DetermineStartCommand(config)

assert.Contains(t, actualCommand, expectedCommand)
}

func TestDetermineBuildCommand_Default(t *testing.T) {
fs := afero.NewMemMapFs()
config := plan.NewProjectConfigurationFromFs(fs, "")
command := php.DetermineBuildCommand(fs, config, nil)
command := php.DetermineBuildCommand(fs, config)

assert.Equal(t, "", command)
}
Expand All @@ -202,17 +192,7 @@ func TestDetermineBuildCommand_CustomInConfig(t *testing.T) {
config := plan.NewProjectConfigurationFromFs(fs, "")
config.Set(plan.ConfigBuildCommand, expectedCommand)

actualCommand := php.DetermineBuildCommand(fs, config, nil)

assert.Equal(t, expectedCommand, actualCommand)
}

func TestDetermineBuildCommand_CustomInOptions(t *testing.T) {
const expectedCommand = "php bin/build"

fs := afero.NewMemMapFs()
config := plan.NewProjectConfigurationFromFs(fs, "")
actualCommand := php.DetermineBuildCommand(fs, config, lo.ToPtr(expectedCommand))
actualCommand := php.DetermineBuildCommand(fs, config)

assert.Equal(t, expectedCommand, actualCommand)
}
Expand All @@ -225,7 +205,7 @@ func TestDetermineBuildCommand_NPMBuild(t *testing.T) {
}
}`), 0o644)
config := plan.NewProjectConfigurationFromFs(fs, "")
command := php.DetermineBuildCommand(fs, config, nil)
command := php.DetermineBuildCommand(fs, config)

assert.Equal(t, "npm install && npm run build", command)
}
9 changes: 3 additions & 6 deletions pkg/plan/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,9 @@ type planner struct {

// NewPlannerOptions is the options for NewPlanner.
type NewPlannerOptions struct {
Source afero.Fs
Config ImmutableProjectConfiguration
SubmoduleName string
CustomBuildCommand *string
CustomStartCommand *string
OutputDir *string
Source afero.Fs
Config ImmutableProjectConfiguration
SubmoduleName string

AWSConfig *AWSConfig
}
Expand Down
55 changes: 0 additions & 55 deletions pkg/zeaburpack/config.go

This file was deleted.

107 changes: 0 additions & 107 deletions pkg/zeaburpack/config_test.go

This file was deleted.

Loading

0 comments on commit aa8f872

Please sign in to comment.