feat(core): Initial project scaffold and implementation: Deno CLI, ISO tooling, cloud-init generation, packaging and installer scripts
This commit is contained in:
63
ts/paths.ts
Normal file
63
ts/paths.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
Reference in New Issue
Block a user