| 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 'dart:convert'; |
| 6 import 'dart:io'; |
| 7 |
| 5 import 'package:grinder/grinder.dart'; | 8 import 'package:grinder/grinder.dart'; |
| 9 import "package:node_preamble/preamble.dart" as preamble; |
| 6 import 'package:pub_semver/pub_semver.dart'; | 10 import 'package:pub_semver/pub_semver.dart'; |
| 7 import 'package:yaml/yaml.dart' as yaml; | 11 import 'package:yaml/yaml.dart' as yaml; |
| 8 | 12 |
| 9 /// Matches the version line in dart_style's pubspec. | 13 /// Matches the version line in dart_style's pubspec. |
| 10 final _versionPattern = new RegExp(r"^version: .*$", multiLine: true); | 14 final _versionPattern = new RegExp(r"^version: .*$", multiLine: true); |
| 11 | 15 |
| 12 main(args) => grind(args); | 16 main(List<String> args) => grind(args); |
| 13 | 17 |
| 14 @DefaultTask() | 18 @DefaultTask() |
| 15 @Task() | 19 @Task() |
| 16 validate() async { | 20 validate() async { |
| 17 // Test it. | 21 // Test it. |
| 18 await new TestRunner().testAsync(); | 22 await new TestRunner().testAsync(); |
| 19 | 23 |
| 20 // Make sure it's warning clean. | 24 // Make sure it's warning clean. |
| 21 Analyzer.analyze("bin/format.dart", fatalWarnings: true); | 25 Analyzer.analyze("bin/format.dart", fatalWarnings: true); |
| 22 | 26 |
| 23 // Format it. | 27 // Format it. |
| 24 Dart.run("bin/format.dart", arguments: ["-w", "."]); | 28 Dart.run("bin/format.dart", arguments: ["-w", "."]); |
| 25 } | 29 } |
| 26 | 30 |
| 31 @Task('Publish to npm') |
| 32 npm() { |
| 33 var out = 'dist'; |
| 34 |
| 35 var pubspec = yaml.loadYaml(getFile("pubspec.yaml").readAsStringSync()); |
| 36 var homepage = pubspec["homepage"]; |
| 37 var fileName = 'index.js'; |
| 38 |
| 39 // Generate modified dart2js output suitable to run on node. |
| 40 var tempFile = new File('${Directory.systemTemp.path}/temp.js'); |
| 41 |
| 42 Dart2js.compile(new File('tool/node_format_service.dart'), |
| 43 outFile: tempFile, categories: 'all'); |
| 44 var dart2jsOutput = tempFile.readAsStringSync(); |
| 45 new File('$out/$fileName').writeAsStringSync('''${preamble.getPreamble()} |
| 46 self.exports = exports; // Temporary hack for Dart-JS Interop under node. |
| 47 $dart2jsOutput'''); |
| 48 |
| 49 new File('$out/package.json') |
| 50 .writeAsStringSync(const JsonEncoder.withIndent(' ').convert({ |
| 51 "name": "dart-style", |
| 52 "version": pubspec["version"], |
| 53 "description": pubspec["description"], |
| 54 "main": fileName, |
| 55 "typings": "dart-style.d.ts", |
| 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 |