@pixpilot/scaffoldfy 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,468 @@
1
+ //#region src/types.d.ts
2
+ /**
3
+ * Task Types and Interfaces for Template Initialization
4
+ */
5
+ interface InitConfig {
6
+ repoName: string;
7
+ repoOwner: string;
8
+ repoUrl: string;
9
+ author: string;
10
+ baseRepoUrl: string;
11
+ orgName: string;
12
+ [key: string]: unknown;
13
+ }
14
+ /**
15
+ * Prompt type definitions for task-embedded prompts
16
+ */
17
+ type PromptType = 'input' | 'select' | 'confirm' | 'password' | 'number';
18
+ /**
19
+ * Default value types for prompts
20
+ * - 'value': Static value
21
+ * - 'execute': Execute a command to get the value
22
+ */
23
+ type DefaultValueType = 'value' | 'execute';
24
+ /**
25
+ * Default value configuration for prompts
26
+ */
27
+ interface DefaultValueConfig<T = string | number | boolean> {
28
+ type: DefaultValueType;
29
+ value: T | string;
30
+ }
31
+ /**
32
+ * Type for default values that can be either static or executable
33
+ */
34
+ type DefaultValue<T = string | number | boolean> = T | DefaultValueConfig<T>;
35
+ interface BasePrompt {
36
+ id: string;
37
+ type: PromptType;
38
+ message: string;
39
+ required?: boolean;
40
+ global?: boolean;
41
+ }
42
+ interface InputPrompt extends BasePrompt {
43
+ type: 'input' | 'password';
44
+ default?: DefaultValue<string>;
45
+ placeholder?: string;
46
+ }
47
+ interface NumberPrompt extends BasePrompt {
48
+ type: 'number';
49
+ default?: DefaultValue<number>;
50
+ min?: number;
51
+ max?: number;
52
+ }
53
+ interface SelectPrompt extends BasePrompt {
54
+ type: 'select';
55
+ choices: Array<{
56
+ name: string;
57
+ value: string | number | boolean;
58
+ }>;
59
+ default?: DefaultValue<string | number | boolean>;
60
+ }
61
+ interface ConfirmPrompt extends BasePrompt {
62
+ type: 'confirm';
63
+ default?: DefaultValue<boolean>;
64
+ }
65
+ type PromptDefinition = InputPrompt | NumberPrompt | SelectPrompt | ConfirmPrompt;
66
+ type TaskType = 'update-json' | 'template' | 'regex-replace' | 'replace-in-file' | 'delete' | 'rename' | 'git-init' | 'exec';
67
+ interface RollbackConfig {
68
+ type: TaskType;
69
+ config: unknown;
70
+ }
71
+ interface TaskDefinition {
72
+ id: string;
73
+ name: string;
74
+ description: string;
75
+ required: boolean;
76
+ enabled: boolean;
77
+ type: TaskType;
78
+ config: unknown;
79
+ dependencies?: string[];
80
+ rollback?: RollbackConfig;
81
+ prompts?: PromptDefinition[];
82
+ }
83
+ interface UpdateJsonConfig {
84
+ file: string;
85
+ updates: Record<string, unknown>;
86
+ condition?: string;
87
+ }
88
+ interface TemplateConfig {
89
+ file: string;
90
+ template?: string;
91
+ templateFile?: string;
92
+ condition?: string;
93
+ }
94
+ interface RegexReplaceConfig {
95
+ file: string;
96
+ pattern: string;
97
+ flags?: string;
98
+ replacement: string;
99
+ condition?: string;
100
+ }
101
+ interface ReplaceInFileConfig {
102
+ file: string;
103
+ replacements: Array<{
104
+ find: string;
105
+ replace: string;
106
+ }>;
107
+ condition?: string;
108
+ }
109
+ interface DeleteConfig {
110
+ paths: string[];
111
+ condition?: string;
112
+ }
113
+ interface RenameConfig {
114
+ from: string;
115
+ to: string;
116
+ condition?: string;
117
+ }
118
+ interface GitInitConfig {
119
+ removeExisting: boolean;
120
+ initialCommit: boolean;
121
+ message?: string;
122
+ condition?: string;
123
+ }
124
+ interface ExecConfig {
125
+ command: string;
126
+ cwd?: string;
127
+ condition?: string;
128
+ }
129
+ interface InitializationMetadata {
130
+ initializedAt: string;
131
+ config: InitConfig;
132
+ completedTasks: string[];
133
+ version: string;
134
+ }
135
+ /**
136
+ * Configuration file structure for template tasks
137
+ */
138
+ interface TasksConfiguration {
139
+ extends?: string | string[];
140
+ tasks: TaskDefinition[];
141
+ }
142
+ /**
143
+ * Plugin interface for custom task types
144
+ */
145
+ interface TaskPlugin {
146
+ name: string;
147
+ version?: string;
148
+ taskTypes: string[];
149
+ execute: (task: TaskDefinition, config: InitConfig, options: {
150
+ dryRun: boolean;
151
+ }) => Promise<void>;
152
+ getDiff?: (task: TaskDefinition, config: InitConfig) => Promise<string>;
153
+ validate?: (task: TaskDefinition) => string[];
154
+ }
155
+ /**
156
+ * Plugin lifecycle hooks
157
+ */
158
+ interface PluginHooks {
159
+ beforeAll?: (config: InitConfig) => Promise<void>;
160
+ afterAll?: (config: InitConfig) => Promise<void>;
161
+ beforeTask?: (task: TaskDefinition, config: InitConfig) => Promise<void>;
162
+ afterTask?: (task: TaskDefinition, config: InitConfig) => Promise<void>;
163
+ onError?: (error: Error, task?: TaskDefinition) => Promise<void>;
164
+ }
165
+ //#endregion
166
+ //#region src/config.d.ts
167
+ /**
168
+ * Validate the initialization configuration
169
+ */
170
+ declare function validateConfig(config: InitConfig): string[];
171
+ /**
172
+ * Collect configuration from user interactively
173
+ */
174
+ declare function collectConfig(dryRun?: boolean): Promise<InitConfig>;
175
+ //#endregion
176
+ //#region src/dry-run.d.ts
177
+ /**
178
+ * Get diff for update-json task
179
+ */
180
+ declare function getUpdateJsonDiff(config: UpdateJsonConfig, initConfig: InitConfig): Promise<string>;
181
+ /**
182
+ * Get diff for template task
183
+ */
184
+ declare function getTemplateDiff(config: TemplateConfig, initConfig: InitConfig): Promise<string>;
185
+ /**
186
+ * Get diff for regex-replace task
187
+ */
188
+ declare function getRegexReplaceDiff(config: RegexReplaceConfig, initConfig: InitConfig): Promise<string>;
189
+ /**
190
+ * Get diff for replace-in-file task
191
+ */
192
+ declare function getReplaceInFileDiff(config: ReplaceInFileConfig, initConfig: InitConfig): Promise<string>;
193
+ /**
194
+ * Get diff for delete task
195
+ */
196
+ declare function getDeleteDiff(config: DeleteConfig, initConfig: InitConfig): string;
197
+ /**
198
+ * Get diff for rename task
199
+ */
200
+ declare function getRenameDiff(config: RenameConfig, initConfig: InitConfig): string;
201
+ /**
202
+ * Get diff for git-init task
203
+ */
204
+ declare function getGitInitDiff(config: GitInitConfig): string;
205
+ /**
206
+ * Get diff for exec task
207
+ */
208
+ declare function getExecDiff(config: ExecConfig, initConfig: InitConfig): string;
209
+ /**
210
+ * Get diff for any task type
211
+ */
212
+ declare function getTaskDiff(task: TaskDefinition, initConfig: InitConfig): Promise<string>;
213
+ /**
214
+ * Display diffs for all tasks
215
+ */
216
+ declare function displayTasksDiff(tasks: TaskDefinition[], initConfig: InitConfig): Promise<void>;
217
+ //#endregion
218
+ //#region src/plugin.d.ts
219
+ /**
220
+ * Register a plugin
221
+ * @param plugin - The plugin to register
222
+ */
223
+ declare function registerPlugin(plugin: TaskPlugin): void;
224
+ /**
225
+ * Unregister a plugin
226
+ * @param pluginName - Name of the plugin to unregister
227
+ */
228
+ declare function unregisterPlugin(pluginName: string): void;
229
+ /**
230
+ * Get a plugin by name
231
+ * @param pluginName - Name of the plugin
232
+ * @returns The plugin or undefined if not found
233
+ */
234
+ declare function getPlugin(pluginName: string): TaskPlugin | undefined;
235
+ /**
236
+ * Get a plugin for a task type
237
+ * @param taskType - The task type
238
+ * @returns The plugin or undefined if not found
239
+ */
240
+ declare function getPluginForTaskType(taskType: string): TaskPlugin | undefined;
241
+ /**
242
+ * Check if a task type is handled by a plugin
243
+ * @param taskType - The task type to check
244
+ * @returns True if a plugin handles this task type
245
+ */
246
+ declare function isPluginTaskType(taskType: string): boolean;
247
+ /**
248
+ * List all registered plugins
249
+ * @returns Array of plugin names
250
+ */
251
+ declare function listPlugins(): string[];
252
+ /**
253
+ * Clear all registered plugins (useful for testing)
254
+ */
255
+ declare function clearPlugins(): void;
256
+ /**
257
+ * Register global lifecycle hooks
258
+ * @param hooks - Hook functions to register
259
+ */
260
+ declare function registerHooks(hooks: Partial<PluginHooks>): void;
261
+ /**
262
+ * Call a lifecycle hook
263
+ * @param hookName - Name of the hook
264
+ * @param config - Initialization config for beforeAll/afterAll
265
+ */
266
+ declare function callHook(hookName: 'beforeAll' | 'afterAll', config: InitConfig): Promise<void>;
267
+ /**
268
+ * Call a lifecycle hook
269
+ * @param hookName - Name of the hook
270
+ * @param task - Task definition for beforeTask/afterTask
271
+ * @param config - Initialization config
272
+ */
273
+ declare function callHook(hookName: 'beforeTask' | 'afterTask', task: TaskDefinition, config: InitConfig): Promise<void>;
274
+ /**
275
+ * Call a lifecycle hook
276
+ * @param hookName - Name of the hook
277
+ * @param error - Error that occurred
278
+ * @param task - Optional task definition
279
+ */
280
+ declare function callHook(hookName: 'onError', error: Error, task?: TaskDefinition): Promise<void>;
281
+ /**
282
+ * Execute a plugin task
283
+ * @param task - The task to execute
284
+ * @param config - The initialization config
285
+ * @param options - Execution options
286
+ * @param options.dryRun - Whether to run in dry-run mode
287
+ * @returns Promise that resolves when the task is complete
288
+ */
289
+ declare function executePluginTask(task: TaskDefinition, config: InitConfig, options: {
290
+ dryRun: boolean;
291
+ }): Promise<void>;
292
+ /**
293
+ * Get diff for a plugin task
294
+ * @param task - The task to generate diff for
295
+ * @param config - The initialization config
296
+ * @returns Diff string or undefined if not supported
297
+ */
298
+ declare function getPluginTaskDiff(task: TaskDefinition, config: InitConfig): Promise<string | undefined>;
299
+ /**
300
+ * Validate a plugin task
301
+ * @param task - The task to validate
302
+ * @returns Array of validation errors
303
+ */
304
+ declare function validatePluginTask(task: TaskDefinition): string[];
305
+ /**
306
+ * Create a simple plugin
307
+ * @param name - Plugin name
308
+ * @param taskType - Task type this plugin handles
309
+ * @param execute - Execute function
310
+ * @param options - Optional configuration
311
+ * @param options.version - Plugin version
312
+ * @param options.getDiff - Function to generate diff preview
313
+ * @param options.validate - Function to validate task configuration
314
+ * @returns A TaskPlugin object
315
+ */
316
+ declare function createPlugin(name: string, taskType: string, execute: (task: TaskDefinition, config: InitConfig, options: {
317
+ dryRun: boolean;
318
+ }) => Promise<void>, options?: {
319
+ version?: string;
320
+ getDiff?: (task: TaskDefinition, config: InitConfig) => Promise<string>;
321
+ validate?: (task: TaskDefinition) => string[];
322
+ }): TaskPlugin;
323
+ //#endregion
324
+ //#region src/prompts.d.ts
325
+ /**
326
+ * Resolve a default value that may be static or executable
327
+ * @param defaultValue - The default value configuration
328
+ * @param promptId - The prompt ID for error reporting
329
+ * @returns The resolved default value
330
+ */
331
+ declare function resolveDefaultValue<T = string | number | boolean>(defaultValue: DefaultValue<T> | undefined, promptId: string): Promise<T | undefined>;
332
+ /**
333
+ * Pre-resolve all executable default values in parallel
334
+ * @param prompts - Array of prompt definitions
335
+ * @returns Map of prompt IDs to their resolved default values
336
+ */
337
+ declare function resolveAllDefaultValues(prompts: PromptDefinition[]): Promise<Map<string, unknown>>;
338
+ /**
339
+ * Collect prompt answers from task-defined prompts
340
+ * @param prompts - Array of prompt definitions from tasks
341
+ * @param resolvedDefaults - Map of pre-resolved default values
342
+ * @returns Object mapping prompt IDs to their values
343
+ */
344
+ declare function collectPrompts(prompts: PromptDefinition[], resolvedDefaults?: Map<string, unknown>): Promise<Record<string, unknown>>;
345
+ /**
346
+ * Validate prompt definitions
347
+ * @param prompts - Array of prompt definitions to validate
348
+ * @returns Array of validation error messages
349
+ */
350
+ declare function validatePrompts(prompts: PromptDefinition[]): string[];
351
+ //#endregion
352
+ //#region src/state.d.ts
353
+ /**
354
+ * Load initialization state from file
355
+ */
356
+ declare function loadInitializationState(): InitializationMetadata | null;
357
+ /**
358
+ * Save initialization state to file
359
+ */
360
+ declare function saveInitializationState(config: InitConfig, completedTasks: string[], dryRun?: boolean): void;
361
+ //#endregion
362
+ //#region src/task-executors.d.ts
363
+ /**
364
+ * Execute a task based on its type
365
+ */
366
+ declare function executeTask(task: TaskDefinition, config: InitConfig, dryRun?: boolean): Promise<void>;
367
+ /**
368
+ * Run a single task with error handling
369
+ */
370
+ declare function runTask(task: TaskDefinition, config: InitConfig, taskNumber: number, totalTasks: number, dryRun?: boolean): Promise<boolean>;
371
+ //#endregion
372
+ //#region src/task-resolver.d.ts
373
+ /**
374
+ * Sort tasks by dependencies using topological sort
375
+ */
376
+ declare function topologicalSort(tasks: TaskDefinition[]): TaskDefinition[];
377
+ //#endregion
378
+ //#region src/template-inheritance.d.ts
379
+ /**
380
+ * Load a template configuration file
381
+ * @param templatePath - Path to the template file
382
+ * @param visitedPaths - Set of already visited paths to detect circular dependencies
383
+ * @returns The loaded template configuration
384
+ */
385
+ declare function loadTemplate(templatePath: string, visitedPaths?: Set<string>): Promise<TasksConfiguration>;
386
+ /**
387
+ * Recursively load and merge templates
388
+ * @param templatePath - Path to the template file
389
+ * @param baseDir - Base directory for resolving relative paths in extends
390
+ * @param visitedPaths - Set of already visited paths
391
+ * @returns Merged template configuration
392
+ */
393
+ declare function loadAndMergeTemplate(templatePath: string, baseDir?: string, visitedPaths?: Set<string>): Promise<TasksConfiguration>;
394
+ /**
395
+ * Merge multiple template configurations
396
+ * Later templates override earlier ones for conflicting task IDs
397
+ * @param templates - Array of templates to merge (in priority order)
398
+ * @returns Merged template configuration
399
+ */
400
+ declare function mergeTemplates(templates: TasksConfiguration[]): TasksConfiguration;
401
+ /**
402
+ * Clear the template cache (useful for testing)
403
+ */
404
+ declare function clearTemplateCache(): void;
405
+ /**
406
+ * Load tasks from a configuration file with template inheritance support
407
+ * @param tasksFilePath - Path to the tasks configuration file
408
+ * @returns Array of task definitions
409
+ */
410
+ declare function loadTasksWithInheritance(tasksFilePath: string): Promise<TaskDefinition[]>;
411
+ //#endregion
412
+ //#region src/utils.d.ts
413
+ /**
414
+ * Get Git repository information from the current directory
415
+ */
416
+ declare function getGitRepoInfo(): {
417
+ owner: string;
418
+ name: string;
419
+ url: string;
420
+ } | null;
421
+ /**
422
+ * Prompt user for input with optional default value
423
+ */
424
+ declare function prompt(question: string, defaultValue?: string): Promise<string>;
425
+ /**
426
+ * Prompt user for yes/no answer
427
+ */
428
+ declare function promptYesNo(question: string, defaultValue?: boolean): Promise<boolean>;
429
+ /**
430
+ * Log message with colored output
431
+ */
432
+ declare function log(message: string, type?: 'info' | 'success' | 'error' | 'warn'): void;
433
+ /**
434
+ * Interpolate template variables in a string
435
+ */
436
+ declare function interpolateTemplate(template: string, config: InitConfig): string;
437
+ /**
438
+ * Set a nested property in an object using dot notation
439
+ */
440
+ declare function setNestedProperty(obj: Record<string, unknown>, propertyPath: string, value: unknown): void;
441
+ /**
442
+ * Evaluate a condition expression with the given config
443
+ */
444
+ declare function evaluateCondition(condition: string, config: InitConfig): boolean;
445
+ //#endregion
446
+ //#region src/index.d.ts
447
+ /**
448
+ * Main function for running initialization with default/empty tasks
449
+ * For most use cases, you should use runWithTasks() with your custom tasks
450
+ */
451
+ declare function main(customTasks?: TaskDefinition[]): Promise<void>;
452
+ /**
453
+ * Run initialization with custom tasks
454
+ * @param customTasks - Array of task definitions to execute
455
+ * @param options - Optional configuration
456
+ * @param options.dryRun - Preview changes without applying them
457
+ * @param options.force - Force re-initialization even if already initialized
458
+ * @param options.keepTasksFile - Whether to keep the tasks file after initialization
459
+ * @param options.tasksFilePath - Path to the tasks file
460
+ */
461
+ declare function runWithTasks(customTasks: TaskDefinition[], options?: {
462
+ dryRun?: boolean | undefined;
463
+ force?: boolean | undefined;
464
+ keepTasksFile?: boolean | undefined;
465
+ tasksFilePath?: string | undefined;
466
+ }): Promise<void>;
467
+ //#endregion
468
+ export { BasePrompt, ConfirmPrompt, DefaultValue, DefaultValueConfig, DefaultValueType, DeleteConfig, ExecConfig, GitInitConfig, InitConfig, InitializationMetadata, InputPrompt, NumberPrompt, PluginHooks, PromptDefinition, PromptType, RegexReplaceConfig, RenameConfig, ReplaceInFileConfig, RollbackConfig, SelectPrompt, TaskDefinition, TaskPlugin, TaskType, TasksConfiguration, TemplateConfig, UpdateJsonConfig, callHook, clearPlugins, clearTemplateCache, collectConfig, collectPrompts, createPlugin, displayTasksDiff, evaluateCondition, executePluginTask, executeTask, getDeleteDiff, getExecDiff, getGitInitDiff, getGitRepoInfo, getPlugin, getPluginForTaskType, getPluginTaskDiff, getRegexReplaceDiff, getRenameDiff, getReplaceInFileDiff, getTaskDiff, getTemplateDiff, getUpdateJsonDiff, interpolateTemplate, isPluginTaskType, listPlugins, loadAndMergeTemplate, loadInitializationState, loadTasksWithInheritance, loadTemplate, log, main, mergeTemplates, prompt, promptYesNo, registerHooks, registerPlugin, resolveAllDefaultValues, resolveDefaultValue, runTask, runWithTasks, saveInitializationState, setNestedProperty, topologicalSort, unregisterPlugin, validateConfig, validatePluginTask, validatePrompts };