parse static method
- String text
Returns the Version parsed from the text
with the hyphens in
pre-releases being parsed as a separate parts, if any.
Example: 0.1.0-alpha.13-5-qwe
-> preRelease: ['alpha', 13, 5, 'qwe']
.
This is required due to PubspecBuilder using git describe --tags
,
which returns hyphens instead of dots, and replacing that behavior seems a
bigger evil than this.
Implementation
static Version parse(String text) {
final Version parsed = Version.parse(text);
return Version(
parsed.major,
parsed.minor,
parsed.patch,
pre:
parsed.preRelease.isEmpty
? null
: parsed.preRelease
.map((e) => e is String ? e.replaceAll('-', '.') : e)
.join('.'),
build: parsed.build.isEmpty ? null : parsed.build.join('.'),
);
}