Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 /// Simple script to generate a page summarizing all error messages produces by | 5 /// Simple script to generate a page summarizing all error messages produces by |
| 6 /// the polymer compiler code. The generated code will be placed directly under | 6 /// the polymer compiler code. The generated code will be placed directly under |
| 7 /// the `polymer/lib/src/generated` folder. This script should be invoked from | 7 /// the `polymer/lib/src/generated` folder. This script should be invoked from |
| 8 /// the root of the polymer package either by doing: | 8 /// the root of the polymer package either by doing: |
| 9 /// | 9 /// |
| 10 /// dart tool/create_message_details_page.dart | 10 /// dart tool/create_message_details_page.dart |
| 11 /// | 11 /// |
| 12 /// or | 12 /// or |
| 13 /// | 13 /// |
| 14 /// pub run tool/create_message_details_page | 14 /// pub run tool/create_message_details_page |
| 15 library polymer.tool.create_message_details_page; | 15 library polymer.tool.create_message_details_page; |
| 16 | 16 |
| 17 import 'dart:io'; | 17 import 'dart:io'; |
| 18 import 'dart:mirrors'; | 18 import 'dart:mirrors'; |
| 19 | 19 |
| 20 import 'package:code_transformers/messages/messages.dart'; | 20 import 'package:code_transformers/messages/messages.dart'; |
| 21 import 'package:code_transformers/src/messages.dart' as m1; // used via mirrors | 21 import 'package:code_transformers/src/messages.dart' as m1; // used via mirrors |
| 22 import 'package:observe/src/messages.dart' as m2; // used via mirrors | 22 import 'package:observe/src/messages.dart' as m2; // used via mirrors |
| 23 import 'package:polymer/src/build/messages.dart' as m3; // used via mirrors | 23 import 'package:polymer/src/build/messages.dart' as m3; // used via mirrors |
| 24 import 'package:markdown/markdown.dart'; | 24 import 'package:markdown/markdown.dart'; |
| 25 import 'package:path/path.dart' as path; | 25 import 'package:path/path.dart' as path; |
| 26 import 'package:args/args.dart'; | |
| 26 | 27 |
| 27 main() { | 28 main(args) { |
| 29 var options = _parseOptions(args); | |
| 28 var seen = {}; | 30 var seen = {}; |
| 29 var templates = []; | 31 var templates = []; |
| 30 _getMessagesFrom(#polymer.src.build.messages, seen, templates); | 32 _getMessagesFrom(#polymer.src.build.messages, seen, templates); |
| 31 _getMessagesFrom(#code_transformers.src.messages, seen, templates); | 33 _getMessagesFrom(#code_transformers.src.messages, seen, templates); |
| 32 _getMessagesFrom(#observe.src.messages, seen, templates); | 34 _getMessagesFrom(#observe.src.messages, seen, templates); |
| 33 | 35 |
| 34 templates.sort((a, b) => a.id.compareTo(b.id)); | 36 templates.sort((a, b) => a.id.compareTo(b.id)); |
| 35 var sb = new StringBuffer(); | 37 var sb = new StringBuffer(); |
| 36 sb.write(_HEADER); | 38 bool forSite = options['site']; |
| 39 var out = path.join(path.current, options['out']); | |
| 40 var ext = forSite ? '.markdown' : '.html'; | |
| 41 if (!out.endsWith(ext)) { | |
| 42 print('error: expected to have a $ext extension.'); | |
| 43 exit(1); | |
| 44 } | |
| 45 | |
| 46 sb.write(forSite ? _SITE_HEADER : _LOCAL_HEADER); | |
| 37 | 47 |
| 38 var lastPackage = ''; | 48 var lastPackage = ''; |
| 39 for (var t in templates) { | 49 for (var t in templates) { |
| 40 if (lastPackage != t.id.package) { | 50 if (lastPackage != t.id.package) { |
| 41 lastPackage = t.id.package; | 51 lastPackage = t.id.package; |
| 42 sb.write(markdownToHtml( | 52 sb.write(markdownToHtml( |
| 43 '#Messages from package `$lastPackage`\n\n----\n')); | 53 '## Messages from package `$lastPackage`\n\n----\n')); |
| 44 } | 54 } |
| 45 sb.write(_htmlFor(t)); | 55 sb.write(_htmlFor(t, forSite)); |
| 46 } | 56 } |
| 47 sb.write(_FOOTER); | 57 sb.write(forSite ? '' : _LOCAL_FOOTER); |
| 48 new File('lib/src/build/generated/messages.html') | 58 new File(out).writeAsStringSync(sb.toString()); |
| 49 .writeAsStringSync(sb.toString()); | 59 print('updated: ${options["out"]}'); |
| 50 } | 60 } |
| 51 | 61 |
| 52 final _mirrors = currentMirrorSystem(); | 62 final _mirrors = currentMirrorSystem(); |
| 53 | 63 |
| 54 _getMessagesFrom(Symbol libName, Map seen, List templates) { | 64 _getMessagesFrom(Symbol libName, Map seen, List templates) { |
| 55 var lib = _mirrors.findLibrary(libName); | 65 var lib = _mirrors.findLibrary(libName); |
| 56 lib.declarations.forEach((symbol, decl) { | 66 lib.declarations.forEach((symbol, decl) { |
| 57 if (decl is! VariableMirror) return; | 67 if (decl is! VariableMirror) return; |
| 58 var template = lib.getField(symbol).reflectee; | 68 var template = lib.getField(symbol).reflectee; |
| 59 var name = MirrorSystem.getName(symbol); | 69 var name = MirrorSystem.getName(symbol); |
| 60 if (template is! MessageTemplate) return; | 70 if (template is! MessageTemplate) return; |
| 61 var id = template.id; | 71 var id = template.id; |
| 62 if (seen.containsKey(id)) { | 72 if (seen.containsKey(id)) { |
| 63 print('error: duplicate id `$id`. ' | 73 print('error: duplicate id `$id`. ' |
| 64 'Currently set for both `$name` and `${seen[id]}`.'); | 74 'Currently set for both `$name` and `${seen[id]}`.'); |
| 65 } | 75 } |
| 66 seen[id] = name; | 76 seen[id] = name; |
| 67 templates.add(template); | 77 templates.add(template); |
| 68 }); | 78 }); |
| 69 } | 79 } |
| 70 | 80 |
| 71 _htmlFor(MessageTemplate template) { | 81 _htmlFor(MessageTemplate template, bool forSite) { |
| 72 var details = template.details == null | 82 var details = template.details == null |
| 73 ? 'No details available' : template.details; | 83 ? 'No details available' : template.details; |
| 74 var id = template.id; | 84 var id = template.id; |
| 75 var hashTag = 'msg_${id.package}_${id.id}'; | 85 var hashTag = '${id.package}_${id.id}'; |
| 76 var markdown = | 86 var markdown = |
| 77 '## ${template.description} [#${id.id}](#$hashTag)\n\n$details\n\n----\n'; | 87 '### ${template.description} [#${id.id}](#$hashTag)\n\n$details\n\n----\n' ; |
| 78 var html = markdownToHtml(markdown); | 88 // We add the anchor inside the <h3> title, otherwise the link doesn't work. |
| 79 // We add the anchor inside the <h2> title, otherwise the link doesn't work. | 89 var clazz = forSite ? 'class="has-permalink"' : ''; |
| 80 return '\n\n${html.replaceFirst("<h2>", "<h2 id=\"$hashTag\">")}'; | 90 var html = markdownToHtml(markdown) |
| 91 .replaceFirst('<h3>', '<h3 id="$hashTag" $clazz>'); | |
| 92 return '\n\n$html'; | |
| 81 } | 93 } |
| 82 | 94 |
| 83 const _HEADER = ''' | 95 _parseOptions(args) { |
| 96 var parser = new ArgParser(allowTrailingOptions: true) | |
| 97 ..addOption('out', abbr: 'o', | |
| 98 defaultsTo: 'lib/src/build/generated/messages.html', | |
| 99 help: 'the output file path') | |
| 100 ..addFlag('site', abbr: 's', negatable: false, | |
| 101 help: 'generate contents for the dartlang.org site') | |
| 102 ..addFlag('help', abbr: 'h', negatable: false); | |
| 103 | |
| 104 var options = parser.parse(args); | |
| 105 if (options['help']) { | |
| 106 var command = Platform.script.path; | |
| 107 var relPath = path.relative(command, from: path.current); | |
| 108 if (!relPath.startsWith('../')) command = relPath; | |
| 109 print('usage: dart $command [-o path_to_output_file] [-s]'); | |
| 110 print(parser.getUsage()); | |
| 111 exit(0); | |
| 112 } | |
| 113 return options; | |
| 114 } | |
| 115 | |
| 116 const _SITE_HEADER = ''' | |
| 117 --- | |
| 118 # WARNING - DO NOT EDIT | |
|
Kathy Walrath
2014/09/05 14:59:01
Let's make this a little more formal and closer to
Siggi Cherem (dart-lang)
2014/09/05 16:13:15
Done.
| |
| 119 # this file was generated automatically from the polymer package | |
| 120 # to regenerate go to the polymer package, then run: | |
| 121 # dart tool/create_message_details_page.dart -s -o path-to-this-file | |
| 122 layout: default | |
| 123 title: "Error messages" | |
| 124 subsite: "Polymer.dart" | |
| 125 description: "Details about error messages from polymer and related packages." | |
| 126 --- | |
| 127 | |
| 128 # {{ page.title }} | |
| 129 | |
| 130 <style> | |
| 131 h3 > a { | |
| 132 display: none; | |
| 133 } | |
| 134 | |
| 135 h3:hover > a { | |
| 136 display: inline; | |
| 137 } | |
| 138 | |
| 139 </style> | |
| 140 | |
| 141 | |
| 142 This page contains a list of error messages produced during `pub build` and `pub | |
| 143 serve` by transformers in polymer and its related packages. You can find here | |
| 144 additional details that can often help understand or debug error messages. | |
|
Kathy Walrath
2014/09/05 14:59:01
understand -> you understand
[debugging error mes
Siggi Cherem (dart-lang)
2014/09/05 16:13:15
how about `figure out how to fix the underlying pr
| |
| 145 '''; | |
| 146 | |
| 147 const _LOCAL_HEADER = ''' | |
| 84 <!doctype html> | 148 <!doctype html> |
| 85 <!-- | 149 <!-- |
| 86 This file is autogenerated with polymer/tool/create_message_details_page.dart | 150 This file is autogenerated with polymer/tool/create_message_details_page.dart |
| 87 --> | 151 --> |
| 88 <html> | 152 <html> |
| 89 <style> | 153 <style> |
| 90 @font-face { | 154 @font-face { |
| 91 font-family: 'Montserrat'; | 155 font-family: 'Montserrat'; |
| 92 font-style: normal; | 156 font-style: normal; |
| 93 font-weight: 400; | 157 font-weight: 400; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 111 font-weight: 400; | 175 font-weight: 400; |
| 112 src: url(https://themes.googleusercontent.com/static/fonts/roboto/v10/CrYjSnGj rRCn0pd9VQsnFOvvDin1pK8aKteLpeZ5c0A.woff) format('woff'); | 176 src: url(https://themes.googleusercontent.com/static/fonts/roboto/v10/CrYjSnGj rRCn0pd9VQsnFOvvDin1pK8aKteLpeZ5c0A.woff) format('woff'); |
| 113 } | 177 } |
| 114 | 178 |
| 115 body { | 179 body { |
| 116 width: 80vw; | 180 width: 80vw; |
| 117 margin: 20px; | 181 margin: 20px; |
| 118 font-family: Roboto, sans-serif; | 182 font-family: Roboto, sans-serif; |
| 119 } | 183 } |
| 120 | 184 |
| 121 h1 { | 185 h2 { |
| 122 font-family: Montserrat, sans-serif; | 186 font-family: Montserrat, sans-serif; |
| 123 box-sizing: border-box; | 187 box-sizing: border-box; |
| 124 color: rgb(72, 72, 72); | 188 color: rgb(72, 72, 72); |
| 125 display: block; | 189 display: block; |
| 126 font-style: normal; | 190 font-style: normal; |
| 127 font-variant: normal; | 191 font-variant: normal; |
| 128 font-weight: normal; | 192 font-weight: normal; |
| 129 } | 193 } |
| 130 | 194 |
| 131 h2 { | 195 h3 { |
| 132 font-family: Montserrat, sans-serif; | 196 font-family: Montserrat, sans-serif; |
| 133 box-sizing: border-box; | 197 box-sizing: border-box; |
| 134 color: rgb(72, 72, 72); | 198 color: rgb(72, 72, 72); |
| 135 display: block; | 199 display: block; |
| 136 font-style: normal; | 200 font-style: normal; |
| 137 font-variant: normal; | 201 font-variant: normal; |
| 138 font-weight: normal; | 202 font-weight: normal; |
| 139 } | 203 } |
| 140 | 204 |
| 141 pre { | 205 pre { |
| 142 display: block; | 206 display: block; |
| 143 padding: 9.5px; | 207 padding: 9.5px; |
| 144 margin: 0 0 10px; | 208 margin: 0 0 10px; |
| 145 line-height: 1.42857143; | |
| 146 color: #333; | 209 color: #333; |
| 147 word-break: break-all; | 210 word-break: break-all; |
| 148 word-wrap: break-word; | 211 word-wrap: break-word; |
| 149 background-color: #f5f5f5; | 212 background-color: #f5f5f5; |
| 150 border: 1px solid #ccc; | 213 border: 1px solid #ccc; |
| 151 border-radius: 4px; | 214 border-radius: 4px; |
| 152 } | 215 } |
| 153 | 216 |
| 154 code { | 217 code { |
| 155 font-family: Menlo,Monaco,Consolas,"Courier New",monospace; | 218 font-family: Menlo,Monaco,Consolas,"Courier New",monospace; |
| 156 box-sizing: border-box; | 219 box-sizing: border-box; |
| 157 padding: 0; | 220 padding: 0; |
| 158 font-size: 90%; | 221 font-size: 90%; |
| 159 color: #0084c5; | 222 color: #0084c5; |
| 160 white-space: nowrap; | 223 white-space: nowrap; |
| 161 border-radius: 4px; | 224 border-radius: 4px; |
| 162 background-color: #f9f2f4; | 225 background-color: #f9f2f4; |
| 163 } | 226 } |
| 164 | 227 |
| 165 pre > code { | 228 pre code { |
| 166 white-space: inherit; | 229 white-space: inherit; |
| 230 color: inherit; | |
| 231 background-color: inherit; | |
| 167 } | 232 } |
| 168 | 233 |
| 169 a { | 234 a { |
| 170 color: rgb(42, 100, 150); | 235 color: rgb(42, 100, 150); |
| 171 } | 236 } |
| 172 | 237 |
| 173 h2 > a { | 238 h3 > a { |
| 174 display: none; | 239 display: none; |
| 175 font-size: 0.8em; | 240 font-size: 0.8em; |
| 176 } | 241 } |
| 177 | 242 |
| 178 h2:hover > a { | 243 h3:hover > a { |
| 179 display: inline; | 244 display: inline; |
| 180 } | 245 } |
| 181 </style> | 246 </style> |
| 182 <body> | 247 <body> |
| 183 '''; | 248 '''; |
| 184 | 249 |
| 185 const _FOOTER = ''' | 250 const _LOCAL_FOOTER = ''' |
| 186 </body> | 251 </body> |
| 187 </html> | 252 </html> |
| 188 '''; | 253 '''; |
| OLD | NEW |