Skip to content

Commit 9dd2045

Browse files
authored
Initial support for build_runner build (#3)
Supports a subset of arguments to pass through to the build command.
1 parent baa01ec commit 9dd2045

File tree

5 files changed

+63
-0
lines changed

5 files changed

+63
-0
lines changed

webdev/bin/webdev.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import 'dart:async';
2+
3+
import 'package:webdev/webdev.dart';
4+
5+
Future main(List<String> args) async {
6+
await webdevCommandRunner().run(args);
7+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import 'dart:async';
2+
import 'package:io/io.dart';
3+
4+
import 'package:args/command_runner.dart';
5+
6+
/// Command to execute pub run build_runner build.
7+
class BuildCommand extends Command {
8+
@override
9+
final name = 'build';
10+
11+
@override
12+
final description = 'Run builders to build a package.';
13+
14+
BuildCommand() {
15+
// TODO(nshahan) Expose more args passed to build_runner build.
16+
// build_runner might expose args for use in wrapping scripts like this one.
17+
argParser
18+
..addOption('output',
19+
abbr: 'o', help: 'A directory to write the result of a build to.')
20+
..addFlag('verbose',
21+
abbr: 'v',
22+
defaultsTo: false,
23+
negatable: false,
24+
help: 'Enables verbose logging.');
25+
}
26+
27+
@override
28+
Future run() async {
29+
final manager = new ProcessManager();
30+
final executable = 'pub';
31+
final arguments = ['run', 'build_runner', 'build', '--assume-tty'];
32+
arguments.addAll(argResults.arguments);
33+
var spawn = await manager.spawn(executable, arguments);
34+
35+
await spawn.exitCode;
36+
await sharedStdIn.terminate();
37+
}
38+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import 'package:args/command_runner.dart';
2+
3+
import 'command/build_command.dart';
4+
5+
/// All available top level commands.
6+
CommandRunner webdevCommandRunner() {
7+
final commandRunner =
8+
new CommandRunner('webdev', 'A tool to develop Dart web projects.');
9+
10+
commandRunner.addCommand(new BuildCommand());
11+
12+
return commandRunner;
13+
}

webdev/lib/webdev.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export 'src/webdev_command_runner.dart';

webdev/pubspec.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,9 @@ homepage: https://github.com/dart-lang/webdev
66
environment:
77
sdk: ">=2.0.0-dev <2.0.0"
88

9+
dependencies:
10+
args: ^1.2.0
11+
io: ^0.3.1
12+
913
dev_dependencies:
1014
test: "^0.12.0"

0 commit comments

Comments
 (0)