| Index: sdk/lib/_internal/pub_generated/lib/src/command/build.dart
|
| diff --git a/sdk/lib/_internal/pub_generated/lib/src/command/build.dart b/sdk/lib/_internal/pub_generated/lib/src/command/build.dart
|
| index 71736631924748807157883c8f41876c8d7d07b9..5aeb37634abdd88c595a1d82dc3996d3ae72885d 100644
|
| --- a/sdk/lib/_internal/pub_generated/lib/src/command/build.dart
|
| +++ b/sdk/lib/_internal/pub_generated/lib/src/command/build.dart
|
| @@ -1,34 +1,52 @@
|
| +// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
|
| +// for details. All rights reserved. Use of this source code is governed by a
|
| +// BSD-style license that can be found in the LICENSE file.
|
| +
|
| library pub.command.build;
|
| +
|
| import 'dart:async';
|
| +
|
| import 'package:barback/barback.dart';
|
| import 'package:path/path.dart' as path;
|
| +
|
| import '../barback/asset_environment.dart';
|
| import '../exit_codes.dart' as exit_codes;
|
| import '../io.dart';
|
| import '../log.dart' as log;
|
| import '../utils.dart';
|
| import 'barback.dart';
|
| +
|
| final _arrow = getSpecial('\u2192', '=>');
|
| +
|
| +/// Handles the `build` pub command.
|
| class BuildCommand extends BarbackCommand {
|
| String get description => "Apply transformers to build a package.";
|
| String get usage => "pub build [options] [directories...]";
|
| String get docUrl => "http://dartlang.org/tools/pub/cmd/pub-build.html";
|
| List<String> get aliases => const ["deploy", "settle-up"];
|
| +
|
| + /// The path to the application's build output directory.
|
| String get outputDirectory => commandOptions["output"];
|
| +
|
| List<String> get defaultSourceDirectories => ["web"];
|
| +
|
| + /// The number of files that have been built and written to disc so far.
|
| int builtFiles = 0;
|
| +
|
| BuildCommand() {
|
| commandParser.addOption(
|
| "format",
|
| help: "How output should be displayed.",
|
| allowed: ["text", "json"],
|
| defaultsTo: "text");
|
| +
|
| commandParser.addOption(
|
| "output",
|
| abbr: "o",
|
| help: "Directory to write build outputs to.",
|
| defaultsTo: "build");
|
| }
|
| +
|
| Future onRunTransformerCommand() {
|
| final completer0 = new Completer();
|
| scheduleMicrotask(() {
|
| @@ -83,12 +101,17 @@ class BuildCommand extends BarbackCommand {
|
| });
|
| return flushThenExit(exit_codes.DATA);
|
| })));
|
| - } catch (e0) {
|
| - completer0.completeError(e0);
|
| + } catch (e, s) {
|
| + completer0.completeError(e, s);
|
| }
|
| });
|
| return completer0.future;
|
| }
|
| +
|
| + /// Writes [asset] to the appropriate build directory.
|
| + ///
|
| + /// If [asset] is in the special "packages" directory, writes it to every
|
| + /// build directory.
|
| Future _writeAsset(Asset asset) {
|
| final completer0 = new Completer();
|
| scheduleMicrotask(() {
|
| @@ -99,10 +122,9 @@ class BuildCommand extends BarbackCommand {
|
| completer0.complete(_writeOutputFile(asset, destPath));
|
| }
|
| if (path.isWithin("packages", destPath)) {
|
| - completer0.complete(
|
| - Future.wait(
|
| - sourceDirectories.map(
|
| - ((buildDir) => _writeOutputFile(asset, path.join(buildDir, destPath))))));
|
| + completer0.complete(Future.wait(sourceDirectories.map(((buildDir) {
|
| + return _writeOutputFile(asset, path.join(buildDir, destPath));
|
| + }))));
|
| } else {
|
| join1();
|
| }
|
| @@ -112,45 +134,94 @@ class BuildCommand extends BarbackCommand {
|
| } else {
|
| join0();
|
| }
|
| - } catch (e0) {
|
| - completer0.completeError(e0);
|
| + } catch (e, s) {
|
| + completer0.completeError(e, s);
|
| }
|
| });
|
| return completer0.future;
|
| }
|
| +
|
| + /// Converts [id] to a relative path in the output directory for that asset.
|
| + ///
|
| + /// This corresponds to the URL that could be used to request that asset from
|
| + /// pub serve.
|
| + ///
|
| + /// Examples (where entrypoint is "myapp"):
|
| + ///
|
| + /// myapp|web/index.html -> web/index.html
|
| + /// myapp|lib/lib.dart -> packages/myapp/lib.dart
|
| + /// foo|lib/foo.dart -> packages/foo/foo.dart
|
| + /// myapp|test/main.dart -> test/main.dart
|
| + /// foo|test/main.dart -> ERROR
|
| + ///
|
| + /// Throws a [FormatException] if [id] is not a valid public asset.
|
| String _idToPath(AssetId id) {
|
| var parts = path.split(path.fromUri(id.path));
|
| +
|
| if (parts.length < 2) {
|
| throw new FormatException(
|
| "Can not build assets from top-level directory.");
|
| }
|
| +
|
| + // Map "lib" to the "packages" directory.
|
| if (parts[0] == "lib") {
|
| return path.join("packages", id.package, path.joinAll(parts.skip(1)));
|
| }
|
| +
|
| + // Shouldn't be trying to access non-public directories of other packages.
|
| assert(id.package == entrypoint.root.name);
|
| +
|
| + // Allow any path in the entrypoint package.
|
| return path.joinAll(parts);
|
| }
|
| +
|
| + /// Writes the contents of [asset] to [relativePath] within the build
|
| + /// directory.
|
| Future _writeOutputFile(Asset asset, String relativePath) {
|
| builtFiles++;
|
| var destPath = path.join(outputDirectory, relativePath);
|
| ensureDir(path.dirname(destPath));
|
| return createFileFromStream(asset.read(), destPath);
|
| }
|
| +
|
| + /// If this package depends directly on the `browser` package, this ensures
|
| + /// that the JavaScript bootstrap files are copied into `packages/browser/`
|
| + /// directories next to each entrypoint in [entrypoints].
|
| + ///
|
| + /// Returns the number of files it copied.
|
| int _copyBrowserJsFiles(Iterable<AssetId> entrypoints) {
|
| + // Must depend on the browser package.
|
| if (!entrypoint.root.immediateDependencies.any(
|
| (dep) => dep.name == 'browser' && dep.source == 'hosted')) {
|
| return 0;
|
| }
|
| - var entrypointDirs = entrypoints.map(
|
| +
|
| + // Get all of the subdirectories that contain Dart entrypoints.
|
| + var entrypointDirs =
|
| + entrypoints// Convert the asset path to a native-separated one and get the
|
| + // directory containing the entrypoint.
|
| + .map(
|
| (id) =>
|
| path.dirname(
|
| - path.fromUri(id.path))).where((dir) => path.split(dir).length > 1).toSet();
|
| + path.fromUri(
|
| + id.path)))// Don't copy files to the top levels of the build directories since
|
| + // the normal lib asset copying will take care of that.
|
| + .where((dir) => path.split(dir).length > 1).toSet();
|
| +
|
| for (var dir in entrypointDirs) {
|
| + // TODO(nweiz): we should put browser JS files next to any HTML file
|
| + // rather than any entrypoint. An HTML file could import an entrypoint
|
| + // that's not adjacent.
|
| _addBrowserJs(dir, "dart");
|
| _addBrowserJs(dir, "interop");
|
| }
|
| +
|
| return entrypointDirs.length * 2;
|
| }
|
| +
|
| + // TODO(nweiz): do something more principled when issue 6101 is fixed.
|
| + /// Ensures that the [name].js file is copied into [directory] in [target],
|
| + /// under `packages/browser/`.
|
| void _addBrowserJs(String directory, String name) {
|
| var jsPath = entrypoint.root.path(
|
| outputDirectory,
|
| @@ -159,8 +230,14 @@ class BuildCommand extends BarbackCommand {
|
| 'browser',
|
| '$name.js');
|
| ensureDir(path.dirname(jsPath));
|
| +
|
| + // TODO(rnystrom): This won't work if we get rid of symlinks and the top
|
| + // level "packages" directory. Will need to copy from the browser
|
| + // directory.
|
| copyFile(path.join(entrypoint.packagesDir, 'browser', '$name.js'), jsPath);
|
| }
|
| +
|
| + /// Converts [entry] to a JSON object for use with JSON-formatted output.
|
| Map _logEntryToJson(LogEntry entry) {
|
| var data = {
|
| "level": entry.level.name,
|
| @@ -169,7 +246,7 @@ class BuildCommand extends BarbackCommand {
|
| "primaryInput": {
|
| "package": entry.transform.primaryId.package,
|
| "path": entry.transform.primaryId.path
|
| - }
|
| + },
|
| },
|
| "assetId": {
|
| "package": entry.assetId.package,
|
| @@ -177,6 +254,7 @@ class BuildCommand extends BarbackCommand {
|
| },
|
| "message": entry.message
|
| };
|
| +
|
| if (entry.span != null) {
|
| data["span"] = {
|
| "url": entry.span.sourceUrl,
|
| @@ -187,9 +265,10 @@ class BuildCommand extends BarbackCommand {
|
| "end": {
|
| "line": entry.span.end.line,
|
| "column": entry.span.end.column
|
| - }
|
| + },
|
| };
|
| }
|
| +
|
| return data;
|
| }
|
| }
|
|
|