-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
35ad36d
commit 30f47d3
Showing
4 changed files
with
29 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,30 @@ | ||
const util = require("util"); | ||
import * as path from "path"; | ||
import * as fs from "fs"; | ||
import logger from "./log"; | ||
|
||
export const exec = util.promisify(require("child_process").exec); | ||
|
||
export const sleep = (deley) => new Promise((resolve) => setTimeout(resolve, deley)); | ||
|
||
export const deleteDirectory = (path) => { | ||
if (process.platform === "win32") { | ||
return exec(`rd /s /q "${path}"`); | ||
} else { | ||
return exec(`rm -rf "${path}"`); | ||
export const deleteDirectory = (directoryPath: string, fileList: string[] = []) => { | ||
for (const filename of fileList) { | ||
try { | ||
fs.unlinkSync(path.resolve(directoryPath, filename)); | ||
} catch (e) { | ||
logger.debug(e); | ||
logger.warning(`Delete ${path.resolve(directoryPath, filename)} failed, ignored`); | ||
} | ||
} | ||
if (fs.readdirSync(directoryPath).length === 0) { | ||
fs.rmdirSync(directoryPath); | ||
} | ||
}; | ||
|
||
export const forceDeleteDirectory = (directoryPath: string) => { | ||
const fileList = fs.readdirSync(directoryPath); | ||
for (const filename of fileList) { | ||
fs.unlinkSync(path.resolve(directoryPath, filename)); | ||
} | ||
fs.rmdirSync(directoryPath); | ||
}; |