Skip to content

Commit

Permalink
Initial support for build_runner build (#3)
Browse files Browse the repository at this point in the history
Supports a subset of arguments to pass through to the build command.
  • Loading branch information
nshahan authored Jan 11, 2018
1 parent baa01ec commit 9dd2045
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 0 deletions.
7 changes: 7 additions & 0 deletions webdev/bin/webdev.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import 'dart:async';

import 'package:webdev/webdev.dart';

Future main(List<String> args) async {
await webdevCommandRunner().run(args);
}
38 changes: 38 additions & 0 deletions webdev/lib/src/command/build_command.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import 'dart:async';
import 'package:io/io.dart';

import 'package:args/command_runner.dart';

/// Command to execute pub run build_runner build.
class BuildCommand extends Command {
@override
final name = 'build';

@override
final description = 'Run builders to build a package.';

BuildCommand() {
// TODO(nshahan) Expose more args passed to build_runner build.
// build_runner might expose args for use in wrapping scripts like this one.
argParser
..addOption('output',
abbr: 'o', help: 'A directory to write the result of a build to.')
..addFlag('verbose',
abbr: 'v',
defaultsTo: false,
negatable: false,
help: 'Enables verbose logging.');
}

@override
Future run() async {
final manager = new ProcessManager();
final executable = 'pub';
final arguments = ['run', 'build_runner', 'build', '--assume-tty'];
arguments.addAll(argResults.arguments);
var spawn = await manager.spawn(executable, arguments);

await spawn.exitCode;
await sharedStdIn.terminate();
}
}
13 changes: 13 additions & 0 deletions webdev/lib/src/webdev_command_runner.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'package:args/command_runner.dart';

import 'command/build_command.dart';

/// All available top level commands.
CommandRunner webdevCommandRunner() {
final commandRunner =
new CommandRunner('webdev', 'A tool to develop Dart web projects.');

commandRunner.addCommand(new BuildCommand());

return commandRunner;
}
1 change: 1 addition & 0 deletions webdev/lib/webdev.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'src/webdev_command_runner.dart';
4 changes: 4 additions & 0 deletions webdev/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@ homepage: https://github.com/dart-lang/webdev
environment:
sdk: ">=2.0.0-dev <2.0.0"

dependencies:
args: ^1.2.0
io: ^0.3.1

dev_dependencies:
test: "^0.12.0"

0 comments on commit 9dd2045

Please sign in to comment.