-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(back): chdir.back returns a promise, close #3
- Loading branch information
Showing
3 changed files
with
42 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,40 @@ | ||
var la = require('lazy-ass'); | ||
var check = require('check-more-types'); | ||
var la = require('lazy-ass') | ||
var check = require('check-more-types') | ||
|
||
var q = require('q'); | ||
var fs = require('fs'); | ||
var S = require('spots'); | ||
var debug = require('debug')('chdir-promise'); | ||
var q = require('q') | ||
var fs = require('fs') | ||
var S = require('spots') | ||
var debug = require('debug')('chdir-promise') | ||
|
||
// stack | ||
var folders = []; | ||
var folders = [] | ||
|
||
function _to(folderName) { | ||
la(check.unemptyString(folderName), 'missing git repo folder'); | ||
la(fs.existsSync(folderName), 'cannot find folder', folderName); | ||
function _to (folderName) { | ||
la(check.unemptyString(folderName), 'missing git repo folder') | ||
la(fs.existsSync(folderName), 'cannot find folder', folderName) | ||
|
||
var current = process.cwd(); | ||
la(check.unemptyString(folderName), 'missing folder'); | ||
process.chdir(folderName); | ||
debug('chdir to folder', process.cwd()); | ||
var current = process.cwd() | ||
la(check.unemptyString(folderName), 'missing folder') | ||
process.chdir(folderName) | ||
debug('chdir to folder', process.cwd()) | ||
|
||
folders.push(current); | ||
folders.push(current) | ||
|
||
return current; | ||
return current | ||
} | ||
|
||
function comeBack() { | ||
function comeBack () { | ||
if (!folders.length) { | ||
return; | ||
return Promise.resolve() | ||
} | ||
var folder = folders.pop(); | ||
process.chdir(folder); | ||
debug('restored folder', folder); | ||
return folder; | ||
var folder = folders.pop() | ||
process.chdir(folder) | ||
debug('restored folder', folder) | ||
return Promise.resolve(folder) | ||
} | ||
|
||
module.exports = { | ||
to: S(q.try, _to, S), | ||
back: comeBack, | ||
from: comeBack | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters