react-cosmos
Version:
CLI for running React Cosmos inside webpack-powered apps
37 lines (29 loc) • 1.06 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.dirExists = dirExists;
exports.fileExists = fileExists;
exports.moduleExists = moduleExists;
exports.requireModule = requireModule;
var _fs = _interopRequireDefault(require("fs"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// NOTE: This API has been extracted to be easily mocked inside tests
function requireModule(modulePath) {
// This purpose of this wrapper is merely to make it easy to mock user
// modules in tests
return require(modulePath);
} // Better than fs.exists because it works for module paths without an extension
function moduleExists(modulePath) {
try {
return require.resolve(modulePath) && true;
} catch (err) {
return false;
}
}
function fileExists(filePath) {
return _fs.default.existsSync(filePath) && _fs.default.lstatSync(filePath).isFile();
}
function dirExists(dirPath) {
return _fs.default.existsSync(dirPath) && _fs.default.lstatSync(dirPath).isDirectory();
}