Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS d.file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS d.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 library pub_tests; | 5 library pub_tests; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:http/http.dart' as http; | 9 import 'package:http/http.dart' as http; |
| 10 import 'package:scheduled_test/scheduled_process.dart'; | 10 import 'package:scheduled_test/scheduled_process.dart'; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 | 32 |
| 33 Future apply(Transform transform) { | 33 Future apply(Transform transform) { |
| 34 return transform.primaryInput.readAsString().then((contents) { | 34 return transform.primaryInput.readAsString().then((contents) { |
| 35 var id = transform.primaryInput.id.changeExtension(".out"); | 35 var id = transform.primaryInput.id.changeExtension(".out"); |
| 36 transform.addOutput(new Asset.fromString(id, "\$contents.out")); | 36 transform.addOutput(new Asset.fromString(id, "\$contents.out")); |
| 37 }); | 37 }); |
| 38 } | 38 } |
| 39 } | 39 } |
| 40 """; | 40 """; |
| 41 | 41 |
| 42 /// Returns the text of a Dart file containing a transformer that rewrites other | |
| 43 /// Dart files. | |
| 44 /// | |
| 45 /// The transformer defines a constant String named TOKEN whose value is [id]. | |
| 46 /// It then adds [id] to the TOKEN constant of any Dart file that contains such | |
| 47 /// a constant. This means it will modify other similar transformers. | |
|
Bob Nystrom
2013/09/06 18:27:29
This is a brainteaser. How about:
Returns the sou
nweiz
2013/09/09 20:43:38
Done.
| |
| 48 /// | |
| 49 /// If [import] is passed, the primary library of that package will be imported | |
| 50 /// and its TOKEN constant will be added to [id]. | |
| 51 String dartTransformer(String id, {String import}) { | |
| 52 if (import != null) { | |
| 53 id = '$id (imports \${$import.TOKEN})'; | |
| 54 import = 'import "package:$import/$import.dart" as $import;'; | |
| 55 } else { | |
| 56 import = ''; | |
| 57 } | |
| 58 | |
| 59 return """ | |
| 60 import 'dart:async'; | |
| 61 | |
| 62 import 'package:barback/barback.dart'; | |
| 63 $import | |
| 64 | |
| 65 const TOKEN = "$id"; | |
| 66 | |
| 67 final _tokenRegexp = new RegExp(r'^const TOKEN = "(.*?)";\$', multiLine: true); | |
|
Bob Nystrom
2013/09/06 18:27:29
Capitalize "Exp" to match the type name.
nweiz
2013/09/09 20:43:38
Done.
| |
| 68 | |
| 69 class DartTransformer extends Transformer { | |
| 70 DartTransformer(); | |
| 71 | |
| 72 String get allowedExtensions => '.dart'; | |
| 73 | |
| 74 Future apply(Transform transform) { | |
| 75 return transform.primaryInput.readAsString().then((contents) { | |
| 76 transform.addOutput(new Asset.fromString(transform.primaryInput.id, | |
| 77 contents.replaceAllMapped(_tokenRegexp, (match) { | |
| 78 return 'const TOKEN = "\${match[1]}, \$TOKEN";'; | |
| 79 }))); | |
| 80 }); | |
| 81 } | |
| 82 } | |
| 83 """; | |
| 84 } | |
| 85 | |
| 42 /// Schedules starting the "pub serve" process. | 86 /// Schedules starting the "pub serve" process. |
| 43 /// | 87 /// |
| 44 /// If [shouldInstallFirst] is `true`, validates that pub install is run first. | 88 /// If [shouldInstallFirst] is `true`, validates that pub install is run first. |
| 45 /// | 89 /// |
| 46 /// Returns the `pub serve` process. | 90 /// Returns the `pub serve` process. |
| 47 ScheduledProcess startPubServe({bool shouldInstallFirst: false}) { | 91 ScheduledProcess startPubServe({bool shouldInstallFirst: false}) { |
| 48 // Use port 0 to get an ephemeral port. | 92 // Use port 0 to get an ephemeral port. |
| 49 _pubServer = startPub(args: ["serve", "--port=0"]); | 93 _pubServer = startPub(args: ["serve", "--port=0"]); |
| 50 | 94 |
| 51 if (shouldInstallFirst) { | 95 if (shouldInstallFirst) { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 return _pubServer.nextLine().then((line) { | 157 return _pubServer.nextLine().then((line) { |
| 114 if (line.contains("successfully")) return; | 158 if (line.contains("successfully")) return; |
| 115 | 159 |
| 116 // This line wasn't it, so ignore it and keep trying. | 160 // This line wasn't it, so ignore it and keep trying. |
| 117 return nextLine(); | 161 return nextLine(); |
| 118 }); | 162 }); |
| 119 } | 163 } |
| 120 | 164 |
| 121 schedule(nextLine); | 165 schedule(nextLine); |
| 122 } | 166 } |
| OLD | NEW |