2019-03-12 01:52:43 -04:00
|
|
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
2019-03-14 10:24:54 -04:00
|
|
|
|
2019-03-12 01:52:43 -04:00
|
|
|
/**
|
2019-03-14 10:24:54 -04:00
|
|
|
* Ensures that the directory exists.
|
|
|
|
* If the directory structure does not exist, it is created. Like mkdir -p.
|
2019-03-12 01:52:43 -04:00
|
|
|
*/
|
|
|
|
export async function ensureDir(dir: string): Promise<void> {
|
|
|
|
try {
|
|
|
|
// if dir exists
|
|
|
|
await Deno.stat(dir);
|
|
|
|
} catch {
|
|
|
|
// if dir not exists. then create it.
|
|
|
|
await Deno.mkdir(dir, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-03-14 10:24:54 -04:00
|
|
|
* Ensures that the directory exists.
|
|
|
|
* If the directory structure does not exist, it is created. Like mkdir -p.
|
2019-03-12 01:52:43 -04:00
|
|
|
*/
|
|
|
|
export function ensureDirSync(dir: string): void {
|
|
|
|
try {
|
|
|
|
// if dir exists
|
|
|
|
Deno.statSync(dir);
|
|
|
|
} catch {
|
|
|
|
// if dir not exists. then create it.
|
|
|
|
Deno.mkdirSync(dir, true);
|
|
|
|
}
|
|
|
|
}
|