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

Reorganized package, put example it it's own directory, etc #9

Merged
merged 8 commits into from
Mar 20, 2018
Merged
Show file tree
Hide file tree
Changes from 6 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
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
41 changes: 41 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Created with https://github.com/dart-lang/mono_repo
language: dart

jobs:
include:
- stage: analyzer_and_format
script: ./tool/travis.sh dartfmt
env: PKG="example"
dart: dev
- stage: analyzer_and_format
script: ./tool/travis.sh dartanalyzer
env: PKG="example"
dart: dev
- stage: unit_test
script: ./tool/travis.sh test
env: PKG="example"
dart: dev
- stage: analyzer_and_format
script: ./tool/travis.sh dartfmt
env: PKG="webdev"
dart: dev
- stage: analyzer_and_format
script: ./tool/travis.sh dartanalyzer
env: PKG="webdev"
dart: dev
- stage: unit_test
script: ./tool/travis.sh test
env: PKG="webdev"
dart: dev

stages:
- analyzer_and_format
- unit_test

# Only building master means that we don't run two builds for each pull request.
branches:
only: [master]

cache:
directories:
- $HOME/.pub-cache
10 changes: 10 additions & 0 deletions example/.mono_repo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# See https://github.com/dart-lang/mono_repo for details
dart:
- dev

stages:
- analyzer_and_format:
- dartfmt
- dartanalyzer: --fatal-infos --fatal-warnings .
- unit_test:
- test
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:angular/angular.dart';

import 'src/hello_world/hello_world.dart';
Expand Down
File renamed without changes.
14 changes: 14 additions & 0 deletions example/lib/src/hello_world/hello_world.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

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 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we bump to alpha+8?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uh...sure


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
13 changes: 13 additions & 0 deletions example/web/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

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.
45 changes: 45 additions & 0 deletions tool/travis.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash
# Created with https://github.com/dart-lang/mono_repo

if [ -z "$PKG" ]; then
echo -e '\033[31mPKG environment variable must be set!\033[0m'
exit 1
fi

if [ "$#" == "0" ]; then
echo -e '\033[31mAt least one task argument must be provided!\033[0m'
exit 1
fi

pushd $PKG
pub upgrade || exit $?

EXIT_CODE=0

while (( "$#" )); do
TASK=$1
case $TASK in
dartanalyzer) echo
echo -e '\033[1mTASK: dartanalyzer\033[22m'
echo -e 'dartanalyzer --fatal-infos --fatal-warnings .'
dartanalyzer --fatal-infos --fatal-warnings . || EXIT_CODE=$?
;;
dartfmt) echo
echo -e '\033[1mTASK: dartfmt\033[22m'
echo -e 'dartfmt -n --set-exit-if-changed .'
dartfmt -n --set-exit-if-changed . || EXIT_CODE=$?
;;
test) echo
echo -e '\033[1mTASK: test\033[22m'
echo -e 'pub run test'
pub run test || EXIT_CODE=$?
;;
*) echo -e "\033[31mNot expecting TASK '${TASK}'. Error!\033[0m"
EXIT_CODE=1
;;
esac

shift
done

exit $EXIT_CODE
10 changes: 10 additions & 0 deletions webdev/.mono_repo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# See https://github.com/dart-lang/mono_repo for details
dart:
- dev

stages:
- analyzer_and_format:
- dartfmt
- dartanalyzer: --fatal-infos --fatal-warnings .
- unit_test:
- test
19 changes: 17 additions & 2 deletions webdev/bin/webdev.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:async';
import 'dart:io';

import 'package:webdev/webdev.dart';
import 'package:args/command_runner.dart';
import 'package:io/ansi.dart';
import 'package:io/io.dart';
import 'package:webdev/src/webdev_command_runner.dart';

Future main(List<String> args) async {
await webdevCommandRunner().run(args);
try {
await webdevCommandRunner().run(args);
} on UsageException catch (e) {
print(yellow.wrap(e.message));
print(' ');
print(e.usage);
exitCode = ExitCode.usage.code;
}
}
10 changes: 0 additions & 10 deletions webdev/example/lib/src/hello_world/hello_world.dart

This file was deleted.

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.

15 changes: 5 additions & 10 deletions webdev/lib/src/command/build_command.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'dart:async';
import 'dart:isolate';
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:async';
import 'build_runner_command_base.dart';

/// Command to execute pub run build_runner build.
Expand All @@ -12,12 +14,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');
}
106 changes: 98 additions & 8 deletions webdev/lib/src/command/build_runner_command_base.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:async';
import 'dart:io';
import 'dart:isolate';

import 'package:args/command_runner.dart';
import 'package:stack_trace/stack_trace.dart';

/// Extend to get a command with the arguments common to all build_runner
/// commands.
Expand All @@ -19,13 +25,97 @@ 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);

// Heavily inspired by dart-lang/build @ 0c77443dd7
// /build_runner/bin/build_runner.dart#L58-L85
var exitPort = new ReceivePort();
var errorPort = new ReceivePort();
var messagePort = new ReceivePort();
var errorListener = errorPort.listen((e) {
stderr.writeln('\n\nYou have hit a bug in build_runner');
stderr.writeln('Please file an issue with reproduction steps at '
'https://github.com/dart-lang/build/issues\n\n');
final error = e[0];
final trace = e[1] as String;
stderr.writeln(error);
stderr.writeln(new Trace.parse(trace).terse);
if (exitCode == 0) exitCode = 1;
});
await Isolate.spawnUri(
await _buildRunnerScript(), arguments, messagePort.sendPort,
onExit: exitPort.sendPort,
onError: errorPort.sendPort,
automaticPackageResolution: true);
StreamSubscription exitCodeListener;
exitCodeListener = messagePort.listen((isolateExitCode) {
if (isolateExitCode is! int) {
throw new StateError(
'Bad response from isolate, expected an exit code but got '
'$isolateExitCode');
}
exitCode = isolateExitCode as int;
exitCodeListener.cancel();
exitCodeListener = null;
});
await exitPort.first;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an FYI this isn't guaranteed to fire.
See all the extra handling we have for exception cases: https://github.com/dart-lang/build/blob/0c77443dd74edda706e89189c5ccfb70b06a22d1/build_runner/bin/build_runner.dart#L58-L85

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There oughta be a helper...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be a todo? File an issue?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes there should :)

I still haven't made up my mind whether I want a specific helper in build_runner or whether this we should make a more user friendly API around isolates in package:io

await errorListener.cancel();
await exitCodeListener?.cancel();
}
}

Future<Uri> _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));
}
''';
Loading