Repository navigation
Refactor/v0.0.6 - #12
Merged
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed and why
A refactor of the
preaCLI (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.runpasses through, the server environment, the rollback ofnewand the sources thatdevwatches. They pass on the old code.generate.gois split by subject:names.go,templates.goandregistry.go.main.goholds only the entry point, and the command has a package comment.startServer) and thegocommand runs in one place (goCmd). Environment variables are named constants.os.Chdir.newandgenerate prearender the same template tree, and the templates are renamed to*.go.tmpl.devis split into a server (rebuild,shutdown) and a watcher. It builds into a singlenextbinary and renames it over the running one, instead of leaving a new binary behind on every rebuild.newand the registry edit have the same shape: check, then write with rollback, then report.namesandrun.goread top to bottom, with each step in a named function.go get @latestinnewis gone:go mod tidyalone produces the samego.modandgo.sum.docs/is no longer listed in.gitignore.How it was tested
gofmt,go vetandgo test -race github.com/prea-framework/prea/..., withPREA_TEST_DATABASE_URLset. Coverage ofcmd/preawent from 81.2% to 91.5%.diff -rof a project generated byprea new shop --with-dbshows no difference from the one themainbinary generates.End to end, the
mainbinary 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, andrunwith an exit code and with SIGINT.Timings against the
mainbinary:prea new --local: 60 ms before and after.prea newwith network: ~680 ms → ~350 ms.devrebuild, 70 samples: median 1545 ms → 1552 ms, p90 1950 ms → 1963 ms.devdisk use after 10 rebuilds: 286 MB → 26 MB.The tutorial app (
site/examples/todo) passesgofmt,go vetandPREA_PROFILE=tests go test -race -p 1 ./....npm run docs:buildpasses. The CLI reference insite/still matchesprea --help.gofmt,go vet github.com/prea-framework/prea/...andgo test github.com/prea-framework/prea/...passthe docs in
site/are updated, if the change is visible to users (no visible change;prea --helpis unchanged)