-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
67f7656
commit 2d9cfc3
Showing
8 changed files
with
186 additions
and
178 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
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use strict'; | ||
const _ = require('lodash'); | ||
const path = require('path'); | ||
|
||
module.exports = getSearchTerm; | ||
|
||
function getSearchTerm(options) { | ||
let searchTerm; | ||
let defaultToCurrent = _.pick(options, [ | ||
'open', | ||
'edit' | ||
]); | ||
let defaultToWild = _.pick(options, [ | ||
'completions', | ||
'clone-all', | ||
'force-latest', | ||
'pull-all' | ||
]); | ||
if (options._ && options._[0]) { | ||
searchTerm = options._[0]; | ||
} else if (_.keys(defaultToCurrent).length) { | ||
searchTerm = _.reduce(_.values(defaultToCurrent), (acc, value) => { | ||
return _.isString(value) ? value : acc; | ||
}, '^' + _.takeRight(process.cwd().split(path.sep), 3).join(path.sep) + '$'); | ||
} else if (_.keys(defaultToWild).length) { | ||
searchTerm = _.reduce(_.values(defaultToWild), (acc, value) => { | ||
return _.isString(value) ? value : acc; | ||
}, '.*'); | ||
} | ||
return searchTerm; | ||
} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use strict'; | ||
const _ = require('lodash'); | ||
const Promise = require('bluebird'); | ||
const getSourceResult = require('./getSourceResult'); | ||
const output = require('./output'); | ||
const inquirer = require('inquirer'); | ||
const workspaceDir = require('./workspaceDir'); | ||
|
||
module.exports = mapToHandler; | ||
|
||
function mapToHandler(options) { | ||
let { results, confirmMessage, errorMessage, handler } = options; | ||
return Promise.all(_.map(results, getSourceResult)).then((repos) => { | ||
_.each(repos, (r) => output.log(r.name)); | ||
return inquirer.prompt([ | ||
{ | ||
type: 'confirm', | ||
name: 'confirm', | ||
message: confirmMessage, | ||
default: false | ||
} | ||
]).then((answers) => { | ||
if (answers.confirm) { | ||
return Promise.resolve(repos).mapSeries(handler).then(() => { | ||
return { repoDir: workspaceDir }; | ||
}); | ||
} else { | ||
throw new Error(errorMessage); | ||
} | ||
}); | ||
}); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
'use strict'; | ||
const _ = require('lodash'); | ||
const inquirer = require('inquirer'); | ||
const path = require('path'); | ||
const Promise = require('bluebird'); | ||
const workspaceDir = require('./lib/workspaceDir'); | ||
const output = require('./lib/output'); | ||
const getSearchTerm = require('./lib/getSearchTerm'); | ||
const mapToHandler = require('./lib/mapToHandler'); | ||
const syncExisting = require('./lib/syncExisting'); | ||
const getSourceData = require('./lib/getSourceData'); | ||
const getSourceResult = require('./lib/getSourceResult'); | ||
const getPaths = require('./lib/getPaths'); | ||
const maybeClone = require('./lib/maybeClone'); | ||
const maybePull = require('./lib/maybePull'); | ||
const forceLatest = require('./lib/forceLatest'); | ||
const openInBrowser = require('./lib/openInBrowser'); | ||
|
||
module.exports = router; | ||
|
||
function router(options) { | ||
let searchTerm = getSearchTerm(options); | ||
|
||
if (options.version) { | ||
output.log(require('./package.json').version); | ||
return Promise.resolve(); | ||
} | ||
|
||
if (options.setup) { | ||
return require('./setup')(); | ||
} | ||
|
||
if (options['sync-existing']) { | ||
return syncExisting(); | ||
} | ||
|
||
if (options.refresh) { | ||
return getSourceData(true); | ||
} else { | ||
const sourceDataPromise = getSourceData(); | ||
const pathsPromise = sourceDataPromise.then(getPaths).filter((v) => (new RegExp(searchTerm)).test(v)); | ||
if (options.completions) { | ||
return pathsPromise.map((result) => _.tail(result.split(path.sep)).join(path.sep)) | ||
.each(_.ary(output.log, 1)); | ||
} else { | ||
return pathsPromise.then((results) => { | ||
let resultPromise; | ||
if (results.length && options['clone-all']) { | ||
return mapToHandler({ | ||
results, | ||
confirmMessage: 'Are you sure you want clone all of the above?', | ||
errorMessage: 'Clone all aborted', | ||
handler: maybeClone | ||
}); | ||
} else if (results.length && options['pull-all']) { | ||
return mapToHandler({ | ||
results, | ||
confirmMessage: 'Are you sure you want pull all of the above?', | ||
errorMessage: 'Pull all aborted', | ||
handler: (r) => maybeClone(r).then(maybePull) | ||
}); | ||
} else if (results.length && options['force-latest']) { | ||
return mapToHandler({ | ||
results, | ||
confirmMessage: 'Are you sure you want clean and force a hard reset to all of the above?', | ||
errorMessage: 'Force latest aborted', | ||
handler: forceLatest | ||
}); | ||
} else if (results.length > 1) { | ||
resultPromise = inquirer.prompt([ | ||
{ | ||
type: 'list', | ||
name: 'result', | ||
message: 'search results', | ||
choices: results | ||
} | ||
]).then((answers) => getSourceResult(answers.result)); | ||
} else if (results.length) { | ||
resultPromise = getSourceResult(results[0]); | ||
} else { | ||
throw new Error('No results.'); | ||
} | ||
if (options.open) { | ||
resultPromise = resultPromise.then(openInBrowser).then(maybeClone); | ||
} else { | ||
resultPromise = resultPromise.then(maybeClone); | ||
} | ||
return resultPromise; | ||
}); | ||
} | ||
} | ||
} |
Oops, something went wrong.