Skip to content

Commit

Permalink
feat(api): If single version is provided, assuming it is to version a…
Browse files Browse the repository at this point in the history
…nd reads from from the pack

closes #21
  • Loading branch information
bahmutov committed Nov 18, 2015
1 parent 9863ee8 commit ab78389
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
5 changes: 3 additions & 2 deletions bin/changed-log.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ options.auth = _.some(process.argv, function (word) {
});
debug('options', options);

// TODO implement semver in check-more-types
var isValidCliOptions = check.schema.bind(null, {
name: check.unemptyString,
from: check.unemptyString,
to: check.unemptyString
from: check.maybe.unemptyString,
to: check.maybe.unemptyString
});
if (!isValidCliOptions(options)) {
log('%s@%s <package name> <from version> <to version> [options]',
Expand Down
44 changes: 43 additions & 1 deletion src/changed-log.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,53 @@ function changedLogReport(options, reportOptions) {
});
}

function onlyProvidedFromVersion(options) {
return check.unemptyString(options.from) &&
!options.to;
}

function fillMissingFromOptions(options) {
la(check.unemptyString(options.name), 'missing package name', options);
var exists = require('fs').existsSync;
var join = require('path').join;
var packageFileName = join(process.cwd(), 'package.json');
if (!exists(packageFileName)) {
return;
}
var pkg = require(packageFileName);
var dependency = (pkg.dependencies && pkg.dependencies[options.name]) ||
(pkg.devDependencies && pkg.devDependencies[options.name]);
if (dependency) {
options.to = options.from;
options.from = dependency;
console.log('using "from" version from package.json %s', dependency);
}
}

function missingOptions(options) {
var isValidCliOptions = check.schema.bind(null, {
name: check.unemptyString,
from: check.unemptyString,
to: check.unemptyString
});
return !isValidCliOptions(options);
}

function changedLog(options, reportOptions) {
// TODO validate options
options = options || {};
reportOptions = reportOptions || {};

if (onlyProvidedFromVersion(options)) {
// assume we specified target "to" version
fillMissingFromOptions(options);
}

if (missingOptions(options)) {
console.error('Missing options', options);
/* eslint no-process-exit:0 */
process.exit(-1);
}

if (options.auth) {
log('Please login to github to increase the API rate limit');
var githubLogin = require('./github-login');
Expand Down

0 comments on commit ab78389

Please sign in to comment.