engine.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. "format cjs";
  2. var wrap = require('word-wrap');
  3. var map = require('lodash.map');
  4. var longest = require('longest');
  5. var rightPad = require('right-pad');
  6. // This can be any kind of SystemJS compatible module.
  7. // We use Commonjs here, but ES6 or AMD would do just
  8. // fine.
  9. module.exports = function (options) {
  10. var types = options.types;
  11. var length = longest(Object.keys(types)).length + 1;
  12. var choices = map(types, function (type, key) {
  13. return {
  14. name: rightPad(key + ':', length) + ' ' + type.description,
  15. value: key
  16. };
  17. });
  18. return {
  19. // When a user runs `git cz`, prompter will
  20. // be executed. We pass you cz, which currently
  21. // is just an instance of inquirer.js. Using
  22. // this you can ask questions and get answers.
  23. //
  24. // The commit callback should be executed when
  25. // you're ready to send back a commit template
  26. // to git.
  27. //
  28. // By default, we'll de-indent your commit
  29. // template and will keep empty lines.
  30. prompter: function(cz, commit) {
  31. console.log('\nLine 1 will be cropped at 100 characters. All other lines will be wrapped after 100 characters.\n');
  32. // Let's ask some questions of the user
  33. // so that we can populate our commit
  34. // template.
  35. //
  36. // See inquirer.js docs for specifics.
  37. // You can also opt to use another input
  38. // collection library if you prefer.
  39. cz.prompt([
  40. {
  41. type: 'list',
  42. name: 'type',
  43. message: 'Select the type of change that you\'re committing:',
  44. choices: choices
  45. }, {
  46. type: 'input',
  47. name: 'scope',
  48. message: 'Denote the scope of this change ($location, $browser, $compile, etc.):\n'
  49. }, {
  50. type: 'input',
  51. name: 'subject',
  52. message: 'Write a short, imperative tense description of the change:\n'
  53. }, {
  54. type: 'input',
  55. name: 'body',
  56. message: 'Provide a longer description of the change:\n'
  57. }, {
  58. type: 'input',
  59. name: 'footer',
  60. message: 'List any breaking changes or issues closed by this change:\n'
  61. }
  62. ]).then(function(answers) {
  63. var maxLineWidth = 100;
  64. var wrapOptions = {
  65. trim: true,
  66. newline: '\n',
  67. indent:'',
  68. width: maxLineWidth
  69. };
  70. // parentheses are only needed when a scope is present
  71. var scope = answers.scope.trim();
  72. scope = scope ? '(' + answers.scope.trim() + ')' : '';
  73. // Hard limit this line
  74. var head = (answers.type + scope + ': ' + answers.subject.trim()).slice(0, maxLineWidth);
  75. // Wrap these lines at 100 characters
  76. var body = wrap(answers.body, wrapOptions);
  77. var footer = wrap(answers.footer, wrapOptions);
  78. commit(head + '\n\n' + body + '\n\n' + footer);
  79. });
  80. }
  81. };
  82. };