fix: bug in utils path
add an optional arg to create config path
This commit is contained in:
@@ -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)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user