@domain-first/project-structure 8.2.0 → 8.4.0

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/dist/react.js CHANGED
@@ -3,7 +3,7 @@ import { parseArgs } from "node:util";
3
3
  import { select as prompts_select } from "@inquirer/prompts";
4
4
  import { runCLI } from "./561.js";
5
5
  import { outdatedConfigMessage, ProjectRoot, ConfigFile, Folder } from "./870.js";
6
- import { scaffoldReactWidget, moveReactModuleUseCase, scaffoldReactPage, scaffoldReactUIKitComponent, scaffoldReactSharedHook, savePendingChanges } from "./287.js";
6
+ import { scaffoldReactWidget, moveReactModuleUseCase, deleteReactModuleUseCase, scaffoldReactPage, scaffoldReactUIKitComponent, scaffoldReactSharedHook, savePendingChanges } from "./287.js";
7
7
  runCLI('df-react', async ()=>{
8
8
  const help = `Usage: df-react
9
9
 
@@ -54,7 +54,13 @@ Options:
54
54
  'New UI-kit component',
55
55
  'New shared hook',
56
56
  'Move or rename widget',
57
- 'Move or rename page'
57
+ 'Move or rename page',
58
+ 'Move or rename UI-kit component',
59
+ 'Move or rename shared hook',
60
+ 'Delete widget',
61
+ 'Delete page',
62
+ 'Delete UI-kit component',
63
+ 'Delete shared hook'
58
64
  ]
59
65
  });
60
66
  switch(action){
@@ -70,6 +76,18 @@ Options:
70
76
  return void await moveReactModuleUseCase(reactFolder, 'widget');
71
77
  case 'Move or rename page':
72
78
  return void await moveReactModuleUseCase(reactFolder, 'page');
79
+ case 'Delete widget':
80
+ return void await deleteReactModuleUseCase(reactFolder, 'widget');
81
+ case 'Delete page':
82
+ return void await deleteReactModuleUseCase(reactFolder, 'page');
83
+ case 'Move or rename UI-kit component':
84
+ return void await moveReactModuleUseCase(reactFolder, 'ui-kit');
85
+ case 'Move or rename shared hook':
86
+ return void await moveReactModuleUseCase(reactFolder, 'hook');
87
+ case 'Delete UI-kit component':
88
+ return void await deleteReactModuleUseCase(reactFolder, 'ui-kit');
89
+ case 'Delete shared hook':
90
+ return void await deleteReactModuleUseCase(reactFolder, 'hook');
73
91
  default:
74
92
  return;
75
93
  }
@@ -0,0 +1,6 @@
1
+ import type { Folder } from '../file-system';
2
+ /**
3
+ * Deletes a unit of a bounded context or the Shared Kernel with every file
4
+ * of it, once nothing else in the project imports it.
5
+ */
6
+ export declare const deleteBackendUnitUseCase: (ownerFolder: Folder) => Promise<void>;
@@ -0,0 +1,8 @@
1
+ import { type Folder } from '../file-system';
2
+ import { type ReactModuleKind } from '../react-module-move';
3
+ /**
4
+ * Deletes a page or widget with its files once nothing else imports it.
5
+ * With Next.js, a page's own route can go with it: its URL stops working,
6
+ * so it is asked.
7
+ */
8
+ export declare const deleteReactModuleUseCase: (presentationReactFolder: Folder, kind: ReactModuleKind) => Promise<void>;
@@ -1,4 +1,6 @@
1
1
  export * from './add-integration';
2
+ export * from './delete-backend-unit';
3
+ export * from './delete-react-module';
2
4
  export * from './initialize';
3
5
  export * from './move-backend-unit';
4
6
  export * from './move-react-module';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@domain-first/project-structure",
3
3
  "description": "Build and manage your Domain-First project structure with CLI",
4
- "version": "8.2.0",
4
+ "version": "8.4.0",
5
5
  "type": "module",
6
6
  "repository": {
7
7
  "type": "git",
@@ -41,7 +41,7 @@ A business element goes to UI-kit only when several widgets contain the same ele
41
41
 
42
42
  ## Running df-react
43
43
 
44
- Prefer `npx df-react --describe` and `npx df-react --request` JSON. The installed schema lists operations (`page`, `widget`, `ui-kit-component`, `shared-hook`, `move-page`, `move-widget`), fields and current React modules. For example:
44
+ Prefer `npx df-react --describe` and `npx df-react --request` JSON. The installed schema lists operations (`page`, `widget`, `ui-kit-component`, `shared-hook`, `move-page`, `move-widget`, `delete-page`, `delete-widget`, `move-ui-kit-component`, `move-shared-hook`, `delete-ui-kit-component`, `delete-shared-hook`), fields and current React modules. For example:
45
45
 
46
46
  ```bash
47
47
  npx df-react --request '{"operation":"widget","name":"cart","widgetType":"separated"}'
@@ -54,13 +54,15 @@ node <df-ps-scaffold-skill-dir>/scripts/drive.mjs --bin df-react [--cwd <dir>] [
54
54
  node <df-ps-scaffold-skill-dir>/scripts/drive.mjs --bin df-react "pick:New widget" text:cart "pick:with separated ui"
55
55
  ```
56
56
 
57
- Steps and checks are the same as for `df-scaffold` ("Legacy interactive driver" in `df-ps-scaffold`). Its menu: `New widget`, `New page`, `New UI-kit component`, `New shared hook`, `Move or rename widget`, `Move or rename page`. Prompts and output of each: `references/generators.md`.
57
+ Steps and checks are the same as for `df-scaffold` ("Legacy interactive driver" in `df-ps-scaffold`). Its menu: `New widget`, `New page`, `New UI-kit component`, `New shared hook`, `Move or rename widget`, `Move or rename page`, `Move or rename UI-kit component`, `Move or rename shared hook`, `Delete widget`, `Delete page`, `Delete UI-kit component`, `Delete shared hook`. Prompts and output of each: `references/generators.md`.
58
58
 
59
59
  If the CLI cannot run, report the failure and give the user the prepared JSON command (a menu path only for a legacy CLI). Never hand-write its output.
60
60
 
61
61
  ### Moving and renaming
62
62
 
63
- Moving or renaming a page or widget is a df-react run (`Move or rename page` / `Move or rename widget`): it creates the files at the new paths, so it needs an approved plan. With Next.js, moving a page can also move its App Router route and so change its URL: state in the plan whether the route moves (`moveRoute`), and ask the user when the request doesn't say. Don't move, rename, or copy their files by hand, and don't rename their `<Name>Page…`, `<Name>Widget…`, or `use<Name>UIModel` by hand: df-react keeps file names, code names, story titles, and imports in sync. List each move as a run: old → new name, the files to move (`→`), and the files whose imports change (`~`).
63
+ Moving or renaming a page or widget is a df-react run (`Move or rename page` / `Move or rename widget`): it creates the files at the new paths, so it needs an approved plan. With Next.js, moving a page can also move its App Router route and so change its URL: state in the plan whether the route moves (`moveRoute`), and ask the user when the request doesn't say. Don't move, rename, or copy their files by hand, and don't rename their `<Name>Page…`, `<Name>Widget…`, or `use<Name>UIModel` by hand: df-react keeps file names, code names, story titles, and imports in sync. List each move as a plan row (Type `page move` / `widget move` / `ui-kit component move` / `hook move`, Name `old → new`). UI-kit components and shared hooks move and rename the same way (`move-ui-kit-component`, `move-shared-hook`), without folders: their files, `<Name>` / `<Name>Props` / `use<Name>`, story titles and imports follow.
64
+
65
+ Deleting a page or widget is a df-react run too (`Delete page` / `Delete widget`, JSON `delete-page` / `delete-widget`) and needs an approved plan (Type `page delete` / `widget delete`); so is deleting a UI-kit component or shared hook (`delete-ui-kit-component`, `delete-shared-hook`; Type `ui-kit component delete` / `hook delete`). It is refused while other files import the module (`DELETE_NOT_ALLOWED` with `details.usedBy`): remove those uses first, or delete the importing module first. With Next.js, deleting a page can also delete its own route and so its URL: state it in the plan (`deleteRoute`), and ask the user when the request doesn't say. Never delete their files by hand.
64
66
 
65
67
  ### Files you may create by hand
66
68
 
@@ -25,6 +25,14 @@ Page and widget names may have folders before them: `text:admin/panel/users` →
25
25
 
26
26
  Move or rename a page or a widget only with df-react, never by hand: `"pick:Move or rename widget" "pick:admin/users" text:team/users "yes"` (`Move or rename page` for pages; the list shows nested names, the default new name is the current one). It moves the widget folder (or the page with its `<name>-page.*` files), renames files and `<Name>Widget…` / `use<Name>UIModel` / `<Name>Page…` to the new name, updates a generated story title and every import of the module (relative and `tsconfig` aliases; importers of barrels re-exporting it get the renamed classes), and fixes relative imports inside it. Before `Apply?` it prints the files to move and to update; check them. An existing target or a move into itself is rejected.
27
27
 
28
+ ## Move, rename or delete a UI-kit component / shared hook
29
+
30
+ The same runs exist for them: `"pick:Move or rename UI-kit component" pick:button text:primary-button yes`, `"pick:Move or rename shared hook" pick:debounce text:throttle yes`, `"pick:Delete UI-kit component" pick:badge yes`, `"pick:Delete shared hook" pick:toggle yes`. Names have no folders; a hook's name is entered without `use-`. A move renames the folder or `use-<name>.*` files, `<Name>` / `<Name>Props` / `use<Name>`, the `UI-kit/<Name>` story title and every import; a delete is refused while other files import the module.
31
+
32
+ ## Delete page / widget
33
+
34
+ Delete a page or a widget only with df-react: `"pick:Delete widget" "pick:orders/filters" yes` (`Delete page` for pages; with Next.js and the page's own route, a `yes`/`no` for deleting the route comes before `Delete?`). It deletes the widget folder (or the page with its `<name>-page.*` files) and, if confirmed, the route folder's own files. It refuses while other files import the module and lists them; nothing changes then.
35
+
28
36
  ## New UI-kit component
29
37
 
30
38
  `"pick:New UI-kit" text:date-picker` → `…/react/ui-kit/n/`:
@@ -88,7 +88,7 @@ Reply "ok" to start.
88
88
  - **Scaffolding** has one block per owner, in run order: new contexts first, marked `(new)` (and `(provisional)` with the reason when ownership is a reversible default), then existing contexts, `shared-kernel`, React last.
89
89
  - **Why here**: one short sentence on why this owner, not another: the data or rule the context owns; for `shared-kernel`, why several contexts share it; for React, why the UI changes.
90
90
  - **What will be scaffolded**: one table per owner, one row per `df-scaffold`/`df-react` run. Layers in order domain → application → infrastructure → presentation, the layer in bold only on its first row. Repositories go with their aggregate in domain; commands, queries and ports in application (their implementations are Details); endpoints and React modules in presentation.
91
- - **Type**: the unit: aggregate, entity, value object, error, error namespace, service, port, command, query, use case, implementation, endpoint, wire dependency, move; for React: page, widget, ui-kit component, hook, page move, widget move.
91
+ - **Type**: the unit: aggregate, entity, value object, error, error namespace, service, port, command, query, use case, implementation, endpoint, wire dependency, move, delete; for React: page, widget, ui-kit component, hook, page move, widget move, ui-kit component move, hook move, page delete, widget delete, ui-kit component delete, hook delete.
92
92
  - **Name**: the entered name; for a move `old → new`; for an implementation the contract; for wire dependency the module.
93
93
  - **Details**: only what changes behavior: implementation types (`(saved)` when saved for future runs), the test implementation, dependencies (`deps: OrderRepository`), environments, widget type, the endpoint's handler, whether a Next.js route moves (`route moves: /a → /b`). No file paths, no CLI menu paths.
94
94
  - **Why**: at most six words: why this kind of module (`choosing-components.md`).
@@ -117,11 +117,11 @@ Anything else (helpers, types, constants, mappers, wiring, barrels): put it in a
117
117
 
118
118
  If the CLI cannot run, report the failure and give the user the prepared JSON command to run themselves (the menu path and answers only for a legacy CLI). Never hand-write its output. Missing generated files are only recreated by re-running the generator, as an approved overwrite.
119
119
 
120
- Moving or renaming a module (aggregate, entity, value object, service, port, query, command, use case) is a df-scaffold run, `Move or rename` (`references/units/move-or-rename.md`); a page or widget, a df-react run (`df-ps-react`). Never by hand: it creates files at the new paths, so it needs an approved plan.
120
+ Moving or renaming a module (aggregate, entity, value object, service, port, query, command, use case) is a df-scaffold run, `Move or rename` (`references/units/move-or-rename.md`); a page or widget, a df-react run (`df-ps-react`). Never by hand: it creates files at the new paths, so it needs an approved plan. Deleting a module is a df-scaffold run too, `Delete` (`references/units/delete.md`): it removes files, so it needs an approved plan as well.
121
121
 
122
122
  ### 3. New dependencies only through df-scaffold
123
123
 
124
- With `@domain-first/wire`, every new dependency of a wired class (a constructor parameter plus its wire) is added by `df-scaffold`: the generator's `Dependencies:` step for a new module, `Wire dependency` for an existing one, and the `Handler:` pick for an endpoint (its generator is added automatically). Don't add constructor parameters or wire entries by hand, and don't reorder or remove the ones `df-scaffold` added.
124
+ With `@domain-first/wire`, every new dependency of a wired class (a constructor parameter plus its wire) is added by `df-scaffold`: the generator's `Dependencies:` step for a new module, `Wire dependency` for an existing one, and the `Handler:` pick for an endpoint (its generator is added automatically). Don't add constructor parameters or wire entries by hand, and don't reorder or remove the ones `df-scaffold` added. The one exception: an approved plan removes a dependency (from the wire and the constructor together), e.g. before deleting the module it points to.
125
125
 
126
126
  - List each module's dependencies in its plan row's Details (`deps: OrderRepository`); for an existing module, add a `wire dependency` row.
127
127
  - A dependency the CLI doesn't offer is forbidden by the project's dependency rules (the defaults, changed by `backend.rules.dependencies` in the config) or by context isolation: change the design (a port, a query or command, an infrastructure service) instead of adding it by hand.
@@ -150,6 +150,7 @@ One file per unit in `references/units/`: when to choose it, how to generate it
150
150
  | REST endpoint | `endpoint.md` | Presentation → New Handlers-REST Endpoint |
151
151
  | Dependency of an existing module | `wire-dependency.md` | Wire dependency |
152
152
  | Moving or renaming a module | `move-or-rename.md` | Move or rename |
153
+ | Deleting a module | `delete.md` | Delete |
153
154
  | React modules | `df-ps-react` skill | `df-react` |
154
155
 
155
156
  ## Preparing runs
@@ -198,7 +199,7 @@ Check every run: exit code 0, no `WARNING`/`ABORTED`, and exactly the files its
198
199
  | Infrastructure | New Service, New Implementation | New Service, New Implementation |
199
200
  | Presentation | New Handlers-REST Endpoint (needs handlers-rest), New Service | New Service |
200
201
 
201
- With `@domain-first/wire`, the layer menu of a context and of the Shared Kernel also has `Wire dependency`: it adds dependencies to an existing wired module. Every layer menu has `Move or rename`.
202
+ With `@domain-first/wire`, the layer menu of a context and of the Shared Kernel also has `Wire dependency`: it adds dependencies to an existing wired module. Every layer menu has `Move or rename` and `Delete`.
202
203
 
203
204
  The main menu also has `Scaffold new bounded context`. React modules come from a separate CLI, `df-react`: see `df-ps-react`.
204
205
 
@@ -67,6 +67,7 @@ Compare the reported changes with the approved plan, then implement the generate
67
67
  | `CONTEXT_NOT_FOUND`, `TARGET_NOT_FOUND`, `REST_NOT_CONFIGURED` | Create the required context, aggregate, namespace, contract, handler or integration first if that work is authorized; otherwise report the missing prerequisite. A dry run of a prerequisite does not create it. |
68
68
  | `OVERWRITE_REQUIRED` | Preview and inspect the listed paths. Use `overwrite: true` only for replacements already within the approved plan; obtain any required plan change first. |
69
69
  | `MOVE_NOT_ALLOWED` | Review the boundary violations and change the design or move prerequisites first. Do not perform the move by hand. |
70
+ | `DELETE_NOT_ALLOWED` | `details.usedBy` lists `[file, import]` pairs still using the module. Remove those uses first if the plan covers it, or report them; never delete the files by hand. |
70
71
  | `CANCELLED`, `OPERATION_FAILED`, `UNSUPPORTED_PROMPT` | Inspect the message and report the failed operation or unsupported CLI path. Do not treat this as permission to switch to interactive execution or write output by hand. |
71
72
 
72
73
  Failures discard the operation's staged changes. Success can still have follow-up notes: inspect `messages`/`nextSteps` for manual adapter connection, integration installation, custom wiring or an implementation no longer selected by any environment. Check the actual generated files before implementing business logic.
@@ -28,6 +28,7 @@ All operations support `dryRun` and `overwrite`. Except `bounded-context`, they
28
28
  | `endpoint` | `controller`, `method`, `path` | REST package and generator must exist. With wiring and selectable handlers, provide `handler`. Without selectable handlers, omit it; the generated handler remains `never` and needs a later approved generator rerun. |
29
29
  | `wire-dependency` | `module`, `dependencies` | `module` is a wiring target ID, not a contract/unit ID. Adds only eligible dependencies not already wired to that implementation. |
30
30
  | `move` | `module` | `module` is a unit ID. Optional `name`, `targetContext`, `aggregate`; omitted name/context keep the existing ones. A same-owner entity/value-object keeps its aggregate by default. The target aggregate must exist; the target context must be a discovered, allowed destination for that unit kind. Illegal cross-context imports reject the move. |
31
+ | `delete` | `module` | `module` is a unit ID. Deletes every file of the unit and its generated references (aggregate barrel re-export, in-memory DB section). Refused with `DELETE_NOT_ALLOWED` and `details.usedBy` while other files import it; nothing changes. |
31
32
 
32
33
  `implementation` and `testImplementation` contain `type` and optional `save` (default false). Explicit types can be new ordinary names; they need not already be saved. Saving is independent for primary and test roles. The test type must differ from the primary type. Adding a new implementation remembers a saved type according to the selected environments: `test` or primary for other environments. Branches are `backend.envBranches.names` from the config (`test`, `development`, `production` when absent), with `backend.envBranches.test` as the test one; additional names must be offered by the existing branched wire. Custom branches without `test` take no test implementations: omit `testImplementation`. Without usable branching, omit `environments` and follow the returned wiring note.
33
34
 
@@ -118,6 +119,12 @@ The owner configures frontend first. React and Next.js use the same operations.
118
119
  | `shared-hook` | `name` | Single kebab-case name, preferably without `use-`; a leading `use-` is stripped. |
119
120
  | `move-page` | `module`, `name` | `module` is the existing nested page name from discovery; `name` is the target nested name. With Next.js and a route at the page path that renders the page, `moveRoute` (default true) moves that route folder's own files to the new path, changing the URL; `false` keeps the route with its import updated. Omit `moveRoute` when there is no such route. |
120
121
  | `move-widget` | `module`, `name` | Same for widgets. Files, imports, code names and generated story titles follow the move. |
122
+ | `delete-page` | `module` | Deletes the page and its `<name>-page.*` files. With Next.js and the page's own route, `deleteRoute` (default true) deletes that route folder's own files too; `false` keeps the route, which still imports the page, so the delete is refused. Omit `deleteRoute` without such a route. |
123
+ | `delete-widget` | `module` | Deletes the widget folder. Refused with `DELETE_NOT_ALLOWED` and `details.usedBy` while other files import it. |
124
+ | `move-ui-kit-component` | `module`, `name` | Kebab-case names without folders. Folder, files, `<Name>`, `<Name>Props`, the `UI-kit/<Name>` story title and imports follow. |
125
+ | `move-shared-hook` | `module`, `name` | Kebab-case names without folders; a leading `use-` is dropped. `use-<name>.*`, `use<Name>` and imports follow. |
126
+ | `delete-ui-kit-component` | `module` | Deletes the component folder. Refused with `DELETE_NOT_ALLOWED` while other files import it. |
127
+ | `delete-shared-hook` | `module` | Deletes `use-<name>.*`. Refused with `DELETE_NOT_ALLOWED` while other files import it. |
121
128
 
122
129
  All support `dryRun` and `overwrite`. Use CLI moves even for a rename or folder regrouping; an existing target or a move into itself is rejected.
123
130
 
@@ -0,0 +1,19 @@
1
+ # Delete
2
+
3
+ When: a module is no longer needed. Never delete module files by hand: the CLI removes every file of the module and what the generators added for it elsewhere, and refuses while anything still uses it.
4
+
5
+ ## Generate (context and Shared Kernel)
6
+
7
+ Prompts: `Module to delete:` (select, grouped by kind as in Move or rename) → `Delete?` (default No).
8
+
9
+ `… "pick:Delete" pick:orders yes`
10
+
11
+ JSON: `{ "operation": "delete", "context": "sales", "module": "query:orders" }`.
12
+
13
+ Deleted: the files of the unit, as Move or rename moves them (an aggregate with its whole folder, entities and value objects inside included). Cleaned up: an entity's or value object's `export *` in its aggregate's `index.ts`, and an aggregate's in-memory DB section with its import.
14
+
15
+ Refused while other files import the module: other modules, their wires and specs, or importers of the aggregate barrel that name an entity or value object. The CLI prints `Nothing was deleted: these files still use it.` with each `file → import` (JSON: `DELETE_NOT_ALLOWED` with `details.usedBy`) and changes nothing. Remove the uses first: delete the dependent module first, or remove the dependency from its wire and constructor together, which needs the approved plan (rule 3 exception).
16
+
17
+ ## In the plan
18
+
19
+ A delete is a row of its owner: Type `delete`, Name the module, Why the reason it goes. List the uses that have to go first under Writing by hand.
@@ -222,6 +222,7 @@ const created = [...after.keys()].filter((p) => !before.has(p)).map(rel);
222
222
  const changed = [...after.keys()]
223
223
  .filter((p) => before.has(p) && before.get(p) !== after.get(p))
224
224
  .map(rel);
225
+ const deleted = [...before.keys()].filter((p) => !after.has(p)).map(rel);
225
226
 
226
227
  const plain = stripAnsi(output);
227
228
  const answered = [...plain.matchAll(/✔\s*([^\n]*)/g)].map((m) => m[1].trim());
@@ -240,6 +241,10 @@ console.log('\ncreated:');
240
241
  for (const file of created) console.log(` + ${file}`);
241
242
  console.log('\nchanged:');
242
243
  for (const file of changed) console.log(` ~ ${file}`);
244
+ if (deleted.length) {
245
+ console.log('\ndeleted:');
246
+ for (const file of deleted) console.log(` - ${file}`);
247
+ }
243
248
  if (code !== 0 || unansweredPrompt || aborted) {
244
249
  console.log('\nraw output (tail):');
245
250
  console.log(plain.split('\n').slice(-15).join('\n'));