Skip to content

Commit

Permalink
Zeroing out the subsequent parts of the build (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
f3ath authored Aug 18, 2019
1 parent ff71f1f commit 8470405
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 13 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [0.5.0] - 2019-08-18
### Changed
- the `bump build` command sets the subsequent numeric build parts to zeroes

## [0.4.0] - 2019-08-18
### Added
- the `bump build` command
Expand Down Expand Up @@ -37,7 +41,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Initial version

[Unreleased]: https://github.com/f3ath/pubspec-version/compare/0.4.0...HEAD
[Unreleased]: https://github.com/f3ath/pubspec-version/compare/0.5.0...HEAD
[0.5.0]: https://github.com/f3ath/pubspec-version/compare/0.4.0...0.5.0
[0.4.0]: https://github.com/f3ath/pubspec-version/compare/0.3.0...0.4.0
[0.3.0]: https://github.com/f3ath/pubspec-version/compare/0.2.2...0.3.0
[0.2.2]: https://github.com/f3ath/pubspec-version/compare/0.2.1...0.2.2
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ Before | Command | After
0.2.1+42 | `pubver bump build` | 0.2.1+43
0.2.1+foo | `pubver bump build` | 0.2.1+foo.1
0.2.1+42.foo | `pubver bump build` | 0.2.1+43.foo
0.2.1+foo.bar.1.2 | `pubver bump build` | 0.2.1+foo.bar.2.2
0.2.1+foo.bar.1.2 | `pubver bump build` | 0.2.1+foo.bar.2.0

The `bump build` command is a bit tricky. It either increments the first numeric part of the build (if there is a
numeric part) or appends `.1` to the build (otherwise).
numeric part) setting other numeric parts to zeroes, or appends `.1` to the build (otherwise).

### Setting the version
```
Expand Down
17 changes: 9 additions & 8 deletions lib/src/next_build.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import 'package:pub_semver/pub_semver.dart';

Version nextBuild(Version v) {
final build = List.from(v.build);
final firstIntegerIndex = build.indexWhere((_) => _ is int);
if (firstIntegerIndex == -1) return _withBuild(v, (build + [1]).join('.'));
build[firstIntegerIndex] += 1;
return _withBuild(v, (build).join('.'));
var incremented = false;
final build = v.build.map((part) {
if (part is! int) return part;
if (incremented) return 0;
incremented = true;
return part + 1;
}).toList();
if (!incremented) build.add(1);
return Version(v.major, v.minor, v.patch, build: build.join('.'));
}

Version _withBuild(Version v, String build) =>
Version(v.major, v.minor, v.patch, build: build);
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ author: "Alexey Karapetov <[email protected]>"
description: "A CLI tool to set/bump the package version in pubspec.yaml. The \"npm version\" for Dart."
homepage: "https://github.com/f3ath/pubspec-version"
name: "pubspec_version"
version: "0.4.0"
version: "0.5.0"
dependencies:
args: "^1.5.0"
pub_semver: "^1.4.2"
Expand Down
2 changes: 1 addition & 1 deletion test/unit/next_build_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ void main() {

test('in a complex build the first numeric part gets incremented', () async {
final v = Version.parse('1.2.3+foo.1.2.3.bar');
expect(nextBuild(v).toString(), '1.2.3+foo.2.2.3.bar');
expect(nextBuild(v).toString(), '1.2.3+foo.2.0.0.bar');
});
}

0 comments on commit 8470405

Please sign in to comment.