UNPKG

muffin

Version:

The 21st century way of building websites

63 lines (48 loc) 1.31 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.log = log; exports.exists = exists; exports.walkSync = walkSync; var _chalk = require('chalk'); var _chalk2 = _interopRequireDefault(_chalk); var _fsExtra = require('fs-extra'); var _fsExtra2 = _interopRequireDefault(_fsExtra); var _path = require('path'); var _path2 = _interopRequireDefault(_path); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function log(message, err) { // Regular errors if (message instanceof Error) { console.error(err && err.stack); return; } // Ability to add custom message to error if (err instanceof Error) { console.error(_chalk2.default.bold(message) + '\n', err.stack); return; } // The usual loggings console.log(message); } function exists(path) { try { _fsExtra2.default.statSync(path); return true; } catch (err) { return false; } } function walkSync(dir) { const files = _fsExtra2.default.readdirSync(dir); let list = []; files.forEach(file => { if (_fsExtra2.default.statSync(_path2.default.normalize(dir + '/' + file)).isDirectory()) { list = exports.walkSync(dir + file + '/', list); } else { list.push(file); } }); return list; }