OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 /** | 5 /** |
6 * Library for taking a JSON file and putting the comments located within into | 6 * Library for taking a JSON file and putting the comments located within into |
7 * the HTML files the comments are associated with. | 7 * the HTML files the comments are associated with. |
8 * | 8 * |
9 * The format of the JSON file is: | 9 * The format of the JSON file is: |
10 * | 10 * |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 _anyErrors = true; | 59 _anyErrors = true; |
60 completer.complete(false); | 60 completer.complete(false); |
61 } else { | 61 } else { |
62 fileJson = JSON.parse(jsonRead); | 62 fileJson = JSON.parse(jsonRead); |
63 } | 63 } |
64 | 64 |
65 // TODO(amouravski): Refactor to not duplicate code here and in html-to-json. | 65 // TODO(amouravski): Refactor to not duplicate code here and in html-to-json. |
66 // Find html files. (lister) | 66 // Find html files. (lister) |
67 final lister = htmlDir.list(recursive: false); | 67 final lister = htmlDir.list(recursive: false); |
68 | 68 |
| 69 var pathList = <String>[]; |
69 lister.onFile = (String path) { | 70 lister.onFile = (String path) { |
| 71 pathList.add(path); |
| 72 }; |
| 73 |
| 74 getFile(String path) { |
70 final name = new Path.fromNative(path).filename; | 75 final name = new Path.fromNative(path).filename; |
71 | 76 |
72 // Ignore private classes. | 77 // Ignore private classes. |
73 if (name.startsWith('_')) return; | 78 if (name.startsWith('_')) return; |
74 | 79 |
75 // Ignore non-dart files. | 80 // Ignore non-dart files. |
76 if (!name.endsWith('.dart')) return; | 81 if (!name.endsWith('.dart')) return; |
77 | 82 |
78 File file = new File(path); | 83 File file = new File(path); |
79 | 84 |
(...skipping 11 matching lines...) Expand all Loading... |
91 } | 96 } |
92 | 97 |
93 var comments = fileJson[name]; | 98 var comments = fileJson[name]; |
94 | 99 |
95 _convertFile(file, comments); | 100 _convertFile(file, comments); |
96 | 101 |
97 fileJson.remove(name); | 102 fileJson.remove(name); |
98 }; | 103 }; |
99 | 104 |
100 lister.onDone = (_) { | 105 lister.onDone = (_) { |
| 106 while(!pathList.isEmpty) { |
| 107 getFile(pathList.removeLast()); |
| 108 } |
101 | 109 |
102 fileJson.forEach((key, _) { | 110 fileJson.forEach((key, _) { |
103 print('WARNING: the following filename was found in the JSON but not in ' | 111 print('WARNING: the following filename was found in the JSON but not in ' |
104 '${htmlDir.path}:\n"$key"'); | 112 '${htmlDir.path}:\n"$key"'); |
105 _anyErrors = true; | 113 _anyErrors = true; |
106 }); | 114 }); |
107 | 115 |
108 completer.complete(_anyErrors); | 116 completer.complete(_anyErrors); |
109 }; | 117 }; |
110 | 118 |
(...skipping 21 matching lines...) Expand all Loading... |
132 } else { | 140 } else { |
133 unusedComments.putIfAbsent(key, () => comments); | 141 unusedComments.putIfAbsent(key, () => comments); |
134 } | 142 } |
135 }); | 143 }); |
136 | 144 |
137 unusedComments.forEach((String key, _) { | 145 unusedComments.forEach((String key, _) { |
138 print('WARNING: the following key was found in the JSON but not in ' | 146 print('WARNING: the following key was found in the JSON but not in ' |
139 '${new Path(file.fullPathSync()).filename}:\n"$key"'); | 147 '${new Path(file.fullPathSync()).filename}:\n"$key"'); |
140 _anyErrors = true; | 148 _anyErrors = true; |
141 }); | 149 }); |
142 | |
143 // TODO(amouravski): file.writeAsStringSync('${Strings.join(fileLines, '\n')}\
n'); | |
144 var outputStream = file.openOutputStream(); | |
145 outputStream.writeString(Strings.join(fileLines, '\n')); | |
146 outputStream.writeString('\n'); | |
147 | 150 |
148 outputStream.onNoPendingWrites = () { | 151 file.writeAsStringSync('${Strings.join(fileLines, '\n')}\n'); |
149 outputStream.close(); | |
150 }; | |
151 } | 152 } |
OLD | NEW |