genaiscript
Version:
A CLI for GenAIScript, a generative AI scripting framework.
30 lines • 1.29 kB
JavaScript
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { join } from "node:path";
import { dotGenaiscriptPath, sanitizeFilename } from "@genaiscript/core";
import { rmDir } from "@genaiscript/core";
/**
* This module provides a function to clear a specified cache directory.
*/
/**
* Asynchronously clears the specified cache directory.
*
* This function removes all contents within the cache directory. If the 'name'
* parameter is 'tests', it specifically targets and clears a subdirectory named 'tests'
* within the cache directory.
*
* @param name - The name of the subdirectory to clear.
* If 'tests', it targets a specific subdirectory within the cache.
*/
export async function cacheClear(name) {
// Get the base cache directory path using the dotGenaiscriptPath utility function.
let dir = dotGenaiscriptPath("cache");
// If the name is 'tests', adjust the directory path to include the 'tests' subdirectory.
if (["tests"].includes(name))
dir = join(dir, sanitizeFilename(name));
// Log the directory being cleared to the console for debugging purposes.
console.log(`removing ${dir}`);
// Clear the contents of the directory asynchronously.
await rmDir(dir);
}
//# sourceMappingURL=cache.js.map