Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(224)

Side by Side Diff: sdk/lib/_internal/pub/lib/src/command/build.dart

Issue 69043003: Allow user to specify mode for pub build/serve. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Get rid of "--minify" flags. Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 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 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 library pub.command.build; 5 library pub.command.build;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:barback/barback.dart'; 9 import 'package:barback/barback.dart';
10 import 'package:path/path.dart' as path; 10 import 'package:path/path.dart' as path;
11 11
12 import '../barback/dart2js_transformer.dart'; 12 import '../barback/dart2js_transformer.dart';
13 import '../barback/dart_forwarding_transformer.dart';
13 import '../barback.dart' as barback; 14 import '../barback.dart' as barback;
14 import '../command.dart'; 15 import '../command.dart';
15 import '../exit_codes.dart' as exit_codes; 16 import '../exit_codes.dart' as exit_codes;
16 import '../io.dart'; 17 import '../io.dart';
17 import '../log.dart' as log; 18 import '../log.dart' as log;
18 import '../utils.dart'; 19 import '../utils.dart';
19 20
20 final _arrow = getSpecial('\u2192', '=>'); 21 final _arrow = getSpecial('\u2192', '=>');
21 22
22 /// Handles the `build` pub command. 23 /// Handles the `build` pub command.
23 class BuildCommand extends PubCommand { 24 class BuildCommand extends PubCommand {
24 String get description => 25 String get description =>
25 "Copy and compile all Dart entrypoints in the 'web' directory."; 26 "Copy and compile all Dart entrypoints in the 'web' directory.";
26 String get usage => "pub build [options]"; 27 String get usage => "pub build [options]";
27 List<String> get aliases => const ["deploy", "settle-up"]; 28 List<String> get aliases => const ["deploy", "settle-up"];
28 29
29 // TODO(nweiz): make these configurable. 30 // TODO(nweiz): make these configurable.
30 /// The path to the source directory of the application. 31 /// The path to the source directory of the application.
31 String get source => path.join(entrypoint.root.dir, 'web'); 32 String get source => path.join(entrypoint.root.dir, 'web');
32 33
33 /// The path to the application's build output directory. 34 /// The path to the application's build output directory.
34 String get target => path.join(entrypoint.root.dir, 'build'); 35 String get target => path.join(entrypoint.root.dir, 'build');
35 36
36 /// `true` if generated JavaScript should be minified. 37 /// The build mode.
37 bool get minify => commandOptions['minify']; 38 BarbackMode get mode => new BarbackMode(commandOptions['mode']);
38 39
39 BuildCommand() { 40 BuildCommand() {
40 commandParser.addFlag('minify', defaultsTo: true, 41 commandParser.addOption('mode', defaultsTo: BarbackMode.RELEASE.toString(),
41 help: 'Minify generated JavaScript.'); 42 help: 'Mode to run transformers in.');
42 } 43 }
43 44
44 Future onRun() { 45 Future onRun() {
45 if (!dirExists(source)) { 46 if (!dirExists(source)) {
46 throw new ApplicationException("There is no '$source' directory."); 47 throw new ApplicationException("There is no '$source' directory.");
47 } 48 }
48 49
49 cleanDir(target); 50 cleanDir(target);
50 51
51 var dart2jsTransformer; 52 var dart2jsTransformer;
52 53
53 return entrypoint.ensureLockFileIsUpToDate().then((_) { 54 return entrypoint.ensureLockFileIsUpToDate().then((_) {
54 return entrypoint.loadPackageGraph(); 55 return entrypoint.loadPackageGraph();
55 }).then((graph) { 56 }).then((graph) {
56 dart2jsTransformer = new Dart2JSTransformer(graph, minify: minify); 57 dart2jsTransformer = new Dart2JSTransformer(graph, mode);
58 var builtInTransformers = [
59 dart2jsTransformer,
60 new DartForwardingTransformer(mode)
61 ];
57 62
58 // Since this server will only be hit by the transformer loader and isn't 63 // Since this server will only be hit by the transformer loader and isn't
59 // user-facing, just use an IPv4 address to avoid a weird bug on the 64 // user-facing, just use an IPv4 address to avoid a weird bug on the
60 // OS X buildbots. 65 // OS X buildbots.
61 // TODO(rnystrom): Allow specifying mode. 66 // TODO(rnystrom): Allow specifying mode.
62 return barback.createServer("127.0.0.1", 0, graph, BarbackMode.RELEASE, 67 return barback.createServer("127.0.0.1", 0, graph, mode,
63 builtInTransformers: [dart2jsTransformer], 68 builtInTransformers: builtInTransformers,
64 watcher: barback.WatcherType.NONE); 69 watcher: barback.WatcherType.NONE);
65 }).then((server) { 70 }).then((server) {
66 // Show in-progress errors, but not results. Those get handled implicitly 71 // Show in-progress errors, but not results. Those get handled implicitly
67 // by getAllAssets(). 72 // by getAllAssets().
68 server.barback.errors.listen((error) { 73 server.barback.errors.listen((error) {
69 log.error(log.red("Build error:\n$error")); 74 log.error(log.red("Build error:\n$error"));
70 }); 75 });
71 76
72 return log.progress("Building ${entrypoint.root.name}", 77 return log.progress("Building ${entrypoint.root.name}",
73 () => server.barback.getAllAssets()); 78 () => server.barback.getAllAssets());
74 }).then((assets) { 79 }).then((assets) {
75 // Don't copy Dart libraries. Their contents will already be included
76 // in the generated JavaScript.
77 assets = assets.where((asset) => asset.id.extension != ".dart");
78
79 return Future.wait(assets.map((asset) { 80 return Future.wait(assets.map((asset) {
80 // Figure out the output directory for the asset, which is the same 81 // Figure out the output directory for the asset, which is the same
81 // as the path pub serve would use to serve it. 82 // as the path pub serve would use to serve it.
82 var relativeUrl = barback.idtoUrlPath(entrypoint.root.name, asset.id); 83 var relativeUrl = barback.idtoUrlPath(entrypoint.root.name, asset.id);
83 84
84 // Remove the leading "/". 85 // Remove the leading "/".
85 relativeUrl = relativeUrl.substring(1); 86 relativeUrl = relativeUrl.substring(1);
86 87
87 var relativePath = path.fromUri(new Uri(path: relativeUrl)); 88 var relativePath = path.fromUri(new Uri(path: relativeUrl));
88 var destPath = path.join(target, relativePath); 89 var destPath = path.join(target, relativePath);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 // TODO(nweiz): do something more principled when issue 6101 is fixed. 136 // TODO(nweiz): do something more principled when issue 6101 is fixed.
136 /// Ensures that the [name].js file is copied into [directory] in [target], 137 /// Ensures that the [name].js file is copied into [directory] in [target],
137 /// under `packages/browser/`. 138 /// under `packages/browser/`.
138 void _addBrowserJs(String directory, String name) { 139 void _addBrowserJs(String directory, String name) {
139 var jsPath = path.join( 140 var jsPath = path.join(
140 target, directory, 'packages', 'browser', '$name.js'); 141 target, directory, 'packages', 'browser', '$name.js');
141 ensureDir(path.dirname(jsPath)); 142 ensureDir(path.dirname(jsPath));
142 copyFile(path.join(entrypoint.packagesDir, 'browser', '$name.js'), jsPath); 143 copyFile(path.join(entrypoint.packagesDir, 'browser', '$name.js'), jsPath);
143 } 144 }
144 } 145 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698