diff --git a/webdev/bin/webdev.dart b/webdev/bin/webdev.dart new file mode 100644 index 000000000..6c28c16fa --- /dev/null +++ b/webdev/bin/webdev.dart @@ -0,0 +1,7 @@ +import 'dart:async'; + +import 'package:webdev/webdev.dart'; + +Future main(List args) async { + await webdevCommandRunner().run(args); +} diff --git a/webdev/lib/src/command/build_command.dart b/webdev/lib/src/command/build_command.dart new file mode 100644 index 000000000..a09bb441f --- /dev/null +++ b/webdev/lib/src/command/build_command.dart @@ -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(); + } +} diff --git a/webdev/lib/src/webdev_command_runner.dart b/webdev/lib/src/webdev_command_runner.dart new file mode 100644 index 000000000..fd90bfb0c --- /dev/null +++ b/webdev/lib/src/webdev_command_runner.dart @@ -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; +} diff --git a/webdev/lib/webdev.dart b/webdev/lib/webdev.dart new file mode 100644 index 000000000..97ed18291 --- /dev/null +++ b/webdev/lib/webdev.dart @@ -0,0 +1 @@ +export 'src/webdev_command_runner.dart'; diff --git a/webdev/pubspec.yaml b/webdev/pubspec.yaml index 15a158cd2..73b89e5a0 100644 --- a/webdev/pubspec.yaml +++ b/webdev/pubspec.yaml @@ -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"