-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: cleanup .extractinator dir if it's unused
- Loading branch information
Showing
4 changed files
with
37 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'extractinator': patch | ||
--- | ||
|
||
fix: cleanup .extractinator dir if it's unused |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { rm, mkdir, readdir } from 'node:fs/promises' | ||
import { resolve } from 'path' | ||
|
||
/** | ||
* Create a temporary directory under ".extractinator" with the given name. | ||
* @returns The absolute path to the temp dir. | ||
*/ | ||
export async function get_temp_dir(name: string) { | ||
const path = resolve(`.extractinator/${name}`) | ||
|
||
//? Cleanup the temp dir | ||
await rm(path, { force: true, recursive: true }) | ||
await mkdir(path, { recursive: true }) | ||
|
||
return path | ||
} | ||
|
||
export async function clean_temp() { | ||
const TEMP_ROOT = resolve('.extractinator') | ||
|
||
//? Remove the .extractinator dir if it's empty. | ||
if ((await readdir(TEMP_ROOT)).length == 0) { | ||
await rm(TEMP_ROOT, { recursive: true }) | ||
} | ||
} |