@nakedev/go-scaffold 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -46,12 +46,24 @@ missing AutoMigrate wiring, a `repository` interface out of sync with its
|
|
|
46
46
|
Run from the project root:
|
|
47
47
|
|
|
48
48
|
```bash
|
|
49
|
-
go-scaffold generate module <name> [--full] [--auth] [--permission <code>]
|
|
49
|
+
go-scaffold generate module <name> --defaults [--full] [--auth] [--permission <code>]
|
|
50
50
|
go-scaffold generate method <module> <name> --type <get|post|put|patch|delete> [--get-mode all|one] [--field <name>]
|
|
51
51
|
go-scaffold generate migration <name>
|
|
52
|
-
go-scaffold undo module <name>
|
|
52
|
+
go-scaffold undo module <name> -y
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
+
**Every value has to be a flag.** These commands prompt for whatever you
|
|
56
|
+
leave out, and a prompt in a non-interactive shell exits 1 having written
|
|
57
|
+
nothing — so a bare `generate module products` fails rather than taking the
|
|
58
|
+
default. `--defaults` supplies the unasked-for answers (minimal, no auth);
|
|
59
|
+
combine it with `--full`/`--auth`/`--permission` when you want those. The
|
|
60
|
+
same applies to `--get-mode` (required with `--type get`) and `-y` on
|
|
61
|
+
`undo module`. Every `add` command summarises what it will write and asks
|
|
62
|
+
before writing: `-y` skips that confirmation, but `add auth` and `add worker`
|
|
63
|
+
*also* ask which backing store to use — so those two need `--defaults`
|
|
64
|
+
(or their own `--store`/`--queue` flag plus `-y`), while `add rbac -y` and
|
|
65
|
+
`add observability -y` are enough.
|
|
66
|
+
|
|
55
67
|
`<name>` for a module is a domain noun in whatever form reads naturally —
|
|
56
68
|
singular or plural, any case, hyphens or underscores are all accepted and
|
|
57
69
|
normalized (`products` → `product`, `Orders` → `order`, `order-item` →
|
|
@@ -79,7 +91,7 @@ is actually intended — otherwise prefer minimal plus explicit `generate method
|
|
|
79
91
|
calls.
|
|
80
92
|
|
|
81
93
|
`--auth` puts the module's routes behind a valid access token (requires
|
|
82
|
-
`go-scaffold add auth` in this project first). `--permission <code>` also
|
|
94
|
+
`go-scaffold add auth -y` in this project first). `--permission <code>` also
|
|
83
95
|
requires that permission via `authz.Require` and seeds it in its own
|
|
84
96
|
migration — it needs `add rbac`, and `--auth` must be passed alongside it.
|
|
85
97
|
|
|
@@ -114,7 +126,7 @@ domain decided against. Deletes `internal/app/<pkg>/`, the module's
|
|
|
114
126
|
`migrations/<version>_create_<plural>.{up,down}.sql` pair, and reverses
|
|
115
127
|
everything `generate module` wired up in `cmd/api/wiring.go` (and in
|
|
116
128
|
`docs/openapi.yaml` + `docs/<plural>/` when OpenAPI is enabled). `-y` skips
|
|
117
|
-
the confirmation prompt.
|
|
129
|
+
the confirmation prompt, and is required in a non-interactive shell.
|
|
118
130
|
|
|
119
131
|
The migration files go because `migrations/embed.go` is a `//go:embed *`: a
|
|
120
132
|
typo's migration left behind runs on every database created from then on.
|
|
@@ -11,14 +11,24 @@ package with its own model/handler/service/repository), or add a **new**
|
|
|
11
11
|
endpoint to an existing one — stop and run the CLI instead:
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
|
-
go-scaffold generate module <name>
|
|
14
|
+
go-scaffold generate module <name> --defaults
|
|
15
15
|
go-scaffold generate method <module> <name> --type <get|post|put|patch|delete>
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
+
**Pass every value as a flag.** Run interactively, these commands ask for
|
|
19
|
+
anything you left out — which has no answer in a non-interactive shell, so
|
|
20
|
+
they exit 1 having written nothing. `--defaults` on `generate module` means
|
|
21
|
+
"minimal, no auth, ask nothing"; add `--full`/`--auth`/`--permission` to it
|
|
22
|
+
when you want those. Same rule elsewhere: `--get-mode` is required with
|
|
23
|
+
`--type get`, and `undo module` needs `-y`. Every `add` command confirms
|
|
24
|
+
before writing — `-y` skips that, but `add auth`/`add worker` also ask which
|
|
25
|
+
backing store to use, so those two want `--defaults` (or `--store`/`--queue`
|
|
26
|
+
plus `-y`).
|
|
27
|
+
|
|
18
28
|
This applies **even when the request doesn't say "module"/"method" or name
|
|
19
29
|
the CLI at all**. Recognize indirect asks as generation work, for example:
|
|
20
30
|
|
|
21
|
-
- "add a products feature" → a new domain (`generate module products`)
|
|
31
|
+
- "add a products feature" → a new domain (`generate module products --defaults`)
|
|
22
32
|
- "let admins approve orders" → a new method on an existing module
|
|
23
33
|
(`generate method orders approve --type patch`)
|
|
24
34
|
- "we need an endpoint that lists overdue invoices" → a new `get` method
|
|
@@ -45,7 +55,7 @@ hand-rolling anything that looks like scaffolding.
|
|
|
45
55
|
|
|
46
56
|
## Command quick reference
|
|
47
57
|
|
|
48
|
-
- `go-scaffold generate module <name
|
|
58
|
+
- `go-scaffold generate module <name> --defaults` — safe minimal model + errors +
|
|
49
59
|
repository + service/handler plumbing, wired into `cmd/api/wiring.go` and
|
|
50
60
|
appended to `migrations/`. Add endpoints one at a time with `generate
|
|
51
61
|
method`, or pass `--full` to opt into a CRUD skeleton with TODO DTO fields
|
|
@@ -55,7 +65,7 @@ hand-rolling anything that looks like scaffolding.
|
|
|
55
65
|
with the same name — pick a different one if it collides. With OpenAPI
|
|
56
66
|
enabled it also writes a valid TODO path document and wires the index;
|
|
57
67
|
replace placeholder schemas while implementing the method
|
|
58
|
-
- `go-scaffold undo module <name
|
|
68
|
+
- `go-scaffold undo module <name> -y` — takes back a `generate module` that
|
|
59
69
|
shouldn't have happened (typo'd name, domain decided against): deletes the
|
|
60
70
|
package, un-wires main.go/OpenAPI, and deletes the module's migration files.
|
|
61
71
|
It refuses if those migrations are committed to git or already applied to
|