Skip to content

Commit

Permalink
🚿 Get rid of promptly #63
Browse files Browse the repository at this point in the history
  • Loading branch information
quilicicf authored and quilicicf committed Feb 8, 2018
1 parent 201da87 commit 10570fa
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 80 deletions.
2 changes: 1 addition & 1 deletion lib/advanced/ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ module.exports = (() => {
} else if (jobsSize === 1) {
const jobKey = _.keys(allJobs)[ 0 ];
const job = _.values(allJobs)[ 0 ];
prompt.yesNoPromisifiedPrompt(`Do you want to run job ${jobKey.cyan}?`)
prompt.yesNoPrompt({ message: `Do you want to run job ${jobKey.cyan}?`, defaultValue: true })
.then((choice) => {
if (choice) {
executeJob(job, toolConfigurations, accounts);
Expand Down
2 changes: 1 addition & 1 deletion lib/advanced/pr.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module.exports = (() => {
execution.print(`${index}: ${option}`);
});
execution.print('Choose a title for the PR.');
prompt.simpleInputPrompt('You can choose from the list above by number, type a title or q to abort.')
prompt.singleQuestion({ message: 'You can choose from the list above by number, type a title or q to abort.' })
.then((choice) => {
if (choice === 'q') {
execution.exit(0, 'Operation aborted.');
Expand Down
24 changes: 11 additions & 13 deletions lib/git/configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,35 @@ module.exports = (() => {
};

const promptForgePath = (gutOptions) => {
const promptOptions = {
validator: dirPath => {
const evaluatedDirPath = _.includes(dirPath, '$')
? execution.execute(`printf '%s' "${dirPath}"`)
: dirPath;
const validator = (dirPath) => {
const evaluatedDirPath = _.includes(dirPath, '$')
? execution.execute(`printf '%s' "${dirPath}"`)
: dirPath;

if (fs.existsSync(evaluatedDirPath)) {
return evaluatedDirPath;
}

throw Error(`No directory found at ${evaluatedDirPath}`.red);
if (fs.existsSync(evaluatedDirPath)) {
return evaluatedDirPath;
}

throw Error(`No directory found at ${evaluatedDirPath}`.red);
};

return prompt.promisifiedPrompt('Type your git repositories folder', promptOptions)
return prompt.singleQuestion({ message: 'Type your git repositories folder', validator })
.then(forgePath => {
_.set(gutOptions, 'repositoriesPath', forgePath);
return gutOptions;
});
};

const promptGithubUsername = (gutOptions) => {
return prompt.promisifiedPrompt('Type your GitHub account username', {})
return prompt.singleQuestion({ message: 'Type your GitHub account username' })
.then(githubUsername => {
_.set(gutOptions, 'accounts.github.username', githubUsername);
return gutOptions;
});
};

const promptGithubPullRequestToken = (gutOptions) => {
return prompt.promisifiedPrompt('Type your GitHub account PR token', {})
return prompt.singleQuestion({ message: 'Type your GitHub account PR token' })
.then(githubToken => {
_.set(gutOptions, 'accounts.github.pullRequestToken', githubToken);
return gutOptions;
Expand Down
4 changes: 3 additions & 1 deletion lib/git/undo.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ module.exports = (() => {

} else if (args[ ARG_HARD.name ]) {
const commits = execution.execute(`git --no-pager log -n ${commitsNumber} --pretty=format:'%Cred%h%Creset - %s %Cgreen(%cr) %C(bold blue)<%an>%Creset %C(yellow)%d%Creset'`);
prompt.yesNoPromisifiedPrompt(`Are you sure you want to undo these commits ?\n\n${commits}\n\nThey will be lost forever`)

const message = `Are you sure you want to undo these commits ?\n\n${commits}\n\nThey will be lost forever`;
prompt.yesNoPrompt({ message, defaultValue: false })
.then((choice) => {
if (choice) {
const eraseCommand = 'git reset --hard';
Expand Down
45 changes: 6 additions & 39 deletions lib/utils/prompt.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,14 @@
// TODO: get rid of promptly, no need to have to prompt dependencies
const promptly = require('promptly');
const inquirer = require('inquirer');
const prompt = inquirer.createPromptModule();

module.exports = (() => {
const promisifiedPrompt = (message, options) => {
return new Promise((resolve, reject) => {
promptly.prompt(message, options || {}, (error, value) => {
return error
? reject(error)
: resolve(value);
});
});
};

const yesNoPromisifiedPrompt = (message) => {
const options = {
default: 'n',
validator: choice => choice === 'y'
};

return new Promise((resolve, reject) => {
promptly.prompt(`${message} (y/n)`, options, (error, value) => {
return error
? reject(error)
: resolve(value);
});
});
};

const simpleInputPrompt = (message) => {
const question = {
type: 'input',
const singleQuestion = ({ message, validator = () => true, type = 'input' }) => {
return prompt({
message,
validate: validator,
type,
name: 'result'
};

return prompt(question)
.then((answers) => answers.result);
}).then((answers) => answers.result);
};

const yesNoPrompt = ({ message, defaultValue = true }) => {
Expand All @@ -64,11 +35,7 @@ module.exports = (() => {

return {
yesNoPrompt,
simpleInputPrompt,

yesNoPromisifiedPrompt,
promisifiedPrompt,

singleQuestion,
chooseFromList
};
})();
24 changes: 0 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"copy-paste": "1.3.0",
"inquirer": "5.1.0",
"lodash": "4.17.5",
"promptly": "3.0.3",
"utf8": "3.0.0",
"yargs": "11.0.0"
},
Expand Down

0 comments on commit 10570fa

Please sign in to comment.