Skip to content

Commit

Permalink
fix: ensure node4 compat
Browse files Browse the repository at this point in the history
  • Loading branch information
marionebl committed Jul 11, 2017
1 parent fe8caff commit bfeb653
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
13 changes: 8 additions & 5 deletions @commitlint/cli/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ const help = require('./help');
*/
const rules = {
fromStdin: (input, flags) => input.length === 0 &&
flags.from === null &&
flags.to === null &&
typeof flags.from !== 'string' &&
typeof flags.to !== 'string' &&
!flags.edit
};

Expand Down Expand Up @@ -62,7 +62,8 @@ const cli = meow({
const load = seed => core.load(seed);

function main(options) {
const {input: raw, flags} = options;
const raw = options.input;
const flags = options.flags;
const fromStdin = rules.fromStdin(raw, flags);

const range = pick(flags, 'edit', 'from', 'to');
Expand Down Expand Up @@ -93,8 +94,10 @@ function main(options) {
));
}

function getSeed({extends: e}) {
return e ? {extends: e.split(', ')} : {};
function getSeed(seed) {
const e = Array.isArray(seed.extends) ? seed.extends : [seed.extends];
const n = e.filter(i => typeof i === 'string');
return n.length > 0 ? {extends: n} : {};
}

// Start the engine
Expand Down
9 changes: 6 additions & 3 deletions @commitlint/cli/help.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
module.exports = configuration => {
const lines = Object.entries(configuration.description)
.map(entry => {
const [name, desc] = entry;
const name = entry[0];
const desc = entry[1];
const alias = Object.entries(configuration.alias)
.find(entry => entry[1] === name)
.map(entry => entry[0])[0];
Expand All @@ -11,14 +12,16 @@ module.exports = configuration => {

const longest = lines
.map(line => {
const [flags] = line;
const flags = line[0];
return flags.reduce((sum, flag) => sum + flag.length, 0);
})
.sort(Number)[0];

return lines
.map(line => {
const [flags, desc, defaults] = line;
const flags = line[0];
const desc = line[1];
const defaults = line[2];
const fs = flags.map(flag => flag.length > 1 ? `--${flag}` : `-${flag}`);
const ds = defaults ? `, defaults to: ${defaults}` : '';
const length = flags.reduce((sum, flag) => sum + flag.length, 0);
Expand Down
10 changes: 4 additions & 6 deletions @commitlint/core/src/library/resolve-extends.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'path';
import from from 'resolve-from';
import {merge, omit, values} from 'lodash';
import {merge, omit} from 'lodash';

// Resolve extend configs
export default function resolveExtends(config = {}, context = {}) {
Expand All @@ -18,8 +18,7 @@ export default function resolveExtends(config = {}, context = {}) {

// (any, string, string, Function) => any[];
function loadExtends(config = {}, context = {}) {
const toExtend = values(config.extends || []);
return toExtend.reduce((configs, raw) => {
return (config.extends || []).reduce((configs, raw) => {
const id = getId(raw, context.prefix);
const resolve = context.resolve || resolveId;
const resolved = resolve(id, context);
Expand All @@ -46,7 +45,6 @@ function getId(raw = '', prefix = '') {
return (scoped || relative) ? raw : [prefix, raw].filter(String).join('-');
}

function resolveId(id, context) {
const cwd = context.cwd || process.cwd();
return from(cwd, id);
function resolveId(id, context = {}) {
return from(context.cwd || process.cwd(), id);
}

0 comments on commit bfeb653

Please sign in to comment.