|
1 | 1 | var inquirer = require('inquirer'); |
2 | | -var emoji = require('node-emoji') |
| 2 | +var emoji = require('node-emoji'); |
| 3 | +const fs = require('fs'); |
3 | 4 | const { getIssue } = require('./issue.js'); |
| 5 | +const { jsonReader } = require('./funcs/jsonReader.js'); |
4 | 6 |
|
5 | 7 | module.exports = { |
6 | 8 | getQuestions: async () => { |
@@ -49,5 +51,114 @@ module.exports = { |
49 | 51 | // Something else went wrong |
50 | 52 | } |
51 | 53 | }); |
| 54 | + }, |
| 55 | + |
| 56 | + getConfigQuestions: async () => { |
| 57 | + |
| 58 | + inquirer.prompt([{ |
| 59 | + type: 'list', |
| 60 | + message: 'What commit guidelines do you follow?', |
| 61 | + name: 'guidelines', |
| 62 | + choices: [ |
| 63 | + `fix:, feat:, chore:`, |
| 64 | + `fix #`, |
| 65 | + `...(fix #)`, |
| 66 | + `Type your own, if multiple, separate with commas`, |
| 67 | + ] |
| 68 | + }]).then( |
| 69 | + ans => { |
| 70 | + if (ans['guidelines'] === "Type your own, if multiple, separate with commas") { |
| 71 | + inquirer.prompt([ |
| 72 | + { |
| 73 | + // expects issue number as response |
| 74 | + type: 'string', message: 'Type your own guidelines, if multiple, separate with commas\n', name: 'commit' |
| 75 | + } |
| 76 | + ]).then( |
| 77 | + ans1 => { |
| 78 | + jsonReader('./.gitgo', (err, conf) => { |
| 79 | + if (err) { |
| 80 | + console.log('Error reading file:', err) |
| 81 | + return |
| 82 | + } |
| 83 | + conf.commit_guidelines = ans1['commit'].split(','); |
| 84 | + fs.writeFile('./.gitgo', JSON.stringify(conf), (err) => { |
| 85 | + if (err) console.log('Error writing file:', err) |
| 86 | + }) |
| 87 | + }) |
| 88 | + inquirer.prompt([ |
| 89 | + { |
| 90 | + // expects issue number as response |
| 91 | + type: 'string', message: 'Would you be using emojis in your commit messages?(y/n)', name: 'emojis' |
| 92 | + } |
| 93 | + ]).then( |
| 94 | + ans2 => { |
| 95 | + var emo = true; |
| 96 | + if (ans2['emojis'] === "y") { |
| 97 | + console.log("\nWe have an awesome set of emojis in the .gitgo file which will be suggested to you in the commit messages.\n") |
| 98 | + } else { |
| 99 | + emo = false; |
| 100 | + } |
| 101 | + jsonReader('./.gitgo', (err, conf) => { |
| 102 | + if (err) { |
| 103 | + console.log('Error reading file:', err) |
| 104 | + return |
| 105 | + } |
| 106 | + conf.use_emojis = emo; |
| 107 | + fs.writeFile('./.gitgo', JSON.stringify(conf), (err) => { |
| 108 | + if (err) console.log('Error writing file:', err) |
| 109 | + }) |
| 110 | + }) |
| 111 | + console.log("\nSettings for your repo have been stored. Run gg start before working on an issue to get the branch name and commit title automatically. If you would like to change any settings manually, please edit the .gitgo file.\n") |
| 112 | + } |
| 113 | + ) |
| 114 | + } |
| 115 | + ) |
| 116 | + } else { |
| 117 | + jsonReader('./.gitgo', (err, conf) => { |
| 118 | + if (err) { |
| 119 | + console.log('Error reading file:', err) |
| 120 | + return |
| 121 | + } |
| 122 | + conf.commit_guidelines = ans['guidelines'].split(','); |
| 123 | + fs.writeFile('./.gitgo', JSON.stringify(conf), (err) => { |
| 124 | + if (err) console.log('Error writing file:', err) |
| 125 | + }) |
| 126 | + }) |
| 127 | + inquirer.prompt([ |
| 128 | + { |
| 129 | + // expects issue number as response |
| 130 | + type: 'string', message: 'Would you be using emojis in your commit messages?(y/n)', name: 'emojis' |
| 131 | + } |
| 132 | + ]).then( |
| 133 | + ans2 => { |
| 134 | + var emo = true; |
| 135 | + if (ans2['emojis'] === "y") { |
| 136 | + console.log("\nWe have an awesome set of emojis in the .gitgo file which will be suggested to you in the commit messages.\n") |
| 137 | + } else { |
| 138 | + emo = false; |
| 139 | + } |
| 140 | + jsonReader('./.gitgo', (err, conf) => { |
| 141 | + if (err) { |
| 142 | + console.log('Error reading file:', err) |
| 143 | + return |
| 144 | + } |
| 145 | + conf.use_emojis = emo; |
| 146 | + fs.writeFile('./.gitgo', JSON.stringify(conf), (err) => { |
| 147 | + if (err) console.log('Error writing file:', err) |
| 148 | + }) |
| 149 | + }) |
| 150 | + console.log("\nSettings for your repo have been stored. Run gg start before working on an issue to get the branch name and commit title automatically. If you would like to change any settings manually, please edit the .gitgo file.\n") |
| 151 | + } |
| 152 | + ) |
| 153 | + } |
| 154 | + } |
| 155 | + ) |
| 156 | + .catch(error => { |
| 157 | + if (error.isTtyError) { |
| 158 | + // Prompt couldn't render in the current environment |
| 159 | + } else { |
| 160 | + // Something else went wrong |
| 161 | + } |
| 162 | + }); |
52 | 163 | } |
53 | 164 | }; |
0 commit comments