Last active
October 16, 2018 19:11
-
-
Save TravisMullen/9e6e48e38a6cfa74218e97202524b2b4 to your computer and use it in GitHub Desktop.
Check file and delete file.
This file contains hidden or 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
import { statSync } from 'fs' | |
import { spawnSync } from 'child_process' | |
/** | |
* Does file exist. | |
* | |
* @public | |
* @param {string} filePath Path to file. | |
* @return {boolean} File is found. <true> | |
*/ | |
export const checkFile = filePath => { | |
let stats | |
try { | |
stats = statSync(filePath) | |
} catch (err) { | |
stats = err | |
} | |
return !(stats instanceof Error) | |
} | |
/** | |
* Delete file if exists. | |
* | |
* @public | |
* @param {string} filePath Path to file. | |
*/ | |
export const purgeFile = filePath => { | |
if (checkFile(filePath)) { | |
// purge before we begin | |
spawnSync('rm', [filePath]) | |
} | |
} |
This file contains hidden or 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
{ | |
"name": "check-file", | |
"main": "check-file.js", | |
"engines": { | |
"node": ">= 8.6" | |
}, | |
"author": "Travis Mullen <[email protected]> (http://travismullen.com/)", | |
"files": [ | |
"check-file.js" | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment