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; |
10 import 'dart:io'; | |
11 import 'dart:convert'; | |
Bob Nystrom
2016/01/27 20:37:13
Nit: Put "dart:" imports above other ones with a b
Jacob
2016/01/27 20:56:32
why doesn't the formatter do that for me?
| |
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(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('bin/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 "scripts": {"test": "echo \"Error: no test specified\" && exit 1"}, | |
56 "repository": {"type": "git", "url": "git+$homepage"}, | |
57 "author": pubspec["author"], | |
58 "license": "BSD", | |
59 "bugs": {"url": "$homepage/issues"}, | |
60 "homepage": homepage | |
61 })); | |
62 run('npm', arguments: ['publish', out]); | |
63 } | |
64 | |
27 /// Gets ready to publish a new version of the package. | 65 /// Gets ready to publish a new version of the package. |
28 /// | 66 /// |
29 /// To publish a version, you need to: | 67 /// To publish a version, you need to: |
30 /// | 68 /// |
31 /// 1. Make sure the version in the pubspec is a "-dev" number. This should | 69 /// 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 | 70 /// already be the case since you've already landed patches that change |
33 /// the formatter and bumped to that as a consequence. | 71 /// the formatter and bumped to that as a consequence. |
34 /// | 72 /// |
35 /// 2. Run this task: | 73 /// 2. Run this task: |
36 /// | 74 /// |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 pubspec = pubspec.replaceAll(_versionPattern, "version: $bumped"); | 113 pubspec = pubspec.replaceAll(_versionPattern, "version: $bumped"); |
76 pubspecFile.writeAsStringSync(pubspec); | 114 pubspecFile.writeAsStringSync(pubspec); |
77 | 115 |
78 // Update the version constant in bin/format.dart. | 116 // Update the version constant in bin/format.dart. |
79 var binFormatFile = getFile("bin/format.dart"); | 117 var binFormatFile = getFile("bin/format.dart"); |
80 var binFormat = binFormatFile.readAsStringSync().replaceAll( | 118 var binFormat = binFormatFile.readAsStringSync().replaceAll( |
81 new RegExp(r'const version = "[^"]+";'), 'const version = "$bumped";'); | 119 new RegExp(r'const version = "[^"]+";'), 'const version = "$bumped";'); |
82 binFormatFile.writeAsStringSync(binFormat); | 120 binFormatFile.writeAsStringSync(binFormat); |
83 log("Updated version to '$bumped'."); | 121 log("Updated version to '$bumped'."); |
84 } | 122 } |
OLD | NEW |