Skip to content

Commit

Permalink
Require Node.js 6
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Apr 25, 2018
1 parent 09f7ef0 commit 4ab22b1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: node_js
node_js:
- '10'
- '8'
- '6'
- '4'
48 changes: 24 additions & 24 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ const normalizePackageData = require('normalize-package-data');
delete require.cache[__filename];
const parentDir = path.dirname(module.parent.filename);

module.exports = (helpMessage, opts) => {
module.exports = (helpMessage, options) => {
loudRejection();

if (typeof helpMessage === 'object' && !Array.isArray(helpMessage)) {
opts = helpMessage;
options = helpMessage;
helpMessage = '';
}

opts = Object.assign({
options = Object.assign({
pkg: readPkgUp.sync({
cwd: parentDir,
normalize: false
Expand All @@ -34,46 +34,46 @@ module.exports = (helpMessage, opts) => {
autoHelp: true,
autoVersion: true,
booleanDefault: false
}, opts);
}, options);

const minimistFlags = opts.flags && typeof opts.booleanDefault !== 'undefined' ? Object.keys(opts.flags).reduce(
const minimistFlags = options.flags && typeof options.booleanDefault !== 'undefined' ? Object.keys(options.flags).reduce(
(flags, flag) => {
if (flags[flag].type === 'boolean' && !Object.prototype.hasOwnProperty.call(flags[flag], 'default')) {
flags[flag].default = opts.booleanDefault;
flags[flag].default = options.booleanDefault;
}

return flags;
},
opts.flags
) : opts.flags;
options.flags
) : options.flags;

let minimistOpts = Object.assign({
arguments: opts.input
let minimistoptions = Object.assign({
arguments: options.input
}, minimistFlags);

minimistOpts = decamelizeKeys(minimistOpts, '-', {exclude: ['stopEarly', '--']});
minimistoptions = decamelizeKeys(minimistoptions, '-', {exclude: ['stopEarly', '--']});

if (opts.inferType) {
delete minimistOpts.arguments;
if (options.inferType) {
delete minimistoptions.arguments;
}

minimistOpts = buildMinimistOptions(minimistOpts);
minimistoptions = buildMinimistOptions(minimistoptions);

if (minimistOpts['--']) {
minimistOpts.configuration = Object.assign({}, minimistOpts.configuration, {'populate--': true});
if (minimistoptions['--']) {
minimistoptions.configuration = Object.assign({}, minimistoptions.configuration, {'populate--': true});
}

const pkg = opts.pkg;
const argv = yargs(opts.argv, minimistOpts);
let help = redent(trimNewlines((opts.help || '').replace(/\t+\n*$/, '')), 2);
const {pkg} = options;
const argv = yargs(options.argv, minimistoptions);
let help = redent(trimNewlines((options.help || '').replace(/\t+\n*$/, '')), 2);

normalizePackageData(pkg);

process.title = pkg.bin ? Object.keys(pkg.bin)[0] : pkg.name;

let description = opts.description;
let {description} = options;
if (!description && description !== false) {
description = pkg.description;
({description} = pkg);
}

help = (description ? `\n ${description}\n` : '') + (help ? `\n${help}\n` : '\n');
Expand All @@ -84,15 +84,15 @@ module.exports = (helpMessage, opts) => {
};

const showVersion = () => {
console.log(typeof opts.version === 'string' ? opts.version : pkg.version);
console.log(typeof options.version === 'string' ? options.version : pkg.version);
process.exit();
};

if (argv.version && opts.autoVersion) {
if (argv.version && options.autoVersion) {
showVersion();
}

if (argv.help && opts.autoHelp) {
if (argv.help && options.autoHelp) {
showHelp(0);
}

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"url": "sindresorhus.com"
},
"engines": {
"node": ">=4"
"node": ">=6"
},
"scripts": {
"test": "xo && ava"
Expand Down Expand Up @@ -50,7 +50,7 @@
},
"devDependencies": {
"ava": "*",
"execa": "^0.8.0",
"execa": "^0.10.0",
"indent-string": "^3.0.0",
"xo": "*"
},
Expand Down

0 comments on commit 4ab22b1

Please sign in to comment.