fix: bug in utils path

add an optional arg to create config path
This commit is contained in:
Joe Fleming
2026-03-13 20:06:59 -06:00
parent e915dd2922
commit 1dd953d17a

View File

@@ -11,19 +11,25 @@ export function resolvePath(raw: string): string {
return resolve(raw); return resolve(raw);
} }
export function ensureWorkspace(rawPath: string): string { export function ensureWorkspace(rawPath: string, createIfMissing = true): string {
const path = resolvePath(rawPath); const path = resolvePath(rawPath);
if (!existsSync(path)) { if (!existsSync(path)) {
if (createIfMissing) {
mkdirSync(path, { recursive: true }); mkdirSync(path, { recursive: true });
} else {
throw new Error(
`Workspace does not exist: ${path}\nRun 'nanobot onboard' to initialize.`,
);
}
} }
return path; return path;
} }
export function syncTemplates(workspacePath: string): string[] { export function syncTemplates(workspacePath: string): string[] {
// Get project root relative to this file // Get project root relative to this file (src/cli/utils.ts)
const currentFile = fileURLToPath(import.meta.url); const currentFile = fileURLToPath(import.meta.url);
const srcDir = dirname(currentFile); const srcDir = dirname(currentFile);
const projectRoot = resolve(srcDir, '..'); const projectRoot = resolve(srcDir, '..', '..');
const templatesDir = resolve(projectRoot, 'templates'); const templatesDir = resolve(projectRoot, 'templates');
if (!existsSync(templatesDir)) { if (!existsSync(templatesDir)) {