OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013, 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 library barback.barback; |
| 6 |
| 7 import 'dart:async'; |
| 8 |
| 9 import 'asset.dart'; |
| 10 import 'asset_id.dart'; |
| 11 import 'asset_cascade.dart'; |
| 12 import 'package_graph.dart'; |
| 13 import 'package_provider.dart'; |
| 14 |
| 15 /// A general-purpose asynchronous build dependency graph manager. |
| 16 /// |
| 17 /// It consumes source assets (including Dart files) in a set of packages, |
| 18 /// runs transformations on them, and then tracks which sources have been |
| 19 /// modified and which transformations need to be re-run. |
| 20 /// |
| 21 /// To do this, you give barback a [PackageProvider] which can yield a set of |
| 22 /// [Transformer]s and raw source [Asset]s. Then you tell it which input files |
| 23 /// have been added or modified by calling [updateSources]. Barback will |
| 24 /// automatically wire up the appropriate transformers to those inputs and |
| 25 /// start running them asynchronously. If a transformer produces outputs that |
| 26 /// can be consumed by other transformers, they will automatically be pipelined |
| 27 /// correctly. |
| 28 /// |
| 29 /// You can then request assets (either source or generated) by calling |
| 30 /// [getAssetById]. This will wait for any necessary transformations and then |
| 31 /// return the asset. |
| 32 /// |
| 33 /// When source files have been modified or removed, tell barback by calling |
| 34 /// [updateSources] and [removeSources] as appropriate. Barback will |
| 35 /// automatically track which transformations are affected by those changes and |
| 36 /// re-run them as needed. |
| 37 /// |
| 38 /// Barback tries to be resilient to errors since assets are often in an |
| 39 /// in-progress state. When errors occur, they will be captured and emitted on |
| 40 /// the [errors] stream. |
| 41 class Barback { |
| 42 /// The graph managed by this instance. |
| 43 final PackageGraph _graph; |
| 44 |
| 45 /// A stream that emits a [BuildResult] each time the build is completed, |
| 46 /// whether or not it succeeded. |
| 47 /// |
| 48 /// This will emit a result only once every package's [AssetCascade] has |
| 49 /// finished building. |
| 50 /// |
| 51 /// If an unexpected error in barback itself occurs, it will be emitted |
| 52 /// through this stream's error channel. |
| 53 Stream<BuildResult> get results => _graph.results; |
| 54 |
| 55 /// A stream that emits any errors from the graph or the transformers. |
| 56 /// |
| 57 /// This emits errors as they're detected. If an error occurs in one part of |
| 58 /// the graph, unrelated parts will continue building. |
| 59 /// |
| 60 /// This will not emit programming errors from barback itself. Those will be |
| 61 /// emitted through the [results] stream's error channel. |
| 62 Stream get errors => _graph.errors; |
| 63 |
| 64 Barback(PackageProvider provider) |
| 65 : _graph = new PackageGraph(provider); |
| 66 |
| 67 /// Gets the asset identified by [id]. |
| 68 /// |
| 69 /// If [id] is for a generated or transformed asset, this will wait until |
| 70 /// it has been created and return it. If the asset cannot be found, throws |
| 71 /// [AssetNotFoundException]. |
| 72 Future<Asset> getAssetById(AssetId id) => _graph.getAssetById(id); |
| 73 |
| 74 /// Adds [sources] to the graph's known set of source assets. |
| 75 /// |
| 76 /// Begins applying any transforms that can consume any of the sources. If a |
| 77 /// given source is already known, it is considered modified and all |
| 78 /// transforms that use it will be re-applied. |
| 79 void updateSources(Iterable<AssetId> sources) => |
| 80 _graph.updateSources(sources); |
| 81 |
| 82 /// Removes [removed] from the graph's known set of source assets. |
| 83 void removeSources(Iterable<AssetId> removed) => |
| 84 _graph.removeSources(removed); |
| 85 } |
OLD | NEW |