-
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 code and make up to date for soul fighter event
- Loading branch information
Showing
7 changed files
with
62 additions
and
41 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
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
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,36 @@ | ||
import { promises as fsPromises } from 'fs'; | ||
import path from 'path'; | ||
|
||
/** | ||
* Recursively removes empty directories from the given directory. | ||
* | ||
* If the directory itself is empty, it is also removed. | ||
* | ||
* Async code taken from: https://gist.github.com/fixpunkt/fe32afe14fbab99d9feb4e8da7268445 | ||
* Code taken from: https://gist.github.com/jakub-g/5903dc7e4028133704a4 | ||
* | ||
* @param {string} directory Path to the directory to clean up | ||
*/ | ||
export async function removeEmptyDirectories(directory: string): Promise<void> { | ||
// lstat does not follow symlinks (in contrast to stat) | ||
const fileStats = await fsPromises.lstat(directory); | ||
if (!fileStats.isDirectory()) { | ||
return; | ||
} | ||
let fileNames = await fsPromises.readdir(directory); | ||
if (fileNames.length > 0) { | ||
const recursiveRemovalPromises = fileNames.map((fileName) => | ||
removeEmptyDirectories(path.join(directory, fileName)), | ||
); | ||
await Promise.all(recursiveRemovalPromises); | ||
|
||
// re-evaluate fileNames; after deleting subdirectory | ||
// we may have parent directory empty now | ||
fileNames = await fsPromises.readdir(directory); | ||
} | ||
|
||
if (fileNames.length === 0) { | ||
console.log('Removing: ', directory); | ||
await fsPromises.rmdir(directory); | ||
} | ||
} |
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