Skip to content

Commit bf1e804

Browse files
authored
Update build and serve commands to run in an isolate (#6)
Add example angular app to experiment with.
1 parent 7ce4e6a commit bf1e804

15 files changed

+134
-20
lines changed

webdev/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Experimental Usage
2+
3+
The example directory contains a package that is configured to work with
4+
`pub run webdev <command>`. Support for `pub global activate webdev` and simply
5+
adding a dev_dependency to your packages is coming soon.
6+
7+
## Commands
8+
9+
* __build__: Run builders to build a package.
10+
* __help__: Display help information for webdev.
11+
* __serve__: Run a local web development server and a file system watcher that
12+
re-builds on changes.

webdev/example/lib/app_component.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:host {
2+
/* This is equivalent of the 'body' selector of a page. */
3+
}

webdev/example/lib/app_component.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import 'package:angular/angular.dart';
2+
3+
import 'src/hello_world/hello_world.dart';
4+
5+
@Component(
6+
selector: 'my-app',
7+
styleUrls: const ['app_component.css'],
8+
templateUrl: 'app_component.html',
9+
directives: const [HelloWorldComponent],
10+
)
11+
class AppComponent {
12+
// Nothing here.
13+
}

webdev/example/lib/app_component.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<h1>Webdev Example: Angular App</h1>
2+
3+
<hello-world></hello-world>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
div {
2+
color: teal;
3+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import 'package:angular/angular.dart';
2+
3+
@Component(
4+
selector: 'hello-world',
5+
styleUrls: const ['hello_world.css'],
6+
templateUrl: 'hello_world.html',
7+
)
8+
class HelloWorldComponent {
9+
// Nothing here.
10+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div>Hello World<div>

webdev/example/pubspec.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: webdev_example_app
2+
description: A web app example for webdev CLI.
3+
version: 0.0.1
4+
5+
environment:
6+
sdk: ">=2.0.0-dev.3.0 <2.0.0"
7+
8+
dependencies:
9+
angular: ^5.0.0-alpha+3
10+
browser: ^0.10.0
11+
12+
dev_dependencies:
13+
webdev:
14+
path: ../
15+
##############################################################################
16+
# Temporary until build_runner exposes a function to generate it's script.
17+
build_runner:
18+
git:
19+
url: https://github.com/dart-lang/build.git
20+
path: build_runner
21+
##############################################################################
22+
23+
dependency_overrides:
24+
# Necessary with angular: ^5.0.0-alpha+1 dependency.
25+
analyzer: ^0.31.0-alpha.1

webdev/example/web/index.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>webdev example</title>
5+
<meta charset="utf-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1">
7+
<script defer src="main.dart" type="application/dart"></script>
8+
<script defer src="packages/browser/dart.js"></script>
9+
<link rel="stylesheet" href="styles.css">
10+
</head>
11+
<body>
12+
<my-app>Loading...</my-app>
13+
</body>
14+
</html>

webdev/example/web/main.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import 'package:angular/angular.dart';
2+
import 'package:webdev_example_app/app_component.dart';
3+
import 'main.template.dart' as ng;
4+
5+
main() {
6+
bootstrapStatic(AppComponent, [/*providers*/], ng.initReflector);
7+
}

webdev/example/web/styles.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
@import url(https://fonts.googleapis.com/css?family=Roboto);
2+
@import url(https://fonts.googleapis.com/css?family=Material+Icons);
3+
4+
body {
5+
max-width: 600px;
6+
margin: 0 auto;
7+
padding: 5vw;
8+
}
9+
10+
* {
11+
font-family: Roboto, Helvetica, Arial, sans-serif;
12+
}
Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import 'dart:async';
2-
3-
import 'package:io/io.dart';
2+
import 'dart:isolate';
43

54
import 'build_runner_command_base.dart';
65

@@ -14,13 +13,11 @@ class BuildCommand extends BuildRunnerCommandBase {
1413

1514
@override
1615
Future run() async {
17-
final manager = new ProcessManager();
18-
final executable = 'pub';
19-
final arguments = ['run', 'build_runner', 'build', '--assume-tty'];
16+
final arguments = ['build'];
2017
arguments.addAll(argResults.arguments);
21-
var spawn = await manager.spawn(executable, arguments);
22-
23-
await spawn.exitCode;
24-
await sharedStdIn.terminate();
18+
var exitPort = new ReceivePort();
19+
await Isolate.spawnUri(await buildRunnerScript, arguments, null,
20+
onExit: exitPort.sendPort, automaticPackageResolution: true);
21+
await exitPort.first;
2522
}
2623
}

webdev/lib/src/command/build_runner_command_base.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import 'dart:async';
2+
import 'dart:io';
3+
14
import 'package:args/command_runner.dart';
25

36
/// Extend to get a command with the arguments common to all build_runner
@@ -15,4 +18,14 @@ abstract class BuildRunnerCommandBase extends Command {
1518
negatable: false,
1619
help: 'Enables verbose logging.');
1720
}
21+
22+
Future<Uri> get buildRunnerScript async {
23+
// TODO(nshahan) build_runner will expose this as a function call that will
24+
// be imported to avoid running a binary in a transitive dependency with
25+
// pub run.
26+
final executable = 'pub';
27+
final arguments = ['run', 'build_runner', 'generate-build-script'];
28+
final results = await Process.run(executable, arguments);
29+
return new Uri.file(results.stdout.toString().trim());
30+
}
1831
}

webdev/lib/src/command/serve_command.dart

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import 'dart:async';
2-
3-
import 'package:io/io.dart';
2+
import 'dart:isolate';
43

54
import 'build_runner_command_base.dart';
65

@@ -23,13 +22,11 @@ class ServeCommand extends BuildRunnerCommandBase {
2322

2423
@override
2524
Future run() async {
26-
final manager = new ProcessManager();
27-
final executable = 'pub';
28-
final arguments = ['run', 'build_runner', 'serve', '--assume-tty'];
25+
final arguments = ['serve'];
2926
arguments.addAll(argResults.arguments);
30-
var spawn = await manager.spawn(executable, arguments);
31-
32-
await spawn.exitCode;
33-
await sharedStdIn.terminate();
27+
var exitPort = new ReceivePort();
28+
await Isolate.spawnUri(await buildRunnerScript, arguments, null,
29+
onExit: exitPort.sendPort, automaticPackageResolution: true);
30+
await exitPort.first;
3431
}
3532
}

webdev/pubspec.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ author: Dart Team <misc@dartlang.org>
44
homepage: https://github.com/dart-lang/webdev
55

66
environment:
7-
sdk: ">=2.0.0-dev <2.0.0"
7+
sdk: ">=2.0.0-dev.3.0 <2.0.0"
88

99
dependencies:
1010
args: ^1.2.0
11-
io: ^0.3.1
11+
build_runner:
12+
git:
13+
url: https://github.com/dart-lang/build.git
14+
path: build_runner
15+
build_web_compilers: ^0.1.1
1216

1317
dev_dependencies:
1418
test: "^0.12.0"

0 commit comments

Comments
 (0)