-
-
Notifications
You must be signed in to change notification settings - Fork 179
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
Updating scaffolding to create default.css #254
base: main
Are you sure you want to change the base?
Conversation
Thanks for the PR @ralfiannor and for kicking this off! I don't want to remove the default.css without providing a solution to the goal. I've wrote my thoughts up in #253. Let me know if you want to drive one of those solutions forward or if you have any other ideas! |
Update master
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this! I'd just like us to clean a few things up and add a few more tests (maybe in framework/public/public_test.go) and then I think we're good to go!
Fix staticcheck issues and add staticcheck to ci (livebud#263)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just reviewed. This is getting closer @ralfiannor, thank you!
internal/embedded/embedded.go
Outdated
// EmptyCss reset the default css data | ||
func EmptyCss() []byte { | ||
return []byte("/* No Default CSS Loaded */") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be better if the view didn't include the <link />
if a public/default.css
isn't present since that would avoid a roundtrip for this CSS sheet.
Then we can also remove this function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
internal/cli/cli.go
Outdated
@@ -49,6 +49,7 @@ func (c *CLI) Run(ctx context.Context, args ...string) error { | |||
cmd := create.New(cmd, c.in) | |||
cli := cli.Command("create", "create a new app") | |||
cli.Arg("dir").String(&cmd.Dir) | |||
cli.Flag("css", "add a css").String(&cmd.Css).Default("normalize") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove this flag for now, I'm not ready to expose it just yet, especially since it's not really possible to select an alternative.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
framework/public/public_test.go
Outdated
res, err = app.Get("/default.css") | ||
is.NoErr(err) | ||
is.Equal(200, res.Status()) | ||
is.Equal(res.Body().Bytes(), defaultCss2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit hard to follow these changes because there are new conditions added to existing tests.
Let's try to only touch existing tests that need to be updated for the new behavior, then add new tests for the new behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted. No need to update on public.go
just update on ssr.go
framework/view/ssr/svelte.js
Outdated
@@ -327,7 +327,7 @@ var defaultLayout = { | |||
<html> | |||
<head> | |||
<meta charset="utf-8"/> | |||
<style>${defaultCSS}</style> | |||
<link rel="stylesheet" href="default.css" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mind trying to feed the configuration through so you can remove this if public/default.css
doesn't exist? Let me know if it's difficult and I'll give it a go in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will try. I will add the checking file existing in ssr.go
but will call our logic each page loaded. Is it okay ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be done at compile time actually. Do you know how to do this?
I just realized we should also do the same thing for |
update from remote branch
revert the header with chunked change overlay fs to bud fs
1e32ae5
to
f721555
Compare
Can we do it on another PR? |
Thanks for continuing to push this forward @ralfiannor! Do you happen to know the condition in which Go is adding/removing Let's just remove the |
Yes, it happen when we added the CSS into |
Thanks @ralfiannor! I just pulled it down and did some manual testing. Two issues popped up:
Adjusting the global Here's a diff with the 2 fixes above: diff --git a/framework/app/app_test.go b/framework/app/app_test.go
index b5ba644..500a117 100644
--- a/framework/app/app_test.go
+++ b/framework/app/app_test.go
@@ -30,3 +30,26 @@ func TestWelcome(t *testing.T) {
is.NoErr(td.Exists("bud/app"))
is.NoErr(app.Close())
}
+
+func TestWelcomeWithPublic(t *testing.T) {
+ is := is.New(t)
+ ctx, cancel := context.WithCancel(context.Background())
+ defer cancel()
+ dir := t.TempDir()
+ td := testdir.New(dir)
+ td.Files["public/default.css"] = `* { box-sizing: border-box; }`
+ is.NoErr(td.Write(ctx))
+ cli := testcli.New(dir)
+ is.NoErr(td.NotExists("bud/app"))
+ app, err := cli.Start(ctx, "run")
+ is.NoErr(err)
+ res, err := app.Get("/")
+ is.NoErr(err)
+ is.Equal(res.Status(), 200)
+ is.In(res.Body().String(), "Hey Bud")
+ is.In(res.Body().String(), "Hey Bud") // should work multiple times
+ is.Equal(app.Stdout(), "")
+ is.Equal(app.Stderr(), "")
+ is.NoErr(td.Exists("bud/app"))
+ is.NoErr(app.Close())
+}
diff --git a/framework/view/ssr/ssr.go b/framework/view/ssr/ssr.go
index 7116bcd..8bab21c 100644
--- a/framework/view/ssr/ssr.go
+++ b/framework/view/ssr/ssr.go
@@ -50,9 +50,10 @@ type Compiler struct {
func (c *Compiler) Compile(ctx context.Context, fsys budfs.FS) ([]byte, error) {
dir := c.module.Directory()
-
if existCss := vfs.Exist(fsys, "public/default.css"); nil == existCss {
svelteRuntime = strings.Replace(svelteRuntime, `<!-- default css -->`, `<link rel="stylesheet" href="default.css">`, 1)
+ } else {
+ svelteRuntime = strings.Replace(svelteRuntime, `<link rel="stylesheet" href="default.css">`, `<!-- default css -->`, 1)
}
result := esbuild.Build(esbuild.BuildOptions{
diff --git a/framework/web/loader.go b/framework/web/loader.go
index 5f0d149..e4695b8 100644
--- a/framework/web/loader.go
+++ b/framework/web/loader.go
@@ -52,7 +52,10 @@ func (l *loader) Load() (state *State, err error) {
l.imports.AddNamed("webrt", "github.com/livebud/bud/framework/web/webrt")
l.imports.AddNamed("router", "github.com/livebud/bud/package/router")
// Show the welcome page if we don't have controllers, views or public files
- if len(exist) == 0 {
+ //
+ // TODO: welcome should be part of a default controller, then we can support
+ // a simple static file server without generating the welcome page.
+ if len(exist) == 0 || (len(exist) == 1 && exist["bud/internal/app/public/public.go"]) {
l.imports.AddNamed("welcome", "github.com/livebud/bud/framework/web/welcome")
state.ShowWelcome = true
state.Imports = l.imports.List()
|
Any chance of wrapping this up @ralfiannor ? |
Implement #253