Skip to content

Refactor/v0.0.6 - #12

Merged
Pedro77h merged 12 commits into
mainfrom
refactor/v0.0.6
Nov 30, 2026
Merged

Pedro77h merged 12 commits into
mainfrom
refactor/v0.0.6

Conversation

@Pedro77h

Copy link
Copy Markdown
Contributor

What changed and why

A refactor of the prea CLI (cmd/prea), for the v0.0.6 patch release. Users see no change in behavior. The goal is code that reads top to bottom, does less work, and leaves less behind on disk.

  • Tests come first. New ones cover the exit code that run passes through, the server environment, the rollback of new and the sources that dev watches. They pass on the old code.
  • generate.go is split by subject: names.go, templates.go and registry.go. main.go holds only the entry point, and the command has a package comment.
  • The server starts in one place (startServer) and the go command runs in one place (goCmd). Environment variables are named constants.
  • The project directory is passed as a parameter instead of calling os.Chdir. new and generate prea render the same template tree, and the templates are renamed to *.go.tmpl.
  • dev is split into a server (rebuild, shutdown) and a watcher. It builds into a single next binary and renames it over the running one, instead of leaving a new binary behind on every rebuild.
  • The generators, new and the registry edit have the same shape: check, then write with rollback, then report.
  • names and run.go read top to bottom, with each step in a named function.
  • The go get @latest in new is gone: go mod tidy alone produces the same go.mod and go.sum.
  • docs/ is no longer listed in .gitignore.

How it was tested

  • gofmt, go vet and go test -race github.com/prea-framework/prea/..., with PREA_TEST_DATABASE_URL set. Coverage of cmd/prea went from 81.2% to 91.5%.

  • diff -r of a project generated by prea new shop --with-db shows no difference from the one the main binary generates.

  • End to end, the main binary and the new binary produce the same transcript, apart from times and dates. The script covers help, errors, new, generate, build, tests, migrate validate/create/up/status, and run with an exit code and with SIGINT.

  • Timings against the main binary:

    • prea new --local: 60 ms before and after.
    • prea new with network: ~680 ms → ~350 ms.
    • dev rebuild, 70 samples: median 1545 ms → 1552 ms, p90 1950 ms → 1963 ms.
    • dev disk use after 10 rebuilds: 286 MB → 26 MB.
  • The tutorial app (site/examples/todo) passes gofmt, go vet and PREA_PROFILE=tests go test -race -p 1 ./.... npm run docs:build passes. The CLI reference in site/ still matches prea --help.

  • gofmt, go vet github.com/prea-framework/prea/... and go test github.com/prea-framework/prea/... pass

  • the docs in site/ are updated, if the change is visible to users (no visible change; prea --help is unchanged)

Pedro77h and others added 12 commits October 28, 2026 12:16
…and the watched sources

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Move the names and the templates out of generate.go, rename register.go
to registry.go and fold migrate.go into run.go. Name PREA_PROFILE and
PREA_MIGRATE once, use slices.Insert, and share the argument check
between new and generate.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
goCmd takes the directory to run in, startServer starts the built server
for run (and later dev), and hasFlag detects -o and -p for build and
tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… dev

The generators and the go command take the project directory instead of
changing the current one. new and generate prea render templates through
one renderTree. prea new runs only go mod tidy, which resolves the same
go.mod as go get @latest. dev waits for changes in one loop and keeps at
most two binaries instead of one per rebuild.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dev reads as its steps: rebuild, then wait for a change. devServer owns
the binaries and the process, watcher owns the polling, and halt becomes
shutdown.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…shape

newPrea and newMiddleware run every check and write nothing; write
renders, with the rollback in removeOnFailure, which new uses too. The
template paths are named constants, the middleware templates move to
templates/middleware, and declaredIn reads the declarations through
small functions instead of nested loops.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
names reads as splitWords, then camelCase; capitalize handles the
initialisms and wordStartsAt holds the rule snakeCase splits on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
newProject checks the directory and the --local clone before writing,
and write runs the steps with the rollback in one place. Blocks inside
the functions are separated by blank lines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
registered reads as parseRegistry, check and add on a registry type;
the AST lookups are small functions without nested loops, and envVar
builds the environment entries in one place.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…er wait

stopSignals and initialisms move above their first use, runServer's
helpers follow it in call order, and exitCode replaces the if/else on
Wait. waitForChange resets its ticker when it starts, so a change saved
right after a rebuild is seen on the first poll instead of one interval
late.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Pedro77h
Pedro77h merged commit 148a998 into main Nov 30, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant