@giancarl021/cli-core-vault-extension
Version:
Plain and secure storage extension for the @giancarl021/cli-core npm package
17 lines (14 loc) • 467 B
JavaScript
import { existsSync, mkdirSync, lstatSync } from 'node:fs';
/**
* Ensure that the directory for the given path exists, creating it if necessary.
* @param path The path to ensure the directory for.
*/
function assertDir(path) {
if (!existsSync(path)) {
mkdirSync(path, { recursive: true });
}
else if (lstatSync(path).isFile()) {
throw new Error(`Path exists and is not a directory: ${path}`);
}
}
export { assertDir as default };