OLD | NEW |
(Empty) | |
| 1 # Code Transformers |
| 2 This package exposes various tools to help in the creation and testing of |
| 3 barback transformers, as well as an interface for logging messages with |
| 4 constant ids for documentation purposes. |
| 5 |
| 6 ## Messages and logging |
| 7 |
| 8 This package exposes a `BuildLogger` class as well as `Message`, |
| 9 `MessageTemplate`, and `MessageId` classes. These work together to provide |
| 10 stable error messages with ids that can be referenced in documentation. |
| 11 |
| 12 ### MessageId |
| 13 |
| 14 A `MessageId` is a constant definition of a message in a package. These are |
| 15 used to group messages with the same id or link to sections in a document. |
| 16 |
| 17 const myId = const MessageId('myPackage', 0); |
| 18 |
| 19 These ids should typically never change or disappear throughout the entire |
| 20 lifetime of a package. |
| 21 |
| 22 ### Message |
| 23 |
| 24 A `Message` is a const object which has a `MessageId` and `snippet`. |
| 25 |
| 26 const myMessage = const Message(myId, 'my message'); |
| 27 |
| 28 ### MessageTemplate |
| 29 |
| 30 TODO(jakemac): Docs on this, see |
| 31 https://github.com/dart-lang/code-transformers/blob/master/lib/messages/messages
.dart |
| 32 |
| 33 ### BuildLogger |
| 34 |
| 35 The `BuildLogger` class just wraps a normal `TransformLogger` to provide some |
| 36 additional functionality. You use it in the same way as a `TransformLogger` |
| 37 except that the log methods can accept a `String` or a `Message`. This should |
| 38 usually be created in the first step of your transformers `apply` function: |
| 39 |
| 40 apply(Transform transform) { |
| 41 // If detailsUri is passed, then a link will be output with each log |
| 42 // message that follows this format |
| 43 // `$detailsUri#${msg.id.package}_${msg.id.id}`. |
| 44 var logger = new BuildLogger(transform, detailsUri: 'http://foo.com'); |
| 45 } |
| 46 |
| 47 You can optionally dump out a file containing all the logs found in JSON |
| 48 format by calling the `writeOutput` method on the logger when you are done. |
| 49 The output file will have the same file path as the primary input of the |
| 50 transformer, with an extension matching this pattern `._buildLogs.$i`. The |
| 51 `i` increments starting at 0 each time that logs are output (if multiple |
| 52 transformers run on the same file for instance). These can all be combined |
| 53 into a single file later on by calling the static |
| 54 `combineLogFiles(Transform transform)` function. |
| 55 |
| 56 ## Testing Transformers |
| 57 |
| 58 TODO(jakemac): Docs on this, see `testPhases` in |
| 59 https://github.com/dart-lang/code-transformers/blob/master/lib/tests.dart |
| 60 |
| 61 ## Using the Analyzer in Transformers |
| 62 |
| 63 This package exposes a `Resolver` class which helps out when using the |
| 64 analyzer in a transform. |
| 65 |
| 66 TODO(jakemac): Docs on this, see |
| 67 https://github.com/dart-lang/code-transformers/blob/master/lib/src/resolver.dart |
| 68 |
| 69 ## Barback AssetIds and Uris |
| 70 |
| 71 This package also provides some helpers to convert `AssetId`s to and from `Uri`s |
| 72 relative to a source asset. |
| 73 |
| 74 TODO(jakemac): Docs on this, see `uriToAssetId` & `assetIdToUri` in |
| 75 https://github.com/dart-lang/code-transformers/blob/master/lib/assets.dart |
OLD | NEW |