update to smartconfig

This commit is contained in:
2026-03-24 16:10:51 +00:00
parent eda67395fe
commit d0d922e53b
41 changed files with 425 additions and 2091 deletions

View File

@@ -1,42 +1,39 @@
import { BaseFormatter } from '../classes.baseformatter.js';
import type { IPlannedChange } from '../interfaces.format.js';
import * as plugins from '../mod.plugins.js';
import * as paths from '../../paths.js';
import { logger } from '../../gitzone.logging.js';
// Standard gitignore template content (without front-matter)
const GITIGNORE_TEMPLATE = `.nogit/
# artifacts
coverage/
public/
# installs
node_modules/
# caches
.yarn/
.cache/
.rpt2_cache
# builds
dist/
dist_*/
# AI
.claude/
.serena/
#------# custom`;
export class GitignoreFormatter extends BaseFormatter {
get name(): string {
return 'gitignore';
}
/**
* Read the standard gitignore template from the asset file,
* stripping the YAML frontmatter.
*/
private async getStandardTemplate(): Promise<string> {
const templatePath = plugins.path.join(paths.templatesDir, 'gitignore', '_gitignore');
const raw = (await plugins.smartfs
.file(templatePath)
.encoding('utf8')
.read()) as string;
// Strip YAML frontmatter (---\n...\n---)
const frontmatterEnd = raw.indexOf('---', 3);
if (frontmatterEnd !== -1) {
return raw.slice(frontmatterEnd + 3).trimStart();
}
return raw;
}
async analyze(): Promise<IPlannedChange[]> {
const changes: IPlannedChange[] = [];
const gitignorePath = '.gitignore';
const standardTemplate = await this.getStandardTemplate();
// Check if file exists and extract custom content
let customContent = '';
const exists = await plugins.smartfs.file(gitignorePath).exists();
@@ -59,11 +56,11 @@ export class GitignoreFormatter extends BaseFormatter {
}
// Compute new content
let newContent = GITIGNORE_TEMPLATE;
let newContent = standardTemplate;
if (customContent) {
newContent = GITIGNORE_TEMPLATE + '\n' + customContent + '\n';
newContent = standardTemplate + '\n' + customContent + '\n';
} else {
newContent = GITIGNORE_TEMPLATE + '\n';
newContent = standardTemplate + '\n';
}
// Read current content to compare
@@ -75,7 +72,6 @@ export class GitignoreFormatter extends BaseFormatter {
.read()) as string;
}
// Determine change type
if (!exists) {
changes.push({
type: 'create',