captan
Version:
Captan — Command your ownership. A tiny, hackable CLI cap table tool.
35 lines • 1.08 kB
JavaScript
import fs from 'node:fs';
import path from 'node:path';
import { FileModelSchema } from './model.js';
import { getCurrentTimestamp } from './utils/date-utils.js';
export function load(file = 'captable.json') {
if (!fs.existsSync(file)) {
throw new Error(`File not found: ${file}. Run 'captan init' to create a new cap table.`);
}
const content = fs.readFileSync(file, 'utf8');
const data = JSON.parse(content);
return FileModelSchema.parse(data);
}
export function save(model, file = 'captable.json') {
ensureDirFor(file);
fs.writeFileSync(file, JSON.stringify(model, null, 2));
}
export function audit(model, action, data, by = 'cli') {
const entry = {
ts: getCurrentTimestamp(),
by,
action,
data,
};
model.audit.push(entry);
}
export function ensureDirFor(file) {
const dir = path.dirname(path.resolve(file));
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}
}
export function exists(file) {
return fs.existsSync(file);
}
//# sourceMappingURL=store.js.map