@qlover/scripts-context 0.2.1 → 1.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 +36 -1
- package/dist/index.d.ts +3647 -363
- package/dist/index.js +5027 -1
- package/package.json +10 -8
package/dist/index.d.ts
CHANGED
|
@@ -1,161 +1,7 @@
|
|
|
1
1
|
import * as _commitlint_types from '@commitlint/types';
|
|
2
2
|
import { LoggerInterface, FormatterInterface, LogEvent } from '@qlover/logger';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* Configuration search options interface
|
|
6
|
-
* @interface
|
|
7
|
-
* @description
|
|
8
|
-
* Significance: Defines the configuration structure for ConfigSearch initialization
|
|
9
|
-
* Core idea: Centralize configuration search parameters
|
|
10
|
-
* Main function: Type-safe configuration options
|
|
11
|
-
* Main purpose: Standardize configuration initialization
|
|
12
|
-
* Example:
|
|
13
|
-
* ```typescript
|
|
14
|
-
* const options: ConfigSearchOptions = {
|
|
15
|
-
* name: 'myapp',
|
|
16
|
-
* searchPlaces: ['myapp.config.js'],
|
|
17
|
-
* defaultConfig: { port: 3000 }
|
|
18
|
-
* };
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
interface ConfigSearchOptions {
|
|
22
|
-
/** Base name for configuration files */
|
|
23
|
-
name: string;
|
|
24
|
-
/** Custom search locations for config files */
|
|
25
|
-
searchPlaces?: string[];
|
|
26
|
-
/** Default configuration object */
|
|
27
|
-
defaultConfig?: Record<string, unknown>;
|
|
28
|
-
/** Custom loaders for different file types */
|
|
29
|
-
loaders?: Record<string, (filepath: string) => unknown>;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Search options interface for configuration retrieval
|
|
33
|
-
* @interface
|
|
34
|
-
* @description
|
|
35
|
-
* Significance: Defines options for configuration search operation
|
|
36
|
-
* Core idea: Control configuration file search behavior
|
|
37
|
-
* Main function: Customize search parameters
|
|
38
|
-
* Main purpose: Flexible configuration loading
|
|
39
|
-
* Example:
|
|
40
|
-
* ```typescript
|
|
41
|
-
* const searchOptions: SearchOptions = {
|
|
42
|
-
* file: 'custom.config.js',
|
|
43
|
-
* dir: '/path/to/project'
|
|
44
|
-
* };
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
interface SearchOptions {
|
|
48
|
-
/** Specific configuration file to load */
|
|
49
|
-
file?: string | false;
|
|
50
|
-
/** Directory to search in */
|
|
51
|
-
dir?: string;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Configuration search utility class
|
|
55
|
-
* @class
|
|
56
|
-
* @description
|
|
57
|
-
* Significance: Manages configuration file discovery and loading
|
|
58
|
-
* Core idea: Unified configuration management
|
|
59
|
-
* Main function: Search and load configuration from various sources
|
|
60
|
-
* Main purpose: Provide consistent configuration access
|
|
61
|
-
* Example:
|
|
62
|
-
* ```typescript
|
|
63
|
-
* const configSearch = new ConfigSearch({
|
|
64
|
-
* name: 'myapp',
|
|
65
|
-
* defaultConfig: { port: 3000 }
|
|
66
|
-
* });
|
|
67
|
-
* const config = configSearch.config;
|
|
68
|
-
* ```
|
|
69
|
-
*/
|
|
70
|
-
declare class ConfigSearch {
|
|
71
|
-
private name;
|
|
72
|
-
private searchPlaces;
|
|
73
|
-
private _config;
|
|
74
|
-
private loaders?;
|
|
75
|
-
private searchCache?;
|
|
76
|
-
/**
|
|
77
|
-
* Creates a ConfigSearch instance
|
|
78
|
-
* @param options - Configuration search options
|
|
79
|
-
* @throws Error if neither name nor searchPlaces is provided
|
|
80
|
-
* @description
|
|
81
|
-
* Significance: Initializes configuration search environment
|
|
82
|
-
* Core idea: Setup configuration search parameters
|
|
83
|
-
* Main function: Create search instance with options
|
|
84
|
-
* Main purpose: Prepare for configuration discovery
|
|
85
|
-
* Example:
|
|
86
|
-
* ```typescript
|
|
87
|
-
* const search = new ConfigSearch({
|
|
88
|
-
* name: 'myapp',
|
|
89
|
-
* defaultConfig: { debug: true }
|
|
90
|
-
* });
|
|
91
|
-
* ```
|
|
92
|
-
*/
|
|
93
|
-
constructor(options: ConfigSearchOptions);
|
|
94
|
-
/**
|
|
95
|
-
* Get effective configuration
|
|
96
|
-
* @returns Merged configuration object
|
|
97
|
-
* @description
|
|
98
|
-
* Significance: Provides access to final configuration
|
|
99
|
-
* Core idea: Merge default and discovered configurations
|
|
100
|
-
* Main function: Retrieve effective configuration
|
|
101
|
-
* Main purpose: Access complete configuration
|
|
102
|
-
* Example:
|
|
103
|
-
* ```typescript
|
|
104
|
-
* const config = configSearch.config;
|
|
105
|
-
* console.log(config.debug); // true
|
|
106
|
-
* ```
|
|
107
|
-
*/
|
|
108
|
-
get config(): Record<string, unknown>;
|
|
109
|
-
/**
|
|
110
|
-
* Get search locations
|
|
111
|
-
* @returns Array of search locations
|
|
112
|
-
* @description
|
|
113
|
-
* Significance: Exposes configuration search paths
|
|
114
|
-
* Core idea: Provide transparency in search process
|
|
115
|
-
* Main function: Return search locations
|
|
116
|
-
* Main purpose: Debug and verify search paths
|
|
117
|
-
* Example:
|
|
118
|
-
* ```typescript
|
|
119
|
-
* const places = configSearch.getSearchPlaces();
|
|
120
|
-
* // ['package.json', 'myapp.config.js', ...]
|
|
121
|
-
* ```
|
|
122
|
-
*/
|
|
123
|
-
getSearchPlaces(): string[];
|
|
124
|
-
/**
|
|
125
|
-
* Get configuration from specific location
|
|
126
|
-
* @param options - Search options
|
|
127
|
-
* @returns Configuration object
|
|
128
|
-
* @throws Error if configuration file is invalid
|
|
129
|
-
* @description
|
|
130
|
-
* Significance: Load configuration from specific location
|
|
131
|
-
* Core idea: Flexible configuration loading
|
|
132
|
-
* Main function: Load and validate configuration
|
|
133
|
-
* Main purpose: Custom configuration loading
|
|
134
|
-
* Example:
|
|
135
|
-
* ```typescript
|
|
136
|
-
* const config = configSearch.get({
|
|
137
|
-
* file: 'custom.config.js',
|
|
138
|
-
* dir: process.cwd()
|
|
139
|
-
* });
|
|
140
|
-
* ```
|
|
141
|
-
*/
|
|
142
|
-
get(options?: SearchOptions): Record<string, unknown>;
|
|
143
|
-
/**
|
|
144
|
-
* Search for configuration with caching
|
|
145
|
-
* @returns Cached configuration object
|
|
146
|
-
* @description
|
|
147
|
-
* Significance: Provides cached configuration access
|
|
148
|
-
* Core idea: Cache configuration for performance
|
|
149
|
-
* Main function: Search and cache configuration
|
|
150
|
-
* Main purpose: Optimize repeated access
|
|
151
|
-
* Example:
|
|
152
|
-
* ```typescript
|
|
153
|
-
* const config = configSearch.search();
|
|
154
|
-
* // Subsequent calls use cached result
|
|
155
|
-
* ```
|
|
156
|
-
*/
|
|
157
|
-
search(): Record<string, unknown>;
|
|
158
|
-
}
|
|
3
|
+
import { Env } from '@qlover/env-loader';
|
|
4
|
+
import { ExecutorPlugin, ExecutorContext } from '@qlover/fe-corekit';
|
|
159
5
|
|
|
160
6
|
declare const defaultFeConfig: FeConfig;
|
|
161
7
|
type FeConfig = {
|
|
@@ -206,336 +52,3774 @@ type FeConfig = {
|
|
|
206
52
|
*/
|
|
207
53
|
envOrder?: string[];
|
|
208
54
|
};
|
|
209
|
-
|
|
55
|
+
/**
|
|
56
|
+
* Configuration interface for automated release process management
|
|
57
|
+
*
|
|
58
|
+
* Core concept:
|
|
59
|
+
* Defines comprehensive configuration options for automated release
|
|
60
|
+
* processes, including PR management, package publishing, and
|
|
61
|
+
* release workflow customization.
|
|
62
|
+
*
|
|
63
|
+
* Main features:
|
|
64
|
+
* - PR management: Automated pull request creation and management
|
|
65
|
+
* - Dynamic branch naming with template variables
|
|
66
|
+
* - Customizable PR titles and descriptions
|
|
67
|
+
* - Automatic PR labeling and categorization
|
|
68
|
+
* - Configurable auto-merge behavior and strategies
|
|
69
|
+
*
|
|
70
|
+
* - Package publishing: Flexible package distribution configuration
|
|
71
|
+
* - Custom publish paths for different environments
|
|
72
|
+
* - Multi-package directory support for monorepos
|
|
73
|
+
* - Package-specific labeling and tracking
|
|
74
|
+
* - Environment-aware publishing strategies
|
|
75
|
+
*
|
|
76
|
+
* - Release workflow: Comprehensive release process control
|
|
77
|
+
* - Template-based content generation
|
|
78
|
+
* - Environment-specific configurations
|
|
79
|
+
* - Integration with CI/CD pipelines
|
|
80
|
+
* - Automated changelog and version management
|
|
81
|
+
*
|
|
82
|
+
* Design considerations:
|
|
83
|
+
* - All properties are optional for maximum flexibility
|
|
84
|
+
* - Template variables support dynamic content generation
|
|
85
|
+
* - Environment-aware configuration for different deployment stages
|
|
86
|
+
* - Integration with GitHub and other Git hosting platforms
|
|
87
|
+
* - Support for both single-package and monorepo scenarios
|
|
88
|
+
*
|
|
89
|
+
* Template variables:
|
|
90
|
+
* - `${pkgName}`: Package name from package.json
|
|
91
|
+
* - `${tagName}`: Release version tag
|
|
92
|
+
* - `${env}`: Release environment (development, staging, production)
|
|
93
|
+
* - `${branch}`: Source branch name
|
|
94
|
+
* - `${name}`: Package name for labeling
|
|
95
|
+
* - `${changelog}`: Generated changelog content
|
|
96
|
+
*
|
|
97
|
+
* @example Basic release configuration
|
|
98
|
+
* ```typescript
|
|
99
|
+
* const releaseConfig: FeReleaseConfig = {
|
|
100
|
+
* autoMergeReleasePR: true,
|
|
101
|
+
* autoMergeType: 'squash',
|
|
102
|
+
* branchName: 'release-${pkgName}-${tagName}'
|
|
103
|
+
* };
|
|
104
|
+
* ```
|
|
105
|
+
*
|
|
106
|
+
* @example Advanced configuration with custom templates
|
|
107
|
+
* ```typescript
|
|
108
|
+
* const releaseConfig: FeReleaseConfig = {
|
|
109
|
+
* publishPath: './dist',
|
|
110
|
+
* autoMergeReleasePR: false,
|
|
111
|
+
* branchName: 'feat/release-${pkgName}-v${tagName}',
|
|
112
|
+
* PRTitle: '🚀 Release ${pkgName} v${tagName}',
|
|
113
|
+
* PRBody: '## Release ${pkgName} v${tagName}\n\n${changelog}',
|
|
114
|
+
* label: {
|
|
115
|
+
* name: 'release',
|
|
116
|
+
* color: '1A7F37',
|
|
117
|
+
* description: 'Automated release'
|
|
118
|
+
* }
|
|
119
|
+
* };
|
|
120
|
+
* ```
|
|
121
|
+
*
|
|
122
|
+
* @example Monorepo configuration
|
|
123
|
+
* ```typescript
|
|
124
|
+
* const releaseConfig: FeReleaseConfig = {
|
|
125
|
+
* packagesDirectories: ['packages/*', 'apps/*'],
|
|
126
|
+
* changePackagesLabel: 'changes:${name}',
|
|
127
|
+
* autoMergeReleasePR: true
|
|
128
|
+
* };
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
interface FeReleaseConfig {
|
|
210
132
|
/**
|
|
211
133
|
* The path to publish the package
|
|
212
134
|
*
|
|
213
|
-
*
|
|
135
|
+
* Core concept:
|
|
136
|
+
* Specifies the directory path where the package should be
|
|
137
|
+
* published, allowing for custom distribution locations
|
|
138
|
+
* and environment-specific publishing strategies.
|
|
139
|
+
*
|
|
140
|
+
* Publishing behavior:
|
|
141
|
+
* - Overrides default package.json publishConfig
|
|
142
|
+
* - Supports both relative and absolute paths
|
|
143
|
+
* - Used by npm publish and other distribution tools
|
|
144
|
+
* - Enables environment-specific publishing locations
|
|
145
|
+
* - Supports custom registry and distribution strategies
|
|
146
|
+
*
|
|
147
|
+
* Use cases:
|
|
148
|
+
* - Custom npm registry publishing
|
|
149
|
+
* - Environment-specific package distribution
|
|
150
|
+
* - Private package repository publishing
|
|
151
|
+
* - Alternative distribution platforms
|
|
152
|
+
* - Testing and staging package distribution
|
|
153
|
+
*
|
|
154
|
+
* @optional
|
|
155
|
+
* @default `''`
|
|
156
|
+
* @example Basic publish path
|
|
157
|
+
* ```typescript
|
|
158
|
+
* const config: FeReleaseConfig = {
|
|
159
|
+
* publishPath: './dist'
|
|
160
|
+
* };
|
|
161
|
+
* ```
|
|
162
|
+
*
|
|
163
|
+
* @example Custom registry
|
|
164
|
+
* ```typescript
|
|
165
|
+
* const config: FeReleaseConfig = {
|
|
166
|
+
* publishPath: '@myorg/registry'
|
|
167
|
+
* };
|
|
168
|
+
* ```
|
|
214
169
|
*/
|
|
215
170
|
publishPath?: string;
|
|
216
171
|
/**
|
|
217
172
|
* Whether to automatically merge PR when creating and publishing
|
|
218
173
|
*
|
|
219
|
-
*
|
|
174
|
+
* Core concept:
|
|
175
|
+
* Controls whether release pull requests should be automatically
|
|
176
|
+
* merged after successful validation, enabling fully automated
|
|
177
|
+
* release workflows.
|
|
178
|
+
*
|
|
179
|
+
* Auto-merge behavior:
|
|
180
|
+
* - Merges PR after all checks pass
|
|
181
|
+
* - Uses specified auto-merge type (merge/squash/rebase)
|
|
182
|
+
* - Triggers post-merge release actions
|
|
183
|
+
* - Enables continuous deployment workflows
|
|
184
|
+
* - Reduces manual intervention in release process
|
|
185
|
+
*
|
|
186
|
+
* Workflow integration:
|
|
187
|
+
* - Integrates with GitHub auto-merge features
|
|
188
|
+
* - Supports CI/CD pipeline automation
|
|
189
|
+
* - Enables fully automated release processes
|
|
190
|
+
* - Reduces release cycle time
|
|
191
|
+
* - Maintains release quality through automated checks
|
|
192
|
+
*
|
|
193
|
+
* @optional
|
|
194
|
+
* @default `false`
|
|
195
|
+
* @example Enable auto-merge
|
|
196
|
+
* ```typescript
|
|
197
|
+
* const config: FeReleaseConfig = {
|
|
198
|
+
* autoMergeReleasePR: true,
|
|
199
|
+
* autoMergeType: 'squash'
|
|
200
|
+
* };
|
|
201
|
+
* ```
|
|
202
|
+
*
|
|
203
|
+
* @example Manual review required
|
|
204
|
+
* ```typescript
|
|
205
|
+
* const config: FeReleaseConfig = {
|
|
206
|
+
* autoMergeReleasePR: false
|
|
207
|
+
* };
|
|
208
|
+
* ```
|
|
220
209
|
*/
|
|
221
210
|
autoMergeReleasePR?: boolean;
|
|
222
211
|
/**
|
|
223
|
-
* PR auto
|
|
212
|
+
* PR auto-merge strategy for release pull requests
|
|
213
|
+
*
|
|
214
|
+
* Core concept:
|
|
215
|
+
* Defines the merge strategy used when automatically merging
|
|
216
|
+
* release pull requests, affecting commit history and
|
|
217
|
+
* repository structure.
|
|
218
|
+
*
|
|
219
|
+
* Merge strategies:
|
|
220
|
+
* - merge: Creates merge commit with branch history
|
|
221
|
+
* - squash: Combines all commits into single commit
|
|
222
|
+
* - rebase: Replays commits on target branch
|
|
223
|
+
*
|
|
224
|
+
* Strategy considerations:
|
|
225
|
+
* - merge: Preserves complete branch history
|
|
226
|
+
* - squash: Creates clean, linear history
|
|
227
|
+
* - rebase: Maintains chronological order
|
|
228
|
+
* - Affects commit message and history structure
|
|
229
|
+
* - Influences repository maintenance and debugging
|
|
224
230
|
*
|
|
225
|
-
* @
|
|
231
|
+
* @optional
|
|
232
|
+
* @default `'squash'`
|
|
233
|
+
* @example Squash merge
|
|
234
|
+
* ```typescript
|
|
235
|
+
* const config: FeReleaseConfig = {
|
|
236
|
+
* autoMergeType: 'squash'
|
|
237
|
+
* };
|
|
238
|
+
* ```
|
|
239
|
+
*
|
|
240
|
+
* @example Preserve history
|
|
241
|
+
* ```typescript
|
|
242
|
+
* const config: FeReleaseConfig = {
|
|
243
|
+
* autoMergeType: 'merge'
|
|
244
|
+
* };
|
|
245
|
+
* ```
|
|
226
246
|
*/
|
|
227
247
|
autoMergeType?: 'merge' | 'squash' | 'rebase';
|
|
228
248
|
/**
|
|
229
|
-
*
|
|
249
|
+
* Template for creating release branch names
|
|
250
|
+
*
|
|
251
|
+
* Core concept:
|
|
252
|
+
* Defines the naming pattern for release branches using
|
|
253
|
+
* template variables, enabling consistent and descriptive
|
|
254
|
+
* branch naming across different packages and environments.
|
|
255
|
+
*
|
|
256
|
+
* Template variables:
|
|
257
|
+
* - `${pkgName}`: Package name from package.json
|
|
258
|
+
* - `${tagName}`: Release version tag
|
|
259
|
+
* - `${env}`: Release environment
|
|
260
|
+
* - `${branch}`: Source branch name
|
|
261
|
+
*
|
|
262
|
+
* Branch naming patterns:
|
|
263
|
+
* - Descriptive names for easy identification
|
|
264
|
+
* - Consistent format across all releases
|
|
265
|
+
* - Environment and package-specific naming
|
|
266
|
+
* - Supports Git branch naming conventions
|
|
267
|
+
* - Enables automated branch management
|
|
230
268
|
*
|
|
231
|
-
*
|
|
269
|
+
* @optional
|
|
270
|
+
* @default `'release-${pkgName}-${tagName}'`
|
|
271
|
+
* @example Basic branch naming
|
|
272
|
+
* ```typescript
|
|
273
|
+
* const config: FeReleaseConfig = {
|
|
274
|
+
* branchName: 'release-${pkgName}-${tagName}'
|
|
275
|
+
* };
|
|
276
|
+
* ```
|
|
232
277
|
*
|
|
233
|
-
* @
|
|
278
|
+
* @example Environment-aware naming
|
|
279
|
+
* ```typescript
|
|
280
|
+
* const config: FeReleaseConfig = {
|
|
281
|
+
* branchName: 'release/${env}/${pkgName}-${tagName}'
|
|
282
|
+
* };
|
|
283
|
+
* ```
|
|
234
284
|
*/
|
|
235
285
|
branchName?: string;
|
|
236
286
|
/**
|
|
237
|
-
*
|
|
287
|
+
* Template for release pull request titles
|
|
288
|
+
*
|
|
289
|
+
* Core concept:
|
|
290
|
+
* Defines the title format for release pull requests using
|
|
291
|
+
* template variables, providing clear and informative
|
|
292
|
+
* PR titles for release management.
|
|
293
|
+
*
|
|
294
|
+
* Title components:
|
|
295
|
+
* - Package name for identification
|
|
296
|
+
* - Release version for version tracking
|
|
297
|
+
* - Environment for deployment context
|
|
298
|
+
* - Source branch for change tracking
|
|
299
|
+
* - Consistent formatting for automation
|
|
300
|
+
*
|
|
301
|
+
* Template variables:
|
|
302
|
+
* - `${pkgName}`: Package name from package.json
|
|
303
|
+
* - `${tagName}`: Release version tag
|
|
304
|
+
* - `${env}`: Release environment
|
|
305
|
+
* - `${branch}`: Source branch name
|
|
306
|
+
*
|
|
307
|
+
* @optional
|
|
308
|
+
* @default `'[${pkgName} Release] Branch:${branch}, Tag:${tagName}, Env:${env}'`
|
|
309
|
+
* @example Basic PR title
|
|
310
|
+
* ```typescript
|
|
311
|
+
* const config: FeReleaseConfig = {
|
|
312
|
+
* PRTitle: '[${pkgName} Release] v${tagName}'
|
|
313
|
+
* };
|
|
314
|
+
* ```
|
|
238
315
|
*
|
|
239
|
-
* @
|
|
316
|
+
* @example Detailed PR title
|
|
317
|
+
* ```typescript
|
|
318
|
+
* const config: FeReleaseConfig = {
|
|
319
|
+
* PRTitle: '🚀 Release ${pkgName} v${tagName} (${env})'
|
|
320
|
+
* };
|
|
321
|
+
* ```
|
|
240
322
|
*/
|
|
241
323
|
PRTitle?: string;
|
|
242
324
|
/**
|
|
243
|
-
*
|
|
325
|
+
* Template for release pull request body content
|
|
326
|
+
*
|
|
327
|
+
* Core concept:
|
|
328
|
+
* Defines the content template for release pull request
|
|
329
|
+
* descriptions, providing comprehensive release information
|
|
330
|
+
* and automated content generation.
|
|
331
|
+
*
|
|
332
|
+
* Content sections:
|
|
333
|
+
* - Release details and metadata
|
|
334
|
+
* - Generated changelog content
|
|
335
|
+
* - Review checklist and notes
|
|
336
|
+
* - Environment and version information
|
|
337
|
+
* - Automated process notifications
|
|
338
|
+
*
|
|
339
|
+
* Template variables:
|
|
340
|
+
* - `${tagName}`: Release version tag
|
|
341
|
+
* - `${branch}`: Source branch name
|
|
342
|
+
* - `${env}`: Release environment
|
|
343
|
+
* - `${changelog}`: Generated changelog content
|
|
344
|
+
* - `${pkgName}`: Package name
|
|
345
|
+
*
|
|
346
|
+
* @optional
|
|
347
|
+
* @default Comprehensive PR body template with changelog
|
|
348
|
+
* @example Simple PR body
|
|
349
|
+
* ```typescript
|
|
350
|
+
* const config: FeReleaseConfig = {
|
|
351
|
+
* PRBody: 'Release ${pkgName} v${tagName}\n\n${changelog}'
|
|
352
|
+
* };
|
|
353
|
+
* ```
|
|
354
|
+
*
|
|
355
|
+
* @example Detailed PR body
|
|
356
|
+
* ```typescript
|
|
357
|
+
* const config: FeReleaseConfig = {
|
|
358
|
+
* PRBody: `
|
|
359
|
+
* ## Release ${pkgName} v${tagName}
|
|
244
360
|
*
|
|
245
|
-
*
|
|
361
|
+
* **Environment:** ${env}
|
|
362
|
+
* **Branch:** ${branch}
|
|
363
|
+
*
|
|
364
|
+
* ### Changes
|
|
365
|
+
* ${changelog}
|
|
366
|
+
*
|
|
367
|
+
* ### Checklist
|
|
368
|
+
* - [ ] Version number is correct
|
|
369
|
+
* - [ ] All tests pass
|
|
370
|
+
* - [ ] Documentation updated
|
|
371
|
+
* `
|
|
372
|
+
* };
|
|
373
|
+
* ```
|
|
246
374
|
*/
|
|
247
375
|
PRBody?: string;
|
|
248
376
|
/**
|
|
249
|
-
*
|
|
377
|
+
* Configuration for release pull request labels
|
|
378
|
+
*
|
|
379
|
+
* Core concept:
|
|
380
|
+
* Defines the label configuration for release pull requests,
|
|
381
|
+
* enabling automated categorization and visual identification
|
|
382
|
+
* of release-related PRs.
|
|
383
|
+
*
|
|
384
|
+
* Label features:
|
|
385
|
+
* - Automated label application
|
|
386
|
+
* - Customizable label appearance
|
|
387
|
+
* - Consistent release identification
|
|
388
|
+
* - Integration with GitHub labeling system
|
|
389
|
+
* - Support for custom label descriptions
|
|
390
|
+
*
|
|
391
|
+
* Label properties:
|
|
392
|
+
* - name: Label identifier and display name
|
|
393
|
+
* - color: Hexadecimal color code for visual distinction
|
|
394
|
+
* - description: Label description for documentation
|
|
395
|
+
*
|
|
396
|
+
* @optional
|
|
397
|
+
* @example Basic label configuration
|
|
398
|
+
* ```typescript
|
|
399
|
+
* const config: FeReleaseConfig = {
|
|
400
|
+
* label: {
|
|
401
|
+
* name: 'release',
|
|
402
|
+
* color: '1A7F37',
|
|
403
|
+
* description: 'Automated release PR'
|
|
404
|
+
* }
|
|
405
|
+
* };
|
|
406
|
+
* ```
|
|
407
|
+
*
|
|
408
|
+
* @example Custom label
|
|
409
|
+
* ```typescript
|
|
410
|
+
* const config: FeReleaseConfig = {
|
|
411
|
+
* label: {
|
|
412
|
+
* name: 'CI-Release',
|
|
413
|
+
* color: '0366D6',
|
|
414
|
+
* description: 'Release created by CI/CD'
|
|
415
|
+
* }
|
|
416
|
+
* };
|
|
417
|
+
* ```
|
|
250
418
|
*/
|
|
251
419
|
label?: {
|
|
252
420
|
/**
|
|
253
|
-
*
|
|
421
|
+
* Hexadecimal color code for label appearance
|
|
254
422
|
*
|
|
255
|
-
*
|
|
423
|
+
* Color format: 6-character hex string without '#'
|
|
424
|
+
* Used for visual distinction in GitHub interface
|
|
425
|
+
* Supports standard web color codes
|
|
426
|
+
*
|
|
427
|
+
* @optional
|
|
428
|
+
* @default `'1A7F37'`
|
|
429
|
+
* @example Green color
|
|
430
|
+
* ```typescript
|
|
431
|
+
* color: '1A7F37'
|
|
432
|
+
* ```
|
|
433
|
+
*
|
|
434
|
+
* @example Blue color
|
|
435
|
+
* ```typescript
|
|
436
|
+
* color: '0366D6'
|
|
437
|
+
* ```
|
|
256
438
|
*/
|
|
257
439
|
color?: string;
|
|
258
440
|
/**
|
|
259
|
-
*
|
|
441
|
+
* Descriptive text for label documentation
|
|
442
|
+
*
|
|
443
|
+
* Provides context about the label's purpose
|
|
444
|
+
* Used in GitHub label management interface
|
|
445
|
+
* Helps team members understand label usage
|
|
446
|
+
*
|
|
447
|
+
* @optional
|
|
448
|
+
* @default `'Release PR'`
|
|
449
|
+
* @example
|
|
450
|
+
* ```typescript
|
|
451
|
+
* description: 'Automated release pull request'
|
|
452
|
+
* ```
|
|
260
453
|
*/
|
|
261
454
|
description?: string;
|
|
262
455
|
/**
|
|
263
|
-
*
|
|
456
|
+
* Label name for identification and display
|
|
457
|
+
*
|
|
458
|
+
* Used as the primary identifier for the label
|
|
459
|
+
* Displayed in GitHub PR interface
|
|
460
|
+
* Should be descriptive and consistent
|
|
461
|
+
*
|
|
462
|
+
* @optional
|
|
463
|
+
* @default `'CI-Release'`
|
|
464
|
+
* @example
|
|
465
|
+
* ```typescript
|
|
466
|
+
* name: 'release'
|
|
467
|
+
* ```
|
|
264
468
|
*/
|
|
265
469
|
name?: string;
|
|
266
470
|
};
|
|
267
471
|
/**
|
|
268
|
-
*
|
|
472
|
+
* Template for package change labels in monorepos
|
|
473
|
+
*
|
|
474
|
+
* Core concept:
|
|
475
|
+
* Defines the naming pattern for labels that identify
|
|
476
|
+
* which packages have changed in monorepo releases,
|
|
477
|
+
* enabling targeted review and deployment.
|
|
478
|
+
*
|
|
479
|
+
* Label usage:
|
|
480
|
+
* - Applied to PRs when specific packages change
|
|
481
|
+
* - Enables package-specific review processes
|
|
482
|
+
* - Supports selective deployment strategies
|
|
483
|
+
* - Improves monorepo change tracking
|
|
484
|
+
* - Facilitates team collaboration and review
|
|
485
|
+
*
|
|
486
|
+
* Template variables:
|
|
487
|
+
* - `${name}`: Package name for label identification
|
|
488
|
+
*
|
|
489
|
+
* @optional
|
|
490
|
+
* @default `'changes:${name}'`
|
|
491
|
+
* @example Basic change label
|
|
492
|
+
* ```typescript
|
|
493
|
+
* const config: FeReleaseConfig = {
|
|
494
|
+
* changePackagesLabel: 'changes:${name}'
|
|
495
|
+
* };
|
|
496
|
+
* ```
|
|
497
|
+
*
|
|
498
|
+
* @example Custom change label
|
|
499
|
+
* ```typescript
|
|
500
|
+
* const config: FeReleaseConfig = {
|
|
501
|
+
* changePackagesLabel: 'package:${name}'
|
|
502
|
+
* };
|
|
503
|
+
* ```
|
|
269
504
|
*/
|
|
270
505
|
changePackagesLabel?: string;
|
|
271
506
|
/**
|
|
507
|
+
* Directories containing packages for monorepo releases
|
|
508
|
+
*
|
|
509
|
+
* Core concept:
|
|
510
|
+
* Specifies the directories that contain packages for
|
|
511
|
+
* monorepo release management, enabling selective
|
|
512
|
+
* package discovery and release coordination.
|
|
513
|
+
*
|
|
514
|
+
* Directory patterns:
|
|
515
|
+
* - Supports glob patterns for flexible matching
|
|
516
|
+
* - Enables selective package inclusion
|
|
517
|
+
* - Supports nested directory structures
|
|
518
|
+
* - Facilitates monorepo organization
|
|
519
|
+
* - Enables workspace-specific configurations
|
|
520
|
+
*
|
|
521
|
+
* Use cases:
|
|
522
|
+
* - Monorepo package discovery
|
|
523
|
+
* - Selective package releases
|
|
524
|
+
* - Workspace-specific configurations
|
|
525
|
+
* - Multi-package coordination
|
|
526
|
+
* - Dependency-aware releases
|
|
527
|
+
*
|
|
528
|
+
* @optional
|
|
272
529
|
* @default `[]`
|
|
530
|
+
* @example Basic package directories
|
|
531
|
+
* ```typescript
|
|
532
|
+
* const config: FeReleaseConfig = {
|
|
533
|
+
* packagesDirectories: ['packages/*']
|
|
534
|
+
* };
|
|
535
|
+
* ```
|
|
536
|
+
*
|
|
537
|
+
* @example Multiple package directories
|
|
538
|
+
* ```typescript
|
|
539
|
+
* const config: FeReleaseConfig = {
|
|
540
|
+
* packagesDirectories: ['packages/*', 'apps/*', 'libs/*']
|
|
541
|
+
* };
|
|
542
|
+
* ```
|
|
273
543
|
*/
|
|
274
544
|
packagesDirectories?: string[];
|
|
275
|
-
}
|
|
545
|
+
}
|
|
276
546
|
|
|
277
547
|
/**
|
|
278
|
-
*
|
|
548
|
+
* Common/shared configuration options for script execution context
|
|
279
549
|
*
|
|
280
|
-
*
|
|
281
|
-
*
|
|
550
|
+
* Core concept:
|
|
551
|
+
* Defines the fundamental properties that are shared across different
|
|
552
|
+
* script contexts and plugins, providing consistent environment access,
|
|
553
|
+
* project path management, and source branch information for unified
|
|
554
|
+
* configuration management.
|
|
282
555
|
*
|
|
283
|
-
*
|
|
284
|
-
*
|
|
285
|
-
*
|
|
286
|
-
*
|
|
287
|
-
*
|
|
288
|
-
*
|
|
556
|
+
* Main features:
|
|
557
|
+
* - Environment access: Integrated environment variable management
|
|
558
|
+
* - Provides access to loaded environment variables
|
|
559
|
+
* - Supports configuration, secrets, and runtime flags
|
|
560
|
+
* - Integrates with fe-config environment settings
|
|
561
|
+
* - Handles environment file loading and validation
|
|
562
|
+
*
|
|
563
|
+
* - Path management: Project root path for file operations
|
|
564
|
+
* - Used as base directory for all relative file operations
|
|
565
|
+
* - Supports both absolute and relative path resolution
|
|
566
|
+
* - Maintains path consistency across environments
|
|
567
|
+
* - Defaults to current working directory
|
|
568
|
+
*
|
|
569
|
+
* - Branch information: Source branch for build and deployment
|
|
570
|
+
* - Determines source branch for build or deployment processes
|
|
571
|
+
* - Supports environment variable resolution
|
|
572
|
+
* - Provides fallback to default branch
|
|
573
|
+
* - Used in CI/CD and build automation
|
|
574
|
+
*
|
|
575
|
+
* Design considerations:
|
|
576
|
+
* - All properties are optional to allow flexible extension in derived interfaces
|
|
577
|
+
* - Environment and branch information are used for build, deploy, and CI/CD scripts
|
|
578
|
+
* - Path management supports cross-platform compatibility
|
|
579
|
+
* - Provides sensible defaults for all optional properties
|
|
580
|
+
* - Maintains backward compatibility with existing implementations
|
|
581
|
+
*
|
|
582
|
+
* Usage patterns:
|
|
583
|
+
* - Base interface for script-specific option extensions
|
|
584
|
+
* - Common functionality across different script types
|
|
585
|
+
* - Environment-aware configuration management
|
|
586
|
+
* - Path-relative file and directory operations
|
|
587
|
+
*
|
|
588
|
+
* @example Basic usage
|
|
589
|
+
* ```typescript
|
|
590
|
+
* const shared: ScriptSharedInterface = {
|
|
591
|
+
* env: Env.searchEnv(),
|
|
592
|
+
* sourceBranch: 'develop',
|
|
593
|
+
* rootPath: '/project/root'
|
|
594
|
+
* };
|
|
595
|
+
* ```
|
|
596
|
+
*
|
|
597
|
+
* @example With environment variables
|
|
598
|
+
* ```typescript
|
|
599
|
+
* const shared: ScriptSharedInterface = {
|
|
600
|
+
* env: Env.searchEnv(),
|
|
601
|
+
* sourceBranch: process.env.FE_RELEASE_BRANCH || 'master',
|
|
602
|
+
* rootPath: process.cwd()
|
|
289
603
|
* };
|
|
604
|
+
* ```
|
|
605
|
+
*
|
|
606
|
+
* @example Extended interface
|
|
607
|
+
* ```typescript
|
|
608
|
+
* interface BuildOptions extends ScriptSharedInterface {
|
|
609
|
+
* target: 'development' | 'production';
|
|
610
|
+
* outputDir: string;
|
|
611
|
+
* }
|
|
612
|
+
* ```
|
|
290
613
|
*/
|
|
291
|
-
interface
|
|
614
|
+
interface ScriptSharedInterface {
|
|
292
615
|
/**
|
|
293
|
-
*
|
|
616
|
+
* Environment variable accessor instance
|
|
294
617
|
*
|
|
295
|
-
*
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
* Environment variables to be passed to the command.
|
|
618
|
+
* Core concept:
|
|
619
|
+
* Provides access to loaded environment variables for the script
|
|
620
|
+
* context, enabling configuration management, secret access,
|
|
621
|
+
* and runtime flag control.
|
|
300
622
|
*
|
|
301
|
-
*
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
*
|
|
623
|
+
* Environment capabilities:
|
|
624
|
+
* - Automatic loading of .env files with configurable order
|
|
625
|
+
* - Type-safe environment variable access with defaults
|
|
626
|
+
* - Support for environment-specific configurations
|
|
627
|
+
* - Integration with fe-config environment settings
|
|
628
|
+
* - Lazy initialization for performance optimization
|
|
306
629
|
*
|
|
307
|
-
*
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
*
|
|
312
|
-
*
|
|
630
|
+
* Common use cases:
|
|
631
|
+
* - API keys and authentication tokens
|
|
632
|
+
* - Database connection strings
|
|
633
|
+
* - Feature flags and configuration switches
|
|
634
|
+
* - Build and deployment settings
|
|
635
|
+
* - Runtime environment identification
|
|
313
636
|
*
|
|
314
|
-
*
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
*
|
|
637
|
+
* Loading behavior:
|
|
638
|
+
* - Files loaded in priority order (highest first)
|
|
639
|
+
* - Missing files are silently ignored
|
|
640
|
+
* - Variables cached after first load
|
|
641
|
+
* - Environment shared across script instances
|
|
642
|
+
* - Supports both development and production environments
|
|
643
|
+
*
|
|
644
|
+
* @optional
|
|
645
|
+
* @example Basic environment access
|
|
646
|
+
* ```typescript
|
|
647
|
+
* const apiKey = shared.env?.get('API_KEY');
|
|
648
|
+
* const port = shared.env?.get('PORT', '3000');
|
|
649
|
+
* ```
|
|
650
|
+
*
|
|
651
|
+
* @example With defaults
|
|
652
|
+
* ```typescript
|
|
653
|
+
* const databaseUrl = shared.env?.get('DATABASE_URL', 'localhost:5432');
|
|
654
|
+
* const debug = shared.env?.get('DEBUG', 'false');
|
|
655
|
+
* const isDebug = debug === 'true';
|
|
656
|
+
* ```
|
|
319
657
|
*
|
|
320
|
-
* @
|
|
658
|
+
* @example Environment validation
|
|
659
|
+
* ```typescript
|
|
660
|
+
* if (!shared.env?.get('REQUIRED_VAR')) {
|
|
661
|
+
* throw new Error('REQUIRED_VAR environment variable is missing');
|
|
662
|
+
* }
|
|
663
|
+
* ```
|
|
321
664
|
*/
|
|
322
|
-
|
|
665
|
+
env?: Env;
|
|
323
666
|
/**
|
|
324
|
-
*
|
|
667
|
+
* The source branch of the project for build and deployment
|
|
668
|
+
*
|
|
669
|
+
* Core concept:
|
|
670
|
+
* Determines which branch is considered the source for build
|
|
671
|
+
* or deployment processes, supporting environment variable
|
|
672
|
+
* resolution and providing fallback values.
|
|
673
|
+
*
|
|
674
|
+
* Resolution priority:
|
|
675
|
+
* 1. `FE_RELEASE_SOURCE_BRANCH` environment variable (primary)
|
|
676
|
+
* 2. `FE_RELEASE_BRANCH` environment variable (fallback)
|
|
677
|
+
* 3. 'master' (default fallback)
|
|
678
|
+
* 4. Explicitly set value (highest priority)
|
|
679
|
+
*
|
|
680
|
+
* Use cases:
|
|
681
|
+
* - Build automation and CI/CD pipelines
|
|
682
|
+
* - Deployment targeting and branch selection
|
|
683
|
+
* - Release management and versioning
|
|
684
|
+
* - Environment-specific configuration
|
|
685
|
+
* - Git workflow integration
|
|
686
|
+
*
|
|
687
|
+
* Branch handling:
|
|
688
|
+
* - Supports all Git branch naming conventions
|
|
689
|
+
* - Handles special characters and spaces
|
|
690
|
+
* - Validates branch existence when possible
|
|
691
|
+
* - Provides consistent branch reference
|
|
692
|
+
* - Supports both local and remote branches
|
|
693
|
+
*
|
|
694
|
+
* @optional
|
|
695
|
+
* @example Basic branch usage
|
|
696
|
+
* ```typescript
|
|
697
|
+
* const branch = shared.sourceBranch || 'master';
|
|
698
|
+
* console.log('Building from branch:', branch);
|
|
699
|
+
* ```
|
|
700
|
+
*
|
|
701
|
+
* @example With environment resolution
|
|
702
|
+
* ```typescript
|
|
703
|
+
* const branch = shared.sourceBranch ||
|
|
704
|
+
* process.env.FE_RELEASE_SOURCE_BRANCH ||
|
|
705
|
+
* process.env.FE_RELEASE_BRANCH ||
|
|
706
|
+
* 'master';
|
|
707
|
+
* ```
|
|
325
708
|
*
|
|
326
|
-
* @
|
|
709
|
+
* @example Branch validation
|
|
710
|
+
* ```typescript
|
|
711
|
+
* if (shared.sourceBranch === 'main' || shared.sourceBranch === 'master') {
|
|
712
|
+
* console.log('Building from main branch');
|
|
713
|
+
* } else {
|
|
714
|
+
* console.log('Building from feature branch:', shared.sourceBranch);
|
|
715
|
+
* }
|
|
716
|
+
* ```
|
|
327
717
|
*/
|
|
328
|
-
|
|
718
|
+
sourceBranch?: string;
|
|
329
719
|
/**
|
|
330
|
-
*
|
|
720
|
+
* The root path of the project for file operations
|
|
331
721
|
*
|
|
332
|
-
*
|
|
333
|
-
*
|
|
722
|
+
* Core concept:
|
|
723
|
+
* Specifies the base directory for all relative file operations,
|
|
724
|
+
* providing consistent path resolution across different
|
|
725
|
+
* environments and execution contexts.
|
|
726
|
+
*
|
|
727
|
+
* Path behavior:
|
|
728
|
+
* - Used as base directory for all relative file operations
|
|
729
|
+
* - Supports both absolute and relative path resolution
|
|
730
|
+
* - Maintains path consistency across environments
|
|
731
|
+
* - Defaults to current working directory if not specified
|
|
732
|
+
* - Handles cross-platform path separators
|
|
733
|
+
*
|
|
734
|
+
* File operations:
|
|
735
|
+
* - Configuration file loading and searching
|
|
736
|
+
* - Build output directory resolution
|
|
737
|
+
* - Asset and resource file access
|
|
738
|
+
* - Temporary file and cache management
|
|
739
|
+
* - Log file and output directory creation
|
|
740
|
+
*
|
|
741
|
+
* Path resolution:
|
|
742
|
+
* - Absolute paths are used as-is
|
|
743
|
+
* - Relative paths are resolved from root path
|
|
744
|
+
* - Supports nested directory structures
|
|
745
|
+
* - Handles path normalization and validation
|
|
746
|
+
* - Provides consistent path representation
|
|
747
|
+
*
|
|
748
|
+
* @optional
|
|
749
|
+
* @default `process.cwd()`
|
|
750
|
+
* @example Basic path usage
|
|
751
|
+
* ```typescript
|
|
752
|
+
* const root = shared.rootPath || process.cwd();
|
|
753
|
+
* const configPath = path.join(root, 'fe-config.json');
|
|
754
|
+
* ```
|
|
755
|
+
*
|
|
756
|
+
* @example Relative path resolution
|
|
757
|
+
* ```typescript
|
|
758
|
+
* const root = shared.rootPath || process.cwd();
|
|
759
|
+
* const buildDir = path.join(root, 'dist');
|
|
760
|
+
* const srcDir = path.join(root, 'src');
|
|
761
|
+
* ```
|
|
762
|
+
*
|
|
763
|
+
* @example Path validation
|
|
764
|
+
* ```typescript
|
|
765
|
+
* const root = shared.rootPath || process.cwd();
|
|
766
|
+
* if (!fs.existsSync(root)) {
|
|
767
|
+
* throw new Error(`Root path does not exist: ${root}`);
|
|
768
|
+
* }
|
|
769
|
+
* ```
|
|
334
770
|
*/
|
|
335
|
-
|
|
336
|
-
[key: string]: unknown;
|
|
771
|
+
rootPath?: string;
|
|
337
772
|
}
|
|
773
|
+
|
|
338
774
|
/**
|
|
339
|
-
*
|
|
775
|
+
* Options for shell command execution with comprehensive customization
|
|
340
776
|
*
|
|
341
|
-
*
|
|
342
|
-
*
|
|
777
|
+
* Core concept:
|
|
778
|
+
* Defines the configuration options available for executing shell
|
|
779
|
+
* commands, providing flexibility in controlling execution behavior,
|
|
780
|
+
* output handling, and environment configuration.
|
|
343
781
|
*
|
|
344
|
-
*
|
|
345
|
-
*
|
|
346
|
-
*
|
|
347
|
-
*
|
|
348
|
-
*
|
|
349
|
-
*
|
|
350
|
-
*
|
|
351
|
-
*
|
|
352
|
-
|
|
353
|
-
|
|
782
|
+
* Main features:
|
|
783
|
+
* - Execution control: Fine-grained control over command execution
|
|
784
|
+
* - Silent mode for quiet execution
|
|
785
|
+
* - Dry run mode for safe testing
|
|
786
|
+
* - Custom environment variable injection
|
|
787
|
+
* - Working directory specification
|
|
788
|
+
*
|
|
789
|
+
* - Output handling: Flexible output and result management
|
|
790
|
+
* - Encoding specification for output processing
|
|
791
|
+
* - Dry run result customization
|
|
792
|
+
* - Template context for dynamic command generation
|
|
793
|
+
* - Caching support for performance optimization
|
|
794
|
+
*
|
|
795
|
+
* - Environment integration: Comprehensive environment management
|
|
796
|
+
* - Environment variable injection
|
|
797
|
+
* - Template context for variable substitution
|
|
798
|
+
* - Cross-platform compatibility
|
|
799
|
+
* - Security considerations for sensitive data
|
|
800
|
+
*
|
|
801
|
+
* Design considerations:
|
|
802
|
+
* - All options are optional for maximum flexibility
|
|
803
|
+
* - Supports both string and array command formats
|
|
804
|
+
* - Maintains backward compatibility with existing implementations
|
|
805
|
+
* - Provides sensible defaults for all optional properties
|
|
806
|
+
* - Supports extensibility through index signature
|
|
807
|
+
*
|
|
808
|
+
* Usage patterns:
|
|
809
|
+
* - Basic command execution with minimal options
|
|
810
|
+
* - Advanced execution with custom environment and encoding
|
|
811
|
+
* - Template-based command generation with context
|
|
812
|
+
* - Dry run testing and validation
|
|
813
|
+
* - Performance optimization through caching
|
|
814
|
+
*
|
|
815
|
+
* @example Basic usage
|
|
816
|
+
* ```typescript
|
|
817
|
+
* const options: ShellExecOptions = {
|
|
818
|
+
* silent: true,
|
|
819
|
+
* env: { PATH: '/usr/bin' },
|
|
820
|
+
* dryRun: false
|
|
821
|
+
* };
|
|
822
|
+
* ```
|
|
823
|
+
*
|
|
824
|
+
* @example With template context
|
|
825
|
+
* ```typescript
|
|
826
|
+
* const options: ShellExecOptions = {
|
|
827
|
+
* context: { repo: 'https://github.com/user/repo.git' },
|
|
828
|
+
* cwd: '/project/root'
|
|
829
|
+
* };
|
|
830
|
+
* ```
|
|
831
|
+
*
|
|
832
|
+
* @example Dry run mode
|
|
833
|
+
* ```typescript
|
|
834
|
+
* const options: ShellExecOptions = {
|
|
835
|
+
* dryRun: true,
|
|
836
|
+
* dryRunResult: 'Would execute: npm install'
|
|
837
|
+
* };
|
|
838
|
+
* ```
|
|
839
|
+
*/
|
|
840
|
+
interface ShellExecOptions {
|
|
354
841
|
/**
|
|
355
|
-
*
|
|
842
|
+
* Whether to suppress output to the console
|
|
843
|
+
*
|
|
844
|
+
* Core concept:
|
|
845
|
+
* Controls whether command execution details are logged
|
|
846
|
+
* to the console, useful for quiet execution in automated
|
|
847
|
+
* scripts or when detailed logging is not needed.
|
|
848
|
+
*
|
|
849
|
+
* Silent mode behavior:
|
|
850
|
+
* - Suppresses command execution logging
|
|
851
|
+
* - Maintains error logging for debugging
|
|
852
|
+
* - Reduces log noise in automated environments
|
|
853
|
+
* - Useful for background or batch operations
|
|
854
|
+
* - Preserves error handling and reporting
|
|
855
|
+
*
|
|
856
|
+
* Use cases:
|
|
857
|
+
* - Automated script execution
|
|
858
|
+
* - Background command processing
|
|
859
|
+
* - Batch operations with minimal output
|
|
860
|
+
* - Integration with external logging systems
|
|
861
|
+
* - Performance-critical operations
|
|
862
|
+
*
|
|
863
|
+
* @optional
|
|
864
|
+
* @example Basic silent execution
|
|
865
|
+
* ```typescript
|
|
866
|
+
* const options: ShellExecOptions = { silent: true };
|
|
867
|
+
* // Command executes without console output
|
|
868
|
+
* ```
|
|
356
869
|
*
|
|
357
|
-
* @
|
|
358
|
-
*
|
|
359
|
-
*
|
|
870
|
+
* @example Conditional silent mode
|
|
871
|
+
* ```typescript
|
|
872
|
+
* const options: ShellExecOptions = {
|
|
873
|
+
* silent: process.env.NODE_ENV === 'production'
|
|
874
|
+
* };
|
|
875
|
+
* ```
|
|
360
876
|
*/
|
|
361
|
-
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
type ExecPromiseFunction = (command: string | string[], options: ShellExecOptions) => Promise<string>;
|
|
365
|
-
/**
|
|
366
|
-
* Configuration interface for Shell class
|
|
367
|
-
* @interface
|
|
368
|
-
*/
|
|
369
|
-
interface ShellConfig extends ShellExecOptions {
|
|
370
|
-
/** Logger instance */
|
|
371
|
-
logger: LoggerInterface;
|
|
877
|
+
silent?: boolean;
|
|
372
878
|
/**
|
|
373
|
-
*
|
|
879
|
+
* Environment variables to be passed to the command
|
|
880
|
+
*
|
|
881
|
+
* Core concept:
|
|
882
|
+
* Specifies custom environment variables that will be
|
|
883
|
+
* available to the executed command, allowing for
|
|
884
|
+
* environment-specific configuration and behavior.
|
|
885
|
+
*
|
|
886
|
+
* Environment injection:
|
|
887
|
+
* - Variables are merged with existing environment
|
|
888
|
+
* - Overrides existing variables with same names
|
|
889
|
+
* - Supports both string and object value types
|
|
890
|
+
* - Maintains security for sensitive data
|
|
891
|
+
* - Provides cross-platform compatibility
|
|
892
|
+
*
|
|
893
|
+
* Common use cases:
|
|
894
|
+
* - PATH modifications for command resolution
|
|
895
|
+
* - API keys and authentication tokens
|
|
896
|
+
* - Configuration overrides for specific commands
|
|
897
|
+
* - Development vs production environment switching
|
|
898
|
+
* - Custom script environment setup
|
|
899
|
+
*
|
|
900
|
+
* Security considerations:
|
|
901
|
+
* - Sensitive data should be handled carefully
|
|
902
|
+
* - Avoid logging environment variables with secrets
|
|
903
|
+
* - Use appropriate file permissions for environment files
|
|
904
|
+
* - Consider using secure environment variable management
|
|
905
|
+
*
|
|
906
|
+
* @optional
|
|
907
|
+
* @example Basic environment injection
|
|
908
|
+
* ```typescript
|
|
909
|
+
* const options: ShellExecOptions = {
|
|
910
|
+
* env: { PATH: '/usr/bin:/usr/local/bin' }
|
|
911
|
+
* };
|
|
912
|
+
* ```
|
|
913
|
+
*
|
|
914
|
+
* @example With API keys
|
|
915
|
+
* ```typescript
|
|
916
|
+
* const options: ShellExecOptions = {
|
|
917
|
+
* env: {
|
|
918
|
+
* API_KEY: process.env.API_KEY,
|
|
919
|
+
* NODE_ENV: 'production'
|
|
920
|
+
* }
|
|
921
|
+
* };
|
|
922
|
+
* ```
|
|
374
923
|
*/
|
|
375
|
-
|
|
376
|
-
}
|
|
377
|
-
/**
|
|
378
|
-
* Shell class for command execution
|
|
379
|
-
* @class
|
|
380
|
-
* @description Provides methods for executing shell commands with caching and templating support
|
|
381
|
-
*/
|
|
382
|
-
declare class Shell implements ShellInterface {
|
|
383
|
-
config: ShellConfig;
|
|
384
|
-
private cache;
|
|
924
|
+
env?: Record<string, string>;
|
|
385
925
|
/**
|
|
386
|
-
*
|
|
387
|
-
*
|
|
388
|
-
*
|
|
926
|
+
* Result to return when in dry-run mode
|
|
927
|
+
*
|
|
928
|
+
* Core concept:
|
|
929
|
+
* Specifies the value to return when dry-run mode is
|
|
930
|
+
* enabled, allowing for predictable testing and
|
|
931
|
+
* validation without actual command execution.
|
|
932
|
+
*
|
|
933
|
+
* Dry run behavior:
|
|
934
|
+
* - Command is not actually executed
|
|
935
|
+
* - Returns the specified result value
|
|
936
|
+
* - Maintains logging for debugging
|
|
937
|
+
* - Useful for command validation and testing
|
|
938
|
+
* - Supports both string and object result types
|
|
939
|
+
*
|
|
940
|
+
* Testing scenarios:
|
|
941
|
+
* - Command generation validation
|
|
942
|
+
* - Template formatting verification
|
|
943
|
+
* - Configuration testing without side effects
|
|
944
|
+
* - Script logic debugging
|
|
945
|
+
* - Safe exploration of command behavior
|
|
946
|
+
*
|
|
947
|
+
* Result types:
|
|
948
|
+
* - String: Simple text output simulation
|
|
949
|
+
* - Object: Complex result structure simulation
|
|
950
|
+
* - Array: Multiple output line simulation
|
|
951
|
+
* - Function: Dynamic result generation
|
|
952
|
+
*
|
|
953
|
+
* @optional
|
|
954
|
+
* @example Basic dry run result
|
|
955
|
+
* ```typescript
|
|
956
|
+
* const options: ShellExecOptions = {
|
|
957
|
+
* dryRun: true,
|
|
958
|
+
* dryRunResult: 'Command would execute successfully'
|
|
959
|
+
* };
|
|
960
|
+
* ```
|
|
961
|
+
*
|
|
962
|
+
* @example Complex dry run result
|
|
963
|
+
* ```typescript
|
|
964
|
+
* const options: ShellExecOptions = {
|
|
965
|
+
* dryRun: true,
|
|
966
|
+
* dryRunResult: {
|
|
967
|
+
* status: 'success',
|
|
968
|
+
* output: 'Files would be copied',
|
|
969
|
+
* files: ['file1.txt', 'file2.txt']
|
|
970
|
+
* }
|
|
971
|
+
* };
|
|
972
|
+
* ```
|
|
389
973
|
*/
|
|
390
|
-
|
|
974
|
+
dryRunResult?: unknown;
|
|
391
975
|
/**
|
|
392
|
-
*
|
|
976
|
+
* Whether to perform a dry run without actual execution
|
|
977
|
+
*
|
|
978
|
+
* Core concept:
|
|
979
|
+
* Controls whether the command should be executed or
|
|
980
|
+
* simulated, providing a safe way to test command
|
|
981
|
+
* generation and validation without side effects.
|
|
982
|
+
*
|
|
983
|
+
* Dry run mode:
|
|
984
|
+
* - Commands are logged but not executed
|
|
985
|
+
* - Returns predefined result for testing
|
|
986
|
+
* - Useful for command validation and debugging
|
|
987
|
+
* - Maintains logging for debugging purposes
|
|
988
|
+
* - Supports both global and per-command dry run
|
|
989
|
+
*
|
|
990
|
+
* Override behavior:
|
|
991
|
+
* - Overrides shell config.isDryRun if set
|
|
992
|
+
* - Per-command setting takes precedence
|
|
993
|
+
* - Global setting provides default behavior
|
|
994
|
+
* - Allows fine-grained control over execution
|
|
995
|
+
* - Maintains consistency across command types
|
|
996
|
+
*
|
|
997
|
+
* Use cases:
|
|
998
|
+
* - Testing command generation and formatting
|
|
999
|
+
* - Validating configuration and options
|
|
1000
|
+
* - Debugging script logic without side effects
|
|
1001
|
+
* - Safe exploration of script behavior
|
|
1002
|
+
* - CI/CD pipeline validation
|
|
1003
|
+
*
|
|
1004
|
+
* @optional
|
|
1005
|
+
* @example Basic dry run
|
|
1006
|
+
* ```typescript
|
|
1007
|
+
* const options: ShellExecOptions = { dryRun: true };
|
|
1008
|
+
* // Command is logged but not executed
|
|
1009
|
+
* ```
|
|
1010
|
+
*
|
|
1011
|
+
* @example Conditional dry run
|
|
1012
|
+
* ```typescript
|
|
1013
|
+
* const options: ShellExecOptions = {
|
|
1014
|
+
* dryRun: process.env.DRY_RUN === 'true'
|
|
1015
|
+
* };
|
|
1016
|
+
* ```
|
|
393
1017
|
*/
|
|
394
|
-
|
|
1018
|
+
dryRun?: boolean;
|
|
395
1019
|
/**
|
|
396
|
-
*
|
|
397
|
-
*
|
|
398
|
-
*
|
|
399
|
-
*
|
|
1020
|
+
* Template context for command string interpolation
|
|
1021
|
+
*
|
|
1022
|
+
* Core concept:
|
|
1023
|
+
* Provides variables and data for template string
|
|
1024
|
+
* interpolation, enabling dynamic command generation
|
|
1025
|
+
* based on runtime context and configuration.
|
|
1026
|
+
*
|
|
1027
|
+
* Template features:
|
|
1028
|
+
* - Uses lodash template for powerful interpolation
|
|
1029
|
+
* - Supports complex template expressions and logic
|
|
1030
|
+
* - Handles undefined and null context values gracefully
|
|
1031
|
+
* - Enables dynamic command construction
|
|
1032
|
+
* - Supports nested object access and function calls
|
|
1033
|
+
*
|
|
1034
|
+
* Context usage:
|
|
1035
|
+
* - Variable substitution in command strings
|
|
1036
|
+
* - Conditional command generation
|
|
1037
|
+
* - Dynamic path and parameter construction
|
|
1038
|
+
* - Environment-specific command customization
|
|
1039
|
+
* - Runtime configuration injection
|
|
1040
|
+
*
|
|
1041
|
+
* Template syntax:
|
|
1042
|
+
* - `<%= variable %>` for escaped output
|
|
1043
|
+
* - `<%- variable %>` for unescaped output
|
|
1044
|
+
* - `<% code %>` for JavaScript code execution
|
|
1045
|
+
* - Supports nested object access and function calls
|
|
1046
|
+
*
|
|
1047
|
+
* @optional
|
|
1048
|
+
* @example Basic template context
|
|
1049
|
+
* ```typescript
|
|
1050
|
+
* const options: ShellExecOptions = {
|
|
1051
|
+
* context: { repo: 'https://github.com/user/repo.git' }
|
|
1052
|
+
* };
|
|
1053
|
+
* // Used with: 'git clone <%= repo %>'
|
|
1054
|
+
* ```
|
|
1055
|
+
*
|
|
1056
|
+
* @example Complex template context
|
|
1057
|
+
* ```typescript
|
|
1058
|
+
* const options: ShellExecOptions = {
|
|
1059
|
+
* context: {
|
|
1060
|
+
* branch: 'main',
|
|
1061
|
+
* repo: { url: 'https://github.com/user/repo.git' },
|
|
1062
|
+
* flags: ['--depth=1', '--single-branch']
|
|
1063
|
+
* }
|
|
1064
|
+
* };
|
|
1065
|
+
* ```
|
|
400
1066
|
*/
|
|
401
|
-
|
|
1067
|
+
context?: Record<string, unknown>;
|
|
402
1068
|
/**
|
|
403
|
-
*
|
|
404
|
-
*
|
|
405
|
-
*
|
|
406
|
-
*
|
|
407
|
-
*
|
|
1069
|
+
* Encoding for command output processing
|
|
1070
|
+
*
|
|
1071
|
+
* Core concept:
|
|
1072
|
+
* Specifies the character encoding used for command
|
|
1073
|
+
* output processing, ensuring proper handling of
|
|
1074
|
+
* international characters and special symbols.
|
|
1075
|
+
*
|
|
1076
|
+
* Encoding behavior:
|
|
1077
|
+
* - Affects how command output is interpreted
|
|
1078
|
+
* - Ensures proper character encoding for output
|
|
1079
|
+
* - Supports various encoding formats
|
|
1080
|
+
* - Handles international character sets
|
|
1081
|
+
* - Maintains consistency across platforms
|
|
1082
|
+
*
|
|
1083
|
+
* Common encodings:
|
|
1084
|
+
* - 'utf8': Unicode UTF-8 encoding (default)
|
|
1085
|
+
* - 'ascii': ASCII encoding for basic text
|
|
1086
|
+
* - 'base64': Base64 encoding for binary data
|
|
1087
|
+
* - 'hex': Hexadecimal encoding for binary data
|
|
1088
|
+
* - 'latin1': Latin-1 encoding for legacy systems
|
|
1089
|
+
*
|
|
1090
|
+
* Use cases:
|
|
1091
|
+
* - International character handling
|
|
1092
|
+
* - Binary data processing
|
|
1093
|
+
* - Legacy system integration
|
|
1094
|
+
* - Cross-platform compatibility
|
|
1095
|
+
* - Special character processing
|
|
1096
|
+
*
|
|
1097
|
+
* @optional
|
|
1098
|
+
* @example UTF-8 encoding
|
|
1099
|
+
* ```typescript
|
|
1100
|
+
* const options: ShellExecOptions = { encoding: 'utf8' };
|
|
1101
|
+
* ```
|
|
1102
|
+
*
|
|
1103
|
+
* @example Base64 encoding
|
|
1104
|
+
* ```typescript
|
|
1105
|
+
* const options: ShellExecOptions = { encoding: 'base64' };
|
|
1106
|
+
* ```
|
|
408
1107
|
*/
|
|
409
|
-
|
|
1108
|
+
encoding?: BufferEncoding;
|
|
410
1109
|
/**
|
|
411
|
-
*
|
|
412
|
-
*
|
|
413
|
-
*
|
|
414
|
-
*
|
|
1110
|
+
* Whether to cache the command result for performance optimization
|
|
1111
|
+
*
|
|
1112
|
+
* Core concept:
|
|
1113
|
+
* Controls whether the command result should be cached
|
|
1114
|
+
* to avoid repeated execution of identical commands,
|
|
1115
|
+
* providing performance optimization for repeated operations.
|
|
1116
|
+
*
|
|
1117
|
+
* Caching behavior:
|
|
1118
|
+
* - Caches command results for repeated access
|
|
1119
|
+
* - Uses command string as cache key
|
|
1120
|
+
* - Respects per-command and global cache settings
|
|
1121
|
+
* - Provides performance optimization for repeated commands
|
|
1122
|
+
* - Handles cache misses gracefully
|
|
1123
|
+
*
|
|
1124
|
+
* Performance benefits:
|
|
1125
|
+
* - Reduces file system I/O operations
|
|
1126
|
+
* - Avoids repeated command execution
|
|
1127
|
+
* - Particularly beneficial in build tools and CLI applications
|
|
1128
|
+
* - Improves script execution performance
|
|
1129
|
+
* - Reduces resource consumption
|
|
1130
|
+
*
|
|
1131
|
+
* Cache management:
|
|
1132
|
+
* - Cache is shared across command executions
|
|
1133
|
+
* - Supports concurrent command execution
|
|
1134
|
+
* - Automatic memory management
|
|
1135
|
+
* - Cache invalidation through command options
|
|
1136
|
+
* - Simple cache implementation for reliability
|
|
1137
|
+
*
|
|
1138
|
+
* @optional
|
|
1139
|
+
* @default `false`
|
|
1140
|
+
* @example Basic caching
|
|
1141
|
+
* ```typescript
|
|
1142
|
+
* const options: ShellExecOptions = { isCache: true };
|
|
1143
|
+
* // Command result will be cached for future use
|
|
1144
|
+
* ```
|
|
1145
|
+
*
|
|
1146
|
+
* @example Conditional caching
|
|
1147
|
+
* ```typescript
|
|
1148
|
+
* const options: ShellExecOptions = {
|
|
1149
|
+
* isCache: command.includes('npm install')
|
|
1150
|
+
* };
|
|
1151
|
+
* // Only cache npm install commands
|
|
1152
|
+
* ```
|
|
415
1153
|
*/
|
|
416
|
-
|
|
1154
|
+
isCache?: boolean;
|
|
417
1155
|
/**
|
|
418
|
-
*
|
|
419
|
-
*
|
|
420
|
-
*
|
|
421
|
-
*
|
|
422
|
-
*
|
|
1156
|
+
* Additional custom options for extensibility
|
|
1157
|
+
*
|
|
1158
|
+
* Core concept:
|
|
1159
|
+
* Provides extensibility for custom options and
|
|
1160
|
+
* implementation-specific configurations that
|
|
1161
|
+
* may not be covered by the standard interface.
|
|
1162
|
+
*
|
|
1163
|
+
* Extensibility features:
|
|
1164
|
+
* - Supports any additional string-keyed properties
|
|
1165
|
+
* - Maintains type safety for known properties
|
|
1166
|
+
* - Allows implementation-specific customization
|
|
1167
|
+
* - Provides backward compatibility for future extensions
|
|
1168
|
+
* - Supports custom execution strategies
|
|
1169
|
+
*
|
|
1170
|
+
* Use cases:
|
|
1171
|
+
* - Custom execution function parameters
|
|
1172
|
+
* - Implementation-specific configurations
|
|
1173
|
+
* - Third-party integration options
|
|
1174
|
+
* - Future interface extensions
|
|
1175
|
+
* - Custom validation and processing
|
|
1176
|
+
*
|
|
1177
|
+
* @optional
|
|
1178
|
+
* @example Custom options
|
|
1179
|
+
* ```typescript
|
|
1180
|
+
* const options: ShellExecOptions = {
|
|
1181
|
+
* customOption: 'value',
|
|
1182
|
+
* timeout: 5000,
|
|
1183
|
+
* retries: 3
|
|
1184
|
+
* };
|
|
1185
|
+
* ```
|
|
423
1186
|
*/
|
|
424
|
-
|
|
1187
|
+
[key: string]: unknown;
|
|
1188
|
+
}
|
|
1189
|
+
/**
|
|
1190
|
+
* Interface for shell command execution with comprehensive capabilities
|
|
1191
|
+
*
|
|
1192
|
+
* Core concept:
|
|
1193
|
+
* Defines a standardized interface for executing shell commands
|
|
1194
|
+
* with support for various command formats, execution options,
|
|
1195
|
+
* and result handling across different execution environments.
|
|
1196
|
+
*
|
|
1197
|
+
* Main features:
|
|
1198
|
+
* - Command execution: Flexible command execution with options
|
|
1199
|
+
* - Supports both string and array command formats
|
|
1200
|
+
* - Comprehensive execution options for customization
|
|
1201
|
+
* - Promise-based asynchronous execution
|
|
1202
|
+
* - Consistent error handling and reporting
|
|
1203
|
+
*
|
|
1204
|
+
* - Execution abstraction: Platform-independent command execution
|
|
1205
|
+
* - Abstracts shell execution details
|
|
1206
|
+
* - Provides consistent interface across platforms
|
|
1207
|
+
* - Supports custom execution strategies
|
|
1208
|
+
* - Maintains backward compatibility
|
|
1209
|
+
*
|
|
1210
|
+
* - Result handling: Standardized result processing
|
|
1211
|
+
* - Returns command output as string
|
|
1212
|
+
* - Handles both success and error conditions
|
|
1213
|
+
* - Provides consistent error reporting
|
|
1214
|
+
* - Supports output encoding and processing
|
|
1215
|
+
*
|
|
1216
|
+
* Design considerations:
|
|
1217
|
+
* - Simple interface for maximum compatibility
|
|
1218
|
+
* - Promise-based for modern async/await usage
|
|
1219
|
+
* - Extensible through execution options
|
|
1220
|
+
* - Platform-independent implementation
|
|
1221
|
+
* - Consistent error handling across implementations
|
|
1222
|
+
*
|
|
1223
|
+
* Implementation requirements:
|
|
1224
|
+
* - Must handle both string and array command formats
|
|
1225
|
+
* - Should support all ShellExecOptions properties
|
|
1226
|
+
* - Must return Promise<string> for command output
|
|
1227
|
+
* - Should provide meaningful error messages
|
|
1228
|
+
* - Must handle command execution failures gracefully
|
|
1229
|
+
*
|
|
1230
|
+
* @example Basic implementation
|
|
1231
|
+
* ```typescript
|
|
1232
|
+
* const shell: ShellInterface = {
|
|
1233
|
+
* exec: async (command, options) => {
|
|
1234
|
+
* // Logic to execute the command
|
|
1235
|
+
* return 'Command output';
|
|
1236
|
+
* }
|
|
1237
|
+
* };
|
|
1238
|
+
* ```
|
|
1239
|
+
*
|
|
1240
|
+
* @example With error handling
|
|
1241
|
+
* ```typescript
|
|
1242
|
+
* const shell: ShellInterface = {
|
|
1243
|
+
* exec: async (command, options) => {
|
|
1244
|
+
* try {
|
|
1245
|
+
* // Command execution logic
|
|
1246
|
+
* return await executeCommand(command, options);
|
|
1247
|
+
* } catch (error) {
|
|
1248
|
+
* throw new Error(`Command execution failed: ${error.message}`);
|
|
1249
|
+
* }
|
|
1250
|
+
* }
|
|
1251
|
+
* };
|
|
1252
|
+
* ```
|
|
1253
|
+
*
|
|
1254
|
+
* @example Usage with options
|
|
1255
|
+
* ```typescript
|
|
1256
|
+
* const output = await shell.exec('npm install', {
|
|
1257
|
+
* cwd: '/project/root',
|
|
1258
|
+
* silent: true,
|
|
1259
|
+
* env: { NODE_ENV: 'production' }
|
|
1260
|
+
* });
|
|
1261
|
+
* ```
|
|
1262
|
+
*/
|
|
1263
|
+
interface ShellInterface {
|
|
425
1264
|
/**
|
|
426
|
-
*
|
|
427
|
-
*
|
|
428
|
-
*
|
|
429
|
-
*
|
|
1265
|
+
* Execute a shell command with optional configuration
|
|
1266
|
+
*
|
|
1267
|
+
* Core concept:
|
|
1268
|
+
* Provides the main method for executing shell commands
|
|
1269
|
+
* with comprehensive options for customization, error
|
|
1270
|
+
* handling, and result processing.
|
|
1271
|
+
*
|
|
1272
|
+
* Command execution:
|
|
1273
|
+
* - Supports both string and array command formats
|
|
1274
|
+
* - Handles command parsing and validation
|
|
1275
|
+
* - Provides comprehensive execution options
|
|
1276
|
+
* - Returns Promise for asynchronous execution
|
|
1277
|
+
* - Maintains consistent error handling
|
|
1278
|
+
*
|
|
1279
|
+
* Execution options:
|
|
1280
|
+
* - Environment variable injection
|
|
1281
|
+
* - Working directory specification
|
|
1282
|
+
* - Output encoding configuration
|
|
1283
|
+
* - Silent mode for quiet execution
|
|
1284
|
+
* - Dry run mode for safe testing
|
|
1285
|
+
* - Template context for dynamic commands
|
|
1286
|
+
* - Caching for performance optimization
|
|
1287
|
+
*
|
|
1288
|
+
* Result handling:
|
|
1289
|
+
* - Returns command output as string
|
|
1290
|
+
* - Handles both success and error conditions
|
|
1291
|
+
* - Provides consistent error reporting
|
|
1292
|
+
* - Supports output encoding and processing
|
|
1293
|
+
* - Maintains command execution context
|
|
1294
|
+
*
|
|
1295
|
+
* Error handling:
|
|
1296
|
+
* - Throws errors for command execution failures
|
|
1297
|
+
* - Provides meaningful error messages
|
|
1298
|
+
* - Maintains error context and stack traces
|
|
1299
|
+
* - Handles various failure scenarios
|
|
1300
|
+
* - Supports error recovery and retry logic
|
|
1301
|
+
*
|
|
1302
|
+
* @param command - Command to execute (string or array of command parts)
|
|
1303
|
+
* @param options - Optional execution options for customization
|
|
1304
|
+
* @returns Promise resolving to command output string
|
|
1305
|
+
* @throws Error when command execution fails
|
|
1306
|
+
*
|
|
1307
|
+
* @example Basic command execution
|
|
1308
|
+
* ```typescript
|
|
1309
|
+
* const output = await shell.exec('npm install');
|
|
1310
|
+
* console.log('Installation output:', output);
|
|
1311
|
+
* ```
|
|
1312
|
+
*
|
|
1313
|
+
* @example Array command format
|
|
1314
|
+
* ```typescript
|
|
1315
|
+
* const output = await shell.exec(['git', 'commit', '-m', 'Update docs']);
|
|
1316
|
+
* ```
|
|
1317
|
+
*
|
|
1318
|
+
* @example With execution options
|
|
1319
|
+
* ```typescript
|
|
1320
|
+
* const output = await shell.exec('npm run build', {
|
|
1321
|
+
* cwd: '/project/root',
|
|
1322
|
+
* silent: true,
|
|
1323
|
+
* env: { NODE_ENV: 'production' }
|
|
1324
|
+
* });
|
|
1325
|
+
* ```
|
|
1326
|
+
*
|
|
1327
|
+
* @example Template-based command
|
|
1328
|
+
* ```typescript
|
|
1329
|
+
* const output = await shell.exec('git clone <%= repo %>', {
|
|
1330
|
+
* context: { repo: 'https://github.com/user/repo.git' }
|
|
1331
|
+
* });
|
|
1332
|
+
* ```
|
|
430
1333
|
*/
|
|
431
|
-
|
|
1334
|
+
exec(command: string | string[], options?: ShellExecOptions): Promise<string>;
|
|
432
1335
|
}
|
|
433
1336
|
|
|
434
1337
|
/**
|
|
435
|
-
*
|
|
436
|
-
* @param feConfig - Custom fe configuration
|
|
437
|
-
* @returns ConfigSearch instance
|
|
438
|
-
* @description
|
|
439
|
-
* Significance: Creates configuration search utility
|
|
440
|
-
* Core idea: Merge default and custom configurations
|
|
441
|
-
* Main function: Initialize configuration search
|
|
442
|
-
* Main purpose: Provide configuration discovery
|
|
1338
|
+
* Function type for executing shell commands
|
|
443
1339
|
*
|
|
444
|
-
*
|
|
1340
|
+
* Core concept:
|
|
1341
|
+
* Defines the signature for command execution functions that
|
|
1342
|
+
* can be injected into the Shell class for flexible command
|
|
1343
|
+
* execution strategies.
|
|
1344
|
+
*
|
|
1345
|
+
* Function signature:
|
|
1346
|
+
* - Accepts command as string or array of strings
|
|
1347
|
+
* - Accepts execution options for customization
|
|
1348
|
+
* - Returns Promise resolving to command output
|
|
1349
|
+
* - Handles command execution and error conditions
|
|
1350
|
+
*
|
|
1351
|
+
* @param command - Command string or array of command parts
|
|
1352
|
+
* @param options - Shell execution options for customization
|
|
1353
|
+
* @returns Promise resolving to command output (trimmed)
|
|
1354
|
+
*
|
|
1355
|
+
* @example Basic usage
|
|
445
1356
|
* ```typescript
|
|
446
|
-
* const
|
|
1357
|
+
* const execFn: ExecPromiseFunction = async (command, options) => {
|
|
1358
|
+
* // Custom command execution logic
|
|
1359
|
+
* return 'command output';
|
|
1360
|
+
* };
|
|
447
1361
|
* ```
|
|
448
1362
|
*/
|
|
449
|
-
|
|
450
|
-
type ScriptContextOptions<T> = T & {
|
|
451
|
-
execPromise?: ExecPromiseFunction;
|
|
452
|
-
};
|
|
1363
|
+
type ExecPromiseFunction = (command: string | string[], options: ShellExecOptions) => Promise<string>;
|
|
453
1364
|
/**
|
|
454
|
-
*
|
|
455
|
-
* @interface
|
|
456
|
-
* @description
|
|
457
|
-
* Significance: Defines script execution context options
|
|
458
|
-
* Core idea: Centralize script execution configuration
|
|
459
|
-
* Main function: Type-safe context options
|
|
460
|
-
* Main purpose: Configure script execution environment
|
|
1365
|
+
* Configuration interface for Shell class initialization
|
|
461
1366
|
*
|
|
462
|
-
*
|
|
1367
|
+
* Core concept:
|
|
1368
|
+
* Defines the configuration parameters required to initialize
|
|
1369
|
+
* a Shell instance with logging, execution, and caching capabilities.
|
|
1370
|
+
*
|
|
1371
|
+
* Configuration components:
|
|
1372
|
+
* - Logger: Required for command logging and error reporting
|
|
1373
|
+
* - Execution function: Optional custom command execution strategy
|
|
1374
|
+
* - Execution options: Inherited from ShellExecOptions for command customization
|
|
1375
|
+
*
|
|
1376
|
+
* @example Basic configuration
|
|
1377
|
+
* ```typescript
|
|
1378
|
+
* const config: ShellConfig = {
|
|
1379
|
+
* logger: myLogger,
|
|
1380
|
+
* dryRun: false,
|
|
1381
|
+
* isCache: true
|
|
1382
|
+
* };
|
|
1383
|
+
* ```
|
|
1384
|
+
*
|
|
1385
|
+
* @example With custom execution function
|
|
463
1386
|
* ```typescript
|
|
464
|
-
* const
|
|
465
|
-
* logger:
|
|
1387
|
+
* const config: ShellConfig = {
|
|
1388
|
+
* logger: myLogger,
|
|
1389
|
+
* execPromise: customExecFunction,
|
|
466
1390
|
* dryRun: true
|
|
467
1391
|
* };
|
|
468
1392
|
* ```
|
|
469
1393
|
*/
|
|
470
|
-
interface
|
|
471
|
-
/**
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
1394
|
+
interface ShellConfig extends ShellExecOptions {
|
|
1395
|
+
/**
|
|
1396
|
+
* Logger instance for command logging and error reporting
|
|
1397
|
+
*
|
|
1398
|
+
* Used for:
|
|
1399
|
+
* - Logging command execution details
|
|
1400
|
+
* - Reporting template formatting errors
|
|
1401
|
+
* - Debug information for command execution
|
|
1402
|
+
* - Error messages and stack traces
|
|
1403
|
+
*
|
|
1404
|
+
* @example `new Logger({ level: 'info', handlers: new ConsoleHandler() })`
|
|
1405
|
+
*/
|
|
1406
|
+
logger: LoggerInterface;
|
|
1407
|
+
/**
|
|
1408
|
+
* Custom command execution function
|
|
1409
|
+
*
|
|
1410
|
+
* Optional function to override the default command execution
|
|
1411
|
+
* strategy. When not provided, the Shell class will throw an
|
|
1412
|
+
* error if no execution function is available.
|
|
1413
|
+
*
|
|
1414
|
+
* Use cases:
|
|
1415
|
+
* - Custom command execution logic
|
|
1416
|
+
* - Integration with specific shell environments
|
|
1417
|
+
* - Mock functions for testing
|
|
1418
|
+
* - Enhanced error handling and reporting
|
|
1419
|
+
*
|
|
1420
|
+
* @optional
|
|
1421
|
+
* @example
|
|
1422
|
+
* ```typescript
|
|
1423
|
+
* const customExec: ExecPromiseFunction = async (command, options) => {
|
|
1424
|
+
* // Custom execution logic
|
|
1425
|
+
* return await executeCommand(command, options);
|
|
1426
|
+
* };
|
|
1427
|
+
* ```
|
|
1428
|
+
*/
|
|
1429
|
+
execPromise?: ExecPromiseFunction;
|
|
483
1430
|
}
|
|
484
1431
|
/**
|
|
485
|
-
*
|
|
486
|
-
* @class
|
|
487
|
-
* @description
|
|
488
|
-
* Significance: Manages script execution environment
|
|
489
|
-
* Core idea: Provide unified context for script execution
|
|
490
|
-
* Main function: Initialize and maintain script context
|
|
491
|
-
* Main purpose: Standardize script execution environment
|
|
1432
|
+
* Shell class for command execution with templating and caching support
|
|
492
1433
|
*
|
|
493
|
-
*
|
|
1434
|
+
* Core concept:
|
|
1435
|
+
* Provides a comprehensive command execution interface with
|
|
1436
|
+
* template string formatting, command caching, dry run support,
|
|
1437
|
+
* and integrated logging capabilities.
|
|
1438
|
+
*
|
|
1439
|
+
* Main features:
|
|
1440
|
+
* - Template formatting: Dynamic command generation with context
|
|
1441
|
+
* - Uses lodash template for string interpolation
|
|
1442
|
+
* - Supports complex template expressions
|
|
1443
|
+
* - Provides error handling for template failures
|
|
1444
|
+
* - Enables dynamic command construction
|
|
1445
|
+
*
|
|
1446
|
+
* - Command caching: Performance optimization for repeated commands
|
|
1447
|
+
* - Caches command results to avoid repeated execution
|
|
1448
|
+
* - Configurable caching per command
|
|
1449
|
+
* - Memory-efficient cache management
|
|
1450
|
+
* - Cache invalidation through command options
|
|
1451
|
+
*
|
|
1452
|
+
* - Dry run support: Safe command testing and validation
|
|
1453
|
+
* - Executes commands without actual system impact
|
|
1454
|
+
* - Returns predefined results for testing
|
|
1455
|
+
* - Useful for command validation and debugging
|
|
1456
|
+
* - Supports both global and per-command dry run
|
|
1457
|
+
*
|
|
1458
|
+
* - Integrated logging: Comprehensive command execution tracking
|
|
1459
|
+
* - Logs command execution details
|
|
1460
|
+
* - Reports template formatting errors
|
|
1461
|
+
* - Provides debug information for troubleshooting
|
|
1462
|
+
* - Supports silent mode for quiet execution
|
|
1463
|
+
*
|
|
1464
|
+
* Design considerations:
|
|
1465
|
+
* - Uses dependency injection for execution functions
|
|
1466
|
+
* - Provides flexible configuration options
|
|
1467
|
+
* - Maintains backward compatibility with existing interfaces
|
|
1468
|
+
* - Supports both string and array command formats
|
|
1469
|
+
* - Implements proper error handling and reporting
|
|
1470
|
+
*
|
|
1471
|
+
* Performance optimizations:
|
|
1472
|
+
* - Command result caching for repeated executions
|
|
1473
|
+
* - Efficient template compilation and caching
|
|
1474
|
+
* - Minimal memory footprint for cache storage
|
|
1475
|
+
* - Lazy initialization of execution functions
|
|
1476
|
+
*
|
|
1477
|
+
* @example Basic usage
|
|
494
1478
|
* ```typescript
|
|
495
|
-
* const
|
|
496
|
-
*
|
|
497
|
-
*
|
|
1479
|
+
* const shell = new Shell({
|
|
1480
|
+
* logger: myLogger,
|
|
1481
|
+
* dryRun: false
|
|
1482
|
+
* });
|
|
1483
|
+
*
|
|
1484
|
+
* const output = await shell.exec('npm install');
|
|
1485
|
+
* ```
|
|
1486
|
+
*
|
|
1487
|
+
* @example With template formatting
|
|
1488
|
+
* ```typescript
|
|
1489
|
+
* const shell = new Shell({ logger: myLogger });
|
|
1490
|
+
* const output = await shell.exec('git clone <%= repo %>', {
|
|
1491
|
+
* context: { repo: 'https://github.com/user/repo.git' }
|
|
1492
|
+
* });
|
|
1493
|
+
* ```
|
|
1494
|
+
*
|
|
1495
|
+
* @example With caching
|
|
1496
|
+
* ```typescript
|
|
1497
|
+
* const shell = new Shell({ logger: myLogger, isCache: true });
|
|
1498
|
+
* // First execution
|
|
1499
|
+
* await shell.exec('npm install');
|
|
1500
|
+
* // Second execution uses cached result
|
|
1501
|
+
* await shell.exec('npm install');
|
|
1502
|
+
* ```
|
|
1503
|
+
*
|
|
1504
|
+
* @example Dry run mode
|
|
1505
|
+
* ```typescript
|
|
1506
|
+
* const shell = new Shell({ logger: myLogger, dryRun: true });
|
|
1507
|
+
* const output = await shell.exec('rm -rf /', {
|
|
1508
|
+
* dryRunResult: 'Would delete all files'
|
|
498
1509
|
* });
|
|
1510
|
+
* // Returns 'Would delete all files' without executing command
|
|
499
1511
|
* ```
|
|
500
1512
|
*/
|
|
501
|
-
declare class
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
/** Shell instance */
|
|
505
|
-
readonly shell: Shell;
|
|
506
|
-
/** Fe configuration */
|
|
507
|
-
readonly feConfig: FeConfig;
|
|
508
|
-
/** Dry run flag */
|
|
509
|
-
readonly dryRun: boolean;
|
|
510
|
-
/** Verbose logging flag */
|
|
511
|
-
readonly verbose: boolean;
|
|
512
|
-
/** Script-specific options */
|
|
513
|
-
options: ScriptContextOptions<T>;
|
|
1513
|
+
declare class Shell implements ShellInterface {
|
|
1514
|
+
config: ShellConfig;
|
|
1515
|
+
private cache;
|
|
514
1516
|
/**
|
|
515
|
-
* Creates a
|
|
1517
|
+
* Creates a new Shell instance with the specified configuration
|
|
516
1518
|
*
|
|
517
|
-
*
|
|
518
|
-
*
|
|
519
|
-
*
|
|
520
|
-
* Main function: Create context with options
|
|
521
|
-
* Main purpose: Prepare script execution environment
|
|
1519
|
+
* Core concept:
|
|
1520
|
+
* Initializes a Shell instance with logging, execution, and
|
|
1521
|
+
* caching capabilities based on the provided configuration.
|
|
522
1522
|
*
|
|
523
|
-
*
|
|
1523
|
+
* Initialization process:
|
|
1524
|
+
* 1. Validates and stores configuration parameters
|
|
1525
|
+
* 2. Initializes command cache for performance optimization
|
|
1526
|
+
* 3. Sets up logging integration for command tracking
|
|
1527
|
+
* 4. Prepares template formatting capabilities
|
|
1528
|
+
*
|
|
1529
|
+
* Configuration validation:
|
|
1530
|
+
* - Logger is required for command logging and error reporting
|
|
1531
|
+
* - Execution function is optional but required for actual command execution
|
|
1532
|
+
* - Cache is initialized as an empty Map for command result storage
|
|
1533
|
+
* - All ShellExecOptions are inherited and validated
|
|
1534
|
+
*
|
|
1535
|
+
* Cache initialization:
|
|
1536
|
+
* - Uses Map for efficient key-value storage
|
|
1537
|
+
* - Stores Promise<string> for command results
|
|
1538
|
+
* - Supports concurrent command execution
|
|
1539
|
+
* - Provides automatic memory management
|
|
1540
|
+
*
|
|
1541
|
+
* @param config - Shell configuration with logger and execution options
|
|
1542
|
+
* @param cache - Optional command cache map for result storage
|
|
1543
|
+
*
|
|
1544
|
+
* @example Basic initialization
|
|
524
1545
|
* ```typescript
|
|
525
|
-
* const
|
|
1546
|
+
* const shell = new Shell({
|
|
1547
|
+
* logger: myLogger,
|
|
1548
|
+
* dryRun: false,
|
|
1549
|
+
* isCache: true
|
|
1550
|
+
* });
|
|
1551
|
+
* ```
|
|
1552
|
+
*
|
|
1553
|
+
* @example With custom cache
|
|
1554
|
+
* ```typescript
|
|
1555
|
+
* const customCache = new Map<string, Promise<string>>();
|
|
1556
|
+
* const shell = new Shell({ logger: myLogger }, customCache);
|
|
1557
|
+
* ```
|
|
1558
|
+
*/
|
|
1559
|
+
constructor(config: ShellConfig, cache?: Map<string, Promise<string>>);
|
|
1560
|
+
/**
|
|
1561
|
+
* Gets the logger instance for command logging and error reporting
|
|
1562
|
+
*
|
|
1563
|
+
* Core concept:
|
|
1564
|
+
* Provides access to the configured logger instance for
|
|
1565
|
+
* command execution tracking and error reporting.
|
|
1566
|
+
*
|
|
1567
|
+
* Logger usage:
|
|
1568
|
+
* - Command execution logging (debug level)
|
|
1569
|
+
* - Template formatting error reporting
|
|
1570
|
+
* - Command execution error logging
|
|
1571
|
+
* - Debug information for troubleshooting
|
|
1572
|
+
*
|
|
1573
|
+
* @returns Logger instance for command logging and error reporting
|
|
1574
|
+
*
|
|
1575
|
+
* @example Basic usage
|
|
1576
|
+
* ```typescript
|
|
1577
|
+
* const logger = shell.logger;
|
|
1578
|
+
* logger.info('Shell instance created');
|
|
1579
|
+
* ```
|
|
1580
|
+
*/
|
|
1581
|
+
get logger(): LoggerInterface;
|
|
1582
|
+
/**
|
|
1583
|
+
* Formats a template string with context using lodash template
|
|
1584
|
+
*
|
|
1585
|
+
* Core concept:
|
|
1586
|
+
* Provides static template formatting functionality using
|
|
1587
|
+
* lodash template for string interpolation with context data.
|
|
1588
|
+
*
|
|
1589
|
+
* Template features:
|
|
1590
|
+
* - Uses lodash template for powerful string interpolation
|
|
1591
|
+
* - Supports complex template expressions and logic
|
|
1592
|
+
* - Handles undefined and null context values gracefully
|
|
1593
|
+
* - Returns formatted string with context values substituted
|
|
1594
|
+
*
|
|
1595
|
+
* Template syntax:
|
|
1596
|
+
* - `<%= variable %>` for escaped output
|
|
1597
|
+
* - `<%- variable %>` for unescaped output
|
|
1598
|
+
* - `<% code %>` for JavaScript code execution
|
|
1599
|
+
* - Supports nested object access and function calls
|
|
1600
|
+
*
|
|
1601
|
+
* Context handling:
|
|
1602
|
+
* - Accepts any object with string/number/boolean values
|
|
1603
|
+
* - Handles undefined and null values safely
|
|
1604
|
+
* - Supports nested object property access
|
|
1605
|
+
* - Provides fallback for missing context values
|
|
1606
|
+
*
|
|
1607
|
+
* @param template - Template string with interpolation placeholders
|
|
1608
|
+
* @param context - Context object for template variable substitution
|
|
1609
|
+
* @returns Formatted string with context values substituted
|
|
1610
|
+
*
|
|
1611
|
+
* @example Basic template formatting
|
|
1612
|
+
* ```typescript
|
|
1613
|
+
* const result = Shell.format('Hello <%= name %>!', { name: 'World' });
|
|
1614
|
+
* // Returns: 'Hello World!'
|
|
1615
|
+
* ```
|
|
1616
|
+
*
|
|
1617
|
+
* @example Complex template with nested objects
|
|
1618
|
+
* ```typescript
|
|
1619
|
+
* const result = Shell.format(
|
|
1620
|
+
* 'git clone <%= repo.url %> <%= repo.branch %>',
|
|
1621
|
+
* { repo: { url: 'https://github.com/user/repo.git', branch: 'main' } }
|
|
1622
|
+
* );
|
|
1623
|
+
* // Returns: 'git clone https://github.com/user/repo.git main'
|
|
1624
|
+
* ```
|
|
1625
|
+
*
|
|
1626
|
+
* @example Template with conditional logic
|
|
1627
|
+
* ```typescript
|
|
1628
|
+
* const result = Shell.format(
|
|
1629
|
+
* 'npm install<% if (dev) { %> --save-dev<% } %>',
|
|
1630
|
+
* { dev: true }
|
|
1631
|
+
* );
|
|
1632
|
+
* // Returns: 'npm install --save-dev'
|
|
1633
|
+
* ```
|
|
1634
|
+
*/
|
|
1635
|
+
static format(template?: string, context?: Record<string, unknown>): string;
|
|
1636
|
+
/**
|
|
1637
|
+
* Formats a template string with context and comprehensive error handling
|
|
1638
|
+
*
|
|
1639
|
+
* Core concept:
|
|
1640
|
+
* Provides instance-based template formatting with detailed
|
|
1641
|
+
* error logging and exception handling for debugging and
|
|
1642
|
+
* troubleshooting template issues.
|
|
1643
|
+
*
|
|
1644
|
+
* Error handling:
|
|
1645
|
+
* - Catches template compilation errors
|
|
1646
|
+
* - Logs detailed error information including template and context
|
|
1647
|
+
* - Provides stack trace information for debugging
|
|
1648
|
+
* - Re-throws errors for proper error propagation
|
|
1649
|
+
*
|
|
1650
|
+
* Logging features:
|
|
1651
|
+
* - Logs template content for debugging
|
|
1652
|
+
* - Logs context object for variable inspection
|
|
1653
|
+
* - Logs error details and stack traces
|
|
1654
|
+
* - Uses error level for template failures
|
|
1655
|
+
*
|
|
1656
|
+
* Debugging support:
|
|
1657
|
+
* - Provides template content in error messages
|
|
1658
|
+
* - Includes context object for variable inspection
|
|
1659
|
+
* - Logs complete error information for troubleshooting
|
|
1660
|
+
* - Maintains error stack traces for debugging
|
|
1661
|
+
*
|
|
1662
|
+
* @param template - Template string with interpolation placeholders
|
|
1663
|
+
* @param context - Context object for template variable substitution
|
|
1664
|
+
* @returns Formatted string with context values substituted
|
|
1665
|
+
* @throws Error if template formatting fails with detailed logging
|
|
1666
|
+
*
|
|
1667
|
+
* @example Basic formatting
|
|
1668
|
+
* ```typescript
|
|
1669
|
+
* const result = shell.format('Hello <%= name %>!', { name: 'World' });
|
|
1670
|
+
* // Returns: 'Hello World!'
|
|
1671
|
+
* ```
|
|
1672
|
+
*
|
|
1673
|
+
* @example Error handling
|
|
1674
|
+
* ```typescript
|
|
1675
|
+
* try {
|
|
1676
|
+
* const result = shell.format('Hello <%= name %>!', {});
|
|
1677
|
+
* } catch (error) {
|
|
1678
|
+
* // Error is logged with template and context information
|
|
1679
|
+
* console.error('Template formatting failed:', error.message);
|
|
1680
|
+
* }
|
|
1681
|
+
* ```
|
|
1682
|
+
*/
|
|
1683
|
+
format(template?: string, context?: Record<string, unknown>): string;
|
|
1684
|
+
/**
|
|
1685
|
+
* Executes a command with template formatting and execution options
|
|
1686
|
+
*
|
|
1687
|
+
* Core concept:
|
|
1688
|
+
* Provides the main command execution interface with template
|
|
1689
|
+
* formatting support, allowing dynamic command generation
|
|
1690
|
+
* based on context variables.
|
|
1691
|
+
*
|
|
1692
|
+
* Execution process:
|
|
1693
|
+
* 1. Extracts context from options for template formatting
|
|
1694
|
+
* 2. Formats command string with context if command is a string
|
|
1695
|
+
* 3. Passes formatted command to execution engine
|
|
1696
|
+
* 4. Handles both string and array command formats
|
|
1697
|
+
* 5. Applies execution options for customization
|
|
1698
|
+
*
|
|
1699
|
+
* Template formatting:
|
|
1700
|
+
* - Only applies to string commands (not arrays)
|
|
1701
|
+
* - Uses context object for variable substitution
|
|
1702
|
+
* - Handles template formatting errors gracefully
|
|
1703
|
+
* - Supports complex template expressions
|
|
1704
|
+
*
|
|
1705
|
+
* Command handling:
|
|
1706
|
+
* - String commands: Formatted with context before execution
|
|
1707
|
+
* - Array commands: Passed directly to execution engine
|
|
1708
|
+
* - Mixed formats: Handled appropriately based on type
|
|
1709
|
+
* - Options: Applied consistently across all command types
|
|
1710
|
+
*
|
|
1711
|
+
* @param command - Command string (with template) or array of command parts
|
|
1712
|
+
* @param options - Execution options including context for template formatting
|
|
1713
|
+
* @returns Promise resolving to command output
|
|
1714
|
+
*
|
|
1715
|
+
* @example String command with template
|
|
1716
|
+
* ```typescript
|
|
1717
|
+
* const output = await shell.exec('git clone <%= repo %>', {
|
|
1718
|
+
* context: { repo: 'https://github.com/user/repo.git' }
|
|
1719
|
+
* });
|
|
1720
|
+
* ```
|
|
1721
|
+
*
|
|
1722
|
+
* @example Array command
|
|
1723
|
+
* ```typescript
|
|
1724
|
+
* const output = await shell.exec(['git', 'clone', 'https://github.com/user/repo.git']);
|
|
1725
|
+
* ```
|
|
1726
|
+
*
|
|
1727
|
+
* @example With execution options
|
|
1728
|
+
* ```typescript
|
|
1729
|
+
* const output = await shell.exec('npm install', {
|
|
1730
|
+
* cwd: '/path/to/project',
|
|
1731
|
+
* silent: true,
|
|
1732
|
+
* dryRun: false
|
|
1733
|
+
* });
|
|
1734
|
+
* ```
|
|
1735
|
+
*/
|
|
1736
|
+
exec(command: string | string[], options?: ShellExecOptions): Promise<string>;
|
|
1737
|
+
/**
|
|
1738
|
+
* Executes a command silently (deprecated)
|
|
1739
|
+
*
|
|
1740
|
+
* Core concept:
|
|
1741
|
+
* Legacy method for silent command execution, now deprecated
|
|
1742
|
+
* in favor of the more flexible `exec` method with silent option.
|
|
1743
|
+
*
|
|
1744
|
+
* Deprecation notice:
|
|
1745
|
+
* - This method is deprecated and will be removed in future versions
|
|
1746
|
+
* - Use `exec` method with `silent: true` option instead
|
|
1747
|
+
* - Provides backward compatibility for existing code
|
|
1748
|
+
* - Maintains same functionality through `exec` method
|
|
1749
|
+
*
|
|
1750
|
+
* Silent execution:
|
|
1751
|
+
* - Suppresses command logging output
|
|
1752
|
+
* - Maintains error logging for debugging
|
|
1753
|
+
* - Useful for quiet command execution
|
|
1754
|
+
* - Reduces log noise in automated scripts
|
|
1755
|
+
*
|
|
1756
|
+
* @param command - Command string or array
|
|
1757
|
+
* @param options - Execution options (silent mode is automatically enabled)
|
|
1758
|
+
* @returns Promise resolving to command output
|
|
1759
|
+
* @deprecated Use `exec` method with `silent: true` option instead
|
|
1760
|
+
*
|
|
1761
|
+
* @example Deprecated usage
|
|
1762
|
+
* ```typescript
|
|
1763
|
+
* const output = await shell.run('npm install');
|
|
1764
|
+
* ```
|
|
1765
|
+
*
|
|
1766
|
+
* @example Recommended replacement
|
|
1767
|
+
* ```typescript
|
|
1768
|
+
* const output = await shell.exec('npm install', { silent: true });
|
|
1769
|
+
* ```
|
|
1770
|
+
*/
|
|
1771
|
+
run(command: string | string[], options?: ShellExecOptions): Promise<string>;
|
|
1772
|
+
/**
|
|
1773
|
+
* Executes a formatted command with caching and dry run support
|
|
1774
|
+
*
|
|
1775
|
+
* Core concept:
|
|
1776
|
+
* Core execution engine that handles command execution with
|
|
1777
|
+
* caching, dry run support, and comprehensive logging.
|
|
1778
|
+
*
|
|
1779
|
+
* Execution flow:
|
|
1780
|
+
* 1. Validates execution function availability
|
|
1781
|
+
* 2. Determines dry run and caching settings
|
|
1782
|
+
* 3. Logs command for debugging (unless silent)
|
|
1783
|
+
* 4. Returns dry run result or cached result if available
|
|
1784
|
+
* 5. Executes command and caches result if caching enabled
|
|
1785
|
+
* 6. Returns command execution result
|
|
1786
|
+
*
|
|
1787
|
+
* Caching behavior:
|
|
1788
|
+
* - Uses command string as cache key
|
|
1789
|
+
* - Caches Promise<string> for concurrent access
|
|
1790
|
+
* - Respects per-command and global cache settings
|
|
1791
|
+
* - Provides performance optimization for repeated commands
|
|
1792
|
+
* - Handles cache misses gracefully
|
|
1793
|
+
*
|
|
1794
|
+
* Dry run support:
|
|
1795
|
+
* - Returns predefined result without execution
|
|
1796
|
+
* - Supports both global and per-command dry run
|
|
1797
|
+
* - Useful for command validation and testing
|
|
1798
|
+
* - Maintains logging for debugging
|
|
1799
|
+
*
|
|
1800
|
+
* Error handling:
|
|
1801
|
+
* - Validates execution function availability
|
|
1802
|
+
* - Handles cache access errors gracefully
|
|
1803
|
+
* - Propagates execution errors to caller
|
|
1804
|
+
* - Provides detailed logging for debugging
|
|
1805
|
+
*
|
|
1806
|
+
* @param command - Formatted command string or array
|
|
1807
|
+
* @param options - Execution options for customization
|
|
1808
|
+
* @returns Promise resolving to command output
|
|
1809
|
+
* @throws Error if execution function is not available
|
|
1810
|
+
*
|
|
1811
|
+
* @example Basic execution
|
|
1812
|
+
* ```typescript
|
|
1813
|
+
* const output = await shell.execFormattedCommand('npm install');
|
|
1814
|
+
* ```
|
|
1815
|
+
*
|
|
1816
|
+
* @example With caching
|
|
1817
|
+
* ```typescript
|
|
1818
|
+
* const output1 = await shell.execFormattedCommand('npm install', { isCache: true });
|
|
1819
|
+
* const output2 = await shell.execFormattedCommand('npm install', { isCache: true });
|
|
1820
|
+
* // Second call uses cached result
|
|
1821
|
+
* ```
|
|
1822
|
+
*
|
|
1823
|
+
* @example Dry run mode
|
|
1824
|
+
* ```typescript
|
|
1825
|
+
* const output = await shell.execFormattedCommand('rm -rf /', {
|
|
526
1826
|
* dryRun: true,
|
|
527
|
-
*
|
|
1827
|
+
* dryRunResult: 'Would delete all files'
|
|
1828
|
+
* });
|
|
1829
|
+
* // Returns 'Would delete all files' without execution
|
|
1830
|
+
* ```
|
|
1831
|
+
*/
|
|
1832
|
+
execFormattedCommand(command: string | string[], options?: ShellExecOptions): Promise<string>;
|
|
1833
|
+
}
|
|
1834
|
+
|
|
1835
|
+
/**
|
|
1836
|
+
* Core interface for script execution context with integrated capabilities
|
|
1837
|
+
*
|
|
1838
|
+
* Core concept:
|
|
1839
|
+
* Defines the complete interface for script execution contexts that
|
|
1840
|
+
* provide integrated logging, shell execution, configuration management,
|
|
1841
|
+
* and script-specific options in a unified environment.
|
|
1842
|
+
*
|
|
1843
|
+
* Main components:
|
|
1844
|
+
* - Logger: Structured logging with timestamp formatting and verbosity control
|
|
1845
|
+
* - Shell: Command execution with templating, caching, and dry run support
|
|
1846
|
+
* - Configuration: Merged fe-config with script-specific overrides
|
|
1847
|
+
* - Execution control: Dry run and verbose mode flags
|
|
1848
|
+
* - Script options: Type-safe script-specific configuration with execution function
|
|
1849
|
+
*
|
|
1850
|
+
* Design considerations:
|
|
1851
|
+
* - Uses generic type constraints for type-safe script options
|
|
1852
|
+
* - Provides readonly properties for immutable context components
|
|
1853
|
+
* - Integrates execution function into script options for flexibility
|
|
1854
|
+
* - Maintains backward compatibility with existing implementations
|
|
1855
|
+
* - Supports both development and production environments
|
|
1856
|
+
*
|
|
1857
|
+
* Type safety:
|
|
1858
|
+
* - Generic type parameter ensures script-specific option types
|
|
1859
|
+
* - Readonly properties prevent accidental modification
|
|
1860
|
+
* - Optional execution function for custom command execution
|
|
1861
|
+
* - Extends ScriptSharedInterface for common functionality
|
|
1862
|
+
*
|
|
1863
|
+
* @example Basic usage
|
|
1864
|
+
* ```typescript
|
|
1865
|
+
* interface BuildOptions extends ScriptSharedInterface {
|
|
1866
|
+
* target: 'development' | 'production';
|
|
1867
|
+
* outputDir: string;
|
|
1868
|
+
* }
|
|
1869
|
+
*
|
|
1870
|
+
* const context: ScriptContextInterface<BuildOptions> = {
|
|
1871
|
+
* logger: myLogger,
|
|
1872
|
+
* shell: myShell,
|
|
1873
|
+
* feConfig: mergedConfig,
|
|
1874
|
+
* dryRun: false,
|
|
1875
|
+
* verbose: true,
|
|
1876
|
+
* options: {
|
|
1877
|
+
* target: 'production',
|
|
1878
|
+
* outputDir: './dist',
|
|
1879
|
+
* env: environment
|
|
1880
|
+
* }
|
|
1881
|
+
* };
|
|
1882
|
+
* ```
|
|
1883
|
+
*
|
|
1884
|
+
* @example With custom execution function
|
|
1885
|
+
* ```typescript
|
|
1886
|
+
* const context: ScriptContextInterface<DeployOptions> = {
|
|
1887
|
+
* // ... other properties
|
|
1888
|
+
* options: {
|
|
1889
|
+
* region: 'us-east-1',
|
|
1890
|
+
* execPromise: customExecFunction
|
|
1891
|
+
* }
|
|
1892
|
+
* };
|
|
1893
|
+
* ```
|
|
1894
|
+
*/
|
|
1895
|
+
interface ScriptContextInterface<Opt extends ScriptSharedInterface> {
|
|
1896
|
+
/**
|
|
1897
|
+
* Logger instance for structured logging and error reporting
|
|
1898
|
+
*
|
|
1899
|
+
* Core concept:
|
|
1900
|
+
* Provides access to the configured logger instance for
|
|
1901
|
+
* command execution tracking, error reporting, and debug
|
|
1902
|
+
* information throughout the script execution lifecycle.
|
|
1903
|
+
*
|
|
1904
|
+
* Logger capabilities:
|
|
1905
|
+
* - Timestamp-formatted logging with timezone support
|
|
1906
|
+
* - Configurable verbosity levels (debug/info/warn/error)
|
|
1907
|
+
* - Script name identification for multi-script environments
|
|
1908
|
+
* - Console output with structured formatting
|
|
1909
|
+
* - Error logging with stack traces
|
|
1910
|
+
*
|
|
1911
|
+
* Usage patterns:
|
|
1912
|
+
* - Command execution logging (debug level)
|
|
1913
|
+
* - Configuration loading and validation
|
|
1914
|
+
* - Error reporting and debugging
|
|
1915
|
+
* - Progress tracking and status updates
|
|
1916
|
+
*
|
|
1917
|
+
* @readonly
|
|
1918
|
+
* @example
|
|
1919
|
+
* ```typescript
|
|
1920
|
+
* context.logger.info('Starting build process');
|
|
1921
|
+
* context.logger.debug('Configuration loaded:', context.feConfig);
|
|
1922
|
+
* context.logger.error('Build failed:', error);
|
|
1923
|
+
* ```
|
|
1924
|
+
*/
|
|
1925
|
+
readonly logger: LoggerInterface;
|
|
1926
|
+
/**
|
|
1927
|
+
* Shell interface for command execution and management
|
|
1928
|
+
*
|
|
1929
|
+
* Core concept:
|
|
1930
|
+
* Provides command execution capabilities with template
|
|
1931
|
+
* formatting, caching, dry run support, and integrated
|
|
1932
|
+
* logging for comprehensive command management.
|
|
1933
|
+
*
|
|
1934
|
+
* Shell features:
|
|
1935
|
+
* - Template string formatting with context variables
|
|
1936
|
+
* - Command result caching for performance optimization
|
|
1937
|
+
* - Dry run mode for safe command testing
|
|
1938
|
+
* - Silent mode for quiet execution
|
|
1939
|
+
* - Integrated logging for command tracking
|
|
1940
|
+
*
|
|
1941
|
+
* Execution capabilities:
|
|
1942
|
+
* - String and array command formats
|
|
1943
|
+
* - Environment variable injection
|
|
1944
|
+
* - Working directory control
|
|
1945
|
+
* - Custom execution function support
|
|
1946
|
+
* - Error handling and reporting
|
|
1947
|
+
*
|
|
1948
|
+
* @readonly
|
|
1949
|
+
* @example
|
|
1950
|
+
* ```typescript
|
|
1951
|
+
* await context.shell.exec('npm install', { cwd: context.options.rootPath });
|
|
1952
|
+
* await context.shell.exec('git clone <%= repo %>', {
|
|
1953
|
+
* context: { repo: 'https://github.com/user/repo.git' }
|
|
528
1954
|
* });
|
|
529
1955
|
* ```
|
|
530
1956
|
*/
|
|
531
|
-
|
|
1957
|
+
readonly shell: ShellInterface;
|
|
1958
|
+
/**
|
|
1959
|
+
* Merged fe-configuration object with script-specific overrides
|
|
1960
|
+
*
|
|
1961
|
+
* Core concept:
|
|
1962
|
+
* Contains the complete configuration after merging default
|
|
1963
|
+
* fe-config with script-specific overrides, providing a
|
|
1964
|
+
* unified configuration interface.
|
|
1965
|
+
*
|
|
1966
|
+
* Configuration structure:
|
|
1967
|
+
* - Default fe-config provides base values
|
|
1968
|
+
* - Script-specific sections override defaults
|
|
1969
|
+
* - Environment-specific configurations
|
|
1970
|
+
* - Nested object merging with lodash defaultsDeep
|
|
1971
|
+
* - Type-safe configuration access
|
|
1972
|
+
*
|
|
1973
|
+
* Configuration sources:
|
|
1974
|
+
* - Default fe-config files (fe-config.json, etc.)
|
|
1975
|
+
* - Script-specific configuration sections
|
|
1976
|
+
* - Environment variable overrides
|
|
1977
|
+
* - Runtime configuration updates
|
|
1978
|
+
*
|
|
1979
|
+
* @readonly
|
|
1980
|
+
* @example
|
|
1981
|
+
* ```typescript
|
|
1982
|
+
* const buildConfig = context.feConfig.build;
|
|
1983
|
+
* const deployConfig = context.feConfig.deploy;
|
|
1984
|
+
* const envOrder = context.feConfig.envOrder;
|
|
1985
|
+
* ```
|
|
1986
|
+
*/
|
|
1987
|
+
readonly feConfig: FeConfig;
|
|
1988
|
+
/**
|
|
1989
|
+
* Whether to run in dry run mode for safe testing
|
|
1990
|
+
*
|
|
1991
|
+
* Core concept:
|
|
1992
|
+
* Controls whether commands are actually executed or
|
|
1993
|
+
* simulated for safe testing and validation purposes.
|
|
1994
|
+
*
|
|
1995
|
+
* Dry run behavior:
|
|
1996
|
+
* - Commands are logged but not executed
|
|
1997
|
+
* - Returns predefined results for testing
|
|
1998
|
+
* - Useful for command validation and debugging
|
|
1999
|
+
* - Maintains logging for debugging purposes
|
|
2000
|
+
* - Supports both global and per-command dry run
|
|
2001
|
+
*
|
|
2002
|
+
* Use cases:
|
|
2003
|
+
* - Testing command generation and formatting
|
|
2004
|
+
* - Validating configuration and options
|
|
2005
|
+
* - Debugging script logic without side effects
|
|
2006
|
+
* - Safe exploration of script behavior
|
|
2007
|
+
*
|
|
2008
|
+
* @readonly
|
|
2009
|
+
* @example
|
|
2010
|
+
* ```typescript
|
|
2011
|
+
* if (context.dryRun) {
|
|
2012
|
+
* context.logger.info('DRY RUN: Would execute command');
|
|
2013
|
+
* } else {
|
|
2014
|
+
* await context.shell.exec(command);
|
|
2015
|
+
* }
|
|
2016
|
+
* ```
|
|
2017
|
+
*/
|
|
2018
|
+
readonly dryRun: boolean;
|
|
2019
|
+
/**
|
|
2020
|
+
* Whether to enable verbose logging for detailed output
|
|
2021
|
+
*
|
|
2022
|
+
* Core concept:
|
|
2023
|
+
* Controls the level of detail in logging output,
|
|
2024
|
+
* enabling debug-level information for troubleshooting
|
|
2025
|
+
* and detailed execution tracking.
|
|
2026
|
+
*
|
|
2027
|
+
* Verbose mode effects:
|
|
2028
|
+
* - Enables debug-level logging output
|
|
2029
|
+
* - Provides detailed execution information
|
|
2030
|
+
* - Shows configuration loading details
|
|
2031
|
+
* - Displays command execution steps
|
|
2032
|
+
* - Includes performance and timing information
|
|
2033
|
+
*
|
|
2034
|
+
* Logging levels:
|
|
2035
|
+
* - true: Debug level (detailed information)
|
|
2036
|
+
* - false: Info level (essential information only)
|
|
2037
|
+
* - Affects both console output and log filtering
|
|
2038
|
+
* - Maintains error logging regardless of setting
|
|
2039
|
+
*
|
|
2040
|
+
* @readonly
|
|
2041
|
+
* @example
|
|
2042
|
+
* ```typescript
|
|
2043
|
+
* if (context.verbose) {
|
|
2044
|
+
* context.logger.debug('Loading configuration from:', configPath);
|
|
2045
|
+
* context.logger.debug('Environment variables:', envVars);
|
|
2046
|
+
* }
|
|
2047
|
+
* ```
|
|
2048
|
+
*/
|
|
2049
|
+
readonly verbose: boolean;
|
|
2050
|
+
/**
|
|
2051
|
+
* Script-specific options with execution function integration
|
|
2052
|
+
*
|
|
2053
|
+
* Core concept:
|
|
2054
|
+
* Contains all script configuration options with defaults
|
|
2055
|
+
* applied, environment integration, and optional custom
|
|
2056
|
+
* execution function for command handling.
|
|
2057
|
+
*
|
|
2058
|
+
* Option structure:
|
|
2059
|
+
* - Extends ScriptSharedInterface for common functionality
|
|
2060
|
+
* - Includes script-specific configuration properties
|
|
2061
|
+
* - Provides optional custom execution function
|
|
2062
|
+
* - Supports deep merging with default values
|
|
2063
|
+
* - Maintains type safety through generic constraints
|
|
2064
|
+
*
|
|
2065
|
+
* Execution function:
|
|
2066
|
+
* - Optional custom command execution strategy
|
|
2067
|
+
* - Overrides default shell execution behavior
|
|
2068
|
+
* - Useful for testing, mocking, and custom logic
|
|
2069
|
+
* - Maintains compatibility with ShellInterface
|
|
2070
|
+
*
|
|
2071
|
+
* @example Basic options
|
|
2072
|
+
* ```typescript
|
|
2073
|
+
* context.options = {
|
|
2074
|
+
* env: environment,
|
|
2075
|
+
* sourceBranch: 'develop',
|
|
2076
|
+
* rootPath: '/project/root',
|
|
2077
|
+
* target: 'production',
|
|
2078
|
+
* outputDir: './dist'
|
|
2079
|
+
* };
|
|
2080
|
+
* ```
|
|
2081
|
+
*
|
|
2082
|
+
* @example With custom execution function
|
|
2083
|
+
* ```typescript
|
|
2084
|
+
* context.options = {
|
|
2085
|
+
* // ... other options
|
|
2086
|
+
* execPromise: async (command, options) => {
|
|
2087
|
+
* // Custom execution logic
|
|
2088
|
+
* return await customExec(command, options);
|
|
2089
|
+
* }
|
|
2090
|
+
* };
|
|
2091
|
+
* ```
|
|
2092
|
+
*/
|
|
2093
|
+
options: Opt & {
|
|
2094
|
+
/**
|
|
2095
|
+
* Optional custom command execution function
|
|
2096
|
+
*
|
|
2097
|
+
* Overrides the default command execution strategy
|
|
2098
|
+
* for specialized command handling, testing, or
|
|
2099
|
+
* integration with specific execution environments.
|
|
2100
|
+
*
|
|
2101
|
+
* Use cases:
|
|
2102
|
+
* - Mock functions for testing
|
|
2103
|
+
* - Custom execution logic
|
|
2104
|
+
* - Integration with specific shell environments
|
|
2105
|
+
* - Enhanced error handling and reporting
|
|
2106
|
+
*
|
|
2107
|
+
* @optional
|
|
2108
|
+
* @example
|
|
2109
|
+
* ```typescript
|
|
2110
|
+
* execPromise: async (command, options) => {
|
|
2111
|
+
* console.log('Executing:', command);
|
|
2112
|
+
* return await executeWithCustomLogic(command, options);
|
|
2113
|
+
* }
|
|
2114
|
+
* ```
|
|
2115
|
+
*/
|
|
2116
|
+
execPromise?: ExecPromiseFunction;
|
|
2117
|
+
};
|
|
532
2118
|
}
|
|
533
2119
|
|
|
2120
|
+
/**
|
|
2121
|
+
* Color formatter for log output with customizable level-based coloring
|
|
2122
|
+
*
|
|
2123
|
+
* Core concept:
|
|
2124
|
+
* Provides visual distinction between different log levels by applying
|
|
2125
|
+
* chalk color functions to log level text, making log output more readable
|
|
2126
|
+
* and easier to scan for different types of messages.
|
|
2127
|
+
*
|
|
2128
|
+
* Main features:
|
|
2129
|
+
* - Level-based coloring: Each log level (fatal, error, warn, info, debug, trace, log)
|
|
2130
|
+
* has a distinct color scheme for quick visual identification
|
|
2131
|
+
* - Fatal: Red background with white bold text (highest visibility)
|
|
2132
|
+
* - Error: Red bold text (critical issues)
|
|
2133
|
+
* - Warn: Yellow bold text (warnings and potential issues)
|
|
2134
|
+
* - Info: Blue text (general information)
|
|
2135
|
+
* - Debug: Green text (debugging information)
|
|
2136
|
+
* - Trace: Gray text (detailed tracing)
|
|
2137
|
+
* - Log: White text (default logging)
|
|
2138
|
+
*
|
|
2139
|
+
* - Customizable colors: Supports custom color mapping through constructor
|
|
2140
|
+
* - Override default colors for specific levels
|
|
2141
|
+
* - Support both string colors and chalk function references
|
|
2142
|
+
* - Fallback to white color for unknown levels
|
|
2143
|
+
*
|
|
2144
|
+
* - Chalk integration: Leverages chalk library for cross-platform color support
|
|
2145
|
+
* - Consistent colors across different terminals and operating systems
|
|
2146
|
+
* - Support for various color formats and styles
|
|
2147
|
+
* - Automatic color detection and fallback for non-color terminals
|
|
2148
|
+
*
|
|
2149
|
+
* @example Basic usage
|
|
2150
|
+
* ```typescript
|
|
2151
|
+
* const formatter = new ColorFormatter();
|
|
2152
|
+
* const formatted = formatter.format({
|
|
2153
|
+
* level: 'error',
|
|
2154
|
+
* args: ['Database connection failed']
|
|
2155
|
+
* });
|
|
2156
|
+
* // Returns: [chalk.red.bold('ERROR'), 'Database connection failed']
|
|
2157
|
+
* ```
|
|
2158
|
+
*
|
|
2159
|
+
* @example Custom colors
|
|
2160
|
+
* ```typescript
|
|
2161
|
+
* const customFormatter = new ColorFormatter({
|
|
2162
|
+
* error: chalk.magenta.bold,
|
|
2163
|
+
* info: chalk.cyan,
|
|
2164
|
+
* custom: chalk.rainbow
|
|
2165
|
+
* });
|
|
2166
|
+
* ```
|
|
2167
|
+
*/
|
|
534
2168
|
declare class ColorFormatter implements FormatterInterface {
|
|
2169
|
+
/**
|
|
2170
|
+
* Custom color mapping for different log levels
|
|
2171
|
+
*
|
|
2172
|
+
* Overrides default color scheme for specific log levels.
|
|
2173
|
+
* Each level can be mapped to a chalk color function or string.
|
|
2174
|
+
* Unknown levels will use white color as fallback.
|
|
2175
|
+
*
|
|
2176
|
+
* @default `{
|
|
2177
|
+
* fatal: chalk.bgRed.white.bold,
|
|
2178
|
+
* error: chalk.red.bold,
|
|
2179
|
+
* warn: chalk.yellow.bold,
|
|
2180
|
+
* info: chalk.blue,
|
|
2181
|
+
* debug: chalk.green,
|
|
2182
|
+
* trace: chalk.gray,
|
|
2183
|
+
* log: chalk.white
|
|
2184
|
+
* }`
|
|
2185
|
+
*/
|
|
535
2186
|
protected levelColors: Record<string, string | ((...args: unknown[]) => string)>;
|
|
536
|
-
|
|
2187
|
+
/**
|
|
2188
|
+
* Create a new color formatter with optional custom level colors
|
|
2189
|
+
*
|
|
2190
|
+
* @param levelColors - Custom color mapping for log levels
|
|
2191
|
+
* - Keys: Log level names (fatal, error, warn, info, debug, trace, log)
|
|
2192
|
+
* - Values: Chalk color functions or string color names
|
|
2193
|
+
* - Unknown levels fallback to white color
|
|
2194
|
+
* - Supports both function references and string values
|
|
2195
|
+
*
|
|
2196
|
+
* @example Default colors
|
|
2197
|
+
* ```typescript
|
|
2198
|
+
* const formatter = new ColorFormatter();
|
|
2199
|
+
* ```
|
|
2200
|
+
*
|
|
2201
|
+
* @example Custom colors
|
|
2202
|
+
* ```typescript
|
|
2203
|
+
* const formatter = new ColorFormatter({
|
|
2204
|
+
* error: chalk.red.underline,
|
|
2205
|
+
* warn: chalk.orange.bold,
|
|
2206
|
+
* info: chalk.blue.italic
|
|
2207
|
+
* });
|
|
2208
|
+
* ```
|
|
2209
|
+
*/
|
|
2210
|
+
constructor(
|
|
2211
|
+
/**
|
|
2212
|
+
* Custom color mapping for different log levels
|
|
2213
|
+
*
|
|
2214
|
+
* Overrides default color scheme for specific log levels.
|
|
2215
|
+
* Each level can be mapped to a chalk color function or string.
|
|
2216
|
+
* Unknown levels will use white color as fallback.
|
|
2217
|
+
*
|
|
2218
|
+
* @default `{
|
|
2219
|
+
* fatal: chalk.bgRed.white.bold,
|
|
2220
|
+
* error: chalk.red.bold,
|
|
2221
|
+
* warn: chalk.yellow.bold,
|
|
2222
|
+
* info: chalk.blue,
|
|
2223
|
+
* debug: chalk.green,
|
|
2224
|
+
* trace: chalk.gray,
|
|
2225
|
+
* log: chalk.white
|
|
2226
|
+
* }`
|
|
2227
|
+
*/
|
|
2228
|
+
levelColors?: Record<string, string | ((...args: unknown[]) => string)>);
|
|
2229
|
+
/**
|
|
2230
|
+
* Format log event by applying color to the level and preserving original arguments
|
|
2231
|
+
*
|
|
2232
|
+
* Processing steps:
|
|
2233
|
+
* 1. Extract level and arguments from the log event
|
|
2234
|
+
* 2. Look up the appropriate color function for the log level
|
|
2235
|
+
* 3. Apply color function to uppercase level text
|
|
2236
|
+
* 4. Return colored level followed by original arguments
|
|
2237
|
+
*
|
|
2238
|
+
* Color application:
|
|
2239
|
+
* - Uses chalk color functions for consistent cross-platform support
|
|
2240
|
+
* - Converts level to uppercase for better visibility
|
|
2241
|
+
* - Preserves all original log arguments unchanged
|
|
2242
|
+
* - Handles both function and string color values
|
|
2243
|
+
*
|
|
2244
|
+
* @param event - Log event containing level and arguments
|
|
2245
|
+
* @returns Array with colored level text followed by original arguments
|
|
2246
|
+
*
|
|
2247
|
+
* @example Error level formatting
|
|
2248
|
+
* ```typescript
|
|
2249
|
+
* const result = formatter.format({
|
|
2250
|
+
* level: 'error',
|
|
2251
|
+
* args: ['Connection failed', { retryCount: 3 }]
|
|
2252
|
+
* });
|
|
2253
|
+
* // Returns: [chalk.red.bold('ERROR'), 'Connection failed', { retryCount: 3 }]
|
|
2254
|
+
* ```
|
|
2255
|
+
*
|
|
2256
|
+
* @example Unknown level fallback
|
|
2257
|
+
* ```typescript
|
|
2258
|
+
* const result = formatter.format({
|
|
2259
|
+
* level: 'unknown',
|
|
2260
|
+
* args: ['Custom message']
|
|
2261
|
+
* });
|
|
2262
|
+
* // Returns: [chalk.white('UNKNOWN'), 'Custom message']
|
|
2263
|
+
* ```
|
|
2264
|
+
*/
|
|
537
2265
|
format(event: LogEvent): unknown[];
|
|
538
2266
|
}
|
|
539
2267
|
|
|
540
|
-
|
|
541
|
-
|
|
2268
|
+
/**
|
|
2269
|
+
* Configuration search options for initializing ConfigSearch instances
|
|
2270
|
+
*
|
|
2271
|
+
* Core concept:
|
|
2272
|
+
* Defines the configuration parameters for setting up a configuration search
|
|
2273
|
+
* utility that can discover and load configuration files from various locations
|
|
2274
|
+
* in a project directory structure.
|
|
2275
|
+
*
|
|
2276
|
+
* Design considerations:
|
|
2277
|
+
* - Supports both name-based and custom search place configurations
|
|
2278
|
+
* - Provides default configuration fallback for graceful degradation
|
|
2279
|
+
* - Allows custom loaders for specialized file formats
|
|
2280
|
+
* - Maintains backward compatibility with cosmiconfig options
|
|
2281
|
+
* - Enables flexible configuration discovery strategies
|
|
2282
|
+
*
|
|
2283
|
+
* @example Basic usage
|
|
2284
|
+
* ```typescript
|
|
2285
|
+
* const options: ConfigSearchOptions = {
|
|
2286
|
+
* name: 'myapp',
|
|
2287
|
+
* defaultConfig: { port: 3000, debug: false }
|
|
2288
|
+
* };
|
|
2289
|
+
* ```
|
|
2290
|
+
*
|
|
2291
|
+
* @example Advanced usage with custom loaders
|
|
2292
|
+
* ```typescript
|
|
2293
|
+
* const options: ConfigSearchOptions = {
|
|
2294
|
+
* name: 'myapp',
|
|
2295
|
+
* searchPlaces: ['myapp.config.js', 'myapp.config.ts'],
|
|
2296
|
+
* loaders: {
|
|
2297
|
+
* '.toml': (filepath) => parseTOML(readFileSync(filepath, 'utf8'))
|
|
2298
|
+
* }
|
|
2299
|
+
* };
|
|
2300
|
+
* ```
|
|
2301
|
+
*/
|
|
2302
|
+
interface ConfigSearchOptions {
|
|
2303
|
+
/**
|
|
2304
|
+
* Base name for configuration files (used to generate default search patterns)
|
|
2305
|
+
*
|
|
2306
|
+
* This name is used to generate default search patterns for configuration files.
|
|
2307
|
+
* For example, if name is 'myapp', it will search for files like:
|
|
2308
|
+
* - myapp.json
|
|
2309
|
+
* - myapp.js
|
|
2310
|
+
* - myapp.ts
|
|
2311
|
+
* - .myapp.json
|
|
2312
|
+
* - etc.
|
|
2313
|
+
*
|
|
2314
|
+
* The name is also used as the cosmiconfig module name for package.json
|
|
2315
|
+
* configuration discovery.
|
|
2316
|
+
*
|
|
2317
|
+
* @example `'myapp'` // Searches for myapp.* files
|
|
2318
|
+
* @example `'fe-config'` // Searches for fe-config.* files
|
|
2319
|
+
*/
|
|
2320
|
+
name: string;
|
|
2321
|
+
/**
|
|
2322
|
+
* Custom search locations for config files (overrides default patterns)
|
|
2323
|
+
*
|
|
2324
|
+
* When provided, this completely overrides the default search patterns
|
|
2325
|
+
* generated from the name. Useful for projects with specific configuration
|
|
2326
|
+
* file naming conventions or directory structures.
|
|
2327
|
+
*
|
|
2328
|
+
* Search order:
|
|
2329
|
+
* - Files are searched in the order they appear in the array
|
|
2330
|
+
* - First found file is used (cosmiconfig behavior)
|
|
2331
|
+
* - Relative paths are resolved from the search directory
|
|
2332
|
+
*
|
|
2333
|
+
* @optional
|
|
2334
|
+
* @example `['config/app.js', 'app.config.ts']`
|
|
2335
|
+
* @example `['package.json', 'custom.config.js']`
|
|
2336
|
+
*/
|
|
2337
|
+
searchPlaces?: string[];
|
|
2338
|
+
/**
|
|
2339
|
+
* Default configuration object (merged with discovered config)
|
|
2340
|
+
*
|
|
2341
|
+
* Provides fallback values that are merged with discovered configuration.
|
|
2342
|
+
* Uses lodash defaultsDeep for deep merging, so nested objects are
|
|
2343
|
+
* properly merged rather than replaced.
|
|
2344
|
+
*
|
|
2345
|
+
* Merging behavior:
|
|
2346
|
+
* - Default values are used when not found in discovered config
|
|
2347
|
+
* - Discovered config values override defaults
|
|
2348
|
+
* - Nested objects are merged recursively
|
|
2349
|
+
* - Arrays are replaced (not merged)
|
|
2350
|
+
*
|
|
2351
|
+
* @optional
|
|
2352
|
+
* @default `{}`
|
|
2353
|
+
* @example `{ port: 3000, debug: false, database: { host: 'localhost' } }`
|
|
2354
|
+
*/
|
|
2355
|
+
defaultConfig?: Record<string, unknown>;
|
|
2356
|
+
/**
|
|
2357
|
+
* Custom loaders for different file types (extends cosmiconfig loaders)
|
|
2358
|
+
*
|
|
2359
|
+
* Allows loading of custom file formats beyond the built-in support
|
|
2360
|
+
* for JSON, JavaScript, TypeScript, YAML, etc. Each loader function
|
|
2361
|
+
* receives the filepath and should return the parsed configuration object.
|
|
2362
|
+
*
|
|
2363
|
+
* Loader requirements:
|
|
2364
|
+
* - Must be synchronous (cosmiconfigSync requirement)
|
|
2365
|
+
* - Should throw errors for invalid files
|
|
2366
|
+
* - Should return plain objects or throw for invalid configs
|
|
2367
|
+
* - File extension should include the dot (e.g., '.toml')
|
|
2368
|
+
*
|
|
2369
|
+
* @optional
|
|
2370
|
+
* @default `{}`
|
|
2371
|
+
* @example
|
|
2372
|
+
* ```typescript
|
|
2373
|
+
* {
|
|
2374
|
+
* '.toml': (filepath) => parseTOML(readFileSync(filepath, 'utf8')),
|
|
2375
|
+
* '.ini': (filepath) => parseINI(readFileSync(filepath, 'utf8'))
|
|
2376
|
+
* }
|
|
2377
|
+
* ```
|
|
2378
|
+
*/
|
|
2379
|
+
loaders?: Record<string, (filepath: string) => unknown>;
|
|
2380
|
+
}
|
|
2381
|
+
/**
|
|
2382
|
+
* Search options for configuration retrieval operations
|
|
2383
|
+
*
|
|
2384
|
+
* Core concept:
|
|
2385
|
+
* Controls how configuration files are discovered and loaded during
|
|
2386
|
+
* configuration retrieval operations, allowing fine-grained control
|
|
2387
|
+
* over the search behavior.
|
|
2388
|
+
*
|
|
2389
|
+
* Use cases:
|
|
2390
|
+
* - Load configuration from specific files
|
|
2391
|
+
* - Search in specific directories
|
|
2392
|
+
* - Skip file loading for testing or debugging
|
|
2393
|
+
* - Control search scope for performance optimization
|
|
2394
|
+
*
|
|
2395
|
+
* @example Load from specific file
|
|
2396
|
+
* ```typescript
|
|
2397
|
+
* const config = configSearch.get({ file: 'custom.config.js' });
|
|
2398
|
+
* ```
|
|
2399
|
+
*
|
|
2400
|
+
* @example Search in specific directory
|
|
2401
|
+
* ```typescript
|
|
2402
|
+
* const config = configSearch.get({ dir: '/path/to/project' });
|
|
2403
|
+
* ```
|
|
2404
|
+
*
|
|
2405
|
+
* @example Skip file loading (return empty config)
|
|
2406
|
+
* ```typescript
|
|
2407
|
+
* const config = configSearch.get({ file: false });
|
|
2408
|
+
* ```
|
|
2409
|
+
*/
|
|
2410
|
+
interface SearchOptions {
|
|
2411
|
+
/**
|
|
2412
|
+
* Specific configuration file to load (false to skip file loading)
|
|
2413
|
+
*
|
|
2414
|
+
* When provided as a string, loads configuration from the specified file.
|
|
2415
|
+
* When set to false, skips file loading entirely and returns an empty object.
|
|
2416
|
+
* When undefined, performs automatic search in the specified directory.
|
|
2417
|
+
*
|
|
2418
|
+
* File loading behavior:
|
|
2419
|
+
* - Absolute paths are used as-is
|
|
2420
|
+
* - Relative paths are resolved from the search directory
|
|
2421
|
+
* - File must exist and be readable
|
|
2422
|
+
* - File must contain valid configuration data
|
|
2423
|
+
*
|
|
2424
|
+
* @optional
|
|
2425
|
+
* @example `'config/production.js'` // Load specific file
|
|
2426
|
+
* @example `false` // Skip file loading
|
|
2427
|
+
*/
|
|
2428
|
+
file?: string | false;
|
|
2429
|
+
/**
|
|
2430
|
+
* Directory to search in (defaults to process.cwd())
|
|
2431
|
+
*
|
|
2432
|
+
* Specifies the root directory for configuration file search.
|
|
2433
|
+
* The search will look for configuration files in this directory
|
|
2434
|
+
* and its parent directories (cosmiconfig behavior).
|
|
2435
|
+
*
|
|
2436
|
+
* Search behavior:
|
|
2437
|
+
* - Starts from the specified directory
|
|
2438
|
+
* - Searches upward through parent directories
|
|
2439
|
+
* - Stops at the first found configuration file
|
|
2440
|
+
* - Respects .gitignore and other ignore patterns
|
|
2441
|
+
*
|
|
2442
|
+
* @optional
|
|
2443
|
+
* @default `process.cwd()`
|
|
2444
|
+
* @example `'/path/to/project'` // Search in specific directory
|
|
2445
|
+
* @example `process.cwd()` // Search from current working directory
|
|
2446
|
+
*/
|
|
2447
|
+
dir?: string;
|
|
2448
|
+
}
|
|
2449
|
+
/**
|
|
2450
|
+
* Configuration search and loading utility with caching support
|
|
2451
|
+
*
|
|
2452
|
+
* Core concept:
|
|
2453
|
+
* Provides a robust, performant way to discover and load configuration
|
|
2454
|
+
* files from various locations in a project directory structure, with
|
|
2455
|
+
* intelligent caching and merging capabilities.
|
|
2456
|
+
*
|
|
2457
|
+
* Main features:
|
|
2458
|
+
* - File discovery: Automatically finds configuration files in project directories
|
|
2459
|
+
* - Searches multiple file formats (JSON, JS, TS, YAML, etc.)
|
|
2460
|
+
* - Supports both prefixed and non-prefixed file names
|
|
2461
|
+
* - Follows cosmiconfig search patterns and conventions
|
|
2462
|
+
* - Respects .gitignore and other ignore patterns
|
|
2463
|
+
*
|
|
2464
|
+
* - Configuration merging: Intelligently combines default and discovered configs
|
|
2465
|
+
* - Uses lodash defaultsDeep for deep object merging
|
|
2466
|
+
* - Preserves nested object structures
|
|
2467
|
+
* - Provides fallback values for missing configurations
|
|
2468
|
+
* - Handles complex configuration hierarchies
|
|
2469
|
+
*
|
|
2470
|
+
* - Performance optimization: Implements caching to avoid repeated file system operations
|
|
2471
|
+
* - Caches search results for repeated access
|
|
2472
|
+
* - Reduces file system I/O in build tools and CLI applications
|
|
2473
|
+
* - Improves performance for configuration-heavy applications
|
|
2474
|
+
* - Supports cache invalidation when needed
|
|
2475
|
+
*
|
|
2476
|
+
* - Custom loaders: Extends cosmiconfig with custom file format support
|
|
2477
|
+
* - Add support for TOML, INI, or other custom formats
|
|
2478
|
+
* - Maintains compatibility with existing cosmiconfig loaders
|
|
2479
|
+
* - Allows project-specific configuration file formats
|
|
2480
|
+
* - Supports both synchronous and asynchronous loading patterns
|
|
2481
|
+
*
|
|
2482
|
+
* Design considerations:
|
|
2483
|
+
* - Uses cosmiconfig for robust file discovery and loading
|
|
2484
|
+
* - Implements caching to avoid repeated file system operations
|
|
2485
|
+
* - Supports deep merging with lodash defaultsDeep
|
|
2486
|
+
* - Maintains backward compatibility with existing config patterns
|
|
2487
|
+
* - Provides flexible configuration override mechanisms
|
|
2488
|
+
*
|
|
2489
|
+
* Performance optimizations:
|
|
2490
|
+
* - Caches search results to avoid repeated file system access
|
|
2491
|
+
* - Uses synchronous operations for better performance in build tools
|
|
2492
|
+
* - Implements lazy loading of configuration data
|
|
2493
|
+
* - Minimizes memory usage through efficient caching strategies
|
|
2494
|
+
*
|
|
2495
|
+
* @example Basic usage
|
|
2496
|
+
* ```typescript
|
|
2497
|
+
* const configSearch = new ConfigSearch({
|
|
2498
|
+
* name: 'myapp',
|
|
2499
|
+
* defaultConfig: { port: 3000, debug: false }
|
|
2500
|
+
* });
|
|
2501
|
+
*
|
|
2502
|
+
* // Get merged configuration
|
|
2503
|
+
* const config = configSearch.config;
|
|
2504
|
+
* console.log(config.port); // 3000 (from default)
|
|
2505
|
+
* ```
|
|
2506
|
+
*
|
|
2507
|
+
* @example Advanced usage with custom search
|
|
2508
|
+
* ```typescript
|
|
2509
|
+
* const configSearch = new ConfigSearch({
|
|
2510
|
+
* name: 'myapp',
|
|
2511
|
+
* searchPlaces: ['myapp.config.js', 'config/myapp.js'],
|
|
2512
|
+
* defaultConfig: { environment: 'development' }
|
|
2513
|
+
* });
|
|
2514
|
+
*
|
|
2515
|
+
* // Search in specific directory
|
|
2516
|
+
* const config = configSearch.get({ dir: '/path/to/project' });
|
|
2517
|
+
*
|
|
2518
|
+
* // Get search locations for debugging
|
|
2519
|
+
* console.log(configSearch.getSearchPlaces());
|
|
2520
|
+
* ```
|
|
2521
|
+
*
|
|
2522
|
+
* @example Custom file format support
|
|
2523
|
+
* ```typescript
|
|
2524
|
+
* const configSearch = new ConfigSearch({
|
|
2525
|
+
* name: 'myapp',
|
|
2526
|
+
* loaders: {
|
|
2527
|
+
* '.toml': (filepath) => parseTOML(readFileSync(filepath, 'utf8'))
|
|
2528
|
+
* }
|
|
2529
|
+
* });
|
|
2530
|
+
* ```
|
|
2531
|
+
*/
|
|
2532
|
+
declare class ConfigSearch {
|
|
2533
|
+
/**
|
|
2534
|
+
* Base name for configuration files
|
|
2535
|
+
*
|
|
2536
|
+
* Used to generate default search patterns and as the cosmiconfig
|
|
2537
|
+
* module name for package.json configuration discovery.
|
|
2538
|
+
*/
|
|
2539
|
+
private name;
|
|
2540
|
+
/**
|
|
2541
|
+
* Search locations for configuration files
|
|
2542
|
+
*
|
|
2543
|
+
* Array of file patterns to search for, in priority order.
|
|
2544
|
+
* Can be either default patterns generated from name or
|
|
2545
|
+
* custom patterns provided in constructor options.
|
|
2546
|
+
*/
|
|
2547
|
+
private searchPlaces;
|
|
2548
|
+
/**
|
|
2549
|
+
* Default configuration object
|
|
2550
|
+
*
|
|
2551
|
+
* Provides fallback values that are merged with discovered
|
|
2552
|
+
* configuration using lodash defaultsDeep.
|
|
2553
|
+
*/
|
|
2554
|
+
private _config;
|
|
2555
|
+
/**
|
|
2556
|
+
* Custom file loaders for extended format support
|
|
2557
|
+
*
|
|
2558
|
+
* Extends cosmiconfig's built-in loaders with custom file
|
|
2559
|
+
* format support (e.g., TOML, INI, etc.).
|
|
2560
|
+
*/
|
|
2561
|
+
private loaders?;
|
|
2562
|
+
/**
|
|
2563
|
+
* Cache for search results
|
|
2564
|
+
*
|
|
2565
|
+
* Stores the result of the last search operation to avoid
|
|
2566
|
+
* repeated file system access. Simple implementation that
|
|
2567
|
+
* caches the entire search result.
|
|
2568
|
+
*/
|
|
2569
|
+
private searchCache?;
|
|
2570
|
+
/**
|
|
2571
|
+
* Creates a ConfigSearch instance with specified options
|
|
2572
|
+
*
|
|
2573
|
+
* Core concept:
|
|
2574
|
+
* Initializes a configuration search utility with the specified
|
|
2575
|
+
* options, setting up file discovery patterns and default values.
|
|
2576
|
+
*
|
|
2577
|
+
* Validation rules:
|
|
2578
|
+
* - Either name or searchPlaces must be provided
|
|
2579
|
+
* - Name is used to generate default search patterns if searchPlaces not provided
|
|
2580
|
+
* - Default configuration provides fallback values
|
|
2581
|
+
* - Custom loaders extend cosmiconfig's built-in support
|
|
2582
|
+
*
|
|
2583
|
+
* Initialization process:
|
|
2584
|
+
* 1. Validates that either name or searchPlaces is provided
|
|
2585
|
+
* 2. Sets up search patterns (custom or generated from name)
|
|
2586
|
+
* 3. Initializes default configuration object
|
|
2587
|
+
* 4. Stores custom loaders for extended format support
|
|
2588
|
+
*
|
|
2589
|
+
* @param options - Configuration search options
|
|
2590
|
+
* @throws {Error} When neither name nor searchPlaces is provided
|
|
2591
|
+
*
|
|
2592
|
+
* @example Using name (generates default search patterns)
|
|
2593
|
+
* ```typescript
|
|
2594
|
+
* const search = new ConfigSearch({
|
|
2595
|
+
* name: 'myapp',
|
|
2596
|
+
* defaultConfig: { debug: true }
|
|
2597
|
+
* });
|
|
2598
|
+
* ```
|
|
2599
|
+
*
|
|
2600
|
+
* @example Using custom search places
|
|
2601
|
+
* ```typescript
|
|
2602
|
+
* const search = new ConfigSearch({
|
|
2603
|
+
* searchPlaces: ['custom.config.js'],
|
|
2604
|
+
* defaultConfig: { port: 8080 }
|
|
2605
|
+
* });
|
|
2606
|
+
* ```
|
|
2607
|
+
*
|
|
2608
|
+
* @example With custom loaders
|
|
2609
|
+
* ```typescript
|
|
2610
|
+
* const search = new ConfigSearch({
|
|
2611
|
+
* name: 'myapp',
|
|
2612
|
+
* loaders: {
|
|
2613
|
+
* '.toml': (filepath) => parseTOML(readFileSync(filepath, 'utf8'))
|
|
2614
|
+
* }
|
|
2615
|
+
* });
|
|
2616
|
+
* ```
|
|
2617
|
+
*/
|
|
2618
|
+
constructor(options: ConfigSearchOptions);
|
|
2619
|
+
/**
|
|
2620
|
+
* Gets the effective configuration with deep merging
|
|
2621
|
+
*
|
|
2622
|
+
* Core concept:
|
|
2623
|
+
* Retrieves the complete configuration by merging default values
|
|
2624
|
+
* with discovered configuration files, providing a unified
|
|
2625
|
+
* configuration object for the application.
|
|
2626
|
+
*
|
|
2627
|
+
* Merging strategy:
|
|
2628
|
+
* - Default configuration provides base values
|
|
2629
|
+
* - Discovered configuration overrides defaults
|
|
2630
|
+
* - Uses lodash defaultsDeep for nested object merging
|
|
2631
|
+
* - Returns a new object to prevent mutation
|
|
2632
|
+
* - Handles complex nested structures properly
|
|
2633
|
+
*
|
|
2634
|
+
* Merging behavior:
|
|
2635
|
+
* - Primitive values: Discovered values override defaults
|
|
2636
|
+
* - Objects: Deep merge, preserving both default and discovered properties
|
|
2637
|
+
* - Arrays: Discovered arrays replace default arrays (not merged)
|
|
2638
|
+
* - Undefined values: Default values are preserved
|
|
2639
|
+
* - Null values: Treated as explicit values (override defaults)
|
|
2640
|
+
*
|
|
2641
|
+
* Performance considerations:
|
|
2642
|
+
* - Uses cached search results when available
|
|
2643
|
+
* - Performs deep merge only when necessary
|
|
2644
|
+
* - Returns new object to prevent external mutation
|
|
2645
|
+
*
|
|
2646
|
+
* @returns Merged configuration object
|
|
2647
|
+
*
|
|
2648
|
+
* @example Basic merging
|
|
2649
|
+
* ```typescript
|
|
2650
|
+
* const configSearch = new ConfigSearch({
|
|
2651
|
+
* name: 'myapp',
|
|
2652
|
+
* defaultConfig: {
|
|
2653
|
+
* server: { port: 3000, host: 'localhost' },
|
|
2654
|
+
* debug: false
|
|
2655
|
+
* }
|
|
2656
|
+
* });
|
|
2657
|
+
*
|
|
2658
|
+
* // If myapp.config.js contains: { server: { port: 8080 }, log: true }
|
|
2659
|
+
* const config = configSearch.config;
|
|
2660
|
+
* // Result: { server: { port: 8080, host: 'localhost' }, debug: false, log: true }
|
|
2661
|
+
* ```
|
|
2662
|
+
*
|
|
2663
|
+
* @example Complex nested merging
|
|
2664
|
+
* ```typescript
|
|
2665
|
+
* const configSearch = new ConfigSearch({
|
|
2666
|
+
* name: 'myapp',
|
|
2667
|
+
* defaultConfig: {
|
|
2668
|
+
* database: {
|
|
2669
|
+
* host: 'localhost',
|
|
2670
|
+
* options: { timeout: 5000, retries: 3 }
|
|
2671
|
+
* }
|
|
2672
|
+
* }
|
|
2673
|
+
* });
|
|
2674
|
+
*
|
|
2675
|
+
* // If config file contains: { database: { port: 5432, options: { timeout: 10000 } } }
|
|
2676
|
+
* const config = configSearch.config;
|
|
2677
|
+
* // Result: {
|
|
2678
|
+
* // database: {
|
|
2679
|
+
* // host: 'localhost',
|
|
2680
|
+
* // port: 5432,
|
|
2681
|
+
* // options: { timeout: 10000, retries: 3 }
|
|
2682
|
+
* // }
|
|
2683
|
+
* // }
|
|
2684
|
+
* ```
|
|
2685
|
+
*/
|
|
2686
|
+
get config(): Record<string, unknown>;
|
|
2687
|
+
/**
|
|
2688
|
+
* Gets the configured search locations for debugging and verification
|
|
2689
|
+
*
|
|
2690
|
+
* Core concept:
|
|
2691
|
+
* Provides access to the search patterns used by this ConfigSearch
|
|
2692
|
+
* instance, useful for debugging configuration discovery issues
|
|
2693
|
+
* and understanding the search behavior.
|
|
2694
|
+
*
|
|
2695
|
+
* Use cases:
|
|
2696
|
+
* - Debug configuration discovery issues
|
|
2697
|
+
* - Verify search patterns are correct
|
|
2698
|
+
* - Document expected configuration file locations
|
|
2699
|
+
* - Understand search priority order
|
|
2700
|
+
* - Validate custom search place configurations
|
|
2701
|
+
*
|
|
2702
|
+
* Search pattern information:
|
|
2703
|
+
* - Returns the exact patterns used for file discovery
|
|
2704
|
+
* - Patterns are in priority order (first match wins)
|
|
2705
|
+
* - Includes both custom and generated patterns
|
|
2706
|
+
* - Useful for troubleshooting missing configuration files
|
|
2707
|
+
*
|
|
2708
|
+
* @returns Array of search locations in priority order
|
|
2709
|
+
*
|
|
2710
|
+
* @example Basic usage
|
|
2711
|
+
* ```typescript
|
|
2712
|
+
* const configSearch = new ConfigSearch({ name: 'myapp' });
|
|
2713
|
+
* const places = configSearch.getSearchPlaces();
|
|
2714
|
+
* console.log('Searching for config in:', places);
|
|
2715
|
+
* // ['package.json', 'myapp.json', 'myapp.js', 'myapp.ts', ...]
|
|
2716
|
+
* ```
|
|
2717
|
+
*
|
|
2718
|
+
* @example Debugging missing configuration
|
|
2719
|
+
* ```typescript
|
|
2720
|
+
* const configSearch = new ConfigSearch({
|
|
2721
|
+
* searchPlaces: ['custom.config.js', 'config/app.js']
|
|
2722
|
+
* });
|
|
2723
|
+
*
|
|
2724
|
+
* const places = configSearch.getSearchPlaces();
|
|
2725
|
+
* console.log('Expected config files:', places);
|
|
2726
|
+
* // ['custom.config.js', 'config/app.js']
|
|
2727
|
+
* ```
|
|
2728
|
+
*/
|
|
2729
|
+
getSearchPlaces(): string[];
|
|
2730
|
+
/**
|
|
2731
|
+
* Loads configuration from a specific location with validation
|
|
2732
|
+
*
|
|
2733
|
+
* Core concept:
|
|
2734
|
+
* Performs targeted configuration loading from specific files or
|
|
2735
|
+
* directories, with comprehensive validation and error handling.
|
|
2736
|
+
*
|
|
2737
|
+
* Loading process:
|
|
2738
|
+
* 1. Creates cosmiconfig instance with configured options
|
|
2739
|
+
* 2. Loads from specific file or searches in directory
|
|
2740
|
+
* 3. Validates configuration is a plain object
|
|
2741
|
+
* 4. Returns empty object for invalid configurations
|
|
2742
|
+
* 5. Handles various error conditions gracefully
|
|
2743
|
+
*
|
|
2744
|
+
* File loading behavior:
|
|
2745
|
+
* - Specific file: Loads configuration from the exact file path
|
|
2746
|
+
* - Directory search: Searches for configuration files in the directory
|
|
2747
|
+
* - Skip loading: Returns empty object when file is false
|
|
2748
|
+
* - Validation: Ensures configuration is a valid plain object
|
|
2749
|
+
*
|
|
2750
|
+
* Error handling:
|
|
2751
|
+
* - Throws error for invalid configuration files (string configs)
|
|
2752
|
+
* - Returns empty object for missing or invalid configurations
|
|
2753
|
+
* - Logs warnings for non-object configurations
|
|
2754
|
+
* - Handles file system errors gracefully
|
|
2755
|
+
* - Validates configuration structure and format
|
|
2756
|
+
*
|
|
2757
|
+
* Validation rules:
|
|
2758
|
+
* - Configuration must be a plain object (not string, array, etc.)
|
|
2759
|
+
* - File must exist and be readable
|
|
2760
|
+
* - File must contain valid configuration data
|
|
2761
|
+
* - Custom loaders must return valid objects
|
|
2762
|
+
*
|
|
2763
|
+
* @param options - Search options for configuration loading
|
|
2764
|
+
* @returns Configuration object from specified location
|
|
2765
|
+
* @throws {Error} When configuration file contains invalid data
|
|
2766
|
+
*
|
|
2767
|
+
* @example Load from specific file
|
|
2768
|
+
* ```typescript
|
|
2769
|
+
* const configSearch = new ConfigSearch({ name: 'myapp' });
|
|
2770
|
+
* const config = configSearch.get({ file: 'custom.config.js' });
|
|
2771
|
+
* ```
|
|
2772
|
+
*
|
|
2773
|
+
* @example Search in current directory
|
|
2774
|
+
* ```typescript
|
|
2775
|
+
* const configSearch = new ConfigSearch({ name: 'myapp' });
|
|
2776
|
+
* const config = configSearch.get({ dir: process.cwd() });
|
|
2777
|
+
* ```
|
|
2778
|
+
*
|
|
2779
|
+
* @example Skip file loading
|
|
2780
|
+
* ```typescript
|
|
2781
|
+
* const configSearch = new ConfigSearch({ name: 'myapp' });
|
|
2782
|
+
* const config = configSearch.get({ file: false }); // Returns {}
|
|
2783
|
+
* ```
|
|
2784
|
+
*
|
|
2785
|
+
* @example Search in specific directory
|
|
2786
|
+
* ```typescript
|
|
2787
|
+
* const configSearch = new ConfigSearch({ name: 'myapp' });
|
|
2788
|
+
* const config = configSearch.get({ dir: '/path/to/project' });
|
|
2789
|
+
* ```
|
|
2790
|
+
*/
|
|
2791
|
+
get(options?: SearchOptions): Record<string, unknown>;
|
|
2792
|
+
/**
|
|
2793
|
+
* Searches for configuration with caching for performance optimization
|
|
2794
|
+
*
|
|
2795
|
+
* Core concept:
|
|
2796
|
+
* Performs configuration file discovery with intelligent caching
|
|
2797
|
+
* to optimize performance for repeated configuration access.
|
|
2798
|
+
*
|
|
2799
|
+
* Caching strategy:
|
|
2800
|
+
* - Caches search results to avoid repeated file system operations
|
|
2801
|
+
* - Cache is invalidated on each search call (simple implementation)
|
|
2802
|
+
* - Improves performance for repeated configuration access
|
|
2803
|
+
* - Reduces file system I/O in build tools and CLI applications
|
|
2804
|
+
*
|
|
2805
|
+
* Performance benefits:
|
|
2806
|
+
* - Reduces file system I/O operations
|
|
2807
|
+
* - Avoids repeated cosmiconfig initialization
|
|
2808
|
+
* - Particularly beneficial in build tools and CLI applications
|
|
2809
|
+
* - Minimizes configuration loading overhead
|
|
2810
|
+
* - Improves application startup time
|
|
2811
|
+
*
|
|
2812
|
+
* Cache behavior:
|
|
2813
|
+
* - First call: Performs full file system search
|
|
2814
|
+
* - Subsequent calls: Returns cached result
|
|
2815
|
+
* - Cache is shared across all method calls
|
|
2816
|
+
* - Simple cache invalidation strategy
|
|
2817
|
+
*
|
|
2818
|
+
* Search process:
|
|
2819
|
+
* 1. Check if cached result exists
|
|
2820
|
+
* 2. If cached, return cached result
|
|
2821
|
+
* 3. If not cached, perform file system search
|
|
2822
|
+
* 4. Cache the search result
|
|
2823
|
+
* 5. Return the discovered configuration
|
|
2824
|
+
*
|
|
2825
|
+
* @returns Cached configuration object from search
|
|
2826
|
+
*
|
|
2827
|
+
* @example Basic usage
|
|
2828
|
+
* ```typescript
|
|
2829
|
+
* const configSearch = new ConfigSearch({ name: 'myapp' });
|
|
2830
|
+
*
|
|
2831
|
+
* // First call performs file system search
|
|
2832
|
+
* const config1 = configSearch.search();
|
|
2833
|
+
*
|
|
2834
|
+
* // Subsequent calls use cached result
|
|
2835
|
+
* const config2 = configSearch.search(); // No file system access
|
|
2836
|
+
*
|
|
2837
|
+
* // Both return the same configuration object
|
|
2838
|
+
* console.log(config1 === config2); // true
|
|
2839
|
+
* ```
|
|
2840
|
+
*
|
|
2841
|
+
* @example Performance optimization
|
|
2842
|
+
* ```typescript
|
|
2843
|
+
* const configSearch = new ConfigSearch({ name: 'myapp' });
|
|
2844
|
+
*
|
|
2845
|
+
* // In a build tool or CLI application
|
|
2846
|
+
* for (let i = 0; i < 100; i++) {
|
|
2847
|
+
* const config = configSearch.search(); // Only first call hits file system
|
|
2848
|
+
* // Use configuration...
|
|
2849
|
+
* }
|
|
2850
|
+
* ```
|
|
2851
|
+
*/
|
|
2852
|
+
search(): Record<string, unknown>;
|
|
2853
|
+
}
|
|
2854
|
+
|
|
2855
|
+
/**
|
|
2856
|
+
* Enhanced script context that provides environment management and configuration utilities
|
|
2857
|
+
*
|
|
2858
|
+
* Core concept:
|
|
2859
|
+
* Provides a comprehensive script execution environment with integrated
|
|
2860
|
+
* configuration management, environment variable handling, logging,
|
|
2861
|
+
* and shell command execution capabilities.
|
|
2862
|
+
*
|
|
2863
|
+
* Main features:
|
|
2864
|
+
* - Environment management: Integrated environment variable handling
|
|
2865
|
+
* - Automatic loading of .env files with configurable order
|
|
2866
|
+
* - Type-safe environment variable access with defaults
|
|
2867
|
+
* - Support for environment-specific configurations
|
|
2868
|
+
* - Integration with fe-config environment settings
|
|
2869
|
+
*
|
|
2870
|
+
* - Configuration management: Unified configuration access and merging
|
|
2871
|
+
* - Script-specific configuration sections
|
|
2872
|
+
* - Deep merging with default values
|
|
2873
|
+
* - Type-safe option access with nested path support
|
|
2874
|
+
* - Configuration validation and fallback handling
|
|
2875
|
+
*
|
|
2876
|
+
* - Logging system: Structured logging with timestamp formatting
|
|
2877
|
+
* - Configurable verbosity levels
|
|
2878
|
+
* - Timestamp formatting with timezone support
|
|
2879
|
+
* - Logger name identification for multi-script environments
|
|
2880
|
+
* - Console output with structured formatting
|
|
2881
|
+
*
|
|
2882
|
+
* - Shell integration: Command execution with dry run support
|
|
2883
|
+
* - Safe command execution with error handling
|
|
2884
|
+
* - Dry run mode for testing and validation
|
|
2885
|
+
* - Integrated logging for command output
|
|
2886
|
+
* - Support for custom execution functions
|
|
2887
|
+
*
|
|
2888
|
+
* Design considerations:
|
|
2889
|
+
* - Uses lodash merge for deep configuration merging
|
|
2890
|
+
* - Supports environment file loading with configurable order
|
|
2891
|
+
* - Provides type-safe option access with fallback values
|
|
2892
|
+
* - Implements proper error handling for missing configurations
|
|
2893
|
+
* - Maintains backward compatibility with existing interfaces
|
|
2894
|
+
* - Supports both development and production environments
|
|
2895
|
+
*
|
|
2896
|
+
* Performance optimizations:
|
|
2897
|
+
* - Lazy environment initialization
|
|
2898
|
+
* - Cached configuration access
|
|
2899
|
+
* - Efficient option merging
|
|
2900
|
+
* - Minimal memory footprint
|
|
2901
|
+
*
|
|
2902
|
+
* @example Basic usage
|
|
2903
|
+
* ```typescript
|
|
2904
|
+
* const context = new ScriptContext('build-script', {
|
|
2905
|
+
* verbose: true,
|
|
2906
|
+
* options: { outputDir: './dist' }
|
|
2907
|
+
* });
|
|
2908
|
+
*
|
|
2909
|
+
* // Access environment variables
|
|
2910
|
+
* const apiKey = context.getEnv('API_KEY', 'default-key');
|
|
2911
|
+
*
|
|
2912
|
+
* // Access configuration options
|
|
2913
|
+
* const outputDir = context.getOptions('outputDir', './build');
|
|
2914
|
+
* ```
|
|
2915
|
+
*
|
|
2916
|
+
* @example Advanced configuration
|
|
2917
|
+
* ```typescript
|
|
2918
|
+
* const context = new ScriptContext('deploy-script', {
|
|
2919
|
+
* feConfig: {
|
|
2920
|
+
* envOrder: ['.env.prod', '.env.local', '.env'],
|
|
2921
|
+
* 'deploy-script': {
|
|
2922
|
+
* target: 'production',
|
|
2923
|
+
* region: 'us-east-1'
|
|
2924
|
+
* }
|
|
2925
|
+
* }
|
|
2926
|
+
* });
|
|
2927
|
+
* ```
|
|
2928
|
+
*
|
|
2929
|
+
* @example With custom components
|
|
2930
|
+
* ```typescript
|
|
2931
|
+
* const context = new ScriptContext('test-script', {
|
|
2932
|
+
* logger: customLogger,
|
|
2933
|
+
* shell: customShell,
|
|
2934
|
+
* dryRun: true,
|
|
2935
|
+
* options: { testMode: true }
|
|
2936
|
+
* });
|
|
2937
|
+
* ```
|
|
2938
|
+
*/
|
|
2939
|
+
declare class ScriptContext<Opt extends ScriptSharedInterface> implements ScriptContextInterface<Opt> {
|
|
2940
|
+
readonly name: string;
|
|
2941
|
+
/**
|
|
2942
|
+
* Logger instance for structured logging
|
|
2943
|
+
*
|
|
2944
|
+
* Provides timestamp-formatted logging with configurable
|
|
2945
|
+
* verbosity levels and script name identification.
|
|
2946
|
+
*/
|
|
2947
|
+
readonly logger: LoggerInterface;
|
|
2948
|
+
/**
|
|
2949
|
+
* Shell interface for command execution
|
|
2950
|
+
*
|
|
2951
|
+
* Handles command execution with dry run support,
|
|
2952
|
+
* error handling, and integrated logging.
|
|
2953
|
+
*/
|
|
2954
|
+
readonly shell: ShellInterface;
|
|
2955
|
+
/**
|
|
2956
|
+
* Merged fe-configuration object
|
|
2957
|
+
*
|
|
2958
|
+
* Contains the complete configuration after merging
|
|
2959
|
+
* default fe-config with script-specific overrides.
|
|
2960
|
+
*/
|
|
2961
|
+
readonly feConfig: FeConfig;
|
|
2962
|
+
/**
|
|
2963
|
+
* Whether to run in dry run mode
|
|
2964
|
+
*
|
|
2965
|
+
* When true, commands are logged but not executed,
|
|
2966
|
+
* useful for testing and validation.
|
|
2967
|
+
*/
|
|
2968
|
+
readonly dryRun: boolean;
|
|
2969
|
+
/**
|
|
2970
|
+
* Whether to enable verbose logging
|
|
2971
|
+
*
|
|
2972
|
+
* Controls debug level logging output and
|
|
2973
|
+
* detailed information display.
|
|
2974
|
+
*/
|
|
2975
|
+
readonly verbose: boolean;
|
|
2976
|
+
/**
|
|
2977
|
+
* Script-specific options
|
|
2978
|
+
*
|
|
2979
|
+
* Contains all script configuration options
|
|
2980
|
+
* with defaults applied and environment integration.
|
|
2981
|
+
*/
|
|
2982
|
+
options: Opt;
|
|
2983
|
+
/**
|
|
2984
|
+
* Creates a new ScriptContext instance with the specified configuration
|
|
2985
|
+
*
|
|
2986
|
+
* Core concept:
|
|
2987
|
+
* Initializes a complete script execution environment with
|
|
2988
|
+
* integrated configuration, logging, and shell capabilities.
|
|
2989
|
+
*
|
|
2990
|
+
* Initialization process:
|
|
2991
|
+
* 1. Validates script name requirement
|
|
2992
|
+
* 2. Sets up logger, shell, and configuration components
|
|
2993
|
+
* 3. Loads environment variables with configurable order
|
|
2994
|
+
* 4. Applies default options and environment integration
|
|
2995
|
+
* 5. Merges script-specific configuration with defaults
|
|
2996
|
+
*
|
|
2997
|
+
* Validation rules:
|
|
2998
|
+
* - Script name must be provided and be a non-empty string
|
|
2999
|
+
* - Options are optional and have sensible defaults
|
|
3000
|
+
* - Environment loading follows configurable priority order
|
|
3001
|
+
* - Configuration merging preserves type safety
|
|
3002
|
+
*
|
|
3003
|
+
* Component initialization:
|
|
3004
|
+
* - Logger: Created with timestamp formatting and verbosity control
|
|
3005
|
+
* - Shell: Set up with dry run support and integrated logging
|
|
3006
|
+
* - Configuration: Merged from fe-config with script-specific overrides
|
|
3007
|
+
* - Environment: Loaded from files with fallback to defaults
|
|
3008
|
+
*
|
|
3009
|
+
* @param name - Script identifier for logging and configuration
|
|
3010
|
+
* @param opts - Optional initialization options
|
|
3011
|
+
* @throws {Error} When script name is not provided or invalid
|
|
3012
|
+
*
|
|
3013
|
+
* @example Basic initialization
|
|
3014
|
+
* ```typescript
|
|
3015
|
+
* const context = new ScriptContext('build-script', {
|
|
3016
|
+
* verbose: true,
|
|
3017
|
+
* dryRun: false
|
|
3018
|
+
* });
|
|
3019
|
+
* ```
|
|
3020
|
+
*
|
|
3021
|
+
* @example With custom options
|
|
3022
|
+
* ```typescript
|
|
3023
|
+
* const context = new ScriptContext('deploy-script', {
|
|
3024
|
+
* feConfig: { target: 'production' },
|
|
3025
|
+
* options: { region: 'us-east-1' }
|
|
3026
|
+
* });
|
|
3027
|
+
* ```
|
|
3028
|
+
*/
|
|
3029
|
+
constructor(name: string, opts?: Partial<ScriptContextInterface<Opt>>);
|
|
3030
|
+
/**
|
|
3031
|
+
* Environment instance for variable access and management
|
|
3032
|
+
*
|
|
3033
|
+
* Core concept:
|
|
3034
|
+
* Provides access to environment variables loaded from
|
|
3035
|
+
* configuration files with type-safe getter methods
|
|
3036
|
+
* and default value support.
|
|
3037
|
+
*
|
|
3038
|
+
* Environment features:
|
|
3039
|
+
* - Automatic file loading (.env.local, .env)
|
|
3040
|
+
* - Type-safe getter methods with defaults
|
|
3041
|
+
* - Configurable file loading order
|
|
3042
|
+
* - Integration with fe-config environment settings
|
|
3043
|
+
* - Lazy initialization for performance
|
|
3044
|
+
*
|
|
3045
|
+
* Loading behavior:
|
|
3046
|
+
* - Files are loaded in priority order (highest first)
|
|
3047
|
+
* - Missing files are silently ignored
|
|
3048
|
+
* - Variables are cached after first load
|
|
3049
|
+
* - Environment is shared across script instances
|
|
3050
|
+
*
|
|
3051
|
+
* Error handling:
|
|
3052
|
+
* - Throws error if environment is not initialized
|
|
3053
|
+
* - Provides clear error messages for debugging
|
|
3054
|
+
* - Graceful handling of missing environment files
|
|
3055
|
+
*
|
|
3056
|
+
* @returns Env instance for environment variable operations
|
|
3057
|
+
* @throws {Error} When environment is not properly initialized
|
|
3058
|
+
*
|
|
3059
|
+
* @example Basic usage
|
|
3060
|
+
* ```typescript
|
|
3061
|
+
* const apiKey = this.env.get('API_KEY');
|
|
3062
|
+
* const port = this.env.get('PORT', '3000');
|
|
3063
|
+
* ```
|
|
3064
|
+
*
|
|
3065
|
+
* @example With defaults
|
|
3066
|
+
* ```typescript
|
|
3067
|
+
* const databaseUrl = this.env.get('DATABASE_URL', 'localhost:5432');
|
|
3068
|
+
* const debug = this.env.get('DEBUG', 'false');
|
|
3069
|
+
* ```
|
|
3070
|
+
*/
|
|
3071
|
+
get env(): Env;
|
|
3072
|
+
/**
|
|
3073
|
+
* Extracts configuration store from feConfig based on script name
|
|
3074
|
+
*
|
|
3075
|
+
* Core concept:
|
|
3076
|
+
* Safely extracts script-specific configuration from the
|
|
3077
|
+
* merged fe-config object, handling various data types
|
|
3078
|
+
* and providing fallback values.
|
|
3079
|
+
*
|
|
3080
|
+
* Extraction process:
|
|
3081
|
+
* 1. Uses lodash get to safely access nested configuration
|
|
3082
|
+
* 2. Validates that the extracted value is an object
|
|
3083
|
+
* 3. Converts primitive values to empty objects
|
|
3084
|
+
* 4. Logs warnings for non-object configurations
|
|
3085
|
+
* 5. Returns type-safe configuration object
|
|
3086
|
+
*
|
|
3087
|
+
* Safety features:
|
|
3088
|
+
* - Safe nested property access with lodash get
|
|
3089
|
+
* - Null and undefined handling
|
|
3090
|
+
* - Type validation for configuration objects
|
|
3091
|
+
* - Warning logging for invalid configurations
|
|
3092
|
+
* - Fallback to empty object for primitives
|
|
3093
|
+
*
|
|
3094
|
+
* Configuration validation:
|
|
3095
|
+
* - Checks if extracted value is an object
|
|
3096
|
+
* - Warns when configuration is not an object
|
|
3097
|
+
* - Converts primitives to empty objects
|
|
3098
|
+
* - Maintains type safety through generic constraints
|
|
3099
|
+
*
|
|
3100
|
+
* @param scriptName - Script name or array of names for nested access
|
|
3101
|
+
* @param sources - Configuration source object (feConfig)
|
|
3102
|
+
* @returns Extracted configuration object with type safety
|
|
3103
|
+
*
|
|
3104
|
+
* @example Basic extraction
|
|
3105
|
+
* ```typescript
|
|
3106
|
+
* const config = this.getDefaultStore('build-script', feConfig);
|
|
3107
|
+
* // Returns configuration from feConfig['build-script']
|
|
3108
|
+
* ```
|
|
3109
|
+
*
|
|
3110
|
+
* @example Nested access
|
|
3111
|
+
* ```typescript
|
|
3112
|
+
* const config = this.getDefaultStore(['scripts', 'build'], feConfig);
|
|
3113
|
+
* // Returns configuration from feConfig.scripts.build
|
|
3114
|
+
* ```
|
|
3115
|
+
*/
|
|
3116
|
+
protected getDefaultStore(scriptName: string | string[], sources: Record<string, unknown>): Opt;
|
|
3117
|
+
/**
|
|
3118
|
+
* Applies default values to script options with environment integration
|
|
3119
|
+
*
|
|
3120
|
+
* Core concept:
|
|
3121
|
+
* Enhances provided options with sensible defaults and
|
|
3122
|
+
* environment variable integration, ensuring all required
|
|
3123
|
+
* configuration is available.
|
|
3124
|
+
*
|
|
3125
|
+
* Default logic:
|
|
3126
|
+
* 1. Uses existing environment or loads from files
|
|
3127
|
+
* 2. Sets rootPath to current working directory if not specified
|
|
3128
|
+
* 3. Determines sourceBranch from environment or defaults to 'master'
|
|
3129
|
+
* 4. Merges all options with proper precedence
|
|
3130
|
+
* 5. Ensures environment is properly initialized
|
|
3131
|
+
*
|
|
3132
|
+
* Environment variable priority:
|
|
3133
|
+
* 1. FE_RELEASE_BRANCH (primary environment variable)
|
|
3134
|
+
* 2. FE_RELEASE_SOURCE_BRANCH (fallback environment variable)
|
|
3135
|
+
* 3. 'master' (default value)
|
|
3136
|
+
* 4. Options.sourceBranch (if provided)
|
|
3137
|
+
*
|
|
3138
|
+
* Path handling:
|
|
3139
|
+
* - rootPath defaults to process.cwd() if not specified
|
|
3140
|
+
* - Supports both absolute and relative paths
|
|
3141
|
+
* - Maintains path consistency across environments
|
|
3142
|
+
* - Used for file operations and configuration loading
|
|
3143
|
+
*
|
|
3144
|
+
* Environment integration:
|
|
3145
|
+
* - Loads environment from files if not provided
|
|
3146
|
+
* - Uses configurable file loading order
|
|
3147
|
+
* - Integrates with fe-config environment settings
|
|
3148
|
+
* - Provides fallback to default environment
|
|
3149
|
+
*
|
|
3150
|
+
* @param options - Current options to enhance with defaults
|
|
3151
|
+
* @returns Options with default values and environment integration
|
|
3152
|
+
*
|
|
3153
|
+
* @example Basic defaults
|
|
3154
|
+
* ```typescript
|
|
3155
|
+
* const options = this.getDefaultOptions({});
|
|
3156
|
+
* // Returns: { rootPath: process.cwd(), sourceBranch: 'master', env: Env instance }
|
|
3157
|
+
* ```
|
|
3158
|
+
*
|
|
3159
|
+
* @example With environment variables
|
|
3160
|
+
* ```typescript
|
|
3161
|
+
* // If FE_RELEASE_BRANCH=develop
|
|
3162
|
+
* const options = this.getDefaultOptions({});
|
|
3163
|
+
* // Returns: { rootPath: process.cwd(), sourceBranch: 'develop', env: Env instance }
|
|
3164
|
+
* ```
|
|
3165
|
+
*/
|
|
3166
|
+
protected getDefaultOptions(options: Opt): Opt;
|
|
3167
|
+
/**
|
|
3168
|
+
* Updates script options with deep merging support
|
|
3169
|
+
*
|
|
3170
|
+
* Core concept:
|
|
3171
|
+
* Merges new options with existing configuration using
|
|
3172
|
+
* lodash merge for deep object merging, preserving
|
|
3173
|
+
* existing options not specified in the update.
|
|
3174
|
+
*
|
|
3175
|
+
* Merging strategy:
|
|
3176
|
+
* - Uses lodash merge for deep object merging
|
|
3177
|
+
* - Preserves existing options not specified in update
|
|
3178
|
+
* - Supports nested object updates
|
|
3179
|
+
* - Maintains type safety through generic constraints
|
|
3180
|
+
* - Handles arrays and primitives appropriately
|
|
3181
|
+
*
|
|
3182
|
+
* Update behavior:
|
|
3183
|
+
* - New options override existing ones
|
|
3184
|
+
* - Nested objects are merged recursively
|
|
3185
|
+
* - Arrays are replaced (not merged)
|
|
3186
|
+
* - Primitives are replaced directly
|
|
3187
|
+
* - Undefined values are ignored
|
|
3188
|
+
*
|
|
3189
|
+
* Type safety:
|
|
3190
|
+
* - Maintains generic type constraints
|
|
3191
|
+
* - Preserves option structure
|
|
3192
|
+
* - Validates option types at runtime
|
|
3193
|
+
* - Supports partial option updates
|
|
3194
|
+
*
|
|
3195
|
+
* @param options - Partial options to merge with current configuration
|
|
3196
|
+
*
|
|
3197
|
+
* @example Basic update
|
|
3198
|
+
* ```typescript
|
|
3199
|
+
* this.setOptions({ debug: true });
|
|
3200
|
+
* // Merges debug: true with existing options
|
|
3201
|
+
* ```
|
|
3202
|
+
*
|
|
3203
|
+
* @example Nested update
|
|
3204
|
+
* ```typescript
|
|
3205
|
+
* this.setOptions({
|
|
3206
|
+
* build: { target: 'production', minify: true }
|
|
3207
|
+
* });
|
|
3208
|
+
* // Merges nested build configuration
|
|
3209
|
+
* ```
|
|
3210
|
+
*/
|
|
3211
|
+
setOptions(options: Partial<Opt>): void;
|
|
3212
|
+
/**
|
|
3213
|
+
* Retrieves environment variable with optional default value
|
|
3214
|
+
*
|
|
3215
|
+
* Core concept:
|
|
3216
|
+
* Provides safe access to environment variables with
|
|
3217
|
+
* default value fallback, delegating to the underlying
|
|
3218
|
+
* Env.get method for consistent behavior.
|
|
3219
|
+
*
|
|
3220
|
+
* Access features:
|
|
3221
|
+
* - Safe access to environment variables
|
|
3222
|
+
* - Default value fallback when variable not found
|
|
3223
|
+
* - Delegates to Env.get method for consistency
|
|
3224
|
+
* - Handles undefined and null values gracefully
|
|
3225
|
+
* - Maintains environment variable type safety
|
|
3226
|
+
*
|
|
3227
|
+
* Default behavior:
|
|
3228
|
+
* - Returns undefined if variable not found and no default provided
|
|
3229
|
+
* - Returns default value if variable not found and default provided
|
|
3230
|
+
* - Returns actual value if variable exists
|
|
3231
|
+
* - Handles empty string values appropriately
|
|
3232
|
+
*
|
|
3233
|
+
* @param key - Environment variable name to retrieve
|
|
3234
|
+
* @param defaultValue - Optional default value if variable not found
|
|
3235
|
+
* @returns Environment variable value or default, undefined if not found
|
|
3236
|
+
*
|
|
3237
|
+
* @example Basic access
|
|
3238
|
+
* ```typescript
|
|
3239
|
+
* const apiKey = this.getEnv('API_KEY');
|
|
3240
|
+
* // Returns API_KEY value or undefined
|
|
3241
|
+
* ```
|
|
3242
|
+
*
|
|
3243
|
+
* @example With default
|
|
3244
|
+
* ```typescript
|
|
3245
|
+
* const port = this.getEnv('PORT', '3000');
|
|
3246
|
+
* // Returns PORT value or '3000' if not found
|
|
3247
|
+
* ```
|
|
3248
|
+
*
|
|
3249
|
+
* @example Boolean handling
|
|
3250
|
+
* ```typescript
|
|
3251
|
+
* const debug = this.getEnv('DEBUG', 'false');
|
|
3252
|
+
* const isDebug = debug === 'true';
|
|
3253
|
+
* ```
|
|
3254
|
+
*/
|
|
3255
|
+
getEnv(key: string, defaultValue?: string): string | undefined;
|
|
3256
|
+
/**
|
|
3257
|
+
* Retrieves configuration options with nested path support
|
|
3258
|
+
*
|
|
3259
|
+
* Core concept:
|
|
3260
|
+
* Provides safe access to configuration options using
|
|
3261
|
+
* lodash get for nested path support, with type-safe
|
|
3262
|
+
* return values and default value fallback.
|
|
3263
|
+
*
|
|
3264
|
+
* Access features:
|
|
3265
|
+
* - Safe nested object access using lodash get
|
|
3266
|
+
* - Type-safe return values with generic constraints
|
|
3267
|
+
* - Default value support for missing keys
|
|
3268
|
+
* - Full options object access when no key provided
|
|
3269
|
+
* - Support for both string and array path formats
|
|
3270
|
+
*
|
|
3271
|
+
* Path formats:
|
|
3272
|
+
* - String: 'build.target' for nested access
|
|
3273
|
+
* - Array: ['build', 'target'] for explicit path
|
|
3274
|
+
* - Empty: Returns full options object
|
|
3275
|
+
* - Invalid: Returns default value or undefined
|
|
3276
|
+
*
|
|
3277
|
+
* Type safety:
|
|
3278
|
+
* - Generic type parameter for return type
|
|
3279
|
+
* - Type inference from default values
|
|
3280
|
+
* - Runtime type validation
|
|
3281
|
+
* - Consistent return type handling
|
|
3282
|
+
*
|
|
3283
|
+
* @param key - Optional path to specific option (string or array)
|
|
3284
|
+
* @param defaultValue - Default value if option not found
|
|
3285
|
+
* @returns Option value or default, full options if no key provided
|
|
3286
|
+
*
|
|
3287
|
+
* @example Basic access
|
|
3288
|
+
* ```typescript
|
|
3289
|
+
* const debug = this.getOptions('debug', false);
|
|
3290
|
+
* // Returns debug option or false if not found
|
|
3291
|
+
* ```
|
|
3292
|
+
*
|
|
3293
|
+
* @example Nested access
|
|
3294
|
+
* ```typescript
|
|
3295
|
+
* const target = this.getOptions('build.target', 'development');
|
|
3296
|
+
* // Returns build.target or 'development' if not found
|
|
3297
|
+
* ```
|
|
3298
|
+
*
|
|
3299
|
+
* @example Array path
|
|
3300
|
+
* ```typescript
|
|
3301
|
+
* const region = this.getOptions(['deploy', 'region'], 'us-east-1');
|
|
3302
|
+
* // Returns deploy.region or 'us-east-1' if not found
|
|
3303
|
+
* ```
|
|
3304
|
+
*
|
|
3305
|
+
* @example Full options
|
|
3306
|
+
* ```typescript
|
|
3307
|
+
* const allOptions = this.getOptions();
|
|
3308
|
+
* // Returns the complete options object
|
|
3309
|
+
* ```
|
|
3310
|
+
*/
|
|
3311
|
+
getOptions<T = unknown>(key?: string | string[], defaultValue?: T): T;
|
|
3312
|
+
}
|
|
3313
|
+
|
|
3314
|
+
/**
|
|
3315
|
+
* Configuration for a single execution step
|
|
3316
|
+
*
|
|
3317
|
+
* Represents a discrete task within a script plugin with:
|
|
3318
|
+
* - Human-readable label for logging
|
|
3319
|
+
* - Optional enable/disable control
|
|
3320
|
+
* - Async task function to execute
|
|
3321
|
+
*
|
|
3322
|
+
* @example
|
|
3323
|
+
* ```typescript
|
|
3324
|
+
* const step: StepOption<string> = {
|
|
3325
|
+
* label: 'Building project',
|
|
3326
|
+
* enabled: true,
|
|
3327
|
+
* task: async () => {
|
|
3328
|
+
* // Build logic here
|
|
3329
|
+
* return 'build completed';
|
|
3330
|
+
* }
|
|
3331
|
+
* };
|
|
3332
|
+
* ```
|
|
3333
|
+
*/
|
|
3334
|
+
type StepOption<T> = {
|
|
3335
|
+
/** Human-readable label for the step, used in logging */
|
|
3336
|
+
label: string;
|
|
3337
|
+
/** Whether the step should be executed (default: true) */
|
|
3338
|
+
enabled?: boolean;
|
|
3339
|
+
/** Async function that performs the actual work */
|
|
3340
|
+
task: () => Promise<T>;
|
|
3341
|
+
};
|
|
3342
|
+
/**
|
|
3343
|
+
* Base properties for script plugin configuration
|
|
3344
|
+
*
|
|
3345
|
+
* Provides common configuration options that all script plugins can use:
|
|
3346
|
+
* - Lifecycle execution control
|
|
3347
|
+
* - Step skipping capabilities
|
|
3348
|
+
* - Plugin-specific overrides
|
|
3349
|
+
*
|
|
3350
|
+
* @example
|
|
3351
|
+
* ```typescript
|
|
3352
|
+
* const props: ScriptPluginProps = {
|
|
3353
|
+
* skip: false // Enable all lifecycle methods
|
|
3354
|
+
* };
|
|
3355
|
+
*
|
|
3356
|
+
* const props: ScriptPluginProps = {
|
|
3357
|
+
* skip: 'onBefore' // Skip only the onBefore lifecycle
|
|
3358
|
+
* };
|
|
3359
|
+
* ```
|
|
3360
|
+
*/
|
|
3361
|
+
interface ScriptPluginProps {
|
|
3362
|
+
/**
|
|
3363
|
+
* Controls whether to skip lifecycle execution
|
|
3364
|
+
*
|
|
3365
|
+
* Skip Options:
|
|
3366
|
+
* - `true` - Skip all lifecycle methods (onBefore, onExec, onSuccess, onError)
|
|
3367
|
+
* - `string` - Skip specific lifecycle method ('onBefore', 'onExec', 'onSuccess', 'onError')
|
|
3368
|
+
* - `false` or `undefined` - Execute all lifecycle methods (default)
|
|
3369
|
+
*
|
|
3370
|
+
* @example
|
|
3371
|
+
* ```typescript
|
|
3372
|
+
* // Skip all lifecycle methods
|
|
3373
|
+
* { skip: true }
|
|
3374
|
+
*
|
|
3375
|
+
* // Skip only onBefore
|
|
3376
|
+
* { skip: 'onBefore' }
|
|
3377
|
+
*
|
|
3378
|
+
* // Skip only onError
|
|
3379
|
+
* { skip: 'onError' }
|
|
3380
|
+
* ```
|
|
3381
|
+
*/
|
|
3382
|
+
skip?: boolean | string;
|
|
3383
|
+
}
|
|
3384
|
+
/**
|
|
3385
|
+
* Abstract base class for script plugins that provides common functionality
|
|
3386
|
+
*
|
|
3387
|
+
* Core Features:
|
|
3388
|
+
* - Lifecycle management (onBefore, onExec, onSuccess, onError)
|
|
3389
|
+
* - Configuration management with priority merging
|
|
3390
|
+
* - Step execution with logging
|
|
3391
|
+
* - Plugin enable/disable control
|
|
3392
|
+
* - Shell and logger access
|
|
3393
|
+
*
|
|
3394
|
+
* Design Considerations:
|
|
3395
|
+
* - Uses generic types for type-safe context and properties
|
|
3396
|
+
* - Implements ExecutorPlugin interface for integration
|
|
3397
|
+
* - Supports configuration from multiple sources with priority
|
|
3398
|
+
* - Provides consistent logging and error handling
|
|
3399
|
+
*
|
|
3400
|
+
* Configuration Priority (highest to lowest):
|
|
3401
|
+
* 1. Constructor props (runtime)
|
|
3402
|
+
* 2. Command line config (context.options[pluginName])
|
|
3403
|
+
* 3. File config (context.getOptions(pluginName))
|
|
3404
|
+
* 4. Default values
|
|
3405
|
+
*
|
|
3406
|
+
* @example Basic Plugin Implementation
|
|
3407
|
+
* ```typescript
|
|
3408
|
+
* class MyPlugin extends ScriptPlugin<MyContext, MyProps> {
|
|
3409
|
+
* async onExec(context: ExecutorContext<MyContext>): Promise<void> {
|
|
3410
|
+
* await this.step({
|
|
3411
|
+
* label: 'Processing files',
|
|
3412
|
+
* task: async () => {
|
|
3413
|
+
* // Process files logic
|
|
3414
|
+
* return 'processed';
|
|
3415
|
+
* }
|
|
3416
|
+
* });
|
|
3417
|
+
* }
|
|
3418
|
+
* }
|
|
3419
|
+
* ```
|
|
3420
|
+
*
|
|
3421
|
+
* @example Plugin with Custom Configuration
|
|
3422
|
+
* ```typescript
|
|
3423
|
+
* interface MyPluginProps extends ScriptPluginProps {
|
|
3424
|
+
* outputDir: string;
|
|
3425
|
+
* verbose: boolean;
|
|
3426
|
+
* }
|
|
3427
|
+
*
|
|
3428
|
+
* class BuildPlugin extends ScriptPlugin<BuildContext, MyPluginProps> {
|
|
3429
|
+
* async onExec(context: ExecutorContext<BuildContext>): Promise<void> {
|
|
3430
|
+
* const outputDir = this.getConfig('outputDir', './dist');
|
|
3431
|
+
* const verbose = this.getConfig('verbose', false);
|
|
3432
|
+
*
|
|
3433
|
+
* if (verbose) {
|
|
3434
|
+
* this.logger.info(`Building to ${outputDir}`);
|
|
3435
|
+
* }
|
|
3436
|
+
* }
|
|
3437
|
+
* }
|
|
3438
|
+
* ```
|
|
3439
|
+
*/
|
|
3440
|
+
declare abstract class ScriptPlugin<Context extends ScriptContext<any>, Props extends ScriptPluginProps = ScriptPluginProps> implements ExecutorPlugin<Context> {
|
|
3441
|
+
protected context: Context;
|
|
3442
|
+
readonly pluginName: string;
|
|
3443
|
+
protected props: Props;
|
|
3444
|
+
/** Ensures only one instance of this plugin can be registered */
|
|
3445
|
+
readonly onlyOne = true;
|
|
3446
|
+
/**
|
|
3447
|
+
* Creates a new script plugin instance
|
|
3448
|
+
*
|
|
3449
|
+
* Initialization Process:
|
|
3450
|
+
* 1. Stores context and plugin name references
|
|
3451
|
+
* 2. Merges configuration from multiple sources
|
|
3452
|
+
* 3. Sets up initial configuration state
|
|
3453
|
+
*
|
|
3454
|
+
* @param context - Script context providing environment and configuration
|
|
3455
|
+
* @param pluginName - Unique identifier for this plugin (used for config namespace)
|
|
3456
|
+
* @param props - Optional runtime configuration overrides
|
|
3457
|
+
*
|
|
3458
|
+
* @example
|
|
3459
|
+
* ```typescript
|
|
3460
|
+
* // Basic initialization
|
|
3461
|
+
* const plugin = new MyPlugin(context, 'my-plugin');
|
|
3462
|
+
*
|
|
3463
|
+
* // With runtime configuration
|
|
3464
|
+
* const plugin = new MyPlugin(context, 'build-plugin', {
|
|
3465
|
+
* outputDir: './custom-dist',
|
|
3466
|
+
* skip: false
|
|
3467
|
+
* });
|
|
3468
|
+
* ```
|
|
3469
|
+
*/
|
|
3470
|
+
constructor(context: Context, pluginName: string, props?: Props);
|
|
3471
|
+
/**
|
|
3472
|
+
* Merges configuration from multiple sources with proper priority
|
|
3473
|
+
*
|
|
3474
|
+
* Configuration Sources (priority order):
|
|
3475
|
+
* 1. Constructor props (highest priority)
|
|
3476
|
+
* 2. Command line config (context.options[pluginName])
|
|
3477
|
+
* 3. File config (context.getOptions(pluginName))
|
|
3478
|
+
* 4. Empty object (fallback)
|
|
3479
|
+
*
|
|
3480
|
+
* @param props - Runtime configuration overrides
|
|
3481
|
+
* @returns Merged configuration object
|
|
3482
|
+
*
|
|
3483
|
+
* @example
|
|
3484
|
+
* ```typescript
|
|
3485
|
+
* // Get merged config from all sources
|
|
3486
|
+
* const config = this.getInitialProps({
|
|
3487
|
+
* outputDir: './runtime-dist' // This will override file config
|
|
3488
|
+
* });
|
|
3489
|
+
* ```
|
|
3490
|
+
*/
|
|
3491
|
+
getInitialProps(props?: Props): Props;
|
|
3492
|
+
/**
|
|
3493
|
+
* Logger instance for structured logging
|
|
3494
|
+
*
|
|
3495
|
+
* Provides access to the context logger with proper type casting
|
|
3496
|
+
* for integration with the logging system.
|
|
3497
|
+
*
|
|
3498
|
+
* @returns LoggerInterface instance for logging operations
|
|
3499
|
+
*
|
|
3500
|
+
* @example
|
|
3501
|
+
* ```typescript
|
|
3502
|
+
* this.logger.info('Starting build process');
|
|
3503
|
+
* this.logger.error('Build failed', error);
|
|
3504
|
+
* this.logger.debug('Debug information', { config: this.options });
|
|
3505
|
+
* ```
|
|
3506
|
+
*/
|
|
3507
|
+
get logger(): LoggerInterface;
|
|
3508
|
+
/**
|
|
3509
|
+
* Shell interface for command execution
|
|
3510
|
+
*
|
|
3511
|
+
* Provides access to shell operations for executing commands,
|
|
3512
|
+
* managing processes, and file system operations.
|
|
3513
|
+
*
|
|
3514
|
+
* @returns ShellInterface instance for shell operations
|
|
3515
|
+
*
|
|
3516
|
+
* @example
|
|
3517
|
+
* ```typescript
|
|
3518
|
+
* // Execute a command
|
|
3519
|
+
* await this.shell.exec('npm run build');
|
|
3520
|
+
*
|
|
3521
|
+
* // Check if file exists
|
|
3522
|
+
* const exists = await this.shell.exists('./package.json');
|
|
3523
|
+
*
|
|
3524
|
+
* // Read file content
|
|
3525
|
+
* const content = await this.shell.readFile('./config.json');
|
|
3526
|
+
* ```
|
|
3527
|
+
*/
|
|
3528
|
+
get shell(): ShellInterface;
|
|
3529
|
+
/**
|
|
3530
|
+
* Current plugin configuration options
|
|
3531
|
+
*
|
|
3532
|
+
* Retrieves the merged configuration for this plugin from the context.
|
|
3533
|
+
* This includes all configuration sources merged with proper priority.
|
|
3534
|
+
*
|
|
3535
|
+
* @returns Current plugin configuration object
|
|
3536
|
+
*
|
|
3537
|
+
* @example
|
|
3538
|
+
* ```typescript
|
|
3539
|
+
* // Access configuration
|
|
3540
|
+
* const { outputDir, verbose } = this.options;
|
|
3541
|
+
*
|
|
3542
|
+
* // Use in conditional logic
|
|
3543
|
+
* if (this.options.skip) {
|
|
3544
|
+
* this.logger.info('Plugin execution skipped');
|
|
3545
|
+
* return;
|
|
3546
|
+
* }
|
|
3547
|
+
* ```
|
|
3548
|
+
*/
|
|
3549
|
+
get options(): Props;
|
|
3550
|
+
/**
|
|
3551
|
+
* Determines whether a lifecycle method should be executed
|
|
3552
|
+
*
|
|
3553
|
+
* Skip Logic:
|
|
3554
|
+
* - Returns `false` if skip is `true` (skip all)
|
|
3555
|
+
* - Returns `false` if skip matches the lifecycle name (skip specific)
|
|
3556
|
+
* - Returns `true` otherwise (execute normally)
|
|
3557
|
+
*
|
|
3558
|
+
* @param _name - Name of the lifecycle method being checked
|
|
3559
|
+
* @param _context - Executor context (unused in base implementation)
|
|
3560
|
+
* @returns Whether the lifecycle method should be executed
|
|
3561
|
+
*
|
|
3562
|
+
* @example
|
|
3563
|
+
* ```typescript
|
|
3564
|
+
* // Skip all lifecycle methods
|
|
3565
|
+
* const plugin = new MyPlugin(context, 'my-plugin', { skip: true });
|
|
3566
|
+
* plugin.enabled('onBefore', context); // Returns false
|
|
3567
|
+
*
|
|
3568
|
+
* // Skip specific lifecycle method
|
|
3569
|
+
* const plugin = new MyPlugin(context, 'my-plugin', { skip: 'onBefore' });
|
|
3570
|
+
* plugin.enabled('onBefore', context); // Returns false
|
|
3571
|
+
* plugin.enabled('onExec', context); // Returns true
|
|
3572
|
+
* ```
|
|
3573
|
+
*/
|
|
3574
|
+
enabled(_name: string, _context: ExecutorContext<Context>): boolean;
|
|
3575
|
+
/**
|
|
3576
|
+
* Retrieves configuration values with nested path support
|
|
3577
|
+
*
|
|
3578
|
+
* Features:
|
|
3579
|
+
* - Safe nested object access using lodash get
|
|
3580
|
+
* - Automatic plugin namespace prefixing
|
|
3581
|
+
* - Default value support for missing keys
|
|
3582
|
+
* - Type-safe return values
|
|
3583
|
+
*
|
|
3584
|
+
* @param keys - Optional path to specific configuration (string or array)
|
|
3585
|
+
* @param defaultValue - Default value if configuration not found
|
|
3586
|
+
* @returns Configuration value or default, full config if no keys provided
|
|
3587
|
+
*
|
|
3588
|
+
* @example
|
|
3589
|
+
* ```typescript
|
|
3590
|
+
* // Get full plugin configuration
|
|
3591
|
+
* const config = this.getConfig();
|
|
3592
|
+
*
|
|
3593
|
+
* // Get specific configuration value
|
|
3594
|
+
* const outputDir = this.getConfig('outputDir', './dist');
|
|
3595
|
+
*
|
|
3596
|
+
* // Get nested configuration
|
|
3597
|
+
* const buildMode = this.getConfig(['build', 'mode'], 'development');
|
|
3598
|
+
*
|
|
3599
|
+
* // Get with type safety
|
|
3600
|
+
* const port = this.getConfig<number>('port', 3000);
|
|
3601
|
+
*
|
|
3602
|
+
* // Get array configuration
|
|
3603
|
+
* const plugins = this.getConfig<string[]>('plugins', []);
|
|
3604
|
+
* ```
|
|
3605
|
+
*/
|
|
3606
|
+
getConfig<T>(keys?: string | string[], defaultValue?: T): T;
|
|
3607
|
+
/**
|
|
3608
|
+
* Updates plugin configuration with deep merging
|
|
3609
|
+
*
|
|
3610
|
+
* Merging Strategy:
|
|
3611
|
+
* - Uses lodash merge for deep object merging
|
|
3612
|
+
* - Preserves existing configuration not specified in update
|
|
3613
|
+
* - Updates configuration in the plugin's namespace
|
|
3614
|
+
* - Maintains type safety through generic constraints
|
|
3615
|
+
*
|
|
3616
|
+
* @param config - Partial configuration to merge with current settings
|
|
3617
|
+
*
|
|
3618
|
+
* @example
|
|
3619
|
+
* ```typescript
|
|
3620
|
+
* // Update single configuration
|
|
3621
|
+
* this.setConfig({ outputDir: '/new/path' });
|
|
3622
|
+
*
|
|
3623
|
+
* // Update multiple configurations
|
|
3624
|
+
* this.setConfig({
|
|
3625
|
+
* verbose: true,
|
|
3626
|
+
* buildMode: 'production'
|
|
3627
|
+
* });
|
|
3628
|
+
*
|
|
3629
|
+
* // Update nested configuration
|
|
3630
|
+
* this.setConfig({
|
|
3631
|
+
* build: {
|
|
3632
|
+
* minify: true,
|
|
3633
|
+
* sourcemap: false
|
|
3634
|
+
* }
|
|
3635
|
+
* });
|
|
3636
|
+
* ```
|
|
3637
|
+
*/
|
|
3638
|
+
setConfig(config: Partial<Props>): void;
|
|
3639
|
+
/**
|
|
3640
|
+
* Lifecycle method called before script execution
|
|
3641
|
+
*
|
|
3642
|
+
* Override this method to perform setup tasks such as:
|
|
3643
|
+
* - Environment validation
|
|
3644
|
+
* - Configuration verification
|
|
3645
|
+
* - Resource preparation
|
|
3646
|
+
* - Pre-execution checks
|
|
3647
|
+
*
|
|
3648
|
+
* @param _context - Executor context containing execution state
|
|
3649
|
+
*
|
|
3650
|
+
* @example
|
|
3651
|
+
* ```typescript
|
|
3652
|
+
* async onBefore(context: ExecutorContext<MyContext>): Promise<void> {
|
|
3653
|
+
* // Validate required environment variables
|
|
3654
|
+
* const apiKey = this.context.getEnv('API_KEY');
|
|
3655
|
+
* if (!apiKey) {
|
|
3656
|
+
* throw new Error('API_KEY environment variable is required');
|
|
3657
|
+
* }
|
|
3658
|
+
*
|
|
3659
|
+
* // Check if output directory exists
|
|
3660
|
+
* const outputDir = this.getConfig('outputDir', './dist');
|
|
3661
|
+
* if (!(await this.shell.exists(outputDir))) {
|
|
3662
|
+
* await this.shell.mkdir(outputDir);
|
|
3663
|
+
* }
|
|
3664
|
+
* }
|
|
3665
|
+
* ```
|
|
3666
|
+
*/
|
|
3667
|
+
onBefore?(_context: ExecutorContext<Context>): void | Promise<void>;
|
|
3668
|
+
/**
|
|
3669
|
+
* Lifecycle method called during script execution
|
|
3670
|
+
*
|
|
3671
|
+
* Override this method to implement the main plugin logic:
|
|
3672
|
+
* - Core functionality execution
|
|
3673
|
+
* - Business logic implementation
|
|
3674
|
+
* - Task orchestration
|
|
3675
|
+
* - Process management
|
|
3676
|
+
*
|
|
3677
|
+
* @param _context - Executor context containing execution state
|
|
3678
|
+
*
|
|
3679
|
+
* @example
|
|
3680
|
+
* ```typescript
|
|
3681
|
+
* async onExec(context: ExecutorContext<MyContext>): Promise<void> {
|
|
3682
|
+
* await this.step({
|
|
3683
|
+
* label: 'Building project',
|
|
3684
|
+
* task: async () => {
|
|
3685
|
+
* await this.shell.exec('npm run build');
|
|
3686
|
+
* return 'build completed';
|
|
3687
|
+
* }
|
|
3688
|
+
* });
|
|
3689
|
+
*
|
|
3690
|
+
* await this.step({
|
|
3691
|
+
* label: 'Running tests',
|
|
3692
|
+
* task: async () => {
|
|
3693
|
+
* await this.shell.exec('npm test');
|
|
3694
|
+
* return 'tests passed';
|
|
3695
|
+
* }
|
|
3696
|
+
* });
|
|
3697
|
+
* }
|
|
3698
|
+
* ```
|
|
3699
|
+
*/
|
|
3700
|
+
onExec?(_context: ExecutorContext<Context>): void | Promise<void>;
|
|
3701
|
+
/**
|
|
3702
|
+
* Lifecycle method called after successful script execution
|
|
3703
|
+
*
|
|
3704
|
+
* Override this method to perform cleanup tasks such as:
|
|
3705
|
+
* - Resource cleanup
|
|
3706
|
+
* - Success notifications
|
|
3707
|
+
* - Result processing
|
|
3708
|
+
* - Post-execution reporting
|
|
3709
|
+
*
|
|
3710
|
+
* @param _context - Executor context containing execution state
|
|
3711
|
+
*
|
|
3712
|
+
* @example
|
|
3713
|
+
* ```typescript
|
|
3714
|
+
* async onSuccess(context: ExecutorContext<MyContext>): Promise<void> {
|
|
3715
|
+
* // Send success notification
|
|
3716
|
+
* await this.sendNotification('Build completed successfully');
|
|
3717
|
+
*
|
|
3718
|
+
* // Generate success report
|
|
3719
|
+
* await this.generateReport({
|
|
3720
|
+
* status: 'success',
|
|
3721
|
+
* timestamp: new Date(),
|
|
3722
|
+
* duration: context.duration
|
|
3723
|
+
* });
|
|
3724
|
+
*
|
|
3725
|
+
* // Clean up temporary files
|
|
3726
|
+
* await this.shell.rmdir('./temp');
|
|
3727
|
+
* }
|
|
3728
|
+
* ```
|
|
3729
|
+
*/
|
|
3730
|
+
onSuccess?(_context: ExecutorContext<Context>): void | Promise<void>;
|
|
3731
|
+
/**
|
|
3732
|
+
* Lifecycle method called when script execution fails
|
|
3733
|
+
*
|
|
3734
|
+
* Override this method to handle errors such as:
|
|
3735
|
+
* - Error logging and reporting
|
|
3736
|
+
* - Resource cleanup on failure
|
|
3737
|
+
* - Error notifications
|
|
3738
|
+
* - Failure recovery attempts
|
|
3739
|
+
*
|
|
3740
|
+
* @param _context - Executor context containing execution state
|
|
3741
|
+
*
|
|
3742
|
+
* @example
|
|
3743
|
+
* ```typescript
|
|
3744
|
+
* async onError(context: ExecutorContext<MyContext>): Promise<void> {
|
|
3745
|
+
* // Log detailed error information
|
|
3746
|
+
* this.logger.error('Script execution failed', {
|
|
3747
|
+
* error: context.error,
|
|
3748
|
+
* duration: context.duration,
|
|
3749
|
+
* config: this.options
|
|
3750
|
+
* });
|
|
3751
|
+
*
|
|
3752
|
+
* // Send error notification
|
|
3753
|
+
* await this.sendNotification('Build failed', {
|
|
3754
|
+
* error: context.error.message
|
|
3755
|
+
* });
|
|
3756
|
+
*
|
|
3757
|
+
* // Clean up partial results
|
|
3758
|
+
* await this.shell.rmdir('./partial-build');
|
|
3759
|
+
* }
|
|
3760
|
+
* ```
|
|
3761
|
+
*/
|
|
3762
|
+
onError?(_context: ExecutorContext<Context>): void | Promise<void>;
|
|
3763
|
+
/**
|
|
3764
|
+
* Executes a step with structured logging and error handling
|
|
3765
|
+
*
|
|
3766
|
+
* Features:
|
|
3767
|
+
* - Automatic step labeling in logs
|
|
3768
|
+
* - Structured success/failure logging
|
|
3769
|
+
* - Error propagation with context
|
|
3770
|
+
* - Visual separation in log output
|
|
3771
|
+
*
|
|
3772
|
+
* Step Execution Flow:
|
|
3773
|
+
* 1. Log step start with label
|
|
3774
|
+
* 2. Execute task function
|
|
3775
|
+
* 3. Log success or error
|
|
3776
|
+
* 4. Return task result or throw error
|
|
3777
|
+
*
|
|
3778
|
+
* @param options - Step configuration object
|
|
3779
|
+
* @param {string} options.label - Human-readable label for the step
|
|
3780
|
+
* @param {() => Promise<T>} options.task - Async function that performs the step work
|
|
3781
|
+
* @param {boolean} [options.enabled] - Whether the step should be executed (default: true)
|
|
3782
|
+
* @returns The result of the task execution
|
|
3783
|
+
*
|
|
3784
|
+
* @throws {Error} When the task function throws an error
|
|
3785
|
+
*
|
|
3786
|
+
* @example
|
|
3787
|
+
* ```typescript
|
|
3788
|
+
* // Basic step execution
|
|
3789
|
+
* const result = await this.step({
|
|
3790
|
+
* label: 'Installing dependencies',
|
|
3791
|
+
* task: async () => {
|
|
3792
|
+
* await this.shell.exec('npm install');
|
|
3793
|
+
* return 'dependencies installed';
|
|
3794
|
+
* }
|
|
3795
|
+
* });
|
|
3796
|
+
*
|
|
3797
|
+
* // Step with conditional logic
|
|
3798
|
+
* await this.step({
|
|
3799
|
+
* label: 'Running tests',
|
|
3800
|
+
* enabled: this.getConfig('runTests', true),
|
|
3801
|
+
* task: async () => {
|
|
3802
|
+
* await this.shell.exec('npm test');
|
|
3803
|
+
* return 'tests passed';
|
|
3804
|
+
* }
|
|
3805
|
+
* });
|
|
3806
|
+
*
|
|
3807
|
+
* // Step with complex logic
|
|
3808
|
+
* await this.step({
|
|
3809
|
+
* label: 'Building project',
|
|
3810
|
+
* task: async () => {
|
|
3811
|
+
* const buildMode = this.getConfig('buildMode', 'development');
|
|
3812
|
+
* const command = `npm run build:${buildMode}`;
|
|
3813
|
+
* await this.shell.exec(command);
|
|
3814
|
+
* return {
|
|
3815
|
+
* mode: buildMode,
|
|
3816
|
+
* outputDir: this.getConfig('outputDir', './dist')
|
|
3817
|
+
* };
|
|
3818
|
+
* }
|
|
3819
|
+
* });
|
|
3820
|
+
* ```
|
|
3821
|
+
*/
|
|
3822
|
+
step<T>(options: StepOption<T>): Promise<T>;
|
|
3823
|
+
}
|
|
3824
|
+
|
|
3825
|
+
export { ColorFormatter, ConfigSearch, type ConfigSearchOptions, type ExecPromiseFunction, type FeConfig, type FeReleaseConfig, ScriptContext, type ScriptContextInterface, ScriptPlugin, type ScriptPluginProps, type ScriptSharedInterface, Shell, type ShellConfig, type ShellExecOptions, type ShellInterface, type StepOption, defaultFeConfig };
|