diff --git a/dist/diskdb.js b/dist/diskdb.js index 0755cc0..a485433 100644 --- a/dist/diskdb.js +++ b/dist/diskdb.js @@ -16,9 +16,6 @@ Object.defineProperty(exports, "__esModule", { var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); -//local modules - - var _path = require('path'); var _chalk = require('chalk'); @@ -33,6 +30,10 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +var debug = require('debug')('diskdb'); + +//local modules + var DiskDB = function () { function DiskDB() { _classCallCheck(this, DiskDB); @@ -43,13 +44,12 @@ var DiskDB = function () { value: function connect(path, collections) { if ((0, _util.isValidPath)(path)) { this._db = { path: path }; - console.log((0, _chalk.green)('Successfully connected to : ' + path)); + debug('Successfully connected to : ' + path); if (collections) { this.loadCollections(collections); } } else { - console.log((0, _chalk.red)('The DB Path [' + path + '] does not seem to be valid. Recheck the path and try again')); - return false; + throw (0, _chalk.red)('The DB Path [' + path + '] does not seem to be valid. Recheck the path and try again'); } return this; } @@ -59,8 +59,7 @@ var DiskDB = function () { var _this = this; if (!this._db) { - console.log((0, _chalk.red)('Initialize the DB before you add collections. Use : ', 'db.connect(\'path-to-db\');')); - return false; + throw (0, _chalk.red)('Initialize the DB before you add collections. Use : ', 'db.connect(\'path-to-db\');'); } if (Array.isArray(collections)) { collections.forEach(function (collection) { @@ -75,7 +74,7 @@ var DiskDB = function () { _this[collectionName] = new _collection2.default(_this, collectionName); }); } else { - console.log((0, _chalk.red)('Invalid Collections Array.', 'Expected Format : ', '[\'collection1\',\'collection2\',\'collection3\']')); + throw (0, _chalk.red)('Invalid Collections Array.', 'Expected Format : ', '[\'collection1\',\'collection2\',\'collection3\']'); } return this; } diff --git a/lib/diskdb.js b/lib/diskdb.js index 8998cba..4c84ac8 100644 --- a/lib/diskdb.js +++ b/lib/diskdb.js @@ -9,8 +9,9 @@ 'use strict'; // global modules +const debug = require('debug')('diskdb'); import { join } from 'path'; -import { red as e, green as s } from 'chalk'; +import { red as e } from 'chalk'; //local modules import { isValidPath, writeToFile } from './util'; @@ -21,21 +22,19 @@ export default class DiskDB { connect(path, collections) { if (isValidPath(path)) { this._db = { path }; - console.log(s('Successfully connected to : ' + path)); + debug('Successfully connected to : ' + path); if (collections) { this.loadCollections(collections); } } else { - console.log(e('The DB Path [' + path + '] does not seem to be valid. Recheck the path and try again')); - return false; + throw(e('The DB Path [' + path + '] does not seem to be valid. Recheck the path and try again')); } return this; } loadCollections(collections) { if (!this._db) { - console.log(e('Initialize the DB before you add collections. Use : ', 'db.connect(\'path-to-db\');')); - return false; + throw(e('Initialize the DB before you add collections. Use : ', 'db.connect(\'path-to-db\');')); } if (Array.isArray(collections)) { collections.forEach(collection => { @@ -50,7 +49,7 @@ export default class DiskDB { this[collectionName] = new Collection(this, collectionName); }); } else { - console.log(e('Invalid Collections Array.', 'Expected Format : ', '[\'collection1\',\'collection2\',\'collection3\']')); + throw(e('Invalid Collections Array.', 'Expected Format : ', '[\'collection1\',\'collection2\',\'collection3\']')); } return this; } diff --git a/package.json b/package.json index 5d0f182..6298819 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ }, "dependencies": { "chalk": "^0.4.0", + "debug": "^3.1.0", "merge": "^1.1.3", "uuid": "^3.0.0" },