OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 import 'package:grinder/grinder.dart'; |
| 6 import 'package:pub_semver/pub_semver.dart'; |
| 7 import 'package:yaml/yaml.dart' as yaml; |
| 8 |
| 9 /// Matches the version line in dart_style's pubspec. |
| 10 final _versionPattern = new RegExp(r"^version: .*$", multiLine: true); |
| 11 |
| 12 main(args) => grind(args); |
| 13 |
| 14 @DefaultTask() |
| 15 @Task() |
| 16 validate() async { |
| 17 // Test it. |
| 18 await new TestRunner().testAsync(); |
| 19 |
| 20 // Make sure it's warning clean. |
| 21 Analyzer.analyze("bin/format.dart", fatalWarnings: true); |
| 22 |
| 23 // Format it. |
| 24 Dart.run("bin/format.dart", arguments: ["-w", "."]); |
| 25 } |
| 26 |
| 27 /// Gets ready to publish a new version of the package. |
| 28 /// |
| 29 /// To publish a version, you need to: |
| 30 /// |
| 31 /// 1. Make sure the version in the pubspec is a "-dev" number. This should |
| 32 /// already be the case since you've already landed patches that change |
| 33 /// the formatter and bumped to that as a consequence. |
| 34 /// |
| 35 /// 2. Run this task: |
| 36 /// |
| 37 /// pub run grinder bump |
| 38 /// |
| 39 /// 3. Commit the change to a branch. |
| 40 /// |
| 41 /// 4. Send it out for review: |
| 42 /// |
| 43 /// git cl upload |
| 44 /// |
| 45 /// 5. After the review is complete, land it: |
| 46 /// |
| 47 /// git cl land |
| 48 /// |
| 49 /// 6. Tag the commit: |
| 50 /// |
| 51 /// git tag -a "<version>" -m "<version>" |
| 52 /// git push origin <version> |
| 53 /// |
| 54 /// 7. Publish the package: |
| 55 /// |
| 56 /// pub lish |
| 57 @Task() |
| 58 @Depends(validate) |
| 59 bump() async { |
| 60 // Read the version from the pubspec. |
| 61 var pubspecFile = getFile("pubspec.yaml"); |
| 62 var pubspec = pubspecFile.readAsStringSync(); |
| 63 var version = new Version.parse(yaml.loadYaml(pubspec)["version"]); |
| 64 |
| 65 // Require a "-dev" version since we don't otherwise know what to bump it to. |
| 66 if (!version.isPreRelease) throw "Cannot publish non-dev version $version."; |
| 67 |
| 68 // Don't allow versions like "1.2.3-dev+4" because it's not clear if the |
| 69 // user intended the "+4" to be discarded or not. |
| 70 if (version.build.isNotEmpty) throw "Cannot publish build version $version."; |
| 71 |
| 72 var bumped = new Version(version.major, version.minor, version.patch); |
| 73 |
| 74 // Update the version in the pubspec. |
| 75 pubspec = pubspec.replaceAll(_versionPattern, "version: $bumped"); |
| 76 pubspecFile.writeAsStringSync(pubspec); |
| 77 |
| 78 // Update the version constant in bin/format.dart. |
| 79 var binFormatFile = getFile("bin/format.dart"); |
| 80 var binFormat = binFormatFile.readAsStringSync().replaceAll( |
| 81 new RegExp(r'const version = "[^"]+";'), 'const version = "$bumped";'); |
| 82 binFormatFile.writeAsStringSync(binFormat); |
| 83 log("Updated version to '$bumped'."); |
| 84 } |
OLD | NEW |