generateChangelog method
Generate changelog of current version.
Generate a changelog file with the name of outputFilename
,
containing the changelog of current version.
under the root folder. There is supposed to be a pubspec.yaml
manifest file located directly under the root folder,
where it can get current version from.
If there's no CHANGELOG.md
and pubspec.yaml
under the root folder it will throw an Exception.
Implementation
void generateChangelog({String outputFilename = '.changelog.md'}) {
final lines = changelog
.readAsStringSync()
.split('\n')
.map((line) => line.trim());
final buffer = StringBuffer();
var inside = false;
final version = manifest['version'] as String;
for (final line in lines) {
if (line == '## $version') {
inside = true;
} else if (line.startsWith('##') && inside) {
break;
} else if (inside) {
buffer.writeln(line);
}
}
final result = buffer.toString().trim();
File(join(root.path, outputFilename)).writeAsStringSync(result);
}