Files
isocreator/ts/paths.ts

64 lines
1.3 KiB
TypeScript
Raw Normal View History

/**
* Path utilities for isocreator
*/
import { path } from './plugins.ts';
/**
* Get the user's home directory
*/
export function getHomeDir(): string {
return Deno.env.get('HOME') || Deno.env.get('USERPROFILE') || '/tmp';
}
/**
* Get the isocreator cache directory
*/
export function getCacheDir(): string {
const home = getHomeDir();
return path.join(home, '.isocreator', 'cache');
}
/**
* Get the isocreator config directory
*/
export function getConfigDir(): string {
const home = getHomeDir();
return path.join(home, '.isocreator', 'config');
}
/**
* Get the isocreator temp directory
*/
export function getTempDir(): string {
const home = getHomeDir();
return path.join(home, '.isocreator', 'temp');
}
/**
* Ensure a directory exists
*/
export async function ensureDir(dirPath: string): Promise<void> {
try {
await Deno.mkdir(dirPath, { recursive: true });
} catch (err) {
if (!(err instanceof Deno.errors.AlreadyExists)) {
throw err;
}
}
}
/**
* Clean a directory (remove and recreate)
*/
export async function cleanDir(dirPath: string): Promise<void> {
try {
await Deno.remove(dirPath, { recursive: true });
} catch (err) {
if (!(err instanceof Deno.errors.NotFound)) {
throw err;
}
}
await ensureDir(dirPath);
}