-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
263 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export 'package:pubspec_version/src/application.dart'; | ||
export 'package:pubspec_version/src/cli/build_app.dart'; | ||
export 'package:pubspec_version/src/console.dart'; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import 'package:args/command_runner.dart'; | ||
import 'package:pubspec_version/src/cli/command_container.dart'; | ||
import 'package:pubspec_version/src/cli/pub_spec_command.dart'; | ||
import 'package:pubspec_version/src/console.dart'; | ||
|
||
CommandRunner<int> buildApp(Console console) => | ||
CommandRunner<int>('pubver', 'Package version manager.') | ||
..addCommand(CommandContainer( | ||
'bump', | ||
'Bumps the package version.', | ||
[ | ||
PubSpecCommand( | ||
'breaking', | ||
'Bumps the version to the next breaking.', | ||
(_) async { | ||
await _.bumpBreaking(); | ||
console.log(await _.readVersion()); | ||
return 0; | ||
}, | ||
), | ||
PubSpecCommand( | ||
'major', | ||
'Bumps the major version.', | ||
(_) async { | ||
await _.bumpMajor(); | ||
console.log(await _.readVersion()); | ||
return 0; | ||
}, | ||
), | ||
PubSpecCommand( | ||
'minor', | ||
'Bumps the minor version.', | ||
(_) async { | ||
await _.bumpMinor(); | ||
console.log(await _.readVersion()); | ||
return 0; | ||
}, | ||
), | ||
PubSpecCommand( | ||
'patch', | ||
'Bumps the patch version.', | ||
(_) async { | ||
await _.bumpPatch(); | ||
console.log(await _.readVersion()); | ||
return 0; | ||
}, | ||
), | ||
PubSpecCommand( | ||
'build', | ||
'Bumps the first numeric part of the build version.', | ||
(_) async { | ||
await _.bumpBuild(); | ||
console.log(await _.readVersion()); | ||
return 0; | ||
}, | ||
), | ||
], | ||
)) | ||
..addCommand(PubSpecCommand( | ||
'set', | ||
'Sets the package version.', | ||
(_) async { | ||
if (_.arguments.length < 2) { | ||
console.error( | ||
'Please provide the version' + '\n' * 2 + 'Example: set 3.2.1'); | ||
return 64; | ||
} | ||
await _.writeVersion(_.getArgument(1)); | ||
console.log(await _.readVersion()); | ||
return 0; | ||
}, | ||
)) | ||
..addCommand(PubSpecCommand( | ||
'get', | ||
'Gets the current package version.', | ||
(_) async { | ||
console.log(await _.readVersion()); | ||
return 0; | ||
}, | ||
)) | ||
..argParser.addOption('pubspec-dir', | ||
abbr: 'd', | ||
help: 'Directory containing pubspec.yaml.', | ||
defaultsTo: '.') | ||
..argParser.addFlag('retain-build', | ||
abbr: 'b', | ||
help: 'Retain build when bumping major, minor, or patch.', | ||
defaultsTo: false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import 'package:args/command_runner.dart'; | ||
|
||
class CommandContainer<T> extends Command<T> { | ||
final String name; | ||
final String description; | ||
|
||
CommandContainer(this.name, this.description, List<Command<T>> subcommands) { | ||
subcommands.forEach(addSubcommand); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import 'package:args/command_runner.dart'; | ||
import 'package:pubspec_version/src/pubspec_version_app.dart'; | ||
|
||
class PubSpecCommand extends Command<int> { | ||
final String description; | ||
final String name; | ||
final _Payload _payload; | ||
|
||
PubSpecCommand(this.name, this.description, this._payload); | ||
|
||
bool get retainBuild => globalResults['retain-build']; | ||
|
||
Future<String> readVersion() async => (await _app.readVersion()).toString(); | ||
|
||
Future<void> writeVersion(String version) => _app.writeVersionString(version); | ||
|
||
Future<void> bumpBreaking() => _app.bumpBreaking(retainBuild: retainBuild); | ||
|
||
Future<void> bumpMajor() => _app.bumpMajor(retainBuild: retainBuild); | ||
|
||
Future<void> bumpMinor() => _app.bumpMinor(retainBuild: retainBuild); | ||
|
||
Future<void> bumpPatch() => _app.bumpPatch(retainBuild: retainBuild); | ||
|
||
Future<void> bumpBuild() => _app.bumpBuild(); | ||
|
||
String getArgument(int index) => globalResults.arguments[index]; | ||
|
||
List<String> get arguments => globalResults.arguments; | ||
|
||
Future<int> run() => _payload(this); | ||
|
||
PubSpecVersionApp get _app => PubSpecVersionApp(globalResults['pubspec-dir']); | ||
} | ||
|
||
typedef Future<int> _Payload(PubSpecCommand command); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:pub_semver/pub_semver.dart'; | ||
import 'package:pubspec/pubspec.dart' as ps; | ||
import 'package:pubspec_version/src/version_transform.dart'; | ||
|
||
class PubSpecVersionApp { | ||
final Directory _dir; | ||
|
||
PubSpecVersionApp(String path) : _dir = Directory(path); | ||
|
||
Future<VersionTransform> readVersion() async { | ||
final pubSpec = await _load(); | ||
return VersionTransform(pubSpec.version); | ||
} | ||
|
||
Future<void> writeVersion(VersionTransform version) async { | ||
final pubSpec = await _load(); | ||
await pubSpec.copy(version: version.version).save(_dir); | ||
} | ||
|
||
Future<void> writeVersionString(String version) => | ||
writeVersion(VersionTransform(Version.parse(version))); | ||
|
||
Future<void> bumpBreaking({bool retainBuild = false}) => | ||
_update((_) => _.bumpBreaking(), retainBuild: retainBuild); | ||
|
||
Future<void> bumpMajor({bool retainBuild = false}) => | ||
_update((_) => _.bumpMajor(), retainBuild: retainBuild); | ||
|
||
Future<void> bumpMinor({bool retainBuild = false}) => | ||
_update((_) => _.bumpMinor(), retainBuild: retainBuild); | ||
|
||
Future<void> bumpPatch({bool retainBuild = false}) => | ||
_update((_) => _.bumpPatch(), retainBuild: retainBuild); | ||
|
||
Future<void> bumpBuild() => _update((_) => _.bumpBuild()); | ||
|
||
Future<void> _update(VersionTransform mutate(VersionTransform v), | ||
{bool retainBuild = false}) async { | ||
final version = await readVersion(); | ||
var newVersion = | ||
retainBuild ? mutate(version).withBuildFrom(version) : mutate(version); | ||
await writeVersion(newVersion); | ||
} | ||
|
||
Future<ps.PubSpec> _load() => ps.PubSpec.load(_dir); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.