muffin-cli
Version:
The command line utility for building sites using muffin
77 lines (59 loc) • 1.56 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.log = log;
exports.exists = exists;
exports.isSite = isSite;
var _fsExtra = require('fs-extra');
var _fsExtra2 = _interopRequireDefault(_fsExtra);
var _chalk = require('chalk');
var _chalk2 = _interopRequireDefault(_chalk);
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 isSite() {
const pkgPath = process.cwd() + '/package.json';
const mightExist = {
pkg: 'package.json',
dotEnv: '.env',
underscoreEnv: '_env'
};
// If one of the above files exists, return "true"
for (let file in mightExist) {
mightExist[file] = process.cwd() + '/' + mightExist[file];
if (exports.exists(mightExist[file])) {
return true;
}
}
if (!exports.exists(mightExist.pkg)) {
return false;
}
// Load the package.json
const pkg = require(mightExist.pkg);
// Check if muffin has been added to dependencies
if (!pkg.dependencies || !pkg.dependencies.muffin) {
return false;
}
return true;
}