feat(mod_format): Refactor formatting modules to new BaseFormatter and implement concrete analyze/apply logic

This commit is contained in:
2025-12-15 17:07:30 +00:00
parent d5fbeb3fc6
commit b506bf8785
12 changed files with 971 additions and 88 deletions

View File

@@ -1,6 +1,15 @@
import { BaseFormatter } from '../classes.baseformatter.js';
import type { IPlannedChange } from '../interfaces.format.js';
import * as formatReadme from '../format.readme.js';
import * as plugins from '../mod.plugins.js';
import { logger } from '../../gitzone.logging.js';
const DEFAULT_README_CONTENT = `# Project Readme
This is the initial readme file.`;
const DEFAULT_README_HINTS_CONTENT = `# Project Readme Hints
This is the initial readme hints file.`;
export class ReadmeFormatter extends BaseFormatter {
get name(): string {
@@ -8,17 +17,39 @@ export class ReadmeFormatter extends BaseFormatter {
}
async analyze(): Promise<IPlannedChange[]> {
return [
{
type: 'modify',
const changes: IPlannedChange[] = [];
// Check readme.md
const readmeExists = await plugins.smartfs.file('readme.md').exists();
if (!readmeExists) {
changes.push({
type: 'create',
path: 'readme.md',
module: this.name,
description: 'Ensure readme files exist',
},
];
description: 'Create readme.md',
content: DEFAULT_README_CONTENT,
});
}
// Check readme.hints.md
const hintsExists = await plugins.smartfs.file('readme.hints.md').exists();
if (!hintsExists) {
changes.push({
type: 'create',
path: 'readme.hints.md',
module: this.name,
description: 'Create readme.hints.md',
content: DEFAULT_README_HINTS_CONTENT,
});
}
return changes;
}
async applyChange(change: IPlannedChange): Promise<void> {
await formatReadme.run();
if (change.type !== 'create' || !change.content) return;
await this.createFile(change.path, change.content);
logger.log('info', `Created ${change.path}`);
}
}