parent
5b8c9ae418
commit
cac11a76a3
@ -0,0 +1,41 @@
|
||||
part of 'grind.dart';
|
||||
|
||||
@Task('add minor version number')
|
||||
void addVersion() async {
|
||||
String projectPath = Directory('.').absolute.path;
|
||||
String yamlPath = join(projectPath, 'pubspec.yaml');
|
||||
String yamlContent = await File(yamlPath).readAsString();
|
||||
dynamic content = loadYaml(yamlContent);
|
||||
String version = content['version'];
|
||||
//rename version
|
||||
|
||||
Version resultVersion = VersionTool.fromText(version).nextMinorTag('dev');
|
||||
|
||||
String result = yamlContent.replaceFirst(version, resultVersion.toString());
|
||||
await File(yamlPath).writeAsString(result);
|
||||
}
|
||||
|
||||
@Task('add path version number')
|
||||
void addVersionPatch() async {
|
||||
String projectPath = Directory('.').absolute.path;
|
||||
String yamlPath = join(projectPath, 'pubspec.yaml');
|
||||
String yamlContent = await File(yamlPath).readAsString();
|
||||
dynamic content = loadYaml(yamlContent);
|
||||
String version = content['version'];
|
||||
//rename version
|
||||
|
||||
Version resultVersion = VersionTool.fromText(version).nextPatchTag('dev');
|
||||
|
||||
String result = yamlContent.replaceFirst(version, resultVersion.toString());
|
||||
await File(yamlPath).writeAsString(result);
|
||||
}
|
||||
|
||||
@Task()
|
||||
Future<String> getVersion() async {
|
||||
String projectPath = Directory('.').absolute.path;
|
||||
String yamlPath = join(projectPath, 'pubspec.yaml');
|
||||
String yamlContent = await File(yamlPath).readAsString();
|
||||
dynamic content = loadYaml(yamlContent);
|
||||
String version = content['version'];
|
||||
return version;
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
import 'package:pub_semver/pub_semver.dart';
|
||||
|
||||
enum VersionNumber {
|
||||
MAJOR,
|
||||
MINOR,
|
||||
PATCH,
|
||||
}
|
||||
|
||||
class VersionTool {
|
||||
Version version;
|
||||
VersionTool(this.version);
|
||||
VersionTool.fromText(String text) : version = Version.parse(text);
|
||||
|
||||
Version get nextMajor => _addBuildNumber(VersionNumber.MAJOR);
|
||||
Version get nextMinor => _addBuildNumber(VersionNumber.MINOR);
|
||||
Version get nextPatch => _addBuildNumber(VersionNumber.PATCH);
|
||||
|
||||
Version nextMajorTag(String tag) => _addBuildNumber(
|
||||
VersionNumber.MAJOR,
|
||||
tag: tag,
|
||||
);
|
||||
Version nextMinorTag(String tag) => _addBuildNumber(
|
||||
VersionNumber.MINOR,
|
||||
tag: tag,
|
||||
);
|
||||
Version nextPatchTag(String tag) => _addBuildNumber(
|
||||
VersionNumber.PATCH,
|
||||
tag: tag,
|
||||
);
|
||||
|
||||
Version _addBuildNumber(VersionNumber type, {String? tag}) {
|
||||
switch (type) {
|
||||
case VersionNumber.MAJOR:
|
||||
return Version(
|
||||
version.major,
|
||||
version.minor,
|
||||
version.patch + 1,
|
||||
pre: tag,
|
||||
build: '${(version.build.first as int) + 1}',
|
||||
);
|
||||
case VersionNumber.MINOR:
|
||||
return Version(
|
||||
version.major,
|
||||
version.minor + 1,
|
||||
0,
|
||||
pre: tag,
|
||||
build: '${(version.build.first as int) + 1}',
|
||||
);
|
||||
case VersionNumber.PATCH:
|
||||
return Version(
|
||||
version.major + 1,
|
||||
0,
|
||||
0,
|
||||
pre: tag,
|
||||
build: '${(version.build.first as int) + 1}',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue