Skip to content

Commit

Permalink
fix: remove babel
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdlg committed Jan 14, 2018
1 parent 4c4d96b commit 259cc0f
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 59 deletions.
9 changes: 0 additions & 9 deletions .babelrc

This file was deleted.

3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,5 @@ $RECYCLE.BIN/

# End of https://www.gitignore.io/api/macos,windows,linux,node

lib
package-lock.json
yarn.lock
yarn.lock
19 changes: 19 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const types = require('conventional-changelog-metahub/types');
const aliases = require('conventional-changelog-metahub/aliases');
const commitizen = require('commitizen');
const _ = require('lodash');
const questions = require('./lib/questions');
const format = require('./lib/format-commit');

const config = _.merge(commitizen.configLoader.load(), {
'cz-conventional-commit': {maxSubjectLength: 72, bodyLineLength: 100, emoji: false},
})['cz-conventional-commit'];

module.exports = {
prompter(cz, commit) {
return cz
.prompt(questions({types: types.types, aliases}, config))
.then(answers => format(answers, {types: types.types, aliases}, config))
.then(commitMessage => commit(commitMessage));
},
};
17 changes: 8 additions & 9 deletions src/format-commit.js → lib/format-commit.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import wrap from 'word-wrap';
import {truncate} from 'lodash';
const wrap = require('word-wrap');
const _ = require('lodash');

/**
* Create a formatted commit message based on answers provided by user.
Expand All @@ -26,8 +26,7 @@ import {truncate} from 'lodash';
* @param {boolean} config.emoji `true` to add emoji at the end of the commit message
* @return {string} formatted commit
*/
export default function formatCommit(answers, options, config) {
const {types, aliases} = options;
module.exports = (answers, options, config) => {
const wrapOptions = {
trim: true,
newline: '\n',
Expand All @@ -37,12 +36,12 @@ export default function formatCommit(answers, options, config) {
};
// Parentheses are only needed when a scope is present
const scope = answers.scope ? answers.scope.trim() : '';
const isAlias = !Object.prototype.hasOwnProperty.call(types, answers.type);
const type = isAlias ? aliases[answers.type].type : answers.type;
const emoji = config.emoji ? (isAlias ? aliases[answers.type].emoji : types[type].emoji) : '';
const isAlias = !Object.prototype.hasOwnProperty.call(options.types, answers.type);
const type = isAlias ? options.aliases[answers.type].type : answers.type;
const emoji = config.emoji ? (isAlias ? options.aliases[answers.type].emoji : options.types[type].emoji) : '';
// Limit head to maxSubjectLength (including the trailing emoji)
// We use the String.length function to determine the length of the emoji even it returns an innacurate value (2 chars per emoji), because most likely a commit hook or linter veryfyingt he head length will also use String.length.
const head = `${truncate(`${type}${scope ? `(${scope})` : ''}: ${answers.subject.trim()}`, {
const head = `${_.truncate(`${type}${scope ? `(${scope})` : ''}: ${answers.subject.trim()}`, {
length: config.maxSubjectLength - (config.emoji ? emoji.length + 1 : 0),
})}${config.emoji ? ` ${emoji}` : ''}`;
const body = wrap(answers.body, wrapOptions);
Expand All @@ -56,4 +55,4 @@ export default function formatCommit(answers, options, config) {
.join('\n\n');

return [head, body, footer].filter(x => x).join('\n\n');
}
};
23 changes: 12 additions & 11 deletions src/questions.js → lib/questions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {map, padEnd, maxBy} from 'lodash';
import {typesOrder} from 'conventional-changelog-metahub/types';
const _ = require('lodash');
const types = require('conventional-changelog-metahub/types');

/**
* Create the Inquirer.js questions object.
Expand All @@ -18,14 +18,15 @@ import {typesOrder} from 'conventional-changelog-metahub/types';
* @param {string} config.bodyLineLength length of body lines
* @param {boolean} config.emoji `true` to add emoji at the end of the commit message
*/
export default function questions(options, config) {
const {types, aliases} = options;
const allTypes = Object.assign({}, types, aliases);
const length = maxBy(Object.keys(allTypes), type => type.length).length + 1;
const choices = map(allTypes, (type, key) => ({
name: `${padEnd(`${key}:`, length)} ${type.emoji} ${type.description}`,
module.exports = (options, config) => {
const allTypes = Object.assign({}, options.types, options.aliases);
const length = _.maxBy(Object.keys(allTypes), type => type.length).length + 1;
const choices = _.map(allTypes, (type, key) => ({
name: `${_.padEnd(`${key}:`, length)} ${type.emoji} ${type.description}`,
value: key,
})).sort((choice1, choice2) => (typesOrder.indexOf(choice1.value) < typesOrder.indexOf(choice2.value) ? -1 : 1));
})).sort(
(choice1, choice2) => (types.typesOrder.indexOf(choice1.value) < types.typesOrder.indexOf(choice2.value) ? -1 : 1)
);

return [
{type: 'list', name: 'type', message: "Select the type of change that you're committing:", choices},
Expand Down Expand Up @@ -56,7 +57,7 @@ export default function questions(options, config) {
}):\n`,
default(answers) {
if (answers.type === 'initial') {
return aliases[answers.type].description;
return options.aliases[answers.type].description;
}
return null;
},
Expand Down Expand Up @@ -85,4 +86,4 @@ export default function questions(options, config) {
},
},
];
}
};
14 changes: 6 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,13 @@
"devDependencies": {
"@commitlint/core": "^6.0.2",
"ava": "^0.24.0",
"babel-cli": "^6.26.0",
"babel-preset-env": "^1.6.0",
"codecov": "^3.0.0",
"conventional-commits-parser": "^2.0.0",
"emoji-regex": "^6.5.1",
"eslint-config-prettier": "^2.9.0",
"eslint-plugin-prettier": "^2.4.0",
"nyc": "^11.1.0",
"prettier": "~1.10.0",
"rimraf": "^2.6.1",
"semantic-release": "^12.0.0",
"sinon": "^4.0.0",
"stringz": "^0.4.0",
Expand All @@ -34,7 +31,8 @@
"node": ">=4"
},
"files": [
"lib"
"lib",
"index.js"
],
"homepage": "https://github.com/vanduynslagerp/cz-conventional-commit#readme",
"keywords": [
Expand All @@ -47,9 +45,10 @@
"git"
],
"license": "MIT",
"main": "lib/index.js",
"main": "index.js",
"nyc": {
"include": [
"index.js",
"lib/**/*.js"
],
"reporter": [
Expand Down Expand Up @@ -86,12 +85,11 @@
},
"scripts": {
"codecov": "codecov -f coverage/coverage-final.json",
"compile": "rimraf lib && babel src --source-maps --out-dir lib",
"lint": "xo",
"prepublishOnly": "npm run compile",
"pretest": "npm run compile && npm run lint",
"pretest": "npm run lint",
"semantic-release": "semantic-release",
"test": "nyc ava -vv"
"test": "nyc ava -v"
},
"xo": {
"extends": [
Expand Down
19 changes: 0 additions & 19 deletions src/index.js

This file was deleted.

2 changes: 1 addition & 1 deletion test/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import parser from 'conventional-commits-parser';
import {lint, load} from '@commitlint/core';
import {types} from 'conventional-changelog-metahub/types';
import aliases from 'conventional-changelog-metahub/aliases';
import engine from '../lib/index';
import engine from '..';

// eslint-disable-next-line ava/no-cb-test
test.cb(
Expand Down

0 comments on commit 259cc0f

Please sign in to comment.