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

Merge zero #397

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
da73f7b
started the zero example
matthewmueller Mar 10, 2023
e99a649
todo: rework generator api to register instead
matthewmueller Mar 10, 2023
57c00a8
reworked generator api to be more powerful
matthewmueller Mar 11, 2023
cd20f23
setup initial custom web command
matthewmueller Mar 12, 2023
a623cac
add web generator
matthewmueller Mar 18, 2023
d949ae3
package/router: rename Add to Set. Add a Mount method.
matthewmueller Mar 18, 2023
19cc62a
add initial controller generator
matthewmueller Mar 18, 2023
e522bc0
add more controllers
matthewmueller Mar 18, 2023
7670338
initial viewer and view rendering support
matthewmueller Mar 18, 2023
eceff22
add error and layout support
matthewmueller Mar 20, 2023
3cfe5e7
add initial transpiler support to gohtml viewer
matthewmueller Mar 20, 2023
0cca9b6
transpiling markdown files is working. frames are working too
matthewmueller Mar 21, 2023
5f4e763
added a distinct viewer and prepped for bundling within the view gene…
matthewmueller Mar 22, 2023
23d23f8
basic bundling working
matthewmueller Mar 25, 2023
8279d98
env support
matthewmueller Mar 26, 2023
488cf69
initial middleware support
matthewmueller Mar 26, 2023
e9768e6
add wraprw
matthewmueller Mar 26, 2023
08c41c4
hook wraprw middleware up
matthewmueller Mar 26, 2023
25c9fce
wip sessions. remove middleware generator
matthewmueller Mar 27, 2023
2e4bb4d
get tests passing and add a hidden command to commander
matthewmueller Mar 28, 2023
3428a21
initial session support
matthewmueller Mar 28, 2023
76d9b24
bump zero
matthewmueller Apr 17, 2023
86c77b5
lots of changes, this is just saving old work
matthewmueller Sep 9, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ install:
# Examples
##

example.zero:
@ # go run main.go -C example/zero generate2 --embed
@ go run main.go -C example/zero generate2

example.zero.watch:
@ watch --clear -- $(MAKE) example.zero

example.basic:
@ (cd example/basic && npm link ../../livebud)
@ go run main.go -C example/basic run
Expand Down
Binary file added example/zero/_bud/app
Binary file not shown.
56 changes: 56 additions & 0 deletions example/zero/_bud/cmd/app/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package main

import (
command "github.com/livebud/bud/example/zero/bud/internal/command"
env "github.com/livebud/bud/example/zero/bud/internal/env"
transpiler "github.com/livebud/bud/example/zero/bud/pkg/transpiler"
viewer "github.com/livebud/bud/example/zero/bud/pkg/viewer"
web1 "github.com/livebud/bud/example/zero/bud/pkg/web"
controller "github.com/livebud/bud/example/zero/bud/pkg/web/controller"
middleware "github.com/livebud/bud/example/zero/bud/pkg/web/middleware"
view "github.com/livebud/bud/example/zero/bud/pkg/web/view"
web2 "github.com/livebud/bud/example/zero/command/web"
posts "github.com/livebud/bud/example/zero/controller/posts"
sessions "github.com/livebud/bud/example/zero/controller/sessions"
users "github.com/livebud/bud/example/zero/controller/users"
app "github.com/livebud/bud/example/zero/generator/app"
csrf "github.com/livebud/bud/example/zero/middleware/csrf"
wraprw "github.com/livebud/bud/example/zero/middleware/wraprw"
mw "github.com/livebud/bud/example/zero/mw"
goldmark "github.com/livebud/bud/example/zero/transpiler/goldmark"
tailwind "github.com/livebud/bud/example/zero/transpiler/tailwind"
gohtml "github.com/livebud/bud/example/zero/viewer/gohtml"
web "github.com/livebud/bud/example/zero/web"
gomod "github.com/livebud/bud/package/gomod"
log "github.com/livebud/bud/package/log"
)

func main() {
app.Main(loadCLI)
}

func loadCLI(gomodModule *gomod.Module, logLog log.Log) (*command.CLI, error) {
envEnv, err := env.Load()
if err != nil {
return nil, err
}
tailwindTranspiler := &tailwind.Transpiler{Log: logLog}
goldmarkTranspiler := &goldmark.Transpiler{Log: logLog}
transpilerTranspiler := transpiler.Load(tailwindTranspiler, goldmarkTranspiler)
gohtmlViewer := gohtml.New(logLog, transpilerTranspiler)
viewerViewer := viewer.New(transpilerTranspiler, gohtmlViewer)
viewView := view.New(gomodModule, viewerViewer)
postsController := &posts.Controller{}
sessionsController := &sessions.Controller{}
usersController := &users.Controller{Env: envEnv}
controllerController := controller.New(viewView, postsController, sessionsController, usersController)
csrfMiddleware := &csrf.Middleware{Env: envEnv}
wraprwMiddleware := &wraprw.Middleware{}
middlewareMiddleware := middleware.New(csrfMiddleware, wraprwMiddleware)
mwMiddleware := &mw.Middleware{Env: envEnv}
webWeb := &web.Web{Env: envEnv, Controller: controllerController, Middleware: middlewareMiddleware, MW: mwMiddleware, View: viewView}
web1Server := web1.New(webWeb)
web2Command := web2.New(envEnv, logLog, web1Server)
commandCLI := command.New(logLog, web2Command)
return commandCLI, err
}
47 changes: 47 additions & 0 deletions example/zero/_bud/cmd/gen/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package main

import (
generator "github.com/livebud/bud/example/zero/bud/internal/generator"
transpiler "github.com/livebud/bud/example/zero/bud/pkg/transpiler"
viewer "github.com/livebud/bud/example/zero/bud/pkg/viewer"
app "github.com/livebud/bud/example/zero/generator/app"
command "github.com/livebud/bud/example/zero/generator/command"
controller "github.com/livebud/bud/example/zero/generator/controller"
env "github.com/livebud/bud/example/zero/generator/env"
middleware "github.com/livebud/bud/example/zero/generator/middleware"
session "github.com/livebud/bud/example/zero/generator/session"
view "github.com/livebud/bud/example/zero/generator/view"
web "github.com/livebud/bud/example/zero/generator/web"
goldmark "github.com/livebud/bud/example/zero/transpiler/goldmark"
tailwind "github.com/livebud/bud/example/zero/transpiler/tailwind"
gohtml "github.com/livebud/bud/example/zero/viewer/gohtml"
framework "github.com/livebud/bud/framework"
genfs "github.com/livebud/bud/package/genfs"
gomod "github.com/livebud/bud/package/gomod"
log "github.com/livebud/bud/package/log"
gen "github.com/livebud/bud/runtime/gen"
)

func main() {
gen.Main(loadGenerator)
}

func loadGenerator(frameworkFlag *framework.Flag, genfsFileSystem genfs.FileSystem, gomodModule *gomod.Module, logLog log.Log) (*generator.Generator, error) {
genParser := gen.ProvideParser(genfsFileSystem, gomodModule)
genInjector := gen.ProvideInjector(genfsFileSystem, logLog, gomodModule, genParser)
appGenerator := app.New(frameworkFlag, genInjector, gomodModule)
commandGenerator := command.NewGenerator(gomodModule)
webGenerator := web.New(gomodModule)
controllerGenerator := controller.New(genInjector, gomodModule)
tailwindTranspiler := &tailwind.Transpiler{Log: logLog}
goldmarkTranspiler := &goldmark.Transpiler{Log: logLog}
transpilerTranspiler := transpiler.Load(tailwindTranspiler, goldmarkTranspiler)
gohtmlViewer := gohtml.New(logLog, transpilerTranspiler)
viewerViewer := viewer.New(transpilerTranspiler, gohtmlViewer)
viewGenerator := view.New(frameworkFlag, gomodModule, viewerViewer)
envGenerator := env.New(gomodModule)
middlewareGenerator := middleware.New(gomodModule)
sessionGenerator := session.New(gomodModule)
generatorGenerator := generator.NewGenerator(genfsFileSystem, logLog, appGenerator, commandGenerator, webGenerator, controllerGenerator, viewGenerator, envGenerator, middlewareGenerator, sessionGenerator)
return generatorGenerator, nil
}
Binary file added example/zero/_bud/gen
Binary file not shown.
36 changes: 36 additions & 0 deletions example/zero/_bud/internal/command/command.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package command

import (
context "context"
web "github.com/livebud/bud/example/zero/command/web"
command "github.com/livebud/bud/example/zero/generator/command"
log "github.com/livebud/bud/package/log"
)

func New(
log log.Log,
webCmd *web.Command,
) *CLI {
cli := command.New("app")
webIn := new(web.Serve)
cli.Run(func(ctx context.Context) error {
return command.Go(ctx, log,
func(ctx context.Context) error { return webCmd.GoServe(ctx, webIn) },
)
})

{ // web

{ // web:serve
cmd := cli.Command("web:serve", "serve web requests")
in := new(web.Serve)
cmd.Run(func(ctx context.Context) error {
return webCmd.GoServe(ctx, in)
})
}
}

return cli
}

type CLI = command.CLI
19 changes: 19 additions & 0 deletions example/zero/_bud/internal/env/env.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions example/zero/_bud/internal/generator/generator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package generator

import (
app "github.com/livebud/bud/example/zero/generator/app"
command "github.com/livebud/bud/example/zero/generator/command"
controller "github.com/livebud/bud/example/zero/generator/controller"
env "github.com/livebud/bud/example/zero/generator/env"
middleware "github.com/livebud/bud/example/zero/generator/middleware"
session "github.com/livebud/bud/example/zero/generator/session"
view "github.com/livebud/bud/example/zero/generator/view"
web "github.com/livebud/bud/example/zero/generator/web"
log "github.com/livebud/bud/package/log"
generator "github.com/livebud/bud/runtime/generator"
)

func NewGenerator(
genfs generator.FileSystem,
log log.Log,
app *app.Generator,
command *command.Generator,
web *web.Generator,
controller *controller.Generator,
view *view.Generator,
env *env.Generator,
middleware *middleware.Generator,
session *session.Generator,
) *Generator {
return generator.NewGenerator(
genfs,
log,
app,
command,
web,
controller,
view,
env,
middleware,
session,
)
}

type Generator = generator.Generator
130 changes: 130 additions & 0 deletions example/zero/_bud/pkg/sessions/sessions.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions example/zero/_bud/pkg/transpiler/transpiler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package transpiler

import (
errors "errors"
goldmark "github.com/livebud/bud/example/zero/transpiler/goldmark"
tailwind "github.com/livebud/bud/example/zero/transpiler/tailwind"
transpiler "github.com/livebud/bud/runtime/transpiler2"
)

// Load the transpiler
func Load(
tailwind *tailwind.Transpiler,
goldmark *goldmark.Transpiler,
) Transpiler {
tr := transpiler.New()
tr.Add(".gohtml", ".gohtml", tailwind.GohtmlToGohtml)
tr.Add(".md", ".gohtml", goldmark.MdToGohtml)
return &proxy{tr}
}

type Transpiler = transpiler.Interface

type proxy struct {
Transpiler
}

func (p *proxy) Transpile(fromExt, toExt string, code []byte) ([]byte, error) {
transpiled, err := p.Transpiler.Transpile(fromExt, toExt, code)
if err != nil {
if !errors.Is(err, transpiler.ErrNoPath) {
return nil, err
}
return code, nil
}
return transpiled, nil
}
Loading