update to smartconfig
This commit is contained in:
@@ -2,13 +2,12 @@ import * as plugins from './mod.plugins.js';
|
||||
import { FormatContext } from './classes.formatcontext.js';
|
||||
import { BaseFormatter } from './classes.baseformatter.js';
|
||||
import type { IFormatPlan, IPlannedChange } from './interfaces.format.js';
|
||||
import { getModuleIcon } from './interfaces.format.js';
|
||||
import { logger } from '../gitzone.logging.js';
|
||||
import { DependencyAnalyzer } from './classes.dependency-analyzer.js';
|
||||
import { DiffReporter } from './classes.diffreporter.js';
|
||||
|
||||
export class FormatPlanner {
|
||||
private plannedChanges: Map<string, IPlannedChange[]> = new Map();
|
||||
private dependencyAnalyzer = new DependencyAnalyzer();
|
||||
private diffReporter = new DiffReporter();
|
||||
|
||||
async planFormat(modules: BaseFormatter[]): Promise<IFormatPlan> {
|
||||
@@ -18,7 +17,6 @@ export class FormatPlanner {
|
||||
filesAdded: 0,
|
||||
filesModified: 0,
|
||||
filesRemoved: 0,
|
||||
estimatedTime: 0,
|
||||
},
|
||||
changes: [],
|
||||
warnings: [],
|
||||
@@ -32,7 +30,6 @@ export class FormatPlanner {
|
||||
for (const change of changes) {
|
||||
plan.changes.push(change);
|
||||
|
||||
// Update summary
|
||||
switch (change.type) {
|
||||
case 'create':
|
||||
plan.summary.filesAdded++;
|
||||
@@ -58,7 +55,6 @@ export class FormatPlanner {
|
||||
plan.summary.filesAdded +
|
||||
plan.summary.filesModified +
|
||||
plan.summary.filesRemoved;
|
||||
plan.summary.estimatedTime = plan.summary.totalFiles * 100; // 100ms per file estimate
|
||||
|
||||
return plan;
|
||||
}
|
||||
@@ -67,27 +63,20 @@ export class FormatPlanner {
|
||||
plan: IFormatPlan,
|
||||
modules: BaseFormatter[],
|
||||
context: FormatContext,
|
||||
parallel: boolean = false,
|
||||
): Promise<void> {
|
||||
const startTime = Date.now();
|
||||
|
||||
try {
|
||||
// Always use sequential execution to avoid race conditions
|
||||
for (const module of modules) {
|
||||
const changes = this.plannedChanges.get(module.name) || [];
|
||||
for (const module of modules) {
|
||||
const changes = this.plannedChanges.get(module.name) || [];
|
||||
|
||||
if (changes.length > 0) {
|
||||
logger.log('info', `Executing ${module.name} formatter...`);
|
||||
await module.execute(changes);
|
||||
}
|
||||
if (changes.length > 0) {
|
||||
logger.log('info', `Executing ${module.name} formatter...`);
|
||||
await module.execute(changes);
|
||||
}
|
||||
|
||||
const endTime = Date.now();
|
||||
const duration = endTime - startTime;
|
||||
logger.log('info', `Format operations completed in ${duration}ms`);
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
const duration = Date.now() - startTime;
|
||||
logger.log('info', `Format operations completed in ${duration}ms`);
|
||||
}
|
||||
|
||||
async displayPlan(
|
||||
@@ -103,7 +92,6 @@ export class FormatPlanner {
|
||||
console.log('');
|
||||
console.log('Changes by module:');
|
||||
|
||||
// Group changes by module
|
||||
const changesByModule = new Map<string, IPlannedChange[]>();
|
||||
for (const change of plan.changes) {
|
||||
const moduleChanges = changesByModule.get(change.module) || [];
|
||||
@@ -113,14 +101,13 @@ export class FormatPlanner {
|
||||
|
||||
for (const [module, changes] of changesByModule) {
|
||||
console.log(
|
||||
`\n${this.getModuleIcon(module)} ${module} (${changes.length} ${changes.length === 1 ? 'file' : 'files'})`,
|
||||
`\n${getModuleIcon(module)} ${module} (${changes.length} ${changes.length === 1 ? 'file' : 'files'})`,
|
||||
);
|
||||
|
||||
for (const change of changes) {
|
||||
const icon = this.getChangeIcon(change.type);
|
||||
console.log(` ${icon} ${change.path} - ${change.description}`);
|
||||
|
||||
// Show diff for modified files if detailed view is requested
|
||||
if (detailed && change.type === 'modify') {
|
||||
const diff = await this.diffReporter.generateDiffForChange(change);
|
||||
if (diff) {
|
||||
@@ -141,22 +128,6 @@ export class FormatPlanner {
|
||||
console.log('\n' + '━'.repeat(50));
|
||||
}
|
||||
|
||||
private getModuleIcon(module: string): string {
|
||||
const icons: Record<string, string> = {
|
||||
packagejson: '📦',
|
||||
license: '📝',
|
||||
tsconfig: '🔧',
|
||||
cleanup: '🚮',
|
||||
gitignore: '🔒',
|
||||
prettier: '✨',
|
||||
readme: '📖',
|
||||
templates: '📄',
|
||||
npmextra: '⚙️',
|
||||
copy: '📋',
|
||||
};
|
||||
return icons[module] || '📁';
|
||||
}
|
||||
|
||||
private getChangeIcon(type: 'create' | 'modify' | 'delete'): string {
|
||||
switch (type) {
|
||||
case 'create':
|
||||
|
||||
Reference in New Issue
Block a user