56 lines
1.5 KiB
TypeScript
56 lines
1.5 KiB
TypeScript
import { BaseFormatter } from '../classes.baseformatter.js';
|
|
import type { IPlannedChange } from '../interfaces.format.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 {
|
|
return 'readme';
|
|
}
|
|
|
|
async analyze(): Promise<IPlannedChange[]> {
|
|
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: '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> {
|
|
if (change.type !== 'create' || !change.content) return;
|
|
|
|
await this.createFile(change.path, change.content);
|
|
logger.log('info', `Created ${change.path}`);
|
|
}
|
|
}
|