@odg/command 1.13.0 → 1.14.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/agents.md +93 -20
- package/dist/Generators/MakeFile.d.ts +46 -35
- package/dist/Generators/MakeFile.js +94 -52
- package/dist/Generators/MakeFile.js.map +1 -1
- package/dist/Generators/StubCreator.d.ts +1 -1
- package/dist/Generators/StubCreator.js +17 -42
- package/dist/Generators/StubCreator.js.map +1 -1
- package/dist/Registrations/pascal-to-dot-lower.d.ts +15 -0
- package/dist/Registrations/pascal-to-dot-lower.js +31 -0
- package/dist/Registrations/pascal-to-dot-lower.js.map +1 -0
- package/dist/Registrations/register.d.ts +2 -0
- package/dist/Registrations/register.js +215 -0
- package/dist/Registrations/register.js.map +1 -0
- package/dist/Registrations/ts-mutators.d.ts +40 -0
- package/dist/Registrations/ts-mutators.js +202 -0
- package/dist/Registrations/ts-mutators.js.map +1 -0
- package/dist/Registrations/types.d.ts +34 -0
- package/dist/Registrations/types.js +3 -0
- package/dist/Registrations/types.js.map +1 -0
- package/dist/index.js +79 -13
- package/dist/index.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +10 -9
- package/stubs/event.stub +7 -7
- package/stubs/handler.stub +11 -33
- package/stubs/page.stub +2 -20
- package/stubs/selector.stub +2 -0
package/agents.md
CHANGED
|
@@ -32,15 +32,30 @@ Flags:
|
|
|
32
32
|
- `--selectors` → also generate selectors for the page
|
|
33
33
|
- `--selectorPath` → custom selector output path
|
|
34
34
|
- `-e, --event` → also generate the event/listener scaffold for this page
|
|
35
|
-
- `--eventPath` → custom listener output path
|
|
35
|
+
- `--eventPath` → custom listener output path. Default: `./src/app/Listeners/`
|
|
36
36
|
- `--handlerPath` → custom handler output path when generating linked handler
|
|
37
37
|
- `--handler-from` → generate handler using `<from>To<to>Handler` convention
|
|
38
38
|
- `--handler-to` → generate handler using `<from>To<to>Handler` convention
|
|
39
|
+
- `--register` → enable post-scaffold registration. Default: `false`
|
|
40
|
+
- `--containerEnumPath` → custom ContainerName enum path. Default: `./src/app/Enums/ContainerName.ts`
|
|
41
|
+
- `--eventEnumPath` → custom EventName enum path. Default: `./src/app/Enums/EventName.ts`
|
|
42
|
+
- `--configEnumPath` → custom ConfigName enum path. Default: `./src/app/Enums/ConfigName.ts`
|
|
43
|
+
- `--containerInterfacePath` → custom ContainerInterface path. Default: `./@types/ContainerInterface.d.ts`
|
|
44
|
+
- `--eventsInterfacePath` → custom EventsInterface path. Default: `./@types/EventsInterface.d.ts`
|
|
45
|
+
- `--pagesIndexPath` → custom pages barrel path. Default: `./src/Pages/index.ts`
|
|
46
|
+
- `--selectorsIndexPath` → custom selectors barrel path. Default: `./src/Selectors/index.ts`
|
|
47
|
+
- `--handlersIndexPath` → custom handlers barrel path. Default: `./src/Handlers/index.ts`
|
|
48
|
+
- `--listenersIndexPath` → custom listeners barrel path. Default: `./src/app/Listeners/index.ts`
|
|
49
|
+
- `--envExamplePath` → custom `.env.example` path. Default: `./.env.example`
|
|
50
|
+
- `--typeImport <statement>` → explicit top-level import statement to inject. Repeatable.
|
|
51
|
+
- `--eventPayloadType <type>` → explicit EventsInterface payload type. Default: `EventBrowserParameters`
|
|
39
52
|
|
|
40
53
|
Operational notes:
|
|
41
54
|
|
|
42
55
|
- `make:page` only triggers handler generation if `handlerPath` exists and at least one of `handler-from` or `handler-to` is provided.
|
|
43
56
|
- The command input is the base page name, not the final class name with `Page` suffix.
|
|
57
|
+
- When `--register` is enabled, registration flags are also forwarded to selector/event/handler add-ons generated by the same `make:page` command.
|
|
58
|
+
- Prefer explicit registration flags instead of assuming app structure when the target project differs from the default ODG layout.
|
|
44
59
|
|
|
45
60
|
Examples:
|
|
46
61
|
|
|
@@ -85,6 +100,9 @@ yarn odg make:selector <selectorName>
|
|
|
85
100
|
Flags:
|
|
86
101
|
|
|
87
102
|
- `-p, --path` → output path for selectors. Default: `./src/Selectors/`
|
|
103
|
+
- `--register` → enable post-scaffold registration. Default: `false`
|
|
104
|
+
- `--selectorsIndexPath` → custom selectors barrel path. Default: `./src/Selectors/index.ts`
|
|
105
|
+
- `--typeImport <statement>` → explicit top-level import statement to inject. Repeatable.
|
|
88
106
|
|
|
89
107
|
Operational notes:
|
|
90
108
|
|
|
@@ -120,6 +138,11 @@ Flags:
|
|
|
120
138
|
- `--handler-from` → origin name for `FromTo` handler generation
|
|
121
139
|
- `--handler-to` → destination name for `FromTo` handler generation
|
|
122
140
|
- `-p, --path` → output path for handlers. Default: `./src/Handlers/`
|
|
141
|
+
- `--register` → enable post-scaffold registration. Default: `false`
|
|
142
|
+
- `--containerEnumPath` → custom ContainerName enum path. Default: `./src/app/Enums/ContainerName.ts`
|
|
143
|
+
- `--containerInterfacePath` → custom ContainerInterface path. Default: `./@types/ContainerInterface.d.ts`
|
|
144
|
+
- `--handlersIndexPath` → custom handlers barrel path. Default: `./src/Handlers/index.ts`
|
|
145
|
+
- `--typeImport <statement>` → explicit top-level import statement to inject. Repeatable.
|
|
123
146
|
|
|
124
147
|
Generated naming:
|
|
125
148
|
|
|
@@ -163,7 +186,15 @@ yarn odg make:event <eventName>
|
|
|
163
186
|
|
|
164
187
|
Flags:
|
|
165
188
|
|
|
166
|
-
- `-p, --path` → output path for listeners. Default: `./src/app/Listeners
|
|
189
|
+
- `-p, --path` → output path for listeners. Default: `./src/app/Listeners/`
|
|
190
|
+
- `--register` → enable post-scaffold registration. Default: `false`
|
|
191
|
+
- `--containerEnumPath` → custom ContainerName enum path. Default: `./src/app/Enums/ContainerName.ts`
|
|
192
|
+
- `--eventEnumPath` → custom EventName enum path. Default: `./src/app/Enums/EventName.ts`
|
|
193
|
+
- `--containerInterfacePath` → custom ContainerInterface path. Default: `./@types/ContainerInterface.d.ts`
|
|
194
|
+
- `--eventsInterfacePath` → custom EventsInterface path. Default: `./@types/EventsInterface.d.ts`
|
|
195
|
+
- `--listenersIndexPath` → custom listeners barrel path. Default: `./src/app/Listeners/index.ts`
|
|
196
|
+
- `--typeImport <statement>` → explicit top-level import statement to inject. Repeatable.
|
|
197
|
+
- `--eventPayloadType <type>` → explicit EventsInterface payload type. Default: `EventBrowserParameters`
|
|
167
198
|
|
|
168
199
|
Operational notes:
|
|
169
200
|
|
|
@@ -184,6 +215,58 @@ yarn odg make:event Login -p src/app/Listeners/Auth
|
|
|
184
215
|
# yarn odg make:event LoginPageEvent ← gera LoginPageEventEventListener (nome duplicado)
|
|
185
216
|
```
|
|
186
217
|
|
|
218
|
+
### make:config
|
|
219
|
+
|
|
220
|
+
Purpose:
|
|
221
|
+
|
|
222
|
+
- Register a new config key in the existing config wiring.
|
|
223
|
+
|
|
224
|
+
Syntax:
|
|
225
|
+
|
|
226
|
+
```bash
|
|
227
|
+
yarn odg make:config <configName>
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
Flags:
|
|
231
|
+
|
|
232
|
+
- `-v, --validator <validator>` → zod validator expression. Default: `zod.string()`
|
|
233
|
+
- `--register` → enable registration. Default: `false`
|
|
234
|
+
- `--configEnumPath` → custom ConfigName enum path. Default: `./src/app/Enums/ConfigName.ts`
|
|
235
|
+
- `--configValidatorPath` → path to the file containing `configValidator = zod.object({...})`. Default: `./src/Configs/index.ts`
|
|
236
|
+
- `--envExamplePath` → custom `.env.example` path. Default: `./.env.example`
|
|
237
|
+
- `--typeImport <statement>` → explicit top-level import statement to inject. Repeatable.
|
|
238
|
+
|
|
239
|
+
Operational notes:
|
|
240
|
+
|
|
241
|
+
- `make:config` does not create a new config stub file.
|
|
242
|
+
- It mutates the existing `configValidator = zod.object({...})` file and appends a new property.
|
|
243
|
+
- The command input is normalized to `CONST_CASE` before registration.
|
|
244
|
+
- If the input is already `CONST_CASE`, it is preserved as-is.
|
|
245
|
+
- The `.env.example` block is appended with one blank line above it, then:
|
|
246
|
+
`# CONFIG_NAME`
|
|
247
|
+
`CONFIG_NAME=""`
|
|
248
|
+
|
|
249
|
+
Examples:
|
|
250
|
+
|
|
251
|
+
```bash
|
|
252
|
+
# PascalCase input → normalized to APP_URL
|
|
253
|
+
# Mutations:
|
|
254
|
+
# - ConfigName.APP_URL = "APP_URL"
|
|
255
|
+
# - configValidator gains [ConfigName.APP_URL]: zod.string()
|
|
256
|
+
# - .env.example gains a blank line, comment and APP_URL=""
|
|
257
|
+
yarn odg make:config APP_URL --register
|
|
258
|
+
|
|
259
|
+
# CONST_CASE input is preserved as-is
|
|
260
|
+
# Mutations use ZECA_URL, not Z_E_C_A__U_R_L
|
|
261
|
+
yarn odg make:config ZECA_URL --register
|
|
262
|
+
|
|
263
|
+
# Custom validator expression in existing config validator file
|
|
264
|
+
yarn odg make:config USE_HEADLESS --register --validator "CustomValidator.zodStringToBoolean()"
|
|
265
|
+
|
|
266
|
+
# Custom config validator path
|
|
267
|
+
yarn odg make:config APP_URL --register --configValidatorPath src/Config/index.ts
|
|
268
|
+
```
|
|
269
|
+
|
|
187
270
|
### make:exception
|
|
188
271
|
|
|
189
272
|
Purpose:
|
|
@@ -199,7 +282,7 @@ yarn odg make:exception <exceptionName>
|
|
|
199
282
|
Flags:
|
|
200
283
|
|
|
201
284
|
- `-u, --isUnknown` → generate unknown exception variant
|
|
202
|
-
- `-p, --path` → output path for exceptions. Default: `./src/Exceptions
|
|
285
|
+
- `-p, --path` → output path for exceptions. Default: `./src/Exceptions/`
|
|
203
286
|
|
|
204
287
|
Examples:
|
|
205
288
|
|
|
@@ -229,39 +312,29 @@ yarn odg make:exception RequestFailure --isUnknown
|
|
|
229
312
|
### Selector naming
|
|
230
313
|
|
|
231
314
|
- Follow the naming convention already used in the selector namespace.
|
|
232
|
-
- If the domain already uses a prefix such as `googleSearchSelector`, keep the same pattern for new selectors.
|
|
233
315
|
- Do not mix prefixed and non-prefixed selectors in the same domain without explicit reason.
|
|
234
316
|
|
|
235
|
-
## Known Pitfalls
|
|
236
|
-
|
|
237
|
-
- Existing destination file: the command fails if the target file already exists.
|
|
238
|
-
- Existing `index.ts`: scaffold may append exports automatically, which can create duplicates.
|
|
239
|
-
- `make:page` does not always generate a handler; linked handler generation is conditional.
|
|
240
|
-
- Default paths assume a standard `src/...` layout.
|
|
241
|
-
|
|
242
|
-
## Agent Checklist
|
|
243
|
-
|
|
244
|
-
- Identify whether a `make:*` command already solves the requested artifact.
|
|
245
|
-
- Use the base resource name as CLI input.
|
|
246
|
-
- Confirm whether the handler validates a result or a transition.
|
|
247
|
-
- Preserve the selector naming convention already used by the domain.
|
|
248
|
-
- Prefer examples derived from `yarn odg --help` and `yarn odg make:* --help`.
|
|
249
|
-
|
|
250
317
|
## 🚦 Rules (Usage)
|
|
251
318
|
|
|
319
|
+
- Prefer examples derived from `yarn odg --help` and `yarn odg make:* --help`.
|
|
252
320
|
- execute in **root app** where default paths and stubs are expected; otherwise, use `-p` to specify custom paths
|
|
253
321
|
- use `--handler-from` and/or `--handler-to` to trigger linked handler generation
|
|
254
322
|
- if generate page, events, sectors and handlers prefer `yarn odg make:page` with flags instead of separate commands to ensure consistent naming and linking
|
|
323
|
+
- registration is opt-in: only expect enum/interface/barrel mutation when `--register` is explicitly present
|
|
324
|
+
- when registration is enabled, prefer explicit path flags over assumptions if the app does not match the default ODG folder layout
|
|
325
|
+
- `--typeImport` is repeatable and intended for explicit imports required before mutating enums/interfaces/barrels
|
|
255
326
|
|
|
256
327
|
## 💥 Exceptions
|
|
257
328
|
|
|
258
329
|
- `InvalidArgumentException` (`@odg/exception`): if file already exists - message error `The {name} already exists.`
|
|
259
|
-
|
|
330
|
+
- Handling: do not create again with the same name in the same path; delete/rename the existing file or change `-p`/name
|
|
260
331
|
- Node I/O failures (reading stub, writing, mkdir) may propagate native error not encapsulated in package-specific type
|
|
261
332
|
|
|
262
333
|
## ⚠️ Integration Pitfalls
|
|
263
334
|
|
|
264
335
|
- Paths default to `./src/...` structure; if the app has a different structure, the agent must use `-p` to specify correct paths.
|
|
336
|
+
- Registration defaults are conservative: no enum/interface/barrel mutation happens unless `--register` is passed.
|
|
265
337
|
- If `index.ts` exists in the target directory, the generator may **append** `export * from "./{FileName}";` — risk of duplicate or undesired export order
|
|
338
|
+
- `make:page --register` can mutate multiple files transitively if `--selectors`, `--event`, or linked handler generation are also enabled, because registration options propagate to generated add-ons
|
|
266
339
|
- Stubs in `./stubs` in the CWD **override** package stubs for that `.stub` file name
|
|
267
340
|
- `main`/`types` point to `dist/` of runtime CLI; do not expect public API types beyond what the package exports in `package.json` (currently: focus on bin + assets)
|
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
import type { LoggerInterface } from "@odg/log";
|
|
2
|
-
|
|
2
|
+
import type { RegistrationTargets } from "../Registrations/types";
|
|
3
|
+
interface RegistrationOptions {
|
|
4
|
+
register?: boolean;
|
|
5
|
+
registrationTargets?: Omit<RegistrationTargets, "enabled">;
|
|
6
|
+
containerEnumPath?: string;
|
|
7
|
+
eventEnumPath?: string;
|
|
8
|
+
configEnumPath?: string;
|
|
9
|
+
configValidatorPath?: string;
|
|
10
|
+
containerInterfacePath?: string;
|
|
11
|
+
eventsInterfacePath?: string;
|
|
12
|
+
pagesIndexPath?: string;
|
|
13
|
+
selectorsIndexPath?: string;
|
|
14
|
+
handlersIndexPath?: string;
|
|
15
|
+
listenersIndexPath?: string;
|
|
16
|
+
envExamplePath?: string;
|
|
17
|
+
eventPayloadType?: string;
|
|
18
|
+
containerEnumMemberValue?: string;
|
|
19
|
+
typeImport?: string[];
|
|
20
|
+
typeImports?: string[];
|
|
21
|
+
}
|
|
22
|
+
export interface MakePageOptions extends RegistrationOptions {
|
|
3
23
|
selectors: boolean;
|
|
4
24
|
event: boolean;
|
|
5
25
|
path: string;
|
|
@@ -9,63 +29,54 @@ interface MakePageInterface {
|
|
|
9
29
|
handlerFrom?: string;
|
|
10
30
|
handlerTo?: string;
|
|
11
31
|
}
|
|
12
|
-
interface
|
|
32
|
+
export interface MakeSelectorOptions extends RegistrationOptions {
|
|
13
33
|
path: string;
|
|
14
34
|
}
|
|
15
|
-
interface
|
|
35
|
+
export interface MakeHandlerOptions extends RegistrationOptions {
|
|
16
36
|
path: string;
|
|
17
37
|
handlerFrom?: string;
|
|
18
38
|
handlerTo?: string;
|
|
19
39
|
}
|
|
20
|
-
interface
|
|
40
|
+
export interface MakeEventOptions extends RegistrationOptions {
|
|
21
41
|
path: string;
|
|
22
42
|
}
|
|
23
|
-
interface
|
|
43
|
+
export interface MakeExceptionOptions {
|
|
24
44
|
path: string;
|
|
25
45
|
isUnknown: boolean;
|
|
26
46
|
}
|
|
47
|
+
export interface MakeConfigOptions extends RegistrationOptions {
|
|
48
|
+
path?: string;
|
|
49
|
+
/** Zod validator expression written into configValidator, e.g. `zod.string()` */
|
|
50
|
+
validator?: string;
|
|
51
|
+
/** Path to the file that exports `configValidator = zod.object({...})`. */
|
|
52
|
+
configValidatorPath?: string;
|
|
53
|
+
}
|
|
27
54
|
export default class MakeFile {
|
|
28
55
|
private readonly logger;
|
|
56
|
+
private readonly stubCreator;
|
|
29
57
|
constructor(logger: LoggerInterface);
|
|
30
58
|
/**
|
|
31
59
|
* Use this function to create Page Crawler class
|
|
32
60
|
*
|
|
33
61
|
* @param {string} pageName Selector file name
|
|
34
|
-
* @param {
|
|
35
|
-
* @returns {Promise<void>}
|
|
36
|
-
*/
|
|
37
|
-
makePage(pageName: string, options: MakePageInterface): Promise<void>;
|
|
38
|
-
/**
|
|
39
|
-
* Use this function to create selector class
|
|
40
|
-
*
|
|
41
|
-
* @param {string} selectorName Page Selector file name
|
|
42
|
-
* @param {MakeSelectorInterface} options Options command
|
|
43
|
-
* @returns {Promise<void>}
|
|
44
|
-
*/
|
|
45
|
-
makeSelectors(selectorName: string, options: MakeSelectorInterface): Promise<void>;
|
|
46
|
-
/**
|
|
47
|
-
* Use this function to create handler file
|
|
48
|
-
*
|
|
49
|
-
* @param {string} handlerName Handler name to make
|
|
50
|
-
* @param {MakeHandlerInterface} options Options command
|
|
51
|
-
* @returns {Promise<void>}
|
|
52
|
-
*/
|
|
53
|
-
makeHandler(handlerName: string, options: MakeHandlerInterface): Promise<void>;
|
|
54
|
-
/**
|
|
55
|
-
* Use this function to create handler file
|
|
56
|
-
*
|
|
57
|
-
* @param {string} eventName Event name to make
|
|
58
|
-
* @param {MakeEventInterface} options Options command
|
|
62
|
+
* @param {MakePageOptions} options Options command
|
|
59
63
|
* @returns {Promise<void>}
|
|
60
64
|
*/
|
|
61
|
-
|
|
65
|
+
makePage(pageName: string, options: MakePageOptions): Promise<void>;
|
|
66
|
+
makeSelectors(selectorName: string, options: MakeSelectorOptions): Promise<void>;
|
|
67
|
+
makeHandler(handlerName: string, options: MakeHandlerOptions): Promise<void>;
|
|
68
|
+
makeEvent(eventName: string, options: MakeEventOptions): Promise<void>;
|
|
69
|
+
makeConfig(configName: string, options: MakeConfigOptions): Promise<void>;
|
|
70
|
+
makeException(exceptionName: string, options: MakeExceptionOptions): Promise<void>;
|
|
71
|
+
private buildRegistrationTargets;
|
|
62
72
|
/**
|
|
63
|
-
*
|
|
73
|
+
* Runs optional selector, event, and handler file generation from make:page, forwarding `register` and
|
|
74
|
+
* `registrationTargets` so enums and barrels stay in sync with the parent command.
|
|
64
75
|
*
|
|
65
|
-
* @param {string}
|
|
66
|
-
* @param {
|
|
76
|
+
* @param {string} pageName Base page name (same as make:page first argument)
|
|
77
|
+
* @param {MakePageOptions} options Full make:page options including paths and registration targets
|
|
67
78
|
* @returns {Promise<void>}
|
|
68
79
|
*/
|
|
69
|
-
|
|
80
|
+
private scaffoldPageAddOns;
|
|
70
81
|
}
|
|
71
82
|
export {};
|
|
@@ -4,9 +4,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const chemical_x_1 = require("@odg/chemical-x");
|
|
7
|
+
const register_1 = require("../Registrations/register");
|
|
7
8
|
const StubCreator_1 = __importDefault(require("./StubCreator"));
|
|
8
9
|
class MakeFile {
|
|
9
10
|
logger;
|
|
11
|
+
stubCreator = new StubCreator_1.default();
|
|
10
12
|
constructor(logger) {
|
|
11
13
|
this.logger = logger;
|
|
12
14
|
}
|
|
@@ -14,98 +16,138 @@ class MakeFile {
|
|
|
14
16
|
* Use this function to create Page Crawler class
|
|
15
17
|
*
|
|
16
18
|
* @param {string} pageName Selector file name
|
|
17
|
-
* @param {
|
|
19
|
+
* @param {MakePageOptions} options Options command
|
|
18
20
|
* @returns {Promise<void>}
|
|
19
21
|
*/
|
|
20
22
|
async makePage(pageName, options) {
|
|
21
|
-
const stubCreator = new StubCreator_1.default();
|
|
22
23
|
const pageUcFirst = new chemical_x_1.Str(pageName).ucFirst().toString();
|
|
23
|
-
const filePath = await stubCreator.create("page", `${pageUcFirst}Page`, options.path, {
|
|
24
|
+
const filePath = await this.stubCreator.create("page", `${pageUcFirst}Page`, options.path, {
|
|
24
25
|
"PageName:UCFirst": pageUcFirst,
|
|
25
26
|
"PageName:LCFirst": pageName.charAt(0).toLowerCase() + pageName.slice(1),
|
|
26
27
|
});
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
handlerFrom: options.handlerFrom,
|
|
37
|
-
handlerTo: options.handlerTo,
|
|
38
|
-
});
|
|
39
|
-
}
|
|
28
|
+
const targets = this.buildRegistrationTargets(options);
|
|
29
|
+
await this.scaffoldPageAddOns(pageName, options);
|
|
30
|
+
await (0, register_1.registerArtifact)({
|
|
31
|
+
kind: "page",
|
|
32
|
+
name: pageName,
|
|
33
|
+
pageClassName: `${pageUcFirst}Page`,
|
|
34
|
+
containerEnumMember: `${pageUcFirst}Page`,
|
|
35
|
+
filePath,
|
|
36
|
+
}, targets);
|
|
40
37
|
await this.logger.info(`Page created successfully in : ${filePath}`);
|
|
41
38
|
}
|
|
42
|
-
/**
|
|
43
|
-
* Use this function to create selector class
|
|
44
|
-
*
|
|
45
|
-
* @param {string} selectorName Page Selector file name
|
|
46
|
-
* @param {MakeSelectorInterface} options Options command
|
|
47
|
-
* @returns {Promise<void>}
|
|
48
|
-
*/
|
|
49
39
|
async makeSelectors(selectorName, options) {
|
|
50
|
-
const stubCreator = new StubCreator_1.default();
|
|
51
40
|
const pageUcFirst = new chemical_x_1.Str(selectorName).ucFirst().toString();
|
|
52
|
-
const filePath = await stubCreator.create("selector", `${pageUcFirst}Selector`, options.path, {
|
|
41
|
+
const filePath = await this.stubCreator.create("selector", `${pageUcFirst}Selector`, options.path, {
|
|
53
42
|
"SelectorName:UCFirst": pageUcFirst,
|
|
54
43
|
"SelectorName:LCFirst": selectorName.charAt(0).toLowerCase() + selectorName.slice(1),
|
|
55
44
|
});
|
|
45
|
+
await (0, register_1.registerArtifact)({
|
|
46
|
+
kind: "selector",
|
|
47
|
+
name: selectorName,
|
|
48
|
+
selectorClassName: `${pageUcFirst}Selector`,
|
|
49
|
+
filePath,
|
|
50
|
+
}, this.buildRegistrationTargets(options));
|
|
56
51
|
await this.logger.info(`Selector created successfully in : ${filePath}`);
|
|
57
52
|
}
|
|
58
|
-
/**
|
|
59
|
-
* Use this function to create handler file
|
|
60
|
-
*
|
|
61
|
-
* @param {string} handlerName Handler name to make
|
|
62
|
-
* @param {MakeHandlerInterface} options Options command
|
|
63
|
-
* @returns {Promise<void>}
|
|
64
|
-
*/
|
|
65
53
|
async makeHandler(handlerName, options) {
|
|
66
|
-
const stubCreator = new StubCreator_1.default();
|
|
67
54
|
const isTransition = options.handlerFrom !== undefined || options.handlerTo !== undefined;
|
|
68
55
|
const handlerClassName = isTransition
|
|
69
56
|
? `${new chemical_x_1.Str(options.handlerFrom ?? handlerName).ucFirst().toString()}To${new chemical_x_1.Str(options.handlerTo ?? handlerName).ucFirst().toString()}Handler`
|
|
70
57
|
: `${new chemical_x_1.Str(handlerName).ucFirst().toString()}Handler`;
|
|
71
|
-
const
|
|
58
|
+
const handlerPageLcFirst = handlerName.charAt(0).toLowerCase() + handlerName.slice(1);
|
|
59
|
+
const handlerPageSelectorBundle = `${handlerPageLcFirst}Selector`;
|
|
60
|
+
const filePath = await this.stubCreator.create("handler", handlerClassName, options.path, {
|
|
72
61
|
"HandlerClassName": handlerClassName,
|
|
62
|
+
"HandlerPageSelectorBundle": handlerPageSelectorBundle,
|
|
73
63
|
});
|
|
64
|
+
await (0, register_1.registerArtifact)({
|
|
65
|
+
kind: "handler",
|
|
66
|
+
name: handlerName,
|
|
67
|
+
handlerClassName,
|
|
68
|
+
containerEnumMember: handlerClassName,
|
|
69
|
+
filePath,
|
|
70
|
+
}, this.buildRegistrationTargets(options));
|
|
74
71
|
await this.logger.info(`Handler created successfully in : ${filePath}`);
|
|
75
72
|
}
|
|
76
|
-
/**
|
|
77
|
-
* Use this function to create handler file
|
|
78
|
-
*
|
|
79
|
-
* @param {string} eventName Event name to make
|
|
80
|
-
* @param {MakeEventInterface} options Options command
|
|
81
|
-
* @returns {Promise<void>}
|
|
82
|
-
*/
|
|
83
73
|
async makeEvent(eventName, options) {
|
|
84
|
-
const stubCreator = new StubCreator_1.default();
|
|
85
74
|
const pageUcFirst = new chemical_x_1.Str(eventName).ucFirst().toString();
|
|
86
|
-
const
|
|
75
|
+
const listenerClassName = `${pageUcFirst}EventListener`;
|
|
76
|
+
const eventEnumMember = `${pageUcFirst}Event`;
|
|
77
|
+
const containerEnumMember = `${pageUcFirst}EventListener`;
|
|
78
|
+
const filePath = await this.stubCreator.create("event", listenerClassName, options.path, {
|
|
87
79
|
"EventName:UCFirst": pageUcFirst,
|
|
88
80
|
"EventName:LCFirst": eventName.charAt(0).toLowerCase() + eventName.slice(1),
|
|
89
81
|
});
|
|
82
|
+
await (0, register_1.registerArtifact)({
|
|
83
|
+
kind: "event",
|
|
84
|
+
name: eventName,
|
|
85
|
+
listenerClassName,
|
|
86
|
+
eventEnumMember,
|
|
87
|
+
containerEnumMember,
|
|
88
|
+
filePath,
|
|
89
|
+
}, this.buildRegistrationTargets(options));
|
|
90
90
|
await this.logger.info(`Event created successfully in : ${filePath}`);
|
|
91
91
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
92
|
+
async makeConfig(configName, options) {
|
|
93
|
+
const validator = options.validator ?? "zod.string()";
|
|
94
|
+
await (0, register_1.registerArtifact)({
|
|
95
|
+
kind: "config",
|
|
96
|
+
name: configName,
|
|
97
|
+
configEnumMembers: [configName],
|
|
98
|
+
envExampleLines: [`\n# ${configName}`, `${configName}=""`],
|
|
99
|
+
configValidatorType: validator,
|
|
100
|
+
}, this.buildRegistrationTargets(options));
|
|
101
|
+
await this.logger.info(`Config "${configName}" registered successfully`);
|
|
102
|
+
}
|
|
99
103
|
async makeException(exceptionName, options) {
|
|
100
|
-
const stubCreator = new StubCreator_1.default();
|
|
101
104
|
const exceptionUcFirst = new chemical_x_1.Str(exceptionName).ucFirst().toString();
|
|
102
105
|
const exceptionType = options.isUnknown ? "UnknownException" : "Exception";
|
|
103
|
-
const filePath = await stubCreator.create("exception", `${exceptionUcFirst}${exceptionType}`, options.path, {
|
|
106
|
+
const filePath = await this.stubCreator.create("exception", `${exceptionUcFirst}${exceptionType}`, options.path, {
|
|
104
107
|
"ExceptionType": exceptionType,
|
|
105
108
|
"ExceptionName": exceptionUcFirst,
|
|
106
109
|
});
|
|
107
110
|
await this.logger.info(`Exception created successfully in : ${filePath}`);
|
|
108
111
|
}
|
|
112
|
+
buildRegistrationTargets(options) {
|
|
113
|
+
const { register = false, registrationTargets, typeImport, typeImports, ...targets } = options;
|
|
114
|
+
return {
|
|
115
|
+
enabled: register,
|
|
116
|
+
...registrationTargets,
|
|
117
|
+
...targets,
|
|
118
|
+
typeImports: typeImports ?? typeImport ?? registrationTargets?.typeImports,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Runs optional selector, event, and handler file generation from make:page, forwarding `register` and
|
|
123
|
+
* `registrationTargets` so enums and barrels stay in sync with the parent command.
|
|
124
|
+
*
|
|
125
|
+
* @param {string} pageName Base page name (same as make:page first argument)
|
|
126
|
+
* @param {MakePageOptions} options Full make:page options including paths and registration targets
|
|
127
|
+
* @returns {Promise<void>}
|
|
128
|
+
*/
|
|
129
|
+
async scaffoldPageAddOns(pageName, options) {
|
|
130
|
+
if (options.selectors && options.selectorPath) {
|
|
131
|
+
await this.makeSelectors(pageName, {
|
|
132
|
+
...options,
|
|
133
|
+
path: options.selectorPath,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
if (options.event && options.eventPath) {
|
|
137
|
+
await this.makeEvent(pageName, {
|
|
138
|
+
...options,
|
|
139
|
+
path: options.eventPath,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
if (options.handlerPath && (options.handlerFrom ?? options.handlerTo)) {
|
|
143
|
+
await this.makeHandler(pageName, {
|
|
144
|
+
...options,
|
|
145
|
+
path: options.handlerPath,
|
|
146
|
+
handlerFrom: options.handlerFrom,
|
|
147
|
+
handlerTo: options.handlerTo,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
109
151
|
}
|
|
110
152
|
exports.default = MakeFile;
|
|
111
153
|
//# sourceMappingURL=MakeFile.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MakeFile.js","sourceRoot":"","sources":["../../src/Generators/MakeFile.ts"],"names":[],"mappings":";;;;;AAAA,gDAAsC;AAGtC,gEAAwC;
|
|
1
|
+
{"version":3,"file":"MakeFile.js","sourceRoot":"","sources":["../../src/Generators/MakeFile.ts"],"names":[],"mappings":";;;;;AAAA,gDAAsC;AAGtC,wDAA6D;AAG7D,gEAAwC;AA8DxC,MAAqB,QAAQ;IAIW;IAFnB,WAAW,GAAG,IAAI,qBAAW,EAAE,CAAC;IAEjD,YAAoC,MAAuB;QAAvB,WAAM,GAAN,MAAM,CAAiB;IAE3D,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,QAAQ,CAAC,QAAgB,EAAE,OAAwB;QAC5D,MAAM,WAAW,GAAG,IAAI,gBAAG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;;;;;;;OAOG;IACK,KAAK,CAAC,kBAAkB,CAAC,QAAgB,EAAE,OAAwB;QACvE,IAAI,OAAO,CAAC,SAAS,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;YAC5C,MAAM,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE;gBAC/B,GAAG,OAAO;gBACV,IAAI,EAAE,OAAO,CAAC,YAAY;aAC7B,CAAC,CAAC;QACP,CAAC;QAED,IAAI,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;YACrC,MAAM,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE;gBAC3B,GAAG,OAAO;gBACV,IAAI,EAAE,OAAO,CAAC,SAAS;aAC1B,CAAC,CAAC;QACP,CAAC;QAED,IAAI,OAAO,CAAC,WAAW,IAAI,CAAC,OAAO,CAAC,WAAW,IAAI,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;YACpE,MAAM,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE;gBAC7B,GAAG,OAAO;gBACV,IAAI,EAAE,OAAO,CAAC,WAAW;gBACzB,WAAW,EAAE,OAAO,CAAC,WAAW;gBAChC,SAAS,EAAE,OAAO,CAAC,SAAS;aAC/B,CAAC,CAAC;QACP,CAAC;IACL,CAAC;CAEJ;AApLD,2BAoLC"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export default class StubCreator {
|
|
2
|
-
private readonly filesystem;
|
|
3
2
|
create(stub: string, name: string, pathDestination: string, variables: Record<string, number | string>): Promise<string>;
|
|
4
3
|
/**
|
|
5
4
|
* Return stub file content.
|
|
@@ -24,4 +23,5 @@ export default class StubCreator {
|
|
|
24
23
|
* @returns {Promise<string>}
|
|
25
24
|
*/
|
|
26
25
|
getStubPath(name: string): Promise<string>;
|
|
26
|
+
private appendToIndexIfExists;
|
|
27
27
|
}
|
|
@@ -1,60 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
4
|
};
|
|
38
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
const
|
|
6
|
+
const promises_1 = require("node:fs/promises");
|
|
40
7
|
const node_path_1 = __importDefault(require("node:path"));
|
|
41
|
-
const node_util_1 = require("node:util");
|
|
42
8
|
const chemical_x_1 = require("@odg/chemical-x");
|
|
43
9
|
const exception_1 = require("@odg/exception");
|
|
44
10
|
class StubCreator {
|
|
45
|
-
filesystem = Filesystem;
|
|
46
11
|
async create(stub, name, pathDestination, variables) {
|
|
47
12
|
const destination = await this.getPath(name, pathDestination);
|
|
48
13
|
if (await new chemical_x_1.File(destination).exists()) {
|
|
49
14
|
throw new exception_1.InvalidArgumentException(`The ${name} already exists.`);
|
|
50
15
|
}
|
|
51
16
|
const content = await this.getStub(stub, variables);
|
|
52
|
-
await (0,
|
|
53
|
-
await (0,
|
|
17
|
+
await (0, promises_1.mkdir)(pathDestination, { recursive: true });
|
|
18
|
+
await (0, promises_1.writeFile)(destination, content);
|
|
54
19
|
const indexFile = `${pathDestination}/index.ts`;
|
|
55
|
-
|
|
56
|
-
await (0, node_util_1.promisify)(this.filesystem.appendFile)(indexFile, `\nexport * from "./${name}";\n`, {});
|
|
57
|
-
}
|
|
20
|
+
await this.appendToIndexIfExists(indexFile, name);
|
|
58
21
|
return destination;
|
|
59
22
|
}
|
|
60
23
|
/**
|
|
@@ -66,7 +29,7 @@ class StubCreator {
|
|
|
66
29
|
*/
|
|
67
30
|
async getStub(name, variables) {
|
|
68
31
|
const pathStub = await this.getStubPath(name);
|
|
69
|
-
const file = await (0,
|
|
32
|
+
const file = await (0, promises_1.readFile)(`${pathStub}/${name}.stub`);
|
|
70
33
|
return new chemical_x_1.Str(file.toString())
|
|
71
34
|
.formatUnicorn(variables)
|
|
72
35
|
.toString();
|
|
@@ -93,6 +56,18 @@ class StubCreator {
|
|
|
93
56
|
}
|
|
94
57
|
return node_path_1.default.join(process.cwd(), "node_modules/@odg/command/stubs");
|
|
95
58
|
}
|
|
59
|
+
async appendToIndexIfExists(indexFile, name) {
|
|
60
|
+
if (!await new chemical_x_1.File(indexFile).exists()) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const exportLine = `export * from "./${name}";`;
|
|
64
|
+
const existing = await (0, promises_1.readFile)(indexFile, { encoding: "utf8" });
|
|
65
|
+
if (existing.includes(exportLine)) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const insert = existing.endsWith("\n") || existing.length === 0 ? "" : "\n";
|
|
69
|
+
await (0, promises_1.appendFile)(indexFile, `${insert}${exportLine}\n`);
|
|
70
|
+
}
|
|
96
71
|
}
|
|
97
72
|
exports.default = StubCreator;
|
|
98
73
|
//# sourceMappingURL=StubCreator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StubCreator.js","sourceRoot":"","sources":["../../src/Generators/StubCreator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"StubCreator.js","sourceRoot":"","sources":["../../src/Generators/StubCreator.ts"],"names":[],"mappings":";;;;;AAAA,+CAK0B;AAC1B,0DAAiC;AAEjC,gDAA4C;AAC5C,8CAA0D;AAE1D,MAAqB,WAAW;IAErB,KAAK,CAAC,MAAM,CACf,IAAY,EACZ,IAAY,EACZ,eAAuB,EACvB,SAA0C;QAE1C,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;QAE9D,IAAI,MAAM,IAAI,iBAAI,CAAC,WAAW,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC;YACvC,MAAM,IAAI,oCAAwB,CAAC,OAAO,IAAI,kBAAkB,CAAC,CAAC;QACtE,CAAC;QAED,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QAEpD,MAAM,IAAA,gBAAK,EAAC,eAAe,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAClD,MAAM,IAAA,oBAAS,EAAC,WAAW,EAAE,OAAO,CAAC,CAAC;QAEtC,MAAM,SAAS,GAAG,GAAG,eAAe,WAAW,CAAC;QAEhD,MAAM,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