github.com/jfrog/frogbot@v1.1.1-0.20231221090046-821a26f50338/action/node_modules/@kwsites/file-exists/dist/src/index.js (about) 1 "use strict"; 2 var __importDefault = (this && this.__importDefault) || function (mod) { 3 return (mod && mod.__esModule) ? mod : { "default": mod }; 4 }; 5 Object.defineProperty(exports, "__esModule", { value: true }); 6 const fs_1 = require("fs"); 7 const debug_1 = __importDefault(require("debug")); 8 const log = debug_1.default('@kwsites/file-exists'); 9 function check(path, isFile, isDirectory) { 10 log(`checking %s`, path); 11 try { 12 const stat = fs_1.statSync(path); 13 if (stat.isFile() && isFile) { 14 log(`[OK] path represents a file`); 15 return true; 16 } 17 if (stat.isDirectory() && isDirectory) { 18 log(`[OK] path represents a directory`); 19 return true; 20 } 21 log(`[FAIL] path represents something other than a file or directory`); 22 return false; 23 } 24 catch (e) { 25 if (e.code === 'ENOENT') { 26 log(`[FAIL] path is not accessible: %o`, e); 27 return false; 28 } 29 log(`[FATAL] %o`, e); 30 throw e; 31 } 32 } 33 /** 34 * Synchronous validation of a path existing either as a file or as a directory. 35 * 36 * @param {string} path The path to check 37 * @param {number} type One or both of the exported numeric constants 38 */ 39 function exists(path, type = exports.READABLE) { 40 return check(path, (type & exports.FILE) > 0, (type & exports.FOLDER) > 0); 41 } 42 exports.exists = exists; 43 /** 44 * Constant representing a file 45 */ 46 exports.FILE = 1; 47 /** 48 * Constant representing a folder 49 */ 50 exports.FOLDER = 2; 51 /** 52 * Constant representing either a file or a folder 53 */ 54 exports.READABLE = exports.FILE + exports.FOLDER; 55 //# sourceMappingURL=index.js.map