@gravito/scaffold 3.0.0 → 3.1.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/index.cjs +1361 -1642
- package/dist/index.d.cts +378 -308
- package/dist/index.d.ts +378 -308
- package/dist/index.js +1360 -1642
- package/package.json +7 -5
- package/templates/common/Dockerfile.hbs +25 -0
- package/templates/common/env.example.hbs +13 -0
- package/templates/common/gitignore.hbs +10 -0
- package/templates/common/tsconfig.json.hbs +22 -0
- package/templates/features/otel/package.json +6 -6
- package/templates/features/redis/package.json +4 -4
- package/templates/overlays/core/package.json +4 -4
- package/templates/overlays/enterprise/package.json +6 -6
- package/templates/overlays/scale/package.json +5 -5
- package/templates/scripts/check-dependencies.ts.hbs +142 -0
- package/templates/scripts/check.sh.hbs +55 -0
- package/templates/scripts/pre-commit.sh.hbs +58 -0
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,20 @@
|
|
|
1
1
|
import Handlebars from 'handlebars';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Supported project profiles defining the set of included orbits and default drivers.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
* @since 3.0.0
|
|
8
|
+
*/
|
|
3
9
|
type ProfileType = 'core' | 'scale' | 'enterprise';
|
|
10
|
+
/**
|
|
11
|
+
* Resolved configuration for a project profile.
|
|
12
|
+
*
|
|
13
|
+
* @public
|
|
14
|
+
* @since 3.0.0
|
|
15
|
+
*/
|
|
4
16
|
interface ProfileConfig {
|
|
17
|
+
/** Map of default service drivers. */
|
|
5
18
|
drivers: {
|
|
6
19
|
database: string;
|
|
7
20
|
cache: string;
|
|
@@ -9,8 +22,19 @@ interface ProfileConfig {
|
|
|
9
22
|
storage: string;
|
|
10
23
|
session: string;
|
|
11
24
|
};
|
|
25
|
+
/** List of enabled features and orbits. */
|
|
12
26
|
features: string[];
|
|
13
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* ProfileResolver manages the resolution of project profiles and feature add-ons.
|
|
30
|
+
*
|
|
31
|
+
* It maps high-level profiles (Core, Scale, Enterprise) to specific sets of
|
|
32
|
+
* service drivers and orbits, and handles the conditional inclusion of
|
|
33
|
+
* additional features.
|
|
34
|
+
*
|
|
35
|
+
* @public
|
|
36
|
+
* @since 3.0.0
|
|
37
|
+
*/
|
|
14
38
|
declare class ProfileResolver {
|
|
15
39
|
private static readonly DEFAULTS;
|
|
16
40
|
resolve(profile?: ProfileType, withFeatures?: string[]): ProfileConfig;
|
|
@@ -25,16 +49,132 @@ declare class ProfileResolver {
|
|
|
25
49
|
isValidFeature(feature: string): boolean;
|
|
26
50
|
}
|
|
27
51
|
|
|
52
|
+
/**
|
|
53
|
+
* package.json 結構
|
|
54
|
+
*/
|
|
55
|
+
interface PackageJson {
|
|
56
|
+
name?: string;
|
|
57
|
+
version?: string;
|
|
58
|
+
dependencies?: Record<string, string>;
|
|
59
|
+
devDependencies?: Record<string, string>;
|
|
60
|
+
[key: string]: unknown;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* 驗證結果
|
|
64
|
+
*/
|
|
65
|
+
interface ValidationResult {
|
|
66
|
+
/** 是否通過驗證 */
|
|
67
|
+
valid: boolean;
|
|
68
|
+
/** 錯誤訊息列表 (阻塞性問題) */
|
|
69
|
+
errors: string[];
|
|
70
|
+
/** 警告訊息列表 (非阻塞性問題) */
|
|
71
|
+
warnings: string[];
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* 依賴驗證器
|
|
75
|
+
*
|
|
76
|
+
* 負責驗證 Profile 配置的依賴完整性,包括:
|
|
77
|
+
* - Driver 必需的 packages
|
|
78
|
+
* - Feature 之間的衝突
|
|
79
|
+
* - Feature 的依賴關係
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* const validator = new DependencyValidator()
|
|
84
|
+
* const result = validator.validate(profileConfig, packageJson)
|
|
85
|
+
*
|
|
86
|
+
* if (!result.valid) {
|
|
87
|
+
* console.error('依賴驗證失敗:', result.errors)
|
|
88
|
+
* }
|
|
89
|
+
* ```
|
|
90
|
+
*
|
|
91
|
+
* @since 3.1.0
|
|
92
|
+
* @public
|
|
93
|
+
*/
|
|
94
|
+
declare class DependencyValidator {
|
|
95
|
+
/**
|
|
96
|
+
* Driver 到 Package 的映射規則
|
|
97
|
+
*/
|
|
98
|
+
private static readonly DRIVER_DEPENDENCIES;
|
|
99
|
+
/**
|
|
100
|
+
* Feature 衝突規則
|
|
101
|
+
*/
|
|
102
|
+
private static readonly CONFLICTS;
|
|
103
|
+
/**
|
|
104
|
+
* Feature 依賴映射
|
|
105
|
+
*/
|
|
106
|
+
private static readonly FEATURE_DEPENDENCIES;
|
|
107
|
+
/**
|
|
108
|
+
* 驗證 Profile 配置
|
|
109
|
+
*
|
|
110
|
+
* @param config - Profile 配置
|
|
111
|
+
* @param packageJson - 專案的 package.json 內容
|
|
112
|
+
* @returns 驗證結果
|
|
113
|
+
*/
|
|
114
|
+
validate(config: ProfileConfig, packageJson: PackageJson): ValidationResult;
|
|
115
|
+
/**
|
|
116
|
+
* 驗證 driver 依賴
|
|
117
|
+
*/
|
|
118
|
+
private validateDriverDependencies;
|
|
119
|
+
/**
|
|
120
|
+
* 驗證 feature 衝突
|
|
121
|
+
*/
|
|
122
|
+
private validateFeatureConflicts;
|
|
123
|
+
/**
|
|
124
|
+
* 驗證 feature 依賴
|
|
125
|
+
*/
|
|
126
|
+
private validateFeatureDependencies;
|
|
127
|
+
/**
|
|
128
|
+
* 檢查 package.json 是否包含指定 package
|
|
129
|
+
*/
|
|
130
|
+
private hasPackage;
|
|
131
|
+
/**
|
|
132
|
+
* 建議安裝缺失的依賴
|
|
133
|
+
*
|
|
134
|
+
* @param result - 驗證結果
|
|
135
|
+
* @returns 安裝命令建議
|
|
136
|
+
*/
|
|
137
|
+
static suggestInstallCommand(result: ValidationResult): string | null;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Represents the results of an environment detection scan.
|
|
142
|
+
*
|
|
143
|
+
* @public
|
|
144
|
+
* @since 3.0.0
|
|
145
|
+
*/
|
|
28
146
|
interface DetectedEnvironment {
|
|
147
|
+
/** The detected cloud or hosting platform. */
|
|
29
148
|
platform: 'aws' | 'gcp' | 'azure' | 'k8s' | 'vercel' | 'netlify' | 'unknown';
|
|
149
|
+
/** The project profile most suitable for this environment. */
|
|
30
150
|
suggestedProfile: ProfileType;
|
|
151
|
+
/** The degree of certainty in the detection. */
|
|
31
152
|
confidence: 'high' | 'medium' | 'low';
|
|
153
|
+
/** The reason or heuristic used for the detection. */
|
|
32
154
|
reason: string;
|
|
33
155
|
}
|
|
156
|
+
/**
|
|
157
|
+
* EnvironmentDetector inspects environment variables to identify the hosting platform.
|
|
158
|
+
*
|
|
159
|
+
* It uses these heuristics to suggest the most appropriate project profile
|
|
160
|
+
* (Core, Scale, or Enterprise) for the current environment.
|
|
161
|
+
*
|
|
162
|
+
* @public
|
|
163
|
+
* @since 3.0.0
|
|
164
|
+
*/
|
|
34
165
|
declare class EnvironmentDetector {
|
|
35
166
|
detect(): DetectedEnvironment;
|
|
36
167
|
}
|
|
37
168
|
|
|
169
|
+
/**
|
|
170
|
+
* FileMerger handles the intelligent merging of file contents during scaffolding.
|
|
171
|
+
*
|
|
172
|
+
* It understands different file formats (JSON, ENV) and applies appropriate
|
|
173
|
+
* merging strategies instead of simple overwriting.
|
|
174
|
+
*
|
|
175
|
+
* @public
|
|
176
|
+
* @since 3.0.0
|
|
177
|
+
*/
|
|
38
178
|
declare class FileMerger {
|
|
39
179
|
/**
|
|
40
180
|
* Merge content of two files based on their type.
|
|
@@ -45,356 +185,130 @@ declare class FileMerger {
|
|
|
45
185
|
}
|
|
46
186
|
|
|
47
187
|
/**
|
|
48
|
-
* Architecture
|
|
188
|
+
* Architecture patterns supported by the scaffolding engine.
|
|
189
|
+
*
|
|
190
|
+
* @public
|
|
191
|
+
* @since 3.0.0
|
|
49
192
|
*/
|
|
50
193
|
type ArchitectureType = 'enterprise-mvc' | 'clean' | 'ddd' | 'satellite' | 'action-domain' | 'standalone-engine';
|
|
51
194
|
/**
|
|
52
|
-
*
|
|
195
|
+
* Configuration options for creating a new project via Scaffold.
|
|
196
|
+
*
|
|
197
|
+
* @public
|
|
198
|
+
* @since 3.0.0
|
|
53
199
|
*/
|
|
54
200
|
interface ScaffoldOptions {
|
|
55
|
-
/**
|
|
56
|
-
* Project name
|
|
57
|
-
*/
|
|
201
|
+
/** The name of the new project (e.g., 'my-api'). */
|
|
58
202
|
name: string;
|
|
59
|
-
/**
|
|
60
|
-
* Target directory (absolute path)
|
|
61
|
-
*/
|
|
203
|
+
/** Absolute path where the project files should be generated. */
|
|
62
204
|
targetDir: string;
|
|
63
|
-
/**
|
|
64
|
-
* Architecture type
|
|
65
|
-
*/
|
|
205
|
+
/** The primary architectural pattern to apply. */
|
|
66
206
|
architecture: ArchitectureType;
|
|
67
|
-
/**
|
|
68
|
-
* Package manager to use
|
|
69
|
-
* @default 'bun'
|
|
70
|
-
*/
|
|
207
|
+
/** Preferred package manager for dependency installation. @default 'bun' */
|
|
71
208
|
packageManager?: 'bun' | 'npm' | 'yarn' | 'pnpm';
|
|
72
|
-
/**
|
|
73
|
-
* Whether to initialize git
|
|
74
|
-
* @default true
|
|
75
|
-
*/
|
|
209
|
+
/** Whether to run `git init` in the target directory. @default true */
|
|
76
210
|
initGit?: boolean;
|
|
77
|
-
/**
|
|
78
|
-
* Whether to install dependencies
|
|
79
|
-
* @default true
|
|
80
|
-
*/
|
|
211
|
+
/** Whether to automatically run `install` after file generation. @default true */
|
|
81
212
|
installDeps?: boolean;
|
|
82
|
-
/**
|
|
83
|
-
* Whether to include Spectrum debug dashboard
|
|
84
|
-
* @default false
|
|
85
|
-
*/
|
|
213
|
+
/** If true, includes the Spectrum observability dashboard in the scaffolded app. */
|
|
86
214
|
withSpectrum?: boolean;
|
|
87
|
-
/**
|
|
88
|
-
* Whether this is an internal official satellite
|
|
89
|
-
* @default false
|
|
90
|
-
*/
|
|
215
|
+
/** Internal flag for official Gravito satellite projects. */
|
|
91
216
|
isInternal?: boolean;
|
|
92
|
-
/**
|
|
93
|
-
* Profile preset (Core, Scale, Enterprise)
|
|
94
|
-
* @default 'core'
|
|
95
|
-
*/
|
|
217
|
+
/** Selected project profile determining the set of included orbits/packages. */
|
|
96
218
|
profile?: 'core' | 'scale' | 'enterprise';
|
|
97
|
-
/**
|
|
98
|
-
* Feature add-ons (e.g. 'redis', 'queue', 'otel')
|
|
99
|
-
*/
|
|
219
|
+
/** List of additional feature orbits to include (e.g., 'redis', 'queue', 'otel'). */
|
|
100
220
|
features?: string[];
|
|
101
|
-
/**
|
|
102
|
-
* Additional context variables for templates
|
|
103
|
-
*/
|
|
221
|
+
/** Additional template variables to be used during file generation. */
|
|
104
222
|
context?: Record<string, unknown>;
|
|
105
223
|
}
|
|
106
224
|
/**
|
|
107
|
-
*
|
|
225
|
+
* The outcome of a scaffolding operation.
|
|
226
|
+
*
|
|
227
|
+
* @public
|
|
228
|
+
* @since 3.0.0
|
|
108
229
|
*/
|
|
109
230
|
interface ScaffoldResult {
|
|
231
|
+
/** True if the operation completed without fatal errors. */
|
|
110
232
|
success: boolean;
|
|
233
|
+
/** The absolute path where the project was created. */
|
|
111
234
|
targetDir: string;
|
|
235
|
+
/** List of relative file paths that were successfully generated. */
|
|
112
236
|
filesCreated: string[];
|
|
237
|
+
/** Any non-fatal error messages encountered during generation. */
|
|
113
238
|
errors?: string[];
|
|
114
239
|
}
|
|
115
240
|
/**
|
|
116
|
-
*
|
|
241
|
+
* Represents a node in the project file structure blueprint.
|
|
242
|
+
*
|
|
243
|
+
* Used to define the skeleton of a new project before generation.
|
|
244
|
+
*
|
|
245
|
+
* @public
|
|
246
|
+
* @since 3.0.0
|
|
117
247
|
*/
|
|
118
248
|
interface DirectoryNode {
|
|
249
|
+
/** The type of node (file vs folder). */
|
|
119
250
|
type: 'file' | 'directory';
|
|
251
|
+
/** The name of the file or directory. */
|
|
120
252
|
name: string;
|
|
253
|
+
/** Literal string content if this is a file node. */
|
|
121
254
|
content?: string;
|
|
255
|
+
/** The name or path of a template to use for this file's content. */
|
|
122
256
|
template?: string;
|
|
257
|
+
/** Nested nodes if this is a directory. */
|
|
123
258
|
children?: DirectoryNode[];
|
|
124
259
|
}
|
|
125
260
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
*
|
|
132
|
-
* @example
|
|
133
|
-
* ```typescript
|
|
134
|
-
* const generator = new StubGenerator({
|
|
135
|
-
* stubsDir: './stubs',
|
|
136
|
-
* outputDir: './src',
|
|
137
|
-
* });
|
|
138
|
-
*
|
|
139
|
-
* await generator.generate('controller.stub', 'Controllers/UserController.ts', {
|
|
140
|
-
* name: 'User',
|
|
141
|
-
* namespace: 'App\\Controllers',
|
|
142
|
-
* });
|
|
143
|
-
* ```
|
|
144
|
-
*/
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Variables passed to stub templates.
|
|
148
|
-
*/
|
|
149
|
-
interface StubVariables {
|
|
150
|
-
[key: string]: unknown;
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Configuration for StubGenerator.
|
|
154
|
-
*/
|
|
155
|
-
interface StubConfig {
|
|
156
|
-
/**
|
|
157
|
-
* Directory containing stub templates
|
|
158
|
-
*/
|
|
159
|
-
stubsDir: string;
|
|
160
|
-
/**
|
|
161
|
-
* Output directory for generated files
|
|
162
|
-
*/
|
|
163
|
-
outputDir: string;
|
|
164
|
-
/**
|
|
165
|
-
* Default variables applied to all templates
|
|
166
|
-
*/
|
|
167
|
-
defaultVariables?: StubVariables;
|
|
168
|
-
/**
|
|
169
|
-
* Custom Handlebars helpers
|
|
170
|
-
*/
|
|
171
|
-
helpers?: Record<string, Handlebars.HelperDelegate>;
|
|
172
|
-
}
|
|
173
|
-
declare class StubGenerator {
|
|
174
|
-
private config;
|
|
175
|
-
private handlebars;
|
|
176
|
-
constructor(config: StubConfig);
|
|
177
|
-
/**
|
|
178
|
-
* Register built-in Handlebars helpers.
|
|
179
|
-
*/
|
|
180
|
-
private registerBuiltinHelpers;
|
|
181
|
-
/**
|
|
182
|
-
* Generate a file from a stub template.
|
|
183
|
-
*
|
|
184
|
-
* @param stubName - Name of the stub file (relative to stubsDir)
|
|
185
|
-
* @param outputPath - Output path (relative to outputDir)
|
|
186
|
-
* @param variables - Template variables
|
|
187
|
-
* @returns Path to the generated file
|
|
188
|
-
*/
|
|
189
|
-
generate(stubName: string, outputPath: string, variables?: StubVariables): Promise<string>;
|
|
190
|
-
/**
|
|
191
|
-
* Generate multiple files from a stub template.
|
|
192
|
-
*
|
|
193
|
-
* @param stubName - Name of the stub file
|
|
194
|
-
* @param outputs - Array of [outputPath, variables] tuples
|
|
195
|
-
* @returns Array of generated file paths
|
|
196
|
-
*/
|
|
197
|
-
generateMany(stubName: string, outputs: [string, StubVariables][]): Promise<string[]>;
|
|
198
|
-
/**
|
|
199
|
-
* Render a template string directly.
|
|
200
|
-
*
|
|
201
|
-
* @param template - Template string
|
|
202
|
-
* @param variables - Template variables
|
|
203
|
-
* @returns Rendered content
|
|
204
|
-
*/
|
|
205
|
-
render(template: string, variables?: StubVariables): string;
|
|
206
|
-
/**
|
|
207
|
-
* Register a custom Handlebars helper.
|
|
208
|
-
*
|
|
209
|
-
* @param name - Helper name
|
|
210
|
-
* @param helper - Helper function
|
|
211
|
-
*/
|
|
212
|
-
registerHelper(name: string, helper: Handlebars.HelperDelegate): void;
|
|
213
|
-
/**
|
|
214
|
-
* Register a Handlebars partial.
|
|
215
|
-
*
|
|
216
|
-
* @param name - Partial name
|
|
217
|
-
* @param partial - Partial template string
|
|
218
|
-
*/
|
|
219
|
-
registerPartial(name: string, partial: string): void;
|
|
261
|
+
declare class TemplateManager {
|
|
262
|
+
private stubGenerator;
|
|
263
|
+
constructor(templatesDir: string);
|
|
264
|
+
render(template: string, context: Record<string, unknown>): string;
|
|
265
|
+
applyOverlay(sourceDir: string, targetDir: string, context: Record<string, unknown>, fileMerger: FileMerger, log?: (msg: string) => void): Promise<string[]>;
|
|
220
266
|
}
|
|
221
267
|
|
|
222
268
|
/**
|
|
223
269
|
* BaseGenerator - Abstract base class for architecture generators.
|
|
224
|
-
*
|
|
225
|
-
* Provides common functionality for generating project structures,
|
|
226
|
-
* including directory creation, file generation, and context management.
|
|
227
270
|
*/
|
|
228
271
|
|
|
229
|
-
/**
|
|
230
|
-
* Context passed to generators during scaffolding.
|
|
231
|
-
*/
|
|
232
272
|
interface GeneratorContext {
|
|
233
|
-
/**
|
|
234
|
-
* Project name
|
|
235
|
-
*/
|
|
236
273
|
name: string;
|
|
237
|
-
/**
|
|
238
|
-
* Project name in various cases
|
|
239
|
-
*/
|
|
240
274
|
namePascalCase: string;
|
|
241
275
|
nameCamelCase: string;
|
|
242
276
|
nameSnakeCase: string;
|
|
243
277
|
nameKebabCase: string;
|
|
244
|
-
/**
|
|
245
|
-
* Target directory
|
|
246
|
-
*/
|
|
247
278
|
targetDir: string;
|
|
248
|
-
/**
|
|
249
|
-
* Architecture type
|
|
250
|
-
*/
|
|
251
279
|
architecture: ArchitectureType;
|
|
252
|
-
/**
|
|
253
|
-
* Package manager
|
|
254
|
-
*/
|
|
255
280
|
packageManager: 'bun' | 'npm' | 'yarn' | 'pnpm';
|
|
256
|
-
/**
|
|
257
|
-
* Current year (for license headers)
|
|
258
|
-
*/
|
|
259
281
|
year: string;
|
|
260
|
-
/**
|
|
261
|
-
* Current date
|
|
262
|
-
*/
|
|
263
282
|
date: string;
|
|
264
|
-
/**
|
|
265
|
-
* Additional custom context
|
|
266
|
-
*/
|
|
267
283
|
[key: string]: unknown;
|
|
268
284
|
}
|
|
269
|
-
/**
|
|
270
|
-
* Configuration for generators.
|
|
271
|
-
*/
|
|
272
285
|
interface GeneratorConfig {
|
|
273
|
-
/**
|
|
274
|
-
* Directory containing stub templates
|
|
275
|
-
*/
|
|
276
286
|
templatesDir: string;
|
|
277
|
-
/**
|
|
278
|
-
* Verbose logging
|
|
279
|
-
*/
|
|
280
287
|
verbose?: boolean;
|
|
281
288
|
}
|
|
282
|
-
/**
|
|
283
|
-
* Abstract base class for architecture generators.
|
|
284
|
-
*/
|
|
285
289
|
declare abstract class BaseGenerator {
|
|
286
290
|
protected config: GeneratorConfig;
|
|
287
|
-
protected
|
|
291
|
+
protected templateManager: TemplateManager;
|
|
288
292
|
protected fileMerger: FileMerger;
|
|
289
293
|
protected filesCreated: string[];
|
|
290
294
|
constructor(config: GeneratorConfig);
|
|
291
|
-
/**
|
|
292
|
-
* Get the architecture type this generator handles.
|
|
293
|
-
*/
|
|
294
295
|
abstract get architectureType(): ArchitectureType;
|
|
295
|
-
/**
|
|
296
|
-
* Get the display name for this architecture.
|
|
297
|
-
*/
|
|
298
296
|
abstract get displayName(): string;
|
|
299
|
-
/**
|
|
300
|
-
* Get the description for this architecture.
|
|
301
|
-
*/
|
|
302
297
|
abstract get description(): string;
|
|
303
|
-
/**
|
|
304
|
-
* Get the directory structure for this architecture.
|
|
305
|
-
*/
|
|
306
298
|
abstract getDirectoryStructure(context: GeneratorContext): DirectoryNode[];
|
|
307
|
-
/**
|
|
308
|
-
* Generate the project scaffold.
|
|
309
|
-
*
|
|
310
|
-
* @param context - Generator context
|
|
311
|
-
* @returns Array of created file paths
|
|
312
|
-
*/
|
|
313
299
|
generate(context: GeneratorContext): Promise<string[]>;
|
|
314
|
-
/**
|
|
315
|
-
* Create directory structure recursively.
|
|
316
|
-
*/
|
|
317
300
|
protected createStructure(basePath: string, nodes: DirectoryNode[], context: GeneratorContext): Promise<void>;
|
|
318
|
-
/**
|
|
319
|
-
* Generate common files (package.json, .env, etc.)
|
|
320
|
-
*/
|
|
321
301
|
protected generateCommonFiles(context: GeneratorContext): Promise<void>;
|
|
322
|
-
|
|
323
|
-
* Copy AI Skills to the project
|
|
324
|
-
*/
|
|
302
|
+
protected generateFileFromTemplate(tplDir: string, tplName: string, targetName: string, context: GeneratorContext): Promise<void>;
|
|
325
303
|
protected generateSkills(context: GeneratorContext): Promise<void>;
|
|
326
|
-
/**
|
|
327
|
-
* Apply profile-specific overlays
|
|
328
|
-
*/
|
|
329
304
|
protected applyOverlays(context: GeneratorContext): Promise<void>;
|
|
330
|
-
/**
|
|
331
|
-
* Apply feature-specific overlays
|
|
332
|
-
*/
|
|
333
305
|
protected applyFeatureOverlays(context: GeneratorContext): Promise<void>;
|
|
334
|
-
/**
|
|
335
|
-
* Helper to copy/merge an overlay directory into the target
|
|
336
|
-
*/
|
|
337
306
|
protected copyOverlayDirectory(sourceDir: string, context: GeneratorContext): Promise<void>;
|
|
338
|
-
/**
|
|
339
|
-
* Write a file and track it.
|
|
340
|
-
*/
|
|
341
307
|
protected writeFile(basePath: string, relativePath: string, content: string): Promise<void>;
|
|
342
|
-
/**
|
|
343
|
-
* Generate package.json content.
|
|
344
|
-
*/
|
|
345
308
|
protected generatePackageJson(context: GeneratorContext): string;
|
|
346
|
-
/**
|
|
347
|
-
* Generate Dockerfile content.
|
|
348
|
-
*/
|
|
349
|
-
protected generateDockerfile(context: GeneratorContext): string;
|
|
350
|
-
/**
|
|
351
|
-
* Generate .dockerignore content.
|
|
352
|
-
*/
|
|
353
|
-
protected generateDockerIgnore(): string;
|
|
354
|
-
/**
|
|
355
|
-
* Generate .env.example content.
|
|
356
|
-
*/
|
|
357
|
-
protected generateEnvExample(context: GeneratorContext): string;
|
|
358
|
-
/**
|
|
359
|
-
* Generate .gitignore content.
|
|
360
|
-
*/
|
|
361
|
-
protected generateGitignore(): string;
|
|
362
|
-
/**
|
|
363
|
-
* Generate tsconfig.json content.
|
|
364
|
-
*/
|
|
365
|
-
protected generateTsConfig(): string;
|
|
366
|
-
/**
|
|
367
|
-
* Generate ARCHITECTURE.md content.
|
|
368
|
-
* Override in subclasses for architecture-specific docs.
|
|
369
|
-
*/
|
|
370
309
|
protected abstract generateArchitectureDoc(context: GeneratorContext): string;
|
|
371
|
-
/**
|
|
372
|
-
* Generate check scripts for project validation.
|
|
373
|
-
*/
|
|
374
310
|
protected generateCheckScripts(context: GeneratorContext): Promise<void>;
|
|
375
|
-
/**
|
|
376
|
-
* Generate check-dependencies.ts script content.
|
|
377
|
-
*/
|
|
378
|
-
protected generateCheckDependenciesScript(): string;
|
|
379
|
-
/**
|
|
380
|
-
* Generate check.sh script content.
|
|
381
|
-
*/
|
|
382
|
-
protected generateCheckShellScript(): string;
|
|
383
|
-
/**
|
|
384
|
-
* Generate pre-commit.sh script content.
|
|
385
|
-
*/
|
|
386
|
-
protected generatePreCommitScript(): string;
|
|
387
|
-
/**
|
|
388
|
-
* Generate CHECK_SYSTEM.md documentation.
|
|
389
|
-
*/
|
|
390
|
-
protected generateCheckSystemDoc(context: GeneratorContext): string;
|
|
391
|
-
/**
|
|
392
|
-
* Log a message if verbose mode is enabled.
|
|
393
|
-
*/
|
|
394
311
|
protected log(message: string): void;
|
|
395
|
-
/**
|
|
396
|
-
* Create generator context from options.
|
|
397
|
-
*/
|
|
398
312
|
static createContext(name: string, targetDir: string, architecture: ArchitectureType, packageManager?: 'bun' | 'npm' | 'yarn' | 'pnpm', extra?: Record<string, unknown>): GeneratorContext;
|
|
399
313
|
}
|
|
400
314
|
|
|
@@ -408,6 +322,16 @@ declare abstract class BaseGenerator {
|
|
|
408
322
|
* - Interface: HTTP Controllers, Presenters
|
|
409
323
|
*/
|
|
410
324
|
|
|
325
|
+
/**
|
|
326
|
+
* CleanArchitectureGenerator implements Uncle Bob's Clean Architecture pattern.
|
|
327
|
+
*
|
|
328
|
+
* It generates a strictly layered structure including Domain, Application,
|
|
329
|
+
* Infrastructure, and Interface layers, ensuring business logic is isolated
|
|
330
|
+
* from framework and external dependencies.
|
|
331
|
+
*
|
|
332
|
+
* @public
|
|
333
|
+
* @since 3.0.0
|
|
334
|
+
*/
|
|
411
335
|
declare class CleanArchitectureGenerator extends BaseGenerator {
|
|
412
336
|
get architectureType(): "clean";
|
|
413
337
|
get displayName(): string;
|
|
@@ -449,44 +373,29 @@ declare class CleanArchitectureGenerator extends BaseGenerator {
|
|
|
449
373
|
* - Each context has Domain, Application, Infrastructure, UserInterface layers
|
|
450
374
|
*/
|
|
451
375
|
|
|
376
|
+
/**
|
|
377
|
+
* DddGenerator implements the full Domain-Driven Design (DDD) architectural pattern.
|
|
378
|
+
*
|
|
379
|
+
* It generates a sophisticated structure including Bounded Contexts, Aggregates,
|
|
380
|
+
* Value Objects, Domain Events, and a Shared Kernel. It is ideal for complex
|
|
381
|
+
* enterprise applications with rich business logic.
|
|
382
|
+
*
|
|
383
|
+
* @public
|
|
384
|
+
* @since 3.0.0
|
|
385
|
+
*/
|
|
452
386
|
declare class DddGenerator extends BaseGenerator {
|
|
387
|
+
private moduleGenerator;
|
|
388
|
+
private sharedKernelGenerator;
|
|
389
|
+
private bootstrapGenerator;
|
|
390
|
+
constructor(config: GeneratorConfig);
|
|
453
391
|
get architectureType(): "ddd";
|
|
454
392
|
get displayName(): string;
|
|
455
393
|
get description(): string;
|
|
456
394
|
getDirectoryStructure(context: GeneratorContext): DirectoryNode[];
|
|
457
|
-
private generateBootstrapDirectory;
|
|
458
|
-
private generateShared;
|
|
459
|
-
private generateModule;
|
|
460
|
-
private generateBootstrapApp;
|
|
461
|
-
private generateProvidersRegistry;
|
|
462
|
-
private generateEventsRegistry;
|
|
463
|
-
private generateRoutesRegistry;
|
|
464
|
-
private generateMainEntry;
|
|
465
|
-
private generateModulesConfig;
|
|
466
|
-
private generateModuleServiceProvider;
|
|
467
395
|
/**
|
|
468
396
|
* Override package.json for DDD architecture (uses main.ts instead of bootstrap.ts)
|
|
469
397
|
*/
|
|
470
398
|
protected generatePackageJson(context: GeneratorContext): string;
|
|
471
|
-
private generateAppConfig;
|
|
472
|
-
private generateDatabaseConfig;
|
|
473
|
-
private generateCacheConfig;
|
|
474
|
-
private generateLoggingConfig;
|
|
475
|
-
private generateIdValueObject;
|
|
476
|
-
private generateMoneyValueObject;
|
|
477
|
-
private generateEmailValueObject;
|
|
478
|
-
private generateEventDispatcher;
|
|
479
|
-
private generateAggregate;
|
|
480
|
-
private generateAggregateStatus;
|
|
481
|
-
private generateCreatedEvent;
|
|
482
|
-
private generateRepositoryInterface;
|
|
483
|
-
private generateCommand;
|
|
484
|
-
private generateCommandHandler;
|
|
485
|
-
private generateQuery;
|
|
486
|
-
private generateQueryHandler;
|
|
487
|
-
private generateDTO;
|
|
488
|
-
private generateRepository;
|
|
489
|
-
private generateExceptionHandler;
|
|
490
399
|
protected generateArchitectureDoc(context: GeneratorContext): string;
|
|
491
400
|
}
|
|
492
401
|
|
|
@@ -500,6 +409,16 @@ declare class DddGenerator extends BaseGenerator {
|
|
|
500
409
|
* - Http/Kernel for middleware management
|
|
501
410
|
*/
|
|
502
411
|
|
|
412
|
+
/**
|
|
413
|
+
* EnterpriseMvcGenerator implements a Laravel-inspired MVC architectural pattern.
|
|
414
|
+
*
|
|
415
|
+
* It generates a pragmatic, robust structure with Controllers, Services,
|
|
416
|
+
* Repositories, and Service Providers. It is the recommended architecture
|
|
417
|
+
* for most web applications and APIs.
|
|
418
|
+
*
|
|
419
|
+
* @public
|
|
420
|
+
* @since 3.0.0
|
|
421
|
+
*/
|
|
503
422
|
declare class EnterpriseMvcGenerator extends BaseGenerator {
|
|
504
423
|
get architectureType(): "enterprise-mvc";
|
|
505
424
|
get displayName(): string;
|
|
@@ -515,7 +434,6 @@ declare class EnterpriseMvcGenerator extends BaseGenerator {
|
|
|
515
434
|
private generateHomeController;
|
|
516
435
|
private generateAuthMiddleware;
|
|
517
436
|
private generateAppServiceProvider;
|
|
518
|
-
private generateRouteServiceProvider;
|
|
519
437
|
private generateProvidersIndex;
|
|
520
438
|
private generateDatabaseProvider;
|
|
521
439
|
private generateMiddlewareProvider;
|
|
@@ -533,6 +451,15 @@ declare class EnterpriseMvcGenerator extends BaseGenerator {
|
|
|
533
451
|
* Dogfooding support (pre-configured with Gravito modules).
|
|
534
452
|
*/
|
|
535
453
|
|
|
454
|
+
/**
|
|
455
|
+
* SatelliteGenerator scaffolds modular plug-and-play extensions for Gravito.
|
|
456
|
+
*
|
|
457
|
+
* It follows a strict DDD and Clean Architecture pattern to ensure that
|
|
458
|
+
* satellites remain decoupled from the core framework and other satellites.
|
|
459
|
+
*
|
|
460
|
+
* @public
|
|
461
|
+
* @since 3.0.0
|
|
462
|
+
*/
|
|
536
463
|
declare class SatelliteGenerator extends BaseGenerator {
|
|
537
464
|
get architectureType(): "satellite";
|
|
538
465
|
get displayName(): string;
|
|
@@ -548,12 +475,124 @@ declare class SatelliteGenerator extends BaseGenerator {
|
|
|
548
475
|
protected generateArchitectureDoc(context: GeneratorContext): string;
|
|
549
476
|
}
|
|
550
477
|
|
|
478
|
+
/**
|
|
479
|
+
* StubGenerator - Abstract template processor for generating code files.
|
|
480
|
+
*
|
|
481
|
+
* Provides a flexible system for processing stub templates with Handlebars,
|
|
482
|
+
* enabling extensible code generation for any file type.
|
|
483
|
+
*
|
|
484
|
+
* @example
|
|
485
|
+
* ```typescript
|
|
486
|
+
* const generator = new StubGenerator({
|
|
487
|
+
* stubsDir: './stubs',
|
|
488
|
+
* outputDir: './src',
|
|
489
|
+
* });
|
|
490
|
+
*
|
|
491
|
+
* await generator.generate('controller.stub', 'Controllers/UserController.ts', {
|
|
492
|
+
* name: 'User',
|
|
493
|
+
* namespace: 'App\\Controllers',
|
|
494
|
+
* });
|
|
495
|
+
* ```
|
|
496
|
+
*/
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* Variables passed to stub templates during processing.
|
|
500
|
+
*
|
|
501
|
+
* @public
|
|
502
|
+
* @since 3.0.0
|
|
503
|
+
*/
|
|
504
|
+
interface StubVariables {
|
|
505
|
+
[key: string]: unknown;
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* Configuration for the `StubGenerator`.
|
|
509
|
+
*
|
|
510
|
+
* @public
|
|
511
|
+
* @since 3.0.0
|
|
512
|
+
*/
|
|
513
|
+
interface StubConfig {
|
|
514
|
+
/** Directory containing the raw stub templates. */
|
|
515
|
+
stubsDir: string;
|
|
516
|
+
/** Root directory for all generated files. */
|
|
517
|
+
outputDir: string;
|
|
518
|
+
/** Default variables available to all templates. */
|
|
519
|
+
defaultVariables?: StubVariables;
|
|
520
|
+
/** Optional custom Handlebars helper implementations. */
|
|
521
|
+
helpers?: Record<string, Handlebars.HelperDelegate>;
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* StubGenerator processes template stubs using the Handlebars engine.
|
|
525
|
+
*
|
|
526
|
+
* It provides a rich set of built-in helpers for string manipulation
|
|
527
|
+
* (camelCase, PascalCase, etc.) and handles file reading and writing.
|
|
528
|
+
*
|
|
529
|
+
* @public
|
|
530
|
+
* @since 3.0.0
|
|
531
|
+
*/
|
|
532
|
+
declare class StubGenerator {
|
|
533
|
+
private config;
|
|
534
|
+
private handlebars;
|
|
535
|
+
constructor(config: StubConfig);
|
|
536
|
+
/**
|
|
537
|
+
* Register built-in Handlebars helpers.
|
|
538
|
+
*/
|
|
539
|
+
private registerBuiltinHelpers;
|
|
540
|
+
/**
|
|
541
|
+
* Generate a file from a stub template.
|
|
542
|
+
*
|
|
543
|
+
* @param stubName - Name of the stub file (relative to stubsDir)
|
|
544
|
+
* @param outputPath - Output path (relative to outputDir)
|
|
545
|
+
* @param variables - Template variables
|
|
546
|
+
* @returns Path to the generated file
|
|
547
|
+
*/
|
|
548
|
+
generate(stubName: string, outputPath: string, variables?: StubVariables): Promise<string>;
|
|
549
|
+
/**
|
|
550
|
+
* Generate multiple files from a stub template.
|
|
551
|
+
*
|
|
552
|
+
* @param stubName - Name of the stub file
|
|
553
|
+
* @param outputs - Array of [outputPath, variables] tuples
|
|
554
|
+
* @returns Array of generated file paths
|
|
555
|
+
*/
|
|
556
|
+
generateMany(stubName: string, outputs: [string, StubVariables][]): Promise<string[]>;
|
|
557
|
+
/**
|
|
558
|
+
* Render a template string directly.
|
|
559
|
+
*
|
|
560
|
+
* @param template - Template string
|
|
561
|
+
* @param variables - Template variables
|
|
562
|
+
* @returns Rendered content
|
|
563
|
+
*/
|
|
564
|
+
render(template: string, variables?: StubVariables): string;
|
|
565
|
+
/**
|
|
566
|
+
* Register a custom Handlebars helper.
|
|
567
|
+
*
|
|
568
|
+
* @param name - Helper name
|
|
569
|
+
* @param helper - Helper function
|
|
570
|
+
*/
|
|
571
|
+
registerHelper(name: string, helper: Handlebars.HelperDelegate): void;
|
|
572
|
+
/**
|
|
573
|
+
* Register a Handlebars partial.
|
|
574
|
+
*
|
|
575
|
+
* @param name - Partial name
|
|
576
|
+
* @param partial - Partial template string
|
|
577
|
+
*/
|
|
578
|
+
registerPartial(name: string, partial: string): void;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
/**
|
|
582
|
+
* Represents the structure of a `gravito.lock.json` file.
|
|
583
|
+
*
|
|
584
|
+
* @public
|
|
585
|
+
* @since 3.0.0
|
|
586
|
+
*/
|
|
551
587
|
interface LockFile {
|
|
588
|
+
/** Information about the selected project profile. */
|
|
552
589
|
profile: {
|
|
553
590
|
name: ProfileType;
|
|
554
591
|
version: string;
|
|
555
592
|
};
|
|
593
|
+
/** List of enabled features and orbits. */
|
|
556
594
|
features: string[];
|
|
595
|
+
/** Selected default drivers for various services. */
|
|
557
596
|
drivers: {
|
|
558
597
|
database: string;
|
|
559
598
|
cache: string;
|
|
@@ -561,23 +600,46 @@ interface LockFile {
|
|
|
561
600
|
storage: string;
|
|
562
601
|
session: string;
|
|
563
602
|
};
|
|
603
|
+
/** Metadata about the template used for generation. */
|
|
564
604
|
manifest: {
|
|
565
605
|
template: string;
|
|
566
606
|
version: string;
|
|
567
607
|
};
|
|
608
|
+
/** ISO timestamp when the project was scaffolded. */
|
|
568
609
|
createdAt: string;
|
|
569
610
|
}
|
|
611
|
+
/**
|
|
612
|
+
* LockGenerator creates the `gravito.lock.json` file during scaffolding.
|
|
613
|
+
*
|
|
614
|
+
* This file records the architectural choices and feature set of the project,
|
|
615
|
+
* allowing the CLI to perform consistent upgrades and feature injections later.
|
|
616
|
+
*
|
|
617
|
+
* @public
|
|
618
|
+
* @since 3.0.0
|
|
619
|
+
*/
|
|
570
620
|
declare class LockGenerator {
|
|
571
621
|
generate(profileName: ProfileType, config: ProfileConfig, templateName?: string, templateVersion?: string): string;
|
|
572
622
|
}
|
|
573
623
|
|
|
574
624
|
/**
|
|
575
|
-
* Scaffold
|
|
625
|
+
* Scaffold is the primary engine for generating Gravito project structures.
|
|
626
|
+
*
|
|
627
|
+
* It orchestrates dynamic template generation, architecture patterns,
|
|
628
|
+
* profile resolution, and environment setup.
|
|
576
629
|
*
|
|
577
|
-
*
|
|
578
|
-
*
|
|
630
|
+
* @example
|
|
631
|
+
* ```typescript
|
|
632
|
+
* const engine = new Scaffold();
|
|
633
|
+
* const result = await engine.create({
|
|
634
|
+
* name: 'new-app',
|
|
635
|
+
* targetDir: '/path/to/app',
|
|
636
|
+
* architecture: 'enterprise-mvc'
|
|
637
|
+
* });
|
|
638
|
+
* ```
|
|
639
|
+
*
|
|
640
|
+
* @public
|
|
641
|
+
* @since 3.0.0
|
|
579
642
|
*/
|
|
580
|
-
|
|
581
643
|
declare class Scaffold {
|
|
582
644
|
private templatesDir;
|
|
583
645
|
private verbose;
|
|
@@ -586,7 +648,10 @@ declare class Scaffold {
|
|
|
586
648
|
verbose?: boolean;
|
|
587
649
|
});
|
|
588
650
|
/**
|
|
589
|
-
*
|
|
651
|
+
* Returns a list of all architectural patterns supported by the engine,
|
|
652
|
+
* along with human-readable names and descriptions.
|
|
653
|
+
*
|
|
654
|
+
* @returns {Array<{type: ArchitectureType, name: string, description: string}>}
|
|
590
655
|
*/
|
|
591
656
|
getArchitectureTypes(): Array<{
|
|
592
657
|
type: ArchitectureType;
|
|
@@ -594,7 +659,12 @@ declare class Scaffold {
|
|
|
594
659
|
description: string;
|
|
595
660
|
}>;
|
|
596
661
|
/**
|
|
597
|
-
*
|
|
662
|
+
* Orchestrates the complete project generation lifecycle.
|
|
663
|
+
* This includes directory creation, file layout, profile resolution,
|
|
664
|
+
* dependency mapping, and optional post-install hooks.
|
|
665
|
+
*
|
|
666
|
+
* @param {ScaffoldOptions} options - Detailed configuration for the new project.
|
|
667
|
+
* @returns {Promise<ScaffoldResult>}
|
|
598
668
|
*/
|
|
599
669
|
create(options: ScaffoldOptions): Promise<ScaffoldResult>;
|
|
600
670
|
/**
|
|
@@ -613,4 +683,4 @@ declare class Scaffold {
|
|
|
613
683
|
generateProvider(_targetDir: string, _providerName: string): Promise<ScaffoldResult>;
|
|
614
684
|
}
|
|
615
685
|
|
|
616
|
-
export { type ArchitectureType, BaseGenerator, CleanArchitectureGenerator, DddGenerator, type DetectedEnvironment, EnterpriseMvcGenerator, EnvironmentDetector, FileMerger, type GeneratorConfig, type GeneratorContext, type LockFile, LockGenerator, type ProfileConfig, ProfileResolver, type ProfileType, SatelliteGenerator, Scaffold, type ScaffoldOptions, type StubConfig, StubGenerator, type StubVariables };
|
|
686
|
+
export { type ArchitectureType, BaseGenerator, CleanArchitectureGenerator, DddGenerator, DependencyValidator, type DetectedEnvironment, EnterpriseMvcGenerator, EnvironmentDetector, FileMerger, type GeneratorConfig, type GeneratorContext, type LockFile, LockGenerator, type PackageJson, type ProfileConfig, ProfileResolver, type ProfileType, SatelliteGenerator, Scaffold, type ScaffoldOptions, type StubConfig, StubGenerator, type StubVariables, type ValidationResult };
|