Skip to content

Commit

Permalink
Merge branch 'master' into es6
Browse files Browse the repository at this point in the history
  • Loading branch information
raineorshine committed Oct 7, 2019
2 parents b394a94 + 8488887 commit a280c59
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -85,7 +85,7 @@ $ ncu '/^(?!gulp-).*$/'
Options
--------------

--configFilePath rc config file path (default: ./)
--configFilePath rc config file path (default: directory of `packageFile` or ./ otherwise)
--configFileName rc config file name (default: .ncurc.{json,yml,js})
--dep check only a specific section(s) of dependencies:
prod|dev|peer|optional|bundle (comma-delimited)
Expand All @@ -109,7 +109,7 @@ Options
-p, --packageManager npm or bower (default: npm)
--packageData include stringified package file (use stdin instead)
--packageFile package file location (default: ./package.json)
--pre include -alpha, -beta, -rc. Default: 0. Default
--pre include -alpha, -beta, -rc. Default: 0. Default
with --newest and --greatest: 1.
-r, --registry specify third-party NPM registry
--removeRange remove version ranges from the final package version
Expand Down
17 changes: 9 additions & 8 deletions bin/ncu
Expand Up @@ -6,7 +6,6 @@ const program = require('commander');
const updateNotifier = require('update-notifier');
const cint = require('cint');
const _ = require('lodash');
const rcLoader = require('rc-config-loader');
const ncu = require('../lib/npm-check-updates');
const pkg = require('../package.json');

Expand All @@ -19,7 +18,7 @@ if (notifier.update && notifier.update.latest !== pkg.version) {
program
.description('[filter] is a list or regex of package names to check (all others will be ignored).')
.usage('[options] [filter]')
.option('--configFilePath <path>', 'rc config file path (default: ./)')
.option('--configFilePath <path>', 'rc config file path (default: directory of `packageFile` or ./ otherwise)')
.option('--configFileName <path>', 'rc config file name (default: .ncurc.{json,yml,js})')
.option('--dep <dep>', 'check only a specific section(s) of dependencies: prod|dev|peer|optional|bundle (comma-delimited)')
.option('-e, --error-level <n>', 'set the error-level. 1: exits with error code 0 if no errors occur. 2: exits with error code 0 if no packages need updating (useful for continuous integration). Default is 1.', cint.partialAt(parseInt, 1, 10), 1)
Expand Down Expand Up @@ -55,14 +54,16 @@ program

program.parse(process.argv);

const rcFile = rcLoader('ncurc', {
configFileName: program.configFileName || '.ncurc',
defaultExtension: ['.json', '.yml', '.js'],
cwd: program.configFilePath || undefined
const {configFileName, configFilePath, packageFile} = program;

const rcConfig = ncu.getNcurc({
configFileName,
configFilePath,
packageFile
});

const rcArguments = rcFile && rcFile.config ?
_.flatten(_.map(rcFile.config, (value, name) =>
const rcArguments = rcConfig ?
_.flatten(_.map(rcConfig, (value, name) =>
value === true ? [`--${name}`] : [`--${name}`, value]
)) : [];

Expand Down
21 changes: 20 additions & 1 deletion lib/npm-check-updates.js
Expand Up @@ -13,6 +13,7 @@ const Table = require('cli-table');
const chalk = require('chalk');
const {promisify} = require('util');
const fs = require('fs');
const rcLoader = require('rc-config-loader');
const vm = require('./versionmanager');
const packageManagers = require('./package-managers');
const versionUtil = require('./version-util');
Expand Down Expand Up @@ -433,6 +434,24 @@ async function run(options={}) {
return await Promise.race([timeoutPromise, getAnalysis()]);
}

/**
* @param {PlainObject} [cfg]
* @param {string} [cfg.configFileName=".ncurc"]
* @param {string} [cfg.configFilePath]
* @param {string} [cfg.packageFile]
* @returns {PlainObject|undefined}
*/
function getNcurc({configFileName, configFilePath, packageFile} = {}) {
const rcFile = rcLoader('ncurc', {
configFileName: configFileName || '.ncurc',
defaultExtension: ['.json', '.yml', '.js'],
cwd: configFilePath ||
(packageFile ? path.dirname(packageFile) : undefined)
});
return rcFile && rcFile.config;
}

module.exports = Object.assign({
run
run,
getNcurc
}, vm);

0 comments on commit a280c59

Please sign in to comment.