From cfe2534d10a949998a29e49973ced69769febf60 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Fri, 16 Mar 2018 13:09:36 -0700 Subject: [PATCH] Reorganized package, put example it it's own directory, etc --- .gitignore | 9 +-- .../example => example}/lib/app_component.css | 0 .../lib/app_component.dart | 0 .../lib/app_component.html | 0 .../lib/src/hello_world/hello_world.css | 0 .../lib/src/hello_world/hello_world.dart | 0 example/lib/src/hello_world/hello_world.html | 1 + example/pubspec.yaml | 12 ++++ {webdev/example => example}/web/index.html | 3 +- example/web/main.dart | 9 +++ {webdev/example => example}/web/styles.css | 0 webdev/bin/webdev.dart | 2 +- .../lib/src/hello_world/hello_world.html | 1 - webdev/example/pubspec.yaml | 25 ------- webdev/example/web/main.dart | 7 -- webdev/lib/src/command/build_command.dart | 11 +-- .../command/build_runner_command_base.dart | 72 ++++++++++++++++--- webdev/lib/src/command/serve_command.dart | 10 +-- webdev/lib/webdev.dart | 1 - webdev/pubspec.yaml | 12 ++-- 20 files changed, 96 insertions(+), 79 deletions(-) rename {webdev/example => example}/lib/app_component.css (100%) rename {webdev/example => example}/lib/app_component.dart (100%) rename {webdev/example => example}/lib/app_component.html (100%) rename {webdev/example => example}/lib/src/hello_world/hello_world.css (100%) rename {webdev/example => example}/lib/src/hello_world/hello_world.dart (100%) create mode 100644 example/lib/src/hello_world/hello_world.html create mode 100644 example/pubspec.yaml rename {webdev/example => example}/web/index.html (68%) create mode 100644 example/web/main.dart rename {webdev/example => example}/web/styles.css (100%) delete mode 100644 webdev/example/lib/src/hello_world/hello_world.html delete mode 100644 webdev/example/pubspec.yaml delete mode 100644 webdev/example/web/main.dart delete mode 100644 webdev/lib/webdev.dart diff --git a/.gitignore b/.gitignore index 26e9525be..79f51c3d5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,3 @@ -packages -/*/build/ -.pub/ -pubspec.lock - -# Files generated by dart tools .dart_tool -doc/ +.packages +pubspec.lock diff --git a/webdev/example/lib/app_component.css b/example/lib/app_component.css similarity index 100% rename from webdev/example/lib/app_component.css rename to example/lib/app_component.css diff --git a/webdev/example/lib/app_component.dart b/example/lib/app_component.dart similarity index 100% rename from webdev/example/lib/app_component.dart rename to example/lib/app_component.dart diff --git a/webdev/example/lib/app_component.html b/example/lib/app_component.html similarity index 100% rename from webdev/example/lib/app_component.html rename to example/lib/app_component.html diff --git a/webdev/example/lib/src/hello_world/hello_world.css b/example/lib/src/hello_world/hello_world.css similarity index 100% rename from webdev/example/lib/src/hello_world/hello_world.css rename to example/lib/src/hello_world/hello_world.css diff --git a/webdev/example/lib/src/hello_world/hello_world.dart b/example/lib/src/hello_world/hello_world.dart similarity index 100% rename from webdev/example/lib/src/hello_world/hello_world.dart rename to example/lib/src/hello_world/hello_world.dart diff --git a/example/lib/src/hello_world/hello_world.html b/example/lib/src/hello_world/hello_world.html new file mode 100644 index 000000000..88990aa19 --- /dev/null +++ b/example/lib/src/hello_world/hello_world.html @@ -0,0 +1 @@ +
Hello World
diff --git a/example/pubspec.yaml b/example/pubspec.yaml new file mode 100644 index 000000000..4532d19b6 --- /dev/null +++ b/example/pubspec.yaml @@ -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 diff --git a/webdev/example/web/index.html b/example/web/index.html similarity index 68% rename from webdev/example/web/index.html rename to example/web/index.html index c7fe29810..0799eec25 100644 --- a/webdev/example/web/index.html +++ b/example/web/index.html @@ -4,8 +4,7 @@ webdev example - - + diff --git a/example/web/main.dart b/example/web/main.dart new file mode 100644 index 000000000..7dda58045 --- /dev/null +++ b/example/web/main.dart @@ -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); +} diff --git a/webdev/example/web/styles.css b/example/web/styles.css similarity index 100% rename from webdev/example/web/styles.css rename to example/web/styles.css diff --git a/webdev/bin/webdev.dart b/webdev/bin/webdev.dart index 6c28c16fa..dc2e03664 100644 --- a/webdev/bin/webdev.dart +++ b/webdev/bin/webdev.dart @@ -1,6 +1,6 @@ import 'dart:async'; -import 'package:webdev/webdev.dart'; +import 'package:webdev/src/webdev_command_runner.dart'; Future main(List args) async { await webdevCommandRunner().run(args); diff --git a/webdev/example/lib/src/hello_world/hello_world.html b/webdev/example/lib/src/hello_world/hello_world.html deleted file mode 100644 index e5b22f94a..000000000 --- a/webdev/example/lib/src/hello_world/hello_world.html +++ /dev/null @@ -1 +0,0 @@ -
Hello World
diff --git a/webdev/example/pubspec.yaml b/webdev/example/pubspec.yaml deleted file mode 100644 index 5e4f3719d..000000000 --- a/webdev/example/pubspec.yaml +++ /dev/null @@ -1,25 +0,0 @@ -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/main.dart b/webdev/example/web/main.dart deleted file mode 100644 index 78477ff34..000000000 --- a/webdev/example/web/main.dart +++ /dev/null @@ -1,7 +0,0 @@ -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/lib/src/command/build_command.dart b/webdev/lib/src/command/build_command.dart index ac1b646ca..dd2496768 100644 --- a/webdev/lib/src/command/build_command.dart +++ b/webdev/lib/src/command/build_command.dart @@ -1,6 +1,4 @@ import 'dart:async'; -import 'dart:isolate'; - import 'build_runner_command_base.dart'; /// Command to execute pub run build_runner build. @@ -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'); } diff --git a/webdev/lib/src/command/build_runner_command_base.dart b/webdev/lib/src/command/build_runner_command_base.dart index 88f2fc0eb..6570f4e8d 100644 --- a/webdev/lib/src/command/build_runner_command_base.dart +++ b/webdev/lib/src/command/build_runner_command_base.dart @@ -1,5 +1,6 @@ import 'dart:async'; import 'dart:io'; +import 'dart:isolate'; import 'package:args/command_runner.dart'; @@ -19,13 +20,68 @@ abstract class BuildRunnerCommandBase extends Command { 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()); + 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 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 args, [SendPort sendPort]) async { + var buildScript = await generateBuildScript(); + var scriptFile = new File(scriptLocation)..createSync(recursive: true); + scriptFile.writeAsStringSync(buildScript); + sendPort.send(p.absolute(scriptLocation)); } +'''; diff --git a/webdev/lib/src/command/serve_command.dart b/webdev/lib/src/command/serve_command.dart index a8ba022b7..166236ee0 100644 --- a/webdev/lib/src/command/serve_command.dart +++ b/webdev/lib/src/command/serve_command.dart @@ -1,5 +1,4 @@ import 'dart:async'; -import 'dart:isolate'; import 'build_runner_command_base.dart'; @@ -21,12 +20,5 @@ class ServeCommand extends BuildRunnerCommandBase { } @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'); } diff --git a/webdev/lib/webdev.dart b/webdev/lib/webdev.dart deleted file mode 100644 index 97ed18291..000000000 --- a/webdev/lib/webdev.dart +++ /dev/null @@ -1 +0,0 @@ -export 'src/webdev_command_runner.dart'; diff --git a/webdev/pubspec.yaml b/webdev/pubspec.yaml index 5796813f4..443ef325f 100644 --- a/webdev/pubspec.yaml +++ b/webdev/pubspec.yaml @@ -2,17 +2,13 @@ name: webdev description: A CLI for Dart web development. author: Dart Team 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: