| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 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 | |
| 7 /// the `polymer/lib/src/generated` folder. This script should be invoked from | |
| 8 /// the root of the polymer package either by doing: | |
| 9 /// | |
| 10 /// dart tool/create_message_details_page.dart | |
| 11 /// | |
| 12 /// or | |
| 13 /// | |
| 14 /// pub run tool/create_message_details_page | |
| 15 library polymer.tool.create_message_details_page; | |
| 16 | |
| 17 import 'dart:io'; | |
| 18 import 'dart:mirrors'; | |
| 19 | |
| 20 import 'package:code_transformers/messages/messages.dart'; | |
| 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 | |
| 23 import 'package:polymer/src/build/messages.dart' as m3; // used via mirrors | |
| 24 import 'package:markdown/markdown.dart'; | |
| 25 import 'package:path/path.dart' as path; | |
| 26 import 'package:args/args.dart'; | |
| 27 | |
| 28 main(args) { | |
| 29 var options = _parseOptions(args); | |
| 30 var seen = {}; | |
| 31 var templates = []; | |
| 32 _getMessagesFrom(#polymer.src.build.messages, seen, templates); | |
| 33 _getMessagesFrom(#code_transformers.src.messages, seen, templates); | |
| 34 _getMessagesFrom(#observe.src.messages, seen, templates); | |
| 35 | |
| 36 templates.sort((a, b) => a.id.compareTo(b.id)); | |
| 37 var sb = new StringBuffer(); | |
| 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); | |
| 47 | |
| 48 var lastPackage = ''; | |
| 49 for (var t in templates) { | |
| 50 if (lastPackage != t.id.package) { | |
| 51 lastPackage = t.id.package; | |
| 52 var sectionTitle = '## Messages from package `$lastPackage`\n\n----\n\n'; | |
| 53 sb.write(forSite ? sectionTitle : markdownToHtml(sectionTitle)); | |
| 54 } | |
| 55 _generateMessage(t, forSite, sb); | |
| 56 } | |
| 57 sb.write(forSite ? '' : _LOCAL_FOOTER); | |
| 58 new File(out).writeAsStringSync(sb.toString()); | |
| 59 print('updated: ${options["out"]}'); | |
| 60 } | |
| 61 | |
| 62 final _mirrors = currentMirrorSystem(); | |
| 63 | |
| 64 _getMessagesFrom(Symbol libName, Map seen, List templates) { | |
| 65 var lib = _mirrors.findLibrary(libName); | |
| 66 lib.declarations.forEach((symbol, decl) { | |
| 67 if (decl is! VariableMirror) return; | |
| 68 var template = lib.getField(symbol).reflectee; | |
| 69 var name = MirrorSystem.getName(symbol); | |
| 70 if (template is! MessageTemplate) return; | |
| 71 var id = template.id; | |
| 72 if (seen.containsKey(id)) { | |
| 73 print('error: duplicate id `$id`. ' | |
| 74 'Currently set for both `$name` and `${seen[id]}`.'); | |
| 75 } | |
| 76 seen[id] = name; | |
| 77 templates.add(template); | |
| 78 }); | |
| 79 } | |
| 80 | |
| 81 _generateMessage(MessageTemplate template, bool forSite, StringBuffer sb) { | |
| 82 var details = template.details == null | |
| 83 ? 'No details available' : template.details; | |
| 84 if (forSite) details = '{% raw %}$details{% endraw %}'; | |
| 85 var id = template.id; | |
| 86 var hashTag = '${id.package}_${id.id}'; | |
| 87 var title = '### ${template.description} [#${id.id}](#$hashTag)'; | |
| 88 var body = '\n$details\n\n----\n\n'; | |
| 89 // We add the anchor inside the <h3> title, otherwise the link doesn't work. | |
| 90 if (forSite) { | |
| 91 sb..write(title) | |
| 92 ..write('\n{: #$hashTag}\n') | |
| 93 ..write(body); | |
| 94 } else { | |
| 95 var html = markdownToHtml('$title$body').replaceFirst('<hr', '</div><hr'); | |
| 96 sb.write('\n\n<div id="$hashTag">$html'); | |
| 97 } | |
| 98 } | |
| 99 | |
| 100 _parseOptions(args) { | |
| 101 var parser = new ArgParser(allowTrailingOptions: true) | |
| 102 ..addOption('out', abbr: 'o', | |
| 103 defaultsTo: 'lib/src/build/generated/messages.html', | |
| 104 help: 'the output file path') | |
| 105 ..addFlag('site', abbr: 's', negatable: false, | |
| 106 help: 'generate contents for the dartlang.org site') | |
| 107 ..addFlag('help', abbr: 'h', negatable: false); | |
| 108 | |
| 109 var options = parser.parse(args); | |
| 110 if (options['help']) { | |
| 111 var command = Platform.script.path; | |
| 112 var relPath = path.relative(command, from: path.current); | |
| 113 if (!relPath.startsWith('../')) command = relPath; | |
| 114 print('usage: dart $command [-o path_to_output_file] [-s]'); | |
| 115 print(parser.getUsage()); | |
| 116 exit(0); | |
| 117 } | |
| 118 return options; | |
| 119 } | |
| 120 | |
| 121 const _SITE_HEADER = ''' | |
| 122 --- | |
| 123 # WARNING: GENERATED FILE. DO NOT EDIT. | |
| 124 # | |
| 125 # This file was generated automatically from the polymer package. | |
| 126 # To regenerate this file, from the top directory of the polymer package run: | |
| 127 # | |
| 128 # dart tool/create_message_details_page.dart -s -o path_to_this_file | |
| 129 layout: default | |
| 130 title: "Error Messages" | |
| 131 subsite: "Polymer.dart" | |
| 132 description: "Details about error messages from polymer and related packages." | |
| 133 --- | |
| 134 | |
| 135 {% include breadcrumbs.html %} | |
| 136 | |
| 137 # {{ page.title }} | |
| 138 | |
| 139 <style> | |
| 140 h3 > a { | |
| 141 display: none; | |
| 142 } | |
| 143 | |
| 144 h3:hover > a { | |
| 145 display: inline; | |
| 146 } | |
| 147 | |
| 148 </style> | |
| 149 | |
| 150 | |
| 151 This page contains a list of error messages produced during `pub build` and `pub | |
| 152 serve` by transformers in polymer and its related packages. You can find here | |
| 153 additional details that can often help you figure out how to fix the underlying | |
| 154 problem. | |
| 155 | |
| 156 | |
| 157 '''; | |
| 158 | |
| 159 const _LOCAL_HEADER = ''' | |
| 160 <!doctype html> | |
| 161 <!-- | |
| 162 This file is autogenerated with polymer/tool/create_message_details_page.dart | |
| 163 --> | |
| 164 <html> | |
| 165 <style> | |
| 166 @font-face { | |
| 167 font-family: 'Montserrat'; | |
| 168 font-style: normal; | |
| 169 font-weight: 400; | |
| 170 src: url(https://themes.googleusercontent.com/static/fonts/montserrat/v4/zhcz-
_WihjSQC0oHJ9TCYL3hpw3pgy2gAi-Ip7WPMi0.woff) format('woff'); | |
| 171 } | |
| 172 @font-face { | |
| 173 font-family: 'Montserrat'; | |
| 174 font-style: normal; | |
| 175 font-weight: 700; | |
| 176 src: url(https://themes.googleusercontent.com/static/fonts/montserrat/v4/IQHow
_FEYlDC4Gzy_m8fcnbFhgvWbfSbdVg11QabG8w.woff) format('woff'); | |
| 177 } | |
| 178 @font-face { | |
| 179 font-family: 'Roboto'; | |
| 180 font-style: normal; | |
| 181 font-weight: 300; | |
| 182 src: url(https://themes.googleusercontent.com/static/fonts/roboto/v10/Hgo13k-t
fSpn0qi1SFdUfbO3LdcAZYWl9Si6vvxL-qU.woff) format('woff'); | |
| 183 } | |
| 184 @font-face { | |
| 185 font-family: 'Roboto'; | |
| 186 font-style: normal; | |
| 187 font-weight: 400; | |
| 188 src: url(https://themes.googleusercontent.com/static/fonts/roboto/v10/CrYjSnGj
rRCn0pd9VQsnFOvvDin1pK8aKteLpeZ5c0A.woff) format('woff'); | |
| 189 } | |
| 190 | |
| 191 body { | |
| 192 width: 80vw; | |
| 193 margin: 20px; | |
| 194 font-family: Roboto, sans-serif; | |
| 195 background-color: #f0f0f0; | |
| 196 } | |
| 197 | |
| 198 h2 { | |
| 199 font-family: Montserrat, sans-serif; | |
| 200 box-sizing: border-box; | |
| 201 color: rgb(72, 72, 72); | |
| 202 display: block; | |
| 203 font-style: normal; | |
| 204 font-variant: normal; | |
| 205 font-weight: normal; | |
| 206 } | |
| 207 | |
| 208 div:target { | |
| 209 background-color: #fff; | |
| 210 border: 1px solid #888; | |
| 211 border-radius: 5px; | |
| 212 padding: 0px 10px 2px 10px; | |
| 213 box-shadow: 7px 7px 5px #888888; | |
| 214 margin-bottom: 15px; | |
| 215 } | |
| 216 | |
| 217 | |
| 218 h3 { | |
| 219 font-family: Montserrat, sans-serif; | |
| 220 box-sizing: border-box; | |
| 221 color: rgb(72, 72, 72); | |
| 222 display: block; | |
| 223 font-style: normal; | |
| 224 font-variant: normal; | |
| 225 font-weight: normal; | |
| 226 } | |
| 227 | |
| 228 div:target > h3 { | |
| 229 font-weight: bold; | |
| 230 } | |
| 231 | |
| 232 pre { | |
| 233 display: block; | |
| 234 padding: 9.5px; | |
| 235 margin: 0 0 10px; | |
| 236 color: #333; | |
| 237 word-break: break-all; | |
| 238 word-wrap: break-word; | |
| 239 background-color: #f5f5f5; | |
| 240 border: 1px solid #ccc; | |
| 241 border-radius: 4px; | |
| 242 } | |
| 243 | |
| 244 code { | |
| 245 font-family: Menlo,Monaco,Consolas,"Courier New",monospace; | |
| 246 box-sizing: border-box; | |
| 247 padding: 0; | |
| 248 font-size: 90%; | |
| 249 color: #0084c5; | |
| 250 white-space: nowrap; | |
| 251 border-radius: 4px; | |
| 252 background-color: #f9f2f4; | |
| 253 } | |
| 254 | |
| 255 pre code { | |
| 256 white-space: inherit; | |
| 257 color: inherit; | |
| 258 background-color: inherit; | |
| 259 } | |
| 260 | |
| 261 a { | |
| 262 color: rgb(42, 100, 150); | |
| 263 } | |
| 264 | |
| 265 h3 > a { | |
| 266 display: none; | |
| 267 font-size: 0.8em; | |
| 268 } | |
| 269 | |
| 270 h3:hover > a { | |
| 271 display: inline; | |
| 272 } | |
| 273 </style> | |
| 274 <body> | |
| 275 '''; | |
| 276 | |
| 277 const _LOCAL_FOOTER = ''' | |
| 278 </body> | |
| 279 </html> | |
| 280 '''; | |
| OLD | NEW |