Skip to content

Commit

Permalink
feat(commitlint config): ✨ format commit message with local com
Browse files Browse the repository at this point in the history
  • Loading branch information
wheatma committed Jul 2, 2019
1 parent 27948dc commit 3481762
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 2 deletions.
43 changes: 43 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* @since 2016-11-22 13:29
* @author vivaxy
*/
const yargs = require('yargs');
const updateNotifier = require('update-notifier');
const findUp = require('find-up');
const fs = require('fs');

const pkg = require('../package.json');
const index = require('../commands/index.js');

const configureYargs = () => {
const configPath = findUp.sync(['.gacprc', '.gacprc.json']);
const config = configPath ? JSON.parse(fs.readFileSync(configPath)) : {};
return yargs
.options({
push: {
alias: 'p',
describe: 'run git push',
default: true,
},
emoji: {
alias: 'e',
describe: 'use emoji code',
choices: ['code', 'emoji'],
default: 'code',
},
})
.config(config)
.help()
.version().argv._;
};

configureYargs();
updateNotifier({ pkg }).notify();

const argv = yargs.argv;

console.log(argv);
index(argv).catch((ex) => {
throw ex;
});
11 changes: 11 additions & 0 deletions lib/messages/commitlintConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const load = require('@commitlint/load');

module.exports = async () => {
let rules;
try {
rules = await load().then((config) => config.rules);
} catch (e) {
rules = {};
}
return rules;
};
22 changes: 20 additions & 2 deletions lib/prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const {
updateTypesStat,
} = require('./messages/commitTypes.js');
const { getGitmojis, updateGitmojisStat } = require('./messages/gitmojis.js');
const getCommitlintConfigRules = require('./messages/commitlintConfig');

function debug(...message) {
log.debug('gacp:prompt', ...message);
Expand Down Expand Up @@ -109,8 +110,25 @@ module.exports = async function prompt({ emojiType }) {
debug('got answers', answers);
setHistory(answers);

const maxHeaderLength = 72;
const maxLineWidth = 100;
const {
'header-max-length': headerMaxLengthRule,
'body-max-line-length': bodyMaxLengthRule,
} = await getCommitlintConfigRules();

const maxHeaderLength =
headerMaxLengthRule &&
headerMaxLengthRule.length &&
headerMaxLengthRule[0] === 2
? headerMaxLengthRule[2]
: Infinity;
debug('maxHeaderLength:', maxHeaderLength);

const maxLineWidth =
bodyMaxLengthRule && bodyMaxLengthRule.length && bodyMaxLengthRule[0] === 2
? bodyMaxLengthRule[2]
: Infinity;

debug('maxLineWidth:', maxLineWidth);

const wrapOptions = {
trim: true,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
},
"homepage": "/~https://github.com/vivaxy/gacp#readme",
"dependencies": {
"@commitlint/load": "^8.0.0",
"chalk": "^2.4.2",
"conventional-commit-types": "^2.1.1",
"cosmiconfig": "^5.2.1",
Expand Down

0 comments on commit 3481762

Please sign in to comment.