Skip to content
This repository has been archived by the owner on Jun 16, 2021. It is now read-only.

Commit

Permalink
feat: store answers in state
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Jun 5, 2018
1 parent 5212e93 commit 3110e94
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 13 deletions.
2 changes: 2 additions & 0 deletions lib/cli.js
Expand Up @@ -7,6 +7,8 @@ const main = async () => {
const state = createState();
const answers = await runInteractiveQuestions(state);

console.log(state);

console.log(answers);
} catch (error) {
signale.fatal(error);
Expand Down
4 changes: 0 additions & 4 deletions lib/createPrompter.js
@@ -1,9 +1,5 @@
const fs = require('fs');
const wrap = require('word-wrap');
const {
getAllPackages,
getChangedPackages
} = require('./lernaUtils');
const runInteractiveQuestions = require('./runInteractiveQuestions');

const MAX_LINE_WIDTH = 72;
Expand Down
9 changes: 9 additions & 0 deletions lib/createState.js
Expand Up @@ -3,6 +3,15 @@ const getConfig = require('./getConfig');

const createState = () => {
const state = {
answers: {
body: '',
breaking: '',
issues: '',
lerna: '',
scope: '',
subject: '',
type: ''
},
config: getConfig(),
root: String(appRoot)
};
Expand Down
16 changes: 9 additions & 7 deletions lib/defaults.js
Expand Up @@ -61,19 +61,21 @@ const list = [

// https://github.com/angular/angular/blob/master/CONTRIBUTING.md#scope
const scopes = [
'',
'init',
'runner',
'watcher',
'none',
'app',
'electron',
'server',
'lang',
'config',
'web-server',
'changelog'
'changelog',
'runner',
'watcher'
];

const questions = [
'type',
'scope',
'title',
'subject',
'body',
'breaking',
'issues',
Expand Down
2 changes: 1 addition & 1 deletion lib/questions/scope.js
Expand Up @@ -16,7 +16,7 @@ exports.createQuestion = (state) => {
const question = {
choices: scopes,
default: 0,
message: 'Select the scope this component affects:\n',
message: 'Select the scope this component affects:',
name: 'scope',
type: 'list'
};
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/questions/type.js
Expand Up @@ -9,7 +9,7 @@ exports.createQuestion = (state) => {
const {config} = state;
const question = {
choices: config.list.map((type) => typeToListItem(config.types[type])),
message: 'Select the type of change that you\'re committing:\n',
message: 'Select the type of change that you\'re committing:',
name: 'type',
type: 'list'
};
Expand Down
6 changes: 6 additions & 0 deletions lib/runInteractiveQuestions.js
Expand Up @@ -15,6 +15,12 @@ const runInteractiveQuestions = async (state) => {
const questions = createQuestions(state);
const answers = await inquirer.prompt(questions);

Object.keys(state.answers).forEach((key) => {
if (answers[key]) {
state.answers[key] = answers[key];
}
});

return answers;
};

Expand Down

0 comments on commit 3110e94

Please sign in to comment.