Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(version): Added semver versioning flags for convenience #5670

Merged
merged 1 commit into from
Apr 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions __tests__/commands/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,24 @@ test('run version and make sure commit hooks are disabled by config', async ():
expect(spawn.mock.calls[2][0]).toEqual(gitArgs);
});
});

test('run version with --major flag and make sure major version is incremented', (): Promise<void> => {
return runRun([], {gitTagVersion, major: true}, 'no-args', async (config): ?Promise<void> => {
const pkg = await fs.readJson(path.join(config.cwd, 'package.json'));
expect(pkg.version).toEqual('2.0.0');
});
});

test('run version with --minor flag and make sure minor version is incremented', (): Promise<void> => {
return runRun([], {gitTagVersion, minor: true}, 'no-args', async (config): ?Promise<void> => {
const pkg = await fs.readJson(path.join(config.cwd, 'package.json'));
expect(pkg.version).toEqual('1.1.0');
});
});

test('run version with --patch flag and make sure patch version is incremented', (): Promise<void> => {
return runRun([], {gitTagVersion, patch: true}, 'no-args', async (config): ?Promise<void> => {
const pkg = await fs.readJson(path.join(config.cwd, 'package.json'));
expect(pkg.version).toEqual('1.0.1');
});
});
14 changes: 14 additions & 0 deletions src/cli/commands/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ function isValidNewVersion(oldVersion: string, newVersion: string, looseSemver:
export function setFlags(commander: Object) {
commander.description('Update the version of your package via the command line.');
commander.option(NEW_VERSION_FLAG, 'new version');
commander.option('--major', 'auto-increment major version number');
commander.option('--minor', 'auto-increment minor version number');
commander.option('--patch', 'auto-increment patch version number');
commander.option('--message [message]', 'message');
commander.option('--no-git-tag-version', 'no git tag version');
commander.option('--no-commit-hooks', 'bypass git hooks when committing new version');
Expand Down Expand Up @@ -77,6 +80,17 @@ export async function setVersion(
throw new MessageError(reporter.lang('invalidVersion'));
}

// get new version by bumping old version, if requested
if (!newVersion) {
if (flags.major) {
newVersion = semver.inc(oldVersion, 'major');
} else if (flags.minor) {
newVersion = semver.inc(oldVersion, 'minor');
} else if (flags.patch) {
newVersion = semver.inc(oldVersion, 'patch');
}
}

// wasn't passed a version arg so ask interactively
while (!newVersion) {
// make sure we're not running in non-interactive mode before asking for new version
Expand Down