Skip to content

Commit

Permalink
Reorganized package, put example it it's own directory, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
kevmoo committed Mar 18, 2018
1 parent bf1e804 commit 8e85d78
Show file tree
Hide file tree
Showing 20 changed files with 99 additions and 80 deletions.
9 changes: 2 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
packages
/*/build/
.pub/
pubspec.lock

# Files generated by dart tools
.dart_tool
doc/
.packages
pubspec.lock
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions 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>
12 changes: 12 additions & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: webdev_example_app
description: A web app example for webdev CLI.

environment:
sdk: ">=2.0.0-dev.32.0 <2.0.0"

dependencies:
angular: ^5.0.0-alpha+3

dev_dependencies:
build_runner: ^0.8.0
build_web_compilers: ^0.3.4
3 changes: 1 addition & 2 deletions webdev/example/web/index.html → example/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
<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>
<script defer src="main.dart.js"></script>
<link rel="stylesheet" href="styles.css">
</head>
<body>
Expand Down
9 changes: 9 additions & 0 deletions example/web/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import 'package:angular/experimental.dart';

// ignore: uri_has_not_been_generated
import 'package:webdev_example_app/app_component.template.dart' as ng;

main() {
// ignore: argument_type_not_assignable
bootstrapFactory(ng.AppComponentNgFactory);
}
File renamed without changes.
2 changes: 1 addition & 1 deletion webdev/bin/webdev.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:async';

import 'package:webdev/webdev.dart';
import 'package:webdev/src/webdev_command_runner.dart';

Future main(List<String> args) async {
await webdevCommandRunner().run(args);
Expand Down
1 change: 0 additions & 1 deletion webdev/example/lib/src/hello_world/hello_world.html

This file was deleted.

25 changes: 0 additions & 25 deletions webdev/example/pubspec.yaml

This file was deleted.

7 changes: 0 additions & 7 deletions webdev/example/web/main.dart

This file was deleted.

11 changes: 1 addition & 10 deletions webdev/lib/src/command/build_command.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import 'dart:async';
import 'dart:isolate';

import 'build_runner_command_base.dart';

/// Command to execute pub run build_runner build.
Expand All @@ -12,12 +10,5 @@ class BuildCommand extends BuildRunnerCommandBase {
final description = 'Run builders to build a package.';

@override
Future run() async {
final arguments = ['build'];
arguments.addAll(argResults.arguments);
var exitPort = new ReceivePort();
await Isolate.spawnUri(await buildRunnerScript, arguments, null,
onExit: exitPort.sendPort, automaticPackageResolution: true);
await exitPort.first;
}
Future run() => runCore('build');
}
70 changes: 62 additions & 8 deletions webdev/lib/src/command/build_runner_command_base.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:async';
import 'dart:io';
import 'dart:isolate';

import 'package:args/command_runner.dart';

Expand All @@ -19,13 +20,66 @@ abstract class BuildRunnerCommandBase extends Command {
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());
Future runCore(String command) async {
final arguments = [command]..addAll(argResults.arguments);
var exitPort = new ReceivePort();
await Isolate.spawnUri(await _buildRunnerScript, arguments, null,
onExit: exitPort.sendPort, automaticPackageResolution: true);
await exitPort.first;
}
}

Future<Uri> get _buildRunnerScript async {
var dataUri = new Uri.dataFromString(_bootstrapScript);

var messagePort = new ReceivePort();
var exitPort = new ReceivePort();
var errorPort = new ReceivePort();

await Isolate.spawnUri(dataUri, [], messagePort.sendPort,
onExit: exitPort.sendPort,
onError: errorPort.sendPort,
errorsAreFatal: true,
packageConfig: new Uri.file('.packages'));

var allErrorsFuture = errorPort.forEach((error) {
var errorList = error as List;
var message = errorList[0] as String;
var stack = new StackTrace.fromString(errorList[1] as String);

stderr.writeln(message);
stderr.writeln(stack);
});

var items = await Future.wait([
messagePort.toList(),
allErrorsFuture,
exitPort.first.whenComplete(() {
messagePort.close();
errorPort.close();
})
]);

var messages = items[0] as List;
if (messages.isEmpty) {
throw new StateError('An error occurred while running booting.');
}

assert(messages.length == 1);
return new Uri.file(messages.single as String);
}

const _bootstrapScript = r'''
import 'dart:io';
import 'dart:isolate';
import 'package:build_runner/build_script_generate.dart';
import 'package:path/path.dart' as p;
void main(List<String> args, [SendPort sendPort]) async {
var buildScript = await generateBuildScript();
var scriptFile = new File(scriptLocation)..createSync(recursive: true);
scriptFile.writeAsStringSync(buildScript);
sendPort.send(p.absolute(scriptLocation));
}
''';
16 changes: 6 additions & 10 deletions webdev/lib/src/command/serve_command.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'dart:async';
import 'dart:isolate';

import 'build_runner_command_base.dart';

Expand All @@ -17,16 +16,13 @@ class ServeCommand extends BuildRunnerCommandBase {
// build_runner might expose args for use in wrapping scripts like this one.
argParser
..addOption('hostname',
defaultsTo: 'localhost', help: 'Specify the hostname to serve on.');
help: 'Specify the hostname to serve on', defaultsTo: 'localhost')
..addFlag('log-requests',
defaultsTo: false,
negatable: false,
help: 'Enables logging for each request to the server.');
}

@override
Future run() async {
final arguments = ['serve'];
arguments.addAll(argResults.arguments);
var exitPort = new ReceivePort();
await Isolate.spawnUri(await buildRunnerScript, arguments, null,
onExit: exitPort.sendPort, automaticPackageResolution: true);
await exitPort.first;
}
Future run() => runCore('serve');
}
1 change: 0 additions & 1 deletion webdev/lib/webdev.dart

This file was deleted.

12 changes: 4 additions & 8 deletions webdev/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@ name: webdev
description: A CLI for Dart web development.
author: Dart Team <misc@dartlang.org>
homepage: https://github.com/dart-lang/webdev
version: 0.1.0-dev

environment:
sdk: ">=2.0.0-dev.3.0 <2.0.0"
sdk: ">=2.0.0-dev.32.0 <2.0.0"

dependencies:
args: ^1.2.0
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"
executables:
webdev:

0 comments on commit 8e85d78

Please sign in to comment.