Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for Windows builds in make install step #80

Closed
wants to merge 11 commits into from
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ precommit: test.dev
install:
go mod tidy
npm install
ifeq ($(OS), Windows_NT)
cd livebud
npm install
cd ..
else
(cd livebud && npm install)
endif
Copy link
Contributor

@matthewmueller matthewmueller May 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ifeq ($(OS), Windows_NT)
cd livebud
npm install
cd ..
else
(cd livebud && npm install)
endif
@ # Note: We don't use a subshell here to support Windows. See #79.
cd livebud
npm install
cd ..

I'd like to avoid conditionally checking the OS if we can. Since the windows version also works on linux and mac, let's just use that. I also just added a note to my future self not to accidentally change it back 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely understandable!! I just pushed up that change 😋

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @syke99! By the way, next time you can just hit the "Commit suggestion" button if the change works for you 😌

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, didn't even see that option until now 😂 Thanks, I'll use it next time 😋


##
# Examples
Expand Down
2 changes: 2 additions & 0 deletions runtime/generator/controller/controller.gotext
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ func ({{$action.Short}} *{{ $.Pascal }}{{$action.Pascal}}Action) handler(httpReq
{{- if $action.RespondJSON }}
{{- if $action.Results.Result }}
JSON: response.JSON({{ $action.Results.Result }}),
{{- else if $action.Results.IsOnlyError }}
JSON: response.Status(204),
{{- else }}
JSON: response.Status(200).Set("Content-Type", "application/json"),
{{- end }}
Expand Down
10 changes: 5 additions & 5 deletions runtime/generator/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -951,15 +951,14 @@ func TestNestedResource(t *testing.T) {
res, err = server.PatchJSON("/users/10", bytes.NewBufferString(`{"name": "matt", "age": 10}`))
is.NoErr(err)
is.NoErr(res.Expect(`
HTTP/1.1 200 OK
Content-Type: application/json
HTTP/1.1 204 No Content
Content-Length: 0
Date: Fri, 31 Dec 2021 00:00:00 GMT
`))
res, err = server.DeleteJSON("/users/10", nil)
is.NoErr(err)
is.NoErr(res.Expect(`
HTTP/1.1 200 OK
Content-Type: application/json
HTTP/1.1 204 No Content
Date: Fri, 31 Dec 2021 00:00:00 GMT
`))
}
Expand Down Expand Up @@ -1896,11 +1895,11 @@ func TestWorkingChangeWorking(t *testing.T) {
}

func TestEmptyActionWithView(t *testing.T) {
t.SkipNow()
is := is.New(t)
ctx := context.Background()
dir := t.TempDir()
bud := budtest.New(dir)
bud.NodeModules["svelte"] = version.Svelte
bud.Files["controller/controller.go"] = `
package controller
type Controller struct {}
Expand All @@ -1912,6 +1911,7 @@ func TestEmptyActionWithView(t *testing.T) {
app, err := project.Build(ctx)
is.NoErr(err)
is.NoErr(app.Exists("bud/.app/view/view.go"))
is.NoErr(app.Exists("bud/.app/controller/controller.go"))
is.NoErr(app.Exists("bud/.app/main.go"))
server, err := app.Start(ctx)
is.NoErr(err)
Expand Down
16 changes: 10 additions & 6 deletions runtime/generator/controller/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,13 @@ func isList(dataType string) bool {

func (results ActionResults) ViewResult() string {
propsKey := results.propsKey()
if propsKey == "" {
return results.Result()
}
out := new(strings.Builder)
out.WriteString(`map[string]interface{}{`)
out.WriteString(strconv.Quote(propsKey))
out.WriteString(":")
out.WriteString(results.Result())
if propsKey != "" {
out.WriteString(strconv.Quote(propsKey))
out.WriteString(":")
out.WriteString(results.Result())
}
out.WriteString(`},`)
return out.String()
}
Expand Down Expand Up @@ -199,6 +198,11 @@ func (results ActionResults) Error() string {
return ""
}

// Error expression is only return
func (results ActionResults) IsOnlyError() bool {
return len(results) == 1 && results[0].IsError
}

// ActionResult struct
type ActionResult struct {
Name string
Expand Down