diff options
author | Samy Pesse <samypesse@gmail.com> | 2016-04-30 23:07:43 +0200 |
---|---|---|
committer | Samy Pesse <samypesse@gmail.com> | 2016-04-30 23:07:43 +0200 |
commit | c681cd286a746d5cf3f69fc800bcb79a42e70973 (patch) | |
tree | 66b852e90ebfe38da444532af729f7a5af0c6e5d /lib/utils/git.js | |
parent | c1d53ec11fbe085932df911bda5686b7bf671f53 (diff) | |
download | gitbook-c681cd286a746d5cf3f69fc800bcb79a42e70973.zip gitbook-c681cd286a746d5cf3f69fc800bcb79a42e70973.tar.gz gitbook-c681cd286a746d5cf3f69fc800bcb79a42e70973.tar.bz2 |
Remove lodash dependency
Diffstat (limited to 'lib/utils/git.js')
-rw-r--r-- | lib/utils/git.js | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/lib/utils/git.js b/lib/utils/git.js index 52b1096..6884b83 100644 --- a/lib/utils/git.js +++ b/lib/utils/git.js @@ -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(), |