Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update build and serve commands to run in an isolate #6

Merged
merged 1 commit into from
Jan 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions webdev/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Experimental Usage

The example directory contains a package that is configured to work with
`pub run webdev <command>`. 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.
3 changes: 3 additions & 0 deletions webdev/example/lib/app_component.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:host {
/* This is equivalent of the 'body' selector of a page. */
}
13 changes: 13 additions & 0 deletions webdev/example/lib/app_component.dart
Original file line number Diff line number Diff line change
@@ -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.
}
3 changes: 3 additions & 0 deletions webdev/example/lib/app_component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h1>Webdev Example: Angular App</h1>

<hello-world></hello-world>
3 changes: 3 additions & 0 deletions webdev/example/lib/src/hello_world/hello_world.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
div {
color: teal;
}
10 changes: 10 additions & 0 deletions webdev/example/lib/src/hello_world/hello_world.dart
Original file line number Diff line number Diff line change
@@ -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.
}
1 change: 1 addition & 0 deletions webdev/example/lib/src/hello_world/hello_world.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div>Hello World<div>
25 changes: 25 additions & 0 deletions webdev/example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions webdev/example/web/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>webdev example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script defer src="main.dart" type="application/dart"></script>
<script defer src="packages/browser/dart.js"></script>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<my-app>Loading...</my-app>
</body>
</html>
7 changes: 7 additions & 0 deletions webdev/example/web/main.dart
Original file line number Diff line number Diff line change
@@ -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);
}
12 changes: 12 additions & 0 deletions webdev/example/web/styles.css
Original file line number Diff line number Diff line change
@@ -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;
}
15 changes: 6 additions & 9 deletions webdev/lib/src/command/build_command.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'dart:async';

import 'package:io/io.dart';
import 'dart:isolate';

import 'build_runner_command_base.dart';

Expand All @@ -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;
}
}
13 changes: 13 additions & 0 deletions webdev/lib/src/command/build_runner_command_base.dart
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -15,4 +18,14 @@ abstract class BuildRunnerCommandBase extends Command {
negatable: false,
help: 'Enables verbose logging.');
}

Future<Uri> 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());
}
}
15 changes: 6 additions & 9 deletions webdev/lib/src/command/serve_command.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'dart:async';

import 'package:io/io.dart';
import 'dart:isolate';

import 'build_runner_command_base.dart';

Expand All @@ -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;
}
}
8 changes: 6 additions & 2 deletions webdev/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ author: Dart Team <misc@dartlang.org>
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"