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:grinder/src/run.dart' as runner; |
| 10 import "package:node_preamble/preamble.dart" as preamble; |
6 import 'package:pub_semver/pub_semver.dart'; | 11 import 'package:pub_semver/pub_semver.dart'; |
7 import 'package:yaml/yaml.dart' as yaml; | 12 import 'package:yaml/yaml.dart' as yaml; |
8 | 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 "typings": "dart-style.d.ts", |
| 57 "scripts": {"test": "echo \"Error: no test specified\" && exit 1"}, |
| 58 "repository": {"type": "git", "url": "git+$homepage"}, |
| 59 "author": pubspec["author"], |
| 60 "license": "BSD", |
| 61 "bugs": {"url": "$homepage/issues"}, |
| 62 "homepage": homepage |
| 63 })); |
| 64 run('npm', arguments: ['publish', out]); |
| 65 } |
| 66 |
27 /// Gets ready to publish a new version of the package. | 67 /// Gets ready to publish a new version of the package. |
28 /// | 68 /// |
29 /// To publish a version, you need to: | 69 /// To publish a version, you need to: |
30 /// | 70 /// |
31 /// 1. Make sure the version in the pubspec is a "-dev" number. This should | 71 /// 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 | 72 /// already be the case since you've already landed patches that change |
33 /// the formatter and bumped to that as a consequence. | 73 /// the formatter and bumped to that as a consequence. |
34 /// | 74 /// |
35 /// 2. Run this task: | 75 /// 2. Run this task: |
36 /// | 76 /// |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 pubspec = pubspec.replaceAll(_versionPattern, "version: $bumped"); | 115 pubspec = pubspec.replaceAll(_versionPattern, "version: $bumped"); |
76 pubspecFile.writeAsStringSync(pubspec); | 116 pubspecFile.writeAsStringSync(pubspec); |
77 | 117 |
78 // Update the version constant in bin/format.dart. | 118 // Update the version constant in bin/format.dart. |
79 var binFormatFile = getFile("bin/format.dart"); | 119 var binFormatFile = getFile("bin/format.dart"); |
80 var binFormat = binFormatFile.readAsStringSync().replaceAll( | 120 var binFormat = binFormatFile.readAsStringSync().replaceAll( |
81 new RegExp(r'const version = "[^"]+";'), 'const version = "$bumped";'); | 121 new RegExp(r'const version = "[^"]+";'), 'const version = "$bumped";'); |
82 binFormatFile.writeAsStringSync(binFormat); | 122 binFormatFile.writeAsStringSync(binFormat); |
83 log("Updated version to '$bumped'."); | 123 log("Updated version to '$bumped'."); |
84 } | 124 } |
OLD | NEW |