Skip to content

Commit

Permalink
feat: added sync pipe in utils
Browse files Browse the repository at this point in the history
  • Loading branch information
nimish-gupta committed May 9, 2020
1 parent e1319db commit b3a85fc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
28 changes: 17 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@ const parseArgs = (args) => {
};

const getRepoName = async () => {
const repos = await Util.pipe(
const repos = await Util.pipeAsync(
Questions.getSearchPrompt,
Questions.getAnswer('repoQuery'),
Github.search,
Util.exitPromise('repositories'),
Util.spinnerPromise('Searching the repos...')
Util.pipe(
Github.search,
Util.exitPromise('repositories'),
Util.spinnerPromise('Searching the repos...')
)
)();

if (repos.length === 0) {
Expand All @@ -73,15 +75,19 @@ const getRepoName = async () => {
return repo;
};

const getEmailsWithUser = Util.pipe(
Github.getContributorUserNames,
Util.exitPromise('contributors'),
Util.spinnerPromise('Getting the list of contributors...'),
getEmailOfFirstTenCollaborators,
Util.spinnerPromise('Getting the list of users email addresses...')
const getEmailsWithUser = Util.pipeAsync(
Util.pipe(
Github.getContributorUserNames,
Util.exitPromise('contributors'),
Util.spinnerPromise('Getting the list of contributors...')
),
Util.pipe(
getEmailOfFirstTenCollaborators,
Util.spinnerPromise('Getting the list of users email addresses...')
)
);

const main = Util.pipe(
const main = Util.pipeAsync(
parseArgs,
getRepoName,
getEmailsWithUser,
Expand Down
19 changes: 11 additions & 8 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,16 @@ const spinnerPromise = (msg, spinnerOptions = {}) => async (promise) => {
return result;
};

const compose = (...functions) => (input) =>
functions.reduceRight(
(chain, func) => chain.then(func),
Promise.resolve(input)
);

const pipe = (...functions) => (input) =>
const pipeAsync = (...functions) => (input) =>
functions.reduce((chain, func) => chain.then(func), Promise.resolve(input));

module.exports = { promisify, exitPromise, spinnerPromise, compose, pipe };
const pipe = (...functions) => (input) =>
functions.reduce((val, func) => func(val), input);

module.exports = {
promisify,
exitPromise,
spinnerPromise,
pipe,
pipeAsync,
};

0 comments on commit b3a85fc

Please sign in to comment.