mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-16 23:55:20 +00:00
Remove lodash dependency
This commit is contained in:
+2
-1
@@ -3,7 +3,8 @@ var Logger = require('../utils/logger');
|
||||
var logOptions = {
|
||||
name: 'log',
|
||||
description: 'Minimum log level to display',
|
||||
values: Object.keys(Logger.LEVELS)
|
||||
values: Logger.LEVELS
|
||||
.keySeq()
|
||||
.map(function(s) {
|
||||
return s.toLowerCase();
|
||||
}),
|
||||
|
||||
+16
-10
@@ -1,4 +1,3 @@
|
||||
var _ = require('lodash');
|
||||
var childProcess = require('child_process');
|
||||
var spawn = require('spawn-cmd').spawn;
|
||||
var Promise = require('./promise');
|
||||
@@ -62,15 +61,22 @@ function escapeShellArg(s) {
|
||||
}
|
||||
|
||||
function optionsToShellArgs(options) {
|
||||
return _.chain(options)
|
||||
.map(function(value, key) {
|
||||
if (value === null || value === undefined || value === false) return null;
|
||||
if (value === true) return key;
|
||||
return key + '=' + escapeShellArg(value);
|
||||
})
|
||||
.compact()
|
||||
.value()
|
||||
.join(' ');
|
||||
var result = [];
|
||||
|
||||
for (var key in options) {
|
||||
var value = options[key];
|
||||
|
||||
if (value === null || value === undefined || value === false) {
|
||||
continue;
|
||||
}
|
||||
if (value === true) {
|
||||
result.push(key);
|
||||
}
|
||||
|
||||
result.push(key + '=' + escapeShellArg(value));
|
||||
}
|
||||
|
||||
return result.join(' ');
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
||||
+10
-6
@@ -1,4 +1,4 @@
|
||||
var _ = require('lodash');
|
||||
var is = require('is');
|
||||
var path = require('path');
|
||||
var crc = require('crc');
|
||||
var URI = require('urijs');
|
||||
@@ -69,7 +69,7 @@ Git.prototype.resolve = function(giturl) {
|
||||
if (this.resolveRoot(giturl)) return Promise(giturl);
|
||||
return Promise(null);
|
||||
}
|
||||
if (_.isString(giturl)) giturl = Git.parseUrl(giturl);
|
||||
if (is.string(giturl)) giturl = Git.parseUrl(giturl);
|
||||
if (!giturl) return Promise(null);
|
||||
|
||||
// Clone or get from cache
|
||||
@@ -88,8 +88,10 @@ Git.prototype.resolveRoot = function(filepath) {
|
||||
|
||||
// Extract first directory (is the repo id)
|
||||
relativeToGit = path.relative(this.tmpDir, filepath);
|
||||
repoId = _.first(relativeToGit.split(path.sep));
|
||||
if (!repoId) return;
|
||||
repoId = relativeToGit.split(path.sep)[0];
|
||||
if (!repoId) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Return an absolute file
|
||||
return path.resolve(this.tmpDir, repoId);
|
||||
@@ -114,10 +116,12 @@ Git.parseUrl = function(giturl) {
|
||||
// Extract file inside the repo (after the .git)
|
||||
fileParts = uri.path().split('.git');
|
||||
filepath = fileParts.length > 1? fileParts.slice(1).join('.git') : '';
|
||||
if (filepath[0] == '/') filepath = filepath.slice(1);
|
||||
if (filepath[0] == '/') {
|
||||
filepath = filepath.slice(1);
|
||||
}
|
||||
|
||||
// Recreate pathname without the real filename
|
||||
uri.path(_.first(fileParts)+'.git');
|
||||
uri.path(fileParts[0] + '.git');
|
||||
|
||||
return {
|
||||
host: uri.toString(),
|
||||
|
||||
+25
-18
@@ -1,21 +1,22 @@
|
||||
var _ = require('lodash');
|
||||
var is = require('is');
|
||||
var util = require('util');
|
||||
var color = require('bash-color');
|
||||
var Immutable = require('immutable');
|
||||
|
||||
var LEVELS = {
|
||||
var LEVELS = Immutable.Map({
|
||||
DEBUG: 0,
|
||||
INFO: 1,
|
||||
WARN: 2,
|
||||
ERROR: 3,
|
||||
DISABLED: 10
|
||||
};
|
||||
});
|
||||
|
||||
var COLORS = {
|
||||
var COLORS = Immutable.Map({
|
||||
DEBUG: color.purple,
|
||||
INFO: color.cyan,
|
||||
WARN: color.yellow,
|
||||
ERROR: color.red
|
||||
};
|
||||
});
|
||||
|
||||
function Logger(write, logLevel) {
|
||||
if (!(this instanceof Logger)) return new Logger(write, logLevel);
|
||||
@@ -29,17 +30,18 @@ function Logger(write, logLevel) {
|
||||
|
||||
this.setLevel(logLevel || 'info');
|
||||
|
||||
_.bindAll(this);
|
||||
|
||||
// Create easy-to-use method like "logger.debug.ln('....')"
|
||||
_.each(_.omit(LEVELS, 'DISABLED'), function(level, levelKey) {
|
||||
LEVELS.forEach(function(level, levelKey) {
|
||||
if (levelKey === 'DISABLED') {
|
||||
return;
|
||||
}
|
||||
levelKey = levelKey.toLowerCase();
|
||||
|
||||
this[levelKey] = _.partial(this.log, level);
|
||||
this[levelKey].ln = _.partial(this.logLn, level);
|
||||
this[levelKey].ok = _.partial(this.ok, level);
|
||||
this[levelKey].fail = _.partial(this.fail, level);
|
||||
this[levelKey].promise = _.partial(this.promise, level);
|
||||
this[levelKey] = this.log.bind(this, level);
|
||||
this[levelKey].ln = this.logLn.bind(this, level);
|
||||
this[levelKey].ok = this.ok.bind(this, level);
|
||||
this[levelKey].fail = this.fail.bind(this, level);
|
||||
this[levelKey].promise = this.promise.bind(this, level);
|
||||
}, this);
|
||||
}
|
||||
|
||||
@@ -49,7 +51,11 @@ function Logger(write, logLevel) {
|
||||
@param {String} logLevel
|
||||
*/
|
||||
Logger.prototype.setLevel = function(logLevel) {
|
||||
if (_.isString(logLevel)) logLevel = LEVELS[logLevel.toUpperCase()];
|
||||
if (is.string(logLevel)) {
|
||||
logLevel = logLevel.toUpperCase();
|
||||
logLevel = LEVELS.get(logLevel);
|
||||
}
|
||||
|
||||
this.logLevel = logLevel;
|
||||
};
|
||||
|
||||
@@ -60,7 +66,7 @@ Logger.prototype.setLevel = function(logLevel) {
|
||||
*/
|
||||
Logger.prototype.write = function(msg) {
|
||||
msg = msg.toString();
|
||||
this.lastChar = _.last(msg);
|
||||
this.lastChar = msg[msg.length - 1];
|
||||
return this._write(msg);
|
||||
};
|
||||
|
||||
@@ -88,12 +94,14 @@ Logger.prototype.writeLn = function(msg) {
|
||||
Logger.prototype.log = function(level) {
|
||||
if (level < this.logLevel) return;
|
||||
|
||||
var levelKey = _.findKey(LEVELS, function(v) { return v == level; });
|
||||
var levelKey = LEVELS.findKey(function(v) {
|
||||
return v === level;
|
||||
});
|
||||
var args = Array.prototype.slice.apply(arguments, [1]);
|
||||
var msg = this.format.apply(this, args);
|
||||
|
||||
if (this.lastChar == '\n') {
|
||||
msg = COLORS[levelKey](levelKey.toLowerCase()+':')+' '+msg;
|
||||
msg = COLORS.get(levelKey)(levelKey.toLowerCase()+':')+' '+msg;
|
||||
}
|
||||
|
||||
return this.write(msg);
|
||||
@@ -151,6 +159,5 @@ Logger.prototype.promise = function(level, p) {
|
||||
};
|
||||
|
||||
Logger.LEVELS = LEVELS;
|
||||
Logger.COLORS = COLORS;
|
||||
|
||||
module.exports = Logger;
|
||||
|
||||
+3
-7
@@ -1,6 +1,4 @@
|
||||
var _ = require('lodash');
|
||||
var path = require('path');
|
||||
|
||||
var error = require('./error');
|
||||
|
||||
// Normalize a filename
|
||||
@@ -18,17 +16,15 @@ function isInRoot(root, filename) {
|
||||
// Throw error if file is outside this folder
|
||||
function resolveInRoot(root) {
|
||||
var input, result;
|
||||
var args = Array.prototype.slice.call(arguments, 1);
|
||||
|
||||
input = _.chain(arguments)
|
||||
.toArray()
|
||||
.slice(1)
|
||||
input = args
|
||||
.reduce(function(current, p) {
|
||||
// Handle path relative to book root ("/README.md")
|
||||
if (p[0] == '/' || p[0] == '\\') return p.slice(1);
|
||||
|
||||
return current? path.join(current, p) : path.normalize(p);
|
||||
}, '')
|
||||
.value();
|
||||
}, '');
|
||||
|
||||
result = path.resolve(root, input);
|
||||
|
||||
|
||||
@@ -39,7 +39,6 @@
|
||||
"json-schema-defaults": "0.1.1",
|
||||
"jsonschema": "1.1.0",
|
||||
"juice": "1.10.0",
|
||||
"lodash": "3.10.1",
|
||||
"merge-defaults": "0.2.1",
|
||||
"mkdirp": "0.5.1",
|
||||
"moment": "2.12.0",
|
||||
|
||||
Reference in New Issue
Block a user