From 7baf3b230396fe4d513064af0bc8e692ab0e726d Mon Sep 17 00:00:00 2001 From: Nicholas Shahan Date: Fri, 12 Jan 2018 14:45:35 -0800 Subject: [PATCH] Update build and serve commands to run in an isolate Add example angular app to experiment with --- webdev/README.md | 12 +++++++++ webdev/example/lib/app_component.css | 3 +++ webdev/example/lib/app_component.dart | 13 ++++++++++ webdev/example/lib/app_component.html | 3 +++ .../lib/src/hello_world/hello_world.css | 3 +++ .../lib/src/hello_world/hello_world.dart | 10 ++++++++ .../lib/src/hello_world/hello_world.html | 1 + webdev/example/pubspec.yaml | 25 +++++++++++++++++++ webdev/example/web/index.html | 14 +++++++++++ webdev/example/web/main.dart | 7 ++++++ webdev/example/web/styles.css | 12 +++++++++ webdev/lib/src/command/build_command.dart | 15 +++++------ .../command/build_runner_command_base.dart | 13 ++++++++++ webdev/lib/src/command/serve_command.dart | 15 +++++------ webdev/pubspec.yaml | 8 ++++-- 15 files changed, 134 insertions(+), 20 deletions(-) create mode 100644 webdev/README.md create mode 100644 webdev/example/lib/app_component.css create mode 100644 webdev/example/lib/app_component.dart create mode 100644 webdev/example/lib/app_component.html create mode 100644 webdev/example/lib/src/hello_world/hello_world.css create mode 100644 webdev/example/lib/src/hello_world/hello_world.dart create mode 100644 webdev/example/lib/src/hello_world/hello_world.html create mode 100644 webdev/example/pubspec.yaml create mode 100644 webdev/example/web/index.html create mode 100644 webdev/example/web/main.dart create mode 100644 webdev/example/web/styles.css diff --git a/webdev/README.md b/webdev/README.md new file mode 100644 index 000000000..840f95a1a --- /dev/null +++ b/webdev/README.md @@ -0,0 +1,12 @@ +# Experimental Usage + +The example directory contains a package that is configured to work with +`pub run webdev `. Support for `pub global activate webdev` and simply +adding a dev_dependency to your packages is coming soon. + +## Commands + +* __build__: Run builders to build a package. +* __help__: Display help information for webdev. +* __serve__: Run a local web development server and a file system watcher that + re-builds on changes. diff --git a/webdev/example/lib/app_component.css b/webdev/example/lib/app_component.css new file mode 100644 index 000000000..fdc877982 --- /dev/null +++ b/webdev/example/lib/app_component.css @@ -0,0 +1,3 @@ +:host { + /* This is equivalent of the 'body' selector of a page. */ +} diff --git a/webdev/example/lib/app_component.dart b/webdev/example/lib/app_component.dart new file mode 100644 index 000000000..faf444f0c --- /dev/null +++ b/webdev/example/lib/app_component.dart @@ -0,0 +1,13 @@ +import 'package:angular/angular.dart'; + +import 'src/hello_world/hello_world.dart'; + +@Component( + selector: 'my-app', + styleUrls: const ['app_component.css'], + templateUrl: 'app_component.html', + directives: const [HelloWorldComponent], +) +class AppComponent { + // Nothing here. +} diff --git a/webdev/example/lib/app_component.html b/webdev/example/lib/app_component.html new file mode 100644 index 000000000..316bb0d3e --- /dev/null +++ b/webdev/example/lib/app_component.html @@ -0,0 +1,3 @@ +

Webdev Example: Angular App

+ + diff --git a/webdev/example/lib/src/hello_world/hello_world.css b/webdev/example/lib/src/hello_world/hello_world.css new file mode 100644 index 000000000..5764d2a64 --- /dev/null +++ b/webdev/example/lib/src/hello_world/hello_world.css @@ -0,0 +1,3 @@ +div { + color: teal; +} diff --git a/webdev/example/lib/src/hello_world/hello_world.dart b/webdev/example/lib/src/hello_world/hello_world.dart new file mode 100644 index 000000000..f67367f4a --- /dev/null +++ b/webdev/example/lib/src/hello_world/hello_world.dart @@ -0,0 +1,10 @@ +import 'package:angular/angular.dart'; + +@Component( + selector: 'hello-world', + styleUrls: const ['hello_world.css'], + templateUrl: 'hello_world.html', +) +class HelloWorldComponent { + // Nothing here. +} diff --git a/webdev/example/lib/src/hello_world/hello_world.html b/webdev/example/lib/src/hello_world/hello_world.html new file mode 100644 index 000000000..e5b22f94a --- /dev/null +++ b/webdev/example/lib/src/hello_world/hello_world.html @@ -0,0 +1 @@ +
Hello World
diff --git a/webdev/example/pubspec.yaml b/webdev/example/pubspec.yaml new file mode 100644 index 000000000..5e4f3719d --- /dev/null +++ b/webdev/example/pubspec.yaml @@ -0,0 +1,25 @@ +name: webdev_example_app +description: A web app example for webdev CLI. +version: 0.0.1 + +environment: + sdk: ">=2.0.0-dev.3.0 <2.0.0" + +dependencies: + angular: ^5.0.0-alpha+3 + browser: ^0.10.0 + +dev_dependencies: + webdev: + path: ../ + ############################################################################## + # Temporary until build_runner exposes a function to generate it's script. + build_runner: + git: + url: https://github.com/dart-lang/build.git + path: build_runner + ############################################################################## + +dependency_overrides: + # Necessary with angular: ^5.0.0-alpha+1 dependency. + analyzer: ^0.31.0-alpha.1 diff --git a/webdev/example/web/index.html b/webdev/example/web/index.html new file mode 100644 index 000000000..c7fe29810 --- /dev/null +++ b/webdev/example/web/index.html @@ -0,0 +1,14 @@ + + + + webdev example + + + + + + + + Loading... + + diff --git a/webdev/example/web/main.dart b/webdev/example/web/main.dart new file mode 100644 index 000000000..78477ff34 --- /dev/null +++ b/webdev/example/web/main.dart @@ -0,0 +1,7 @@ +import 'package:angular/angular.dart'; +import 'package:webdev_example_app/app_component.dart'; +import 'main.template.dart' as ng; + +main() { + bootstrapStatic(AppComponent, [/*providers*/], ng.initReflector); +} diff --git a/webdev/example/web/styles.css b/webdev/example/web/styles.css new file mode 100644 index 000000000..4eb2ad386 --- /dev/null +++ b/webdev/example/web/styles.css @@ -0,0 +1,12 @@ +@import url(https://fonts.googleapis.com/css?family=Roboto); +@import url(https://fonts.googleapis.com/css?family=Material+Icons); + +body { + max-width: 600px; + margin: 0 auto; + padding: 5vw; +} + +* { + font-family: Roboto, Helvetica, Arial, sans-serif; +} diff --git a/webdev/lib/src/command/build_command.dart b/webdev/lib/src/command/build_command.dart index 9965c27bc..ac1b646ca 100644 --- a/webdev/lib/src/command/build_command.dart +++ b/webdev/lib/src/command/build_command.dart @@ -1,6 +1,5 @@ import 'dart:async'; - -import 'package:io/io.dart'; +import 'dart:isolate'; import 'build_runner_command_base.dart'; @@ -14,13 +13,11 @@ class BuildCommand extends BuildRunnerCommandBase { @override Future run() async { - final manager = new ProcessManager(); - final executable = 'pub'; - final arguments = ['run', 'build_runner', 'build', '--assume-tty']; + final arguments = ['build']; arguments.addAll(argResults.arguments); - var spawn = await manager.spawn(executable, arguments); - - await spawn.exitCode; - await sharedStdIn.terminate(); + var exitPort = new ReceivePort(); + await Isolate.spawnUri(await buildRunnerScript, arguments, null, + onExit: exitPort.sendPort, automaticPackageResolution: true); + await exitPort.first; } } diff --git a/webdev/lib/src/command/build_runner_command_base.dart b/webdev/lib/src/command/build_runner_command_base.dart index d66f7904c..88f2fc0eb 100644 --- a/webdev/lib/src/command/build_runner_command_base.dart +++ b/webdev/lib/src/command/build_runner_command_base.dart @@ -1,3 +1,6 @@ +import 'dart:async'; +import 'dart:io'; + import 'package:args/command_runner.dart'; /// Extend to get a command with the arguments common to all build_runner @@ -15,4 +18,14 @@ abstract class BuildRunnerCommandBase extends Command { negatable: false, help: 'Enables verbose logging.'); } + + Future get buildRunnerScript async { + // TODO(nshahan) build_runner will expose this as a function call that will + // be imported to avoid running a binary in a transitive dependency with + // pub run. + final executable = 'pub'; + final arguments = ['run', 'build_runner', 'generate-build-script']; + final results = await Process.run(executable, arguments); + return new Uri.file(results.stdout.toString().trim()); + } } diff --git a/webdev/lib/src/command/serve_command.dart b/webdev/lib/src/command/serve_command.dart index 221a98909..a8ba022b7 100644 --- a/webdev/lib/src/command/serve_command.dart +++ b/webdev/lib/src/command/serve_command.dart @@ -1,6 +1,5 @@ import 'dart:async'; - -import 'package:io/io.dart'; +import 'dart:isolate'; import 'build_runner_command_base.dart'; @@ -23,13 +22,11 @@ class ServeCommand extends BuildRunnerCommandBase { @override Future run() async { - final manager = new ProcessManager(); - final executable = 'pub'; - final arguments = ['run', 'build_runner', 'serve', '--assume-tty']; + final arguments = ['serve']; arguments.addAll(argResults.arguments); - var spawn = await manager.spawn(executable, arguments); - - await spawn.exitCode; - await sharedStdIn.terminate(); + var exitPort = new ReceivePort(); + await Isolate.spawnUri(await buildRunnerScript, arguments, null, + onExit: exitPort.sendPort, automaticPackageResolution: true); + await exitPort.first; } } diff --git a/webdev/pubspec.yaml b/webdev/pubspec.yaml index 73b89e5a0..5796813f4 100644 --- a/webdev/pubspec.yaml +++ b/webdev/pubspec.yaml @@ -4,11 +4,15 @@ author: Dart Team homepage: https://github.com/dart-lang/webdev environment: - sdk: ">=2.0.0-dev <2.0.0" + sdk: ">=2.0.0-dev.3.0 <2.0.0" dependencies: args: ^1.2.0 - io: ^0.3.1 + build_runner: + git: + url: https://github.com/dart-lang/build.git + path: build_runner + build_web_compilers: ^0.1.1 dev_dependencies: test: "^0.12.0"