Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import 'package:grinder/grinder.dart'; | 5 import 'package:grinder/grinder.dart'; |
| 6 import 'package:grinder/src/run.dart' as runner; | |
| 7 import "package:node_preamble/preamble.dart" as preamble; | |
| 6 import 'package:pub_semver/pub_semver.dart'; | 8 import 'package:pub_semver/pub_semver.dart'; |
| 7 import 'package:yaml/yaml.dart' as yaml; | 9 import 'package:yaml/yaml.dart' as yaml; |
| 8 | 10 |
| 11 import 'dart:convert'; | |
| 12 import 'dart:io'; | |
|
Bob Nystrom
2016/01/27 21:53:46
The blank line is good, but these go *above* the p
| |
| 13 | |
| 9 /// Matches the version line in dart_style's pubspec. | 14 /// Matches the version line in dart_style's pubspec. |
| 10 final _versionPattern = new RegExp(r"^version: .*$", multiLine: true); | 15 final _versionPattern = new RegExp(r"^version: .*$", multiLine: true); |
| 11 | 16 |
| 12 main(args) => grind(args); | 17 main(args) => grind(args); |
| 13 | 18 |
| 14 @DefaultTask() | 19 @DefaultTask() |
| 15 @Task() | 20 @Task() |
| 16 validate() async { | 21 validate() async { |
| 17 // Test it. | 22 // Test it. |
| 18 await new TestRunner().testAsync(); | 23 await new TestRunner().testAsync(); |
| 19 | 24 |
| 20 // Make sure it's warning clean. | 25 // Make sure it's warning clean. |
| 21 Analyzer.analyze("bin/format.dart", fatalWarnings: true); | 26 Analyzer.analyze("bin/format.dart", fatalWarnings: true); |
| 22 | 27 |
| 23 // Format it. | 28 // Format it. |
| 24 Dart.run("bin/format.dart", arguments: ["-w", "."]); | 29 Dart.run("bin/format.dart", arguments: ["-w", "."]); |
| 25 } | 30 } |
| 26 | 31 |
| 32 @Task('Publish to npm') | |
| 33 npm() { | |
| 34 var out = 'dist'; | |
| 35 | |
| 36 var pubspec = yaml.loadYaml(getFile("pubspec.yaml").readAsStringSync()); | |
| 37 var homepage = pubspec["homepage"]; | |
| 38 var fileName = 'index.js'; | |
| 39 | |
| 40 // Generate modified dart2js output suitable to run on node. | |
| 41 var tempFile = new File('${Directory.systemTemp.path}/temp.js'); | |
| 42 | |
| 43 Dart2js.compile(new File('tool/node_format_service.dart'), | |
| 44 outFile: tempFile, categories: 'all'); | |
| 45 var dart2jsOutput = tempFile.readAsStringSync(); | |
| 46 new File('$out/$fileName').writeAsStringSync('''${preamble.getPreamble()} | |
| 47 self.exports = exports; // Temporary hack for Dart-JS Interop under node. | |
| 48 $dart2jsOutput'''); | |
| 49 | |
| 50 new File('$out/package.json') | |
| 51 .writeAsStringSync(const JsonEncoder.withIndent(' ').convert({ | |
| 52 "name": "dart-style", | |
| 53 "version": pubspec["version"], | |
| 54 "description": pubspec["description"], | |
| 55 "main": fileName, | |
| 56 "scripts": {"test": "echo \"Error: no test specified\" && exit 1"}, | |
| 57 "repository": {"type": "git", "url": "git+$homepage"}, | |
| 58 "author": pubspec["author"], | |
| 59 "license": "BSD", | |
| 60 "bugs": {"url": "$homepage/issues"}, | |
| 61 "homepage": homepage | |
| 62 })); | |
| 63 run('npm', arguments: ['publish', out]); | |
| 64 } | |
| 65 | |
| 27 /// Gets ready to publish a new version of the package. | 66 /// Gets ready to publish a new version of the package. |
| 28 /// | 67 /// |
| 29 /// To publish a version, you need to: | 68 /// To publish a version, you need to: |
| 30 /// | 69 /// |
| 31 /// 1. Make sure the version in the pubspec is a "-dev" number. This should | 70 /// 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 | 71 /// already be the case since you've already landed patches that change |
| 33 /// the formatter and bumped to that as a consequence. | 72 /// the formatter and bumped to that as a consequence. |
| 34 /// | 73 /// |
| 35 /// 2. Run this task: | 74 /// 2. Run this task: |
| 36 /// | 75 /// |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 pubspec = pubspec.replaceAll(_versionPattern, "version: $bumped"); | 114 pubspec = pubspec.replaceAll(_versionPattern, "version: $bumped"); |
| 76 pubspecFile.writeAsStringSync(pubspec); | 115 pubspecFile.writeAsStringSync(pubspec); |
| 77 | 116 |
| 78 // Update the version constant in bin/format.dart. | 117 // Update the version constant in bin/format.dart. |
| 79 var binFormatFile = getFile("bin/format.dart"); | 118 var binFormatFile = getFile("bin/format.dart"); |
| 80 var binFormat = binFormatFile.readAsStringSync().replaceAll( | 119 var binFormat = binFormatFile.readAsStringSync().replaceAll( |
| 81 new RegExp(r'const version = "[^"]+";'), 'const version = "$bumped";'); | 120 new RegExp(r'const version = "[^"]+";'), 'const version = "$bumped";'); |
| 82 binFormatFile.writeAsStringSync(binFormat); | 121 binFormatFile.writeAsStringSync(binFormat); |
| 83 log("Updated version to '$bumped'."); | 122 log("Updated version to '$bumped'."); |
| 84 } | 123 } |
| OLD | NEW |