mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-21 18:13:29 +00:00
Remove lodash dependency
This commit is contained in:
+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(),
|
||||
|
||||
Reference in New Issue
Block a user