Skip to content

Commit 18df63a

Browse files
TonyCaseyclaude
andauthored
feat: update init.ts to write YAML config (GIT-90) (#61)
* feat: update init.ts to write YAML config (GIT-90) - Create .git-mem/ directory if it doesn't exist - Write config as YAML to .git-mem/.git-mem.yaml - Update .gitignore to ignore .git-mem/ directory - Parse existing config as YAML when merging Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> AI-Agent: Claude-Code/2.1.42 AI-Model: claude-opus-4-5-20251101 AI-Decision: update init.ts to write YAML config (GIT-90). - Create .git-mem/ directory if it doesn't exist AI-Confidence: medium AI-Tags: commands, typescript AI-Lifecycle: project AI-Memory-Id: 4c2e5a59 AI-Source: heuristic * fix: guard YAML parsing against null values parseYaml() returns null for empty files. Add type guard to coerce null/non-object results to empty object before passing to deepMergeGitMemConfig(). Addresses CodeRabbit review feedback. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> AI-Agent: Claude-Code/2.1.42 AI-Model: claude-opus-4-5-20251101 AI-Gotcha: guard YAML parsing against null values. parseYaml() returns null for empty files. Add type guard to coerce AI-Confidence: medium AI-Tags: commands, typescript AI-Lifecycle: project AI-Memory-Id: 3d999379 AI-Source: heuristic --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 6d1e0c0 commit 18df63a

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

src/commands/init.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { existsSync, readFileSync, writeFileSync, appendFileSync, mkdirSync } fr
99
import { execFileSync } from 'child_process';
1010
import { join } from 'path';
1111
import prompts from 'prompts';
12+
import { parse as parseYaml, stringify as stringifyYaml } from 'yaml';
1213
import type { ILogger } from '../domain/interfaces/ILogger';
1314
import {
1415
getSettingsPath,
@@ -24,6 +25,7 @@ import { installPostCommitHook, uninstallPostCommitHook } from '../hooks/post-co
2425
import { installCommitMsgHook, uninstallCommitMsgHook } from '../hooks/commit-msg';
2526
import { createContainer } from '../infrastructure/di';
2627
import { createStderrProgressHandler } from './progress';
28+
import { getConfigPath, getConfigDir } from '../hooks/utils/config';
2729

2830
interface IInitCommandOptions {
2931
yes?: boolean;
@@ -245,14 +247,26 @@ export async function initCommand(options: IInitCommandOptions, logger?: ILogger
245247
writeFileSync(settingsPath, JSON.stringify(settings, null, 2) + '\n');
246248
console.log(`✓ Created ${settingsPath}`);
247249

248-
// .git-mem.json
249-
const gitMemConfigPath = join(cwd, '.git-mem.json');
250-
const existingGitMemConfig = existsSync(gitMemConfigPath)
251-
? (() => { try { return JSON.parse(readFileSync(gitMemConfigPath, 'utf8')) as Record<string, unknown>; } catch { return {}; } })()
252-
: {};
250+
// .git-mem/.git-mem.yaml
251+
const configDir = getConfigDir(cwd);
252+
const configPath = getConfigPath(cwd);
253+
if (!existsSync(configDir)) {
254+
mkdirSync(configDir, { recursive: true });
255+
}
256+
const existingGitMemConfig = (() => {
257+
if (!existsSync(configPath)) return {};
258+
try {
259+
const parsed = parseYaml(readFileSync(configPath, 'utf8'));
260+
return parsed && typeof parsed === 'object' && !Array.isArray(parsed)
261+
? (parsed as Record<string, unknown>)
262+
: {};
263+
} catch {
264+
return {};
265+
}
266+
})();
253267
const mergedGitMemConfig = deepMergeGitMemConfig(existingGitMemConfig, buildGitMemConfig());
254-
writeFileSync(gitMemConfigPath, JSON.stringify(mergedGitMemConfig, null, 2) + '\n');
255-
console.log('✓ Created .git-mem.json');
268+
writeFileSync(configPath, stringifyYaml(mergedGitMemConfig));
269+
console.log('✓ Created .git-mem/.git-mem.yaml');
256270
}
257271

258272
// ── Git hooks (prepare-commit-msg, commit-msg, post-commit) ─────
@@ -295,7 +309,7 @@ export async function initCommand(options: IInitCommandOptions, logger?: ILogger
295309
}
296310

297311
// ── .gitignore ─────────────────────────────────────────────────
298-
ensureGitignoreEntries(cwd, ['.env', '.git-mem.json']);
312+
ensureGitignoreEntries(cwd, ['.env', '.git-mem/']);
299313
console.log('✓ Updated .gitignore');
300314

301315
// ── .env placeholder ──────────────────────────────────────────

0 commit comments

Comments
 (0)