nest-hex 0.2.0 → 0.3.2

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.
Files changed (51) hide show
  1. package/README.md +155 -267
  2. package/dist/src/cli/bin.js +2644 -0
  3. package/dist/src/cli/commands/index.d.ts +23 -0
  4. package/dist/src/cli/commands/index.js +2609 -0
  5. package/dist/src/cli/config/defaults.d.ts +74 -0
  6. package/dist/src/cli/config/defaults.js +76 -0
  7. package/dist/src/cli/config/define-config.d.ts +74 -0
  8. package/dist/src/cli/config/define-config.js +62 -0
  9. package/dist/src/cli/config/loader.d.ts +74 -0
  10. package/dist/src/cli/config/loader.js +106 -0
  11. package/dist/src/cli/config/validator.d.ts +81 -0
  12. package/dist/src/cli/config/validator.js +108 -0
  13. package/dist/src/cli/generators/adapter.generator.d.ts +235 -0
  14. package/dist/src/cli/generators/adapter.generator.js +377 -0
  15. package/dist/src/cli/generators/base.generator.d.ts +190 -0
  16. package/dist/src/cli/generators/base.generator.js +312 -0
  17. package/dist/src/cli/generators/index.d.ts +264 -0
  18. package/dist/src/cli/generators/index.js +467 -0
  19. package/dist/src/cli/generators/port.generator.d.ts +211 -0
  20. package/dist/src/cli/generators/port.generator.js +364 -0
  21. package/dist/src/cli/generators/service.generator.d.ts +208 -0
  22. package/dist/src/cli/generators/service.generator.js +340 -0
  23. package/dist/src/cli/index.d.ts +74 -0
  24. package/dist/src/cli/index.js +69 -0
  25. package/dist/src/cli/types/config.types.d.ts +73 -0
  26. package/dist/src/cli/types/config.types.js +56 -0
  27. package/dist/src/cli/types/generator.types.d.ts +46 -0
  28. package/dist/src/cli/types/generator.types.js +56 -0
  29. package/dist/src/cli/types/index.d.ts +121 -0
  30. package/dist/src/cli/types/index.js +56 -0
  31. package/dist/src/cli/types/template.types.d.ts +28 -0
  32. package/dist/src/cli/types/template.types.js +56 -0
  33. package/dist/src/cli/ui/components/index.d.ts +97 -0
  34. package/dist/src/cli/ui/components/index.js +1507 -0
  35. package/dist/src/cli/utils/file-writer.d.ts +17 -0
  36. package/dist/src/cli/utils/file-writer.js +100 -0
  37. package/dist/src/cli/utils/linter-detector.d.ts +12 -0
  38. package/dist/src/cli/utils/linter-detector.js +128 -0
  39. package/dist/src/cli/utils/linter-runner.d.ts +17 -0
  40. package/dist/src/cli/utils/linter-runner.js +101 -0
  41. package/dist/src/cli/utils/name-transformer.d.ts +18 -0
  42. package/dist/src/cli/utils/name-transformer.js +90 -0
  43. package/dist/src/cli/utils/path-resolver.d.ts +5 -0
  44. package/dist/src/cli/utils/path-resolver.js +78 -0
  45. package/dist/src/cli/utils/port-scanner.d.ts +93 -0
  46. package/dist/src/cli/utils/port-scanner.js +104 -0
  47. package/dist/src/cli/utils/template-renderer.d.ts +30 -0
  48. package/dist/src/cli/utils/template-renderer.js +95 -0
  49. package/dist/{index.d.ts → src/index.d.ts} +60 -30
  50. package/dist/{index.js → src/index.js} +45 -13
  51. package/package.json +10 -10
@@ -0,0 +1,264 @@
1
+ /**
2
+ * Configuration types for nest-hex CLI
3
+ */
4
+ interface NestHexConfig {
5
+ /**
6
+ * Output directory configuration
7
+ */
8
+ output?: {
9
+ /**
10
+ * Directory for generated ports
11
+ * @default 'src/ports'
12
+ */
13
+ portsDir?: string;
14
+ /**
15
+ * Directory for generated adapters
16
+ * @default 'src/adapters'
17
+ */
18
+ adaptersDir?: string;
19
+ };
20
+ /**
21
+ * Naming conventions
22
+ */
23
+ naming?: {
24
+ /**
25
+ * Suffix for port tokens
26
+ * @default 'PORT'
27
+ */
28
+ portSuffix?: string;
29
+ /**
30
+ * Suffix for adapter classes
31
+ * @default 'Adapter'
32
+ */
33
+ adapterSuffix?: string;
34
+ /**
35
+ * File naming case
36
+ * @default 'kebab'
37
+ */
38
+ fileCase?: "kebab" | "camel" | "pascal";
39
+ };
40
+ /**
41
+ * Code style preferences
42
+ */
43
+ style?: {
44
+ /**
45
+ * Indentation style
46
+ * @default 'tab'
47
+ */
48
+ indent?: "tab" | 2 | 4;
49
+ /**
50
+ * Quote style
51
+ * @default 'single'
52
+ */
53
+ quotes?: "single" | "double";
54
+ /**
55
+ * Use semicolons
56
+ * @default true
57
+ */
58
+ semicolons?: boolean;
59
+ };
60
+ /**
61
+ * Custom template paths
62
+ */
63
+ templates?: {
64
+ portModule?: string;
65
+ portToken?: string;
66
+ portInterface?: string;
67
+ portService?: string;
68
+ adapterModule?: string;
69
+ adapterService?: string;
70
+ adapterTypes?: string;
71
+ };
72
+ }
73
+ /**
74
+ * Generator types for CLI
75
+ */
76
+ interface GeneratorOptions {
77
+ name: string;
78
+ outputPath?: string;
79
+ includeModule?: boolean;
80
+ includeService?: boolean;
81
+ registrationType?: "sync" | "async";
82
+ generateExample?: boolean;
83
+ dryRun?: boolean;
84
+ }
85
+ interface GeneratorContext extends Record<string, unknown> {
86
+ original: string;
87
+ kebab: string;
88
+ camel: string;
89
+ pascal: string;
90
+ snake: string;
91
+ screamingSnake: string;
92
+ nameKebab: string;
93
+ nameCamel: string;
94
+ namePascal: string;
95
+ nameSnake: string;
96
+ nameScreamingSnake: string;
97
+ portSuffix: string;
98
+ adapterSuffix: string;
99
+ fileCase: "kebab" | "camel" | "pascal";
100
+ indent: "tab" | number;
101
+ quotes: "single" | "double";
102
+ semicolons: boolean;
103
+ includeModule: boolean;
104
+ includeService: boolean;
105
+ registrationType: "sync" | "async";
106
+ generateExample: boolean;
107
+ coreImportPath: string;
108
+ }
109
+ interface FileToGenerate {
110
+ path: string;
111
+ content: string;
112
+ }
113
+ interface GeneratorResult {
114
+ files: string[];
115
+ success: boolean;
116
+ message?: string;
117
+ }
118
+ interface NameVariations {
119
+ original: string;
120
+ kebab: string;
121
+ camel: string;
122
+ pascal: string;
123
+ snake: string;
124
+ screamingSnake: string;
125
+ }
126
+ declare function generateNameVariations(name: string): NameVariations;
127
+ /**
128
+ * Abstract base class for all generators.
129
+ *
130
+ * Provides common functionality like:
131
+ * - Template rendering
132
+ * - File writing
133
+ * - Name transformations
134
+ * - Path resolution
135
+ */
136
+ declare abstract class BaseGenerator {
137
+ protected readonly config: NestHexConfig;
138
+ constructor(config: NestHexConfig);
139
+ /**
140
+ * Render a template with the given context.
141
+ *
142
+ * @param templatePath - Path to the Handlebars template file
143
+ * @param context - Template context
144
+ * @returns Rendered template content
145
+ */
146
+ protected renderTemplate(templatePath: string, context: GeneratorContext): Promise<string>;
147
+ /**
148
+ * Write a file to disk.
149
+ *
150
+ * @param filePath - Destination file path
151
+ * @param content - File content
152
+ * @param dryRun - If true, don't actually write the file
153
+ * @returns WriteResult indicating success and conflict status
154
+ */
155
+ protected writeFile(filePath: string, content: string, dryRun?: boolean): Promise<import("../utils/file-writer").WriteResult>;
156
+ /**
157
+ * Generate all name variations for a given name.
158
+ *
159
+ * @param name - Original name
160
+ * @returns Object with all name case variations
161
+ */
162
+ protected getNameVariations(name: string): ReturnType<typeof generateNameVariations>;
163
+ /**
164
+ * Resolve a path relative to the project root.
165
+ *
166
+ * @param relativePath - Relative path
167
+ * @returns Absolute path
168
+ */
169
+ protected resolvePath(relativePath: string): string;
170
+ /**
171
+ * Get the template directory for a specific generator type.
172
+ *
173
+ * @param type - Generator type (port, adapter, service)
174
+ * @returns Absolute path to template directory
175
+ */
176
+ protected getTemplateDir(type: "port" | "adapter" | "service" | "examples"): string;
177
+ /**
178
+ * Create a template context from generator options.
179
+ *
180
+ * @param options - Generator options
181
+ * @param additionalContext - Additional context to merge
182
+ * @returns Complete template context
183
+ */
184
+ protected createTemplateContext(options: GeneratorOptions, additionalContext?: Record<string, unknown>): GeneratorContext;
185
+ /**
186
+ * Generate files from a list of file specifications.
187
+ *
188
+ * @param files - Array of files to generate
189
+ * @param dryRun - If true, don't actually write files
190
+ * @returns Array of successfully generated file paths
191
+ * @throws Error if any files fail to write
192
+ */
193
+ protected generateFiles(files: FileToGenerate[], dryRun?: boolean): Promise<string[]>;
194
+ }
195
+ /**
196
+ * Generator for creating port files.
197
+ *
198
+ * Generates:
199
+ * - Port interface (domain contract)
200
+ * - Port token (dependency injection token)
201
+ * - Port service (optional - domain service using the port)
202
+ * - Port module (optional - feature module wrapper)
203
+ * - Index file (barrel exports)
204
+ */
205
+ declare class PortGenerator extends BaseGenerator {
206
+ /**
207
+ * Generate all port files.
208
+ */
209
+ generate(options: GeneratorOptions): Promise<GeneratorResult>;
210
+ }
211
+ /**
212
+ * Additional options for adapter generation.
213
+ */
214
+ interface AdapterGeneratorOptions extends GeneratorOptions {
215
+ /**
216
+ * Name of the port this adapter implements.
217
+ * Used to generate correct imports and token references.
218
+ */
219
+ portName?: string;
220
+ /**
221
+ * Path to the port interface file (for imports).
222
+ * If not provided, assumes standard structure.
223
+ */
224
+ portPath?: string;
225
+ /**
226
+ * Port token name (e.g., "OBJECT_STORAGE_PORT").
227
+ * Used in the @Port decorator.
228
+ */
229
+ portTokenName?: string;
230
+ /**
231
+ * Technology or service being adapted (e.g., "AWS S3", "HTTP API").
232
+ * Used in documentation comments.
233
+ */
234
+ technology?: string;
235
+ }
236
+ /**
237
+ * Generator for creating adapter files.
238
+ *
239
+ * Generates:
240
+ * - Adapter class (extends Adapter base class with @Port decorator)
241
+ * - Service implementation (implements the port interface)
242
+ * - Types file (adapter configuration options)
243
+ * - Index file (barrel exports)
244
+ */
245
+ declare class AdapterGenerator extends BaseGenerator {
246
+ /**
247
+ * Generate all adapter files.
248
+ */
249
+ generate(options: AdapterGeneratorOptions): Promise<GeneratorResult>;
250
+ }
251
+ /**
252
+ * Generator for creating standalone services.
253
+ *
254
+ * Generates:
255
+ * - Injectable service that uses @InjectPort to inject an existing port
256
+ * - Can be created with or without port injection scaffolding
257
+ */
258
+ declare class ServiceGenerator extends BaseGenerator {
259
+ /**
260
+ * Generate service file.
261
+ */
262
+ generate(options: GeneratorOptions): Promise<GeneratorResult>;
263
+ }
264
+ export { ServiceGenerator, PortGenerator, BaseGenerator, AdapterGeneratorOptions, AdapterGenerator };