Chromium Code Reviews| Index: tool/grind.dart |
| diff --git a/tool/grind.dart b/tool/grind.dart |
| index 6690404c035b9c83e94aba6641e401cb6423f640..cdb14829741252bb86ca7fb7d593e3d994feffe4 100644 |
| --- a/tool/grind.dart |
| +++ b/tool/grind.dart |
| @@ -3,23 +3,34 @@ |
| // BSD-style license that can be found in the LICENSE file. |
| import 'package:grinder/grinder.dart'; |
| +import 'package:pub_semver/pub_semver.dart'; |
| import 'package:yaml/yaml.dart' as yaml; |
| +/// Matches the version line in dart_style's pubspec. |
| +final versionPattern = new RegExp(r"^version: .*$", multiLine: true); |
|
jakemac
2015/12/07 22:25:17
I would typically make this private even in entry
Bob Nystrom
2015/12/07 22:50:35
Done. I don't usually bother for entry points, but
|
| + |
| main(args) => grind(args); |
| @DefaultTask() |
| @Task() |
| validate() async { |
| + // Test it. |
| await new TestRunner().testAsync(); |
| + |
| + // Make sure it's warning clean. |
| Analyzer.analyze("bin/format.dart", fatalWarnings: true); |
| - DartFmt.format("."); |
| + |
| + // Format it. |
| + Dart.run("bin/format.dart", arguments: ["-w", "."]); |
| } |
| /// Gets ready to publish a new version of the package. |
| /// |
| /// To publish a version, you need to: |
| /// |
| -/// 1. Bump the version in the pubspec to a non-dev number. |
| +/// 1. Make sure the version in the pubspec is a "-dev" number. This should |
| +/// already be the case since you've already landed patches that change |
| +/// the formatter and bumped to that as a consequence. |
| /// |
| /// 2. Run this task: |
| /// |
| @@ -47,16 +58,27 @@ validate() async { |
| @Depends(validate) |
| bump() async { |
| // Read the version from the pubspec. |
| - var pubspec = yaml.loadYaml(getFile("pubspec.yaml").readAsStringSync()); |
| - var version = pubspec["version"]; |
| - print(version); |
| + var pubspecFile = getFile("pubspec.yaml"); |
| + var pubspec = pubspecFile.readAsStringSync(); |
| + var version = new Version.parse(yaml.loadYaml(pubspec)["version"]); |
| + |
| + // Require a "-dev" version since we don't otherwise know what to bump it to. |
| + if (!version.isPreRelease) throw "Cannot publish non-dev version $version."; |
| + |
| + // Don't allow versions like "1.2.3-dev+4" because it's not clear if the |
| + // user intended the "+4" to be discarded or not. |
| + if (version.build.isNotEmpty) throw "Cannot publish build version $version."; |
| + |
| + var bumped = new Version(version.major, version.minor, version.patch); |
| - if (version.contains("-dev")) throw "Cannot publish a dev version."; |
| + // Update the version in the pubspec. |
| + pubspec = pubspec.replaceAll(versionPattern, "version: $bumped"); |
|
jakemac
2015/12/07 22:25:17
If the Version class has an explicit getter for th
Bob Nystrom
2015/12/07 22:50:35
I want to not just match the version string in cas
jakemac
2015/12/07 23:02:53
Oh, I wasn't very clear here :). I was just talkin
|
| + pubspecFile.writeAsStringSync(pubspec); |
| // Update the version constant in bin/format.dart. |
| var binFormatFile = getFile("bin/format.dart"); |
| var binFormat = binFormatFile.readAsStringSync().replaceAll( |
| - new RegExp(r'const version = "[^"]+";'), 'const version = "$version";'); |
| + new RegExp(r'const version = "[^"]+";'), 'const version = "$bumped";'); |
| binFormatFile.writeAsStringSync(binFormat); |
| - print("Updated version constant to '$version'."); |
| + log("Updated version to '$bumped'."); |
| } |