import * as plugins from './mod.plugins.js'; export interface ICommitConfig { alwaysTest: boolean; alwaysBuild: boolean; confirmation: 'prompt' | 'auto' | 'plan'; steps: string[]; } /** * Manages commit configuration stored in .smartconfig.json * under @git.zone/cli.commit namespace */ export class CommitConfig { private cwd: string; private config: ICommitConfig; constructor(cwd: string = process.cwd()) { this.cwd = cwd; this.config = { alwaysTest: false, alwaysBuild: false, confirmation: 'prompt', steps: ['analyze', 'changelog', 'commit'] }; } /** * Create a CommitConfig instance from current working directory */ public static async fromCwd(cwd: string = process.cwd()): Promise { const instance = new CommitConfig(cwd); await instance.load(); return instance; } /** * Load configuration from .smartconfig.json */ public async load(): Promise { const smartconfigInstance = new plugins.smartconfig.Smartconfig(this.cwd); const gitzoneConfig = smartconfigInstance.dataFor('@git.zone/cli', {}); const alwaysTest = gitzoneConfig?.commit?.alwaysTest ?? false; const alwaysBuild = gitzoneConfig?.commit?.alwaysBuild ?? false; this.config = { alwaysTest, alwaysBuild, confirmation: gitzoneConfig?.commit?.confirmation ?? 'prompt', steps: gitzoneConfig?.commit?.steps || [ 'analyze', ...(alwaysTest ? ['test'] : []), ...(alwaysBuild ? ['build'] : []), 'changelog', 'commit', ], }; } /** * Save configuration to .smartconfig.json */ public async save(): Promise { const smartconfigPath = plugins.path.join(this.cwd, '.smartconfig.json'); let smartconfigData: any = {}; // Read existing .smartconfig.json if (await plugins.smartfs.file(smartconfigPath).exists()) { const content = await plugins.smartfs.file(smartconfigPath).encoding('utf8').read(); smartconfigData = JSON.parse(content as string); } // Ensure @git.zone/cli namespace exists if (!smartconfigData['@git.zone/cli']) { smartconfigData['@git.zone/cli'] = {}; } // Ensure commit object exists if (!smartconfigData['@git.zone/cli'].commit) { smartconfigData['@git.zone/cli'].commit = {}; } // Update commit settings smartconfigData['@git.zone/cli'].commit.alwaysTest = this.config.alwaysTest; smartconfigData['@git.zone/cli'].commit.alwaysBuild = this.config.alwaysBuild; smartconfigData['@git.zone/cli'].commit.confirmation = this.config.confirmation; smartconfigData['@git.zone/cli'].commit.steps = this.config.steps; // Write back to file await plugins.smartfs .file(smartconfigPath) .encoding('utf8') .write(JSON.stringify(smartconfigData, null, 2)); } /** * Get alwaysTest setting */ public getAlwaysTest(): boolean { return this.config.alwaysTest; } /** * Set alwaysTest setting */ public setAlwaysTest(value: boolean): void { this.config.alwaysTest = value; } /** * Get alwaysBuild setting */ public getAlwaysBuild(): boolean { return this.config.alwaysBuild; } /** * Set alwaysBuild setting */ public setAlwaysBuild(value: boolean): void { this.config.alwaysBuild = value; } public getConfirmation(): 'prompt' | 'auto' | 'plan' { return this.config.confirmation; } public setConfirmation(value: 'prompt' | 'auto' | 'plan'): void { this.config.confirmation = value; } public getSteps(): string[] { return [...this.config.steps]; } public setSteps(steps: string[]): void { this.config.steps = [...steps]; } }