Updated package hot
This commit is contained in:
parent
dd90023342
commit
3e5945b397
2 changed files with 43 additions and 25 deletions
|
@ -9,6 +9,7 @@ import 'package:angel_framework/http.dart';
|
||||||
import 'package:angel_websocket/server.dart';
|
import 'package:angel_websocket/server.dart';
|
||||||
import 'package:charcode/ascii.dart';
|
import 'package:charcode/ascii.dart';
|
||||||
import 'package:glob/glob.dart';
|
import 'package:glob/glob.dart';
|
||||||
|
import 'package:glob/list_local_fs.dart';
|
||||||
import 'package:html_builder/elements.dart';
|
import 'package:html_builder/elements.dart';
|
||||||
import 'package:html_builder/html_builder.dart';
|
import 'package:html_builder/html_builder.dart';
|
||||||
import 'package:io/ansi.dart';
|
import 'package:io/ansi.dart';
|
||||||
|
@ -103,8 +104,9 @@ class HotReloader {
|
||||||
response
|
response
|
||||||
..headers.set(HttpHeaders.contentEncodingHeader, 'gzip')
|
..headers.set(HttpHeaders.contentEncodingHeader, 'gzip')
|
||||||
..add(gzip.encode(utf8.encode(_renderer.render(doc))));
|
..add(gzip.encode(utf8.encode(_renderer.render(doc))));
|
||||||
} else
|
} else {
|
||||||
response.write(_renderer.render(doc));
|
response.write(_renderer.render(doc));
|
||||||
|
}
|
||||||
response.close();
|
response.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,11 +115,11 @@ class HotReloader {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future handleRequest(HttpRequest request) async {
|
Future handleRequest(HttpRequest request) async {
|
||||||
if (_server != null)
|
if (_server != null) {
|
||||||
return await _handle(request);
|
return await _handle(request);
|
||||||
else if (timeout == null)
|
} else if (timeout == null) {
|
||||||
_requestQueue.add(request);
|
_requestQueue.add(request);
|
||||||
else {
|
} else {
|
||||||
_requestQueue.add(request);
|
_requestQueue.add(request);
|
||||||
Timer(timeout, () {
|
Timer(timeout, () {
|
||||||
if (_requestQueue.remove(request)) {
|
if (_requestQueue.remove(request)) {
|
||||||
|
@ -157,9 +159,10 @@ class HotReloader {
|
||||||
var isHot = true;
|
var isHot = true;
|
||||||
_server = await _generateServer();
|
_server = await _generateServer();
|
||||||
|
|
||||||
if (_paths?.isNotEmpty != true)
|
if (_paths?.isNotEmpty != true) {
|
||||||
_logWarning(
|
_logWarning(
|
||||||
'You have instantiated a HotReloader without providing any filesystem paths to watch.');
|
'You have instantiated a HotReloader without providing any filesystem paths to watch.');
|
||||||
|
}
|
||||||
|
|
||||||
bool _sw(String s) {
|
bool _sw(String s) {
|
||||||
return Platform.executableArguments.any((ss) => ss.startsWith(s));
|
return Platform.executableArguments.any((ss) => ss.startsWith(s));
|
||||||
|
@ -173,10 +176,11 @@ class HotReloader {
|
||||||
var info = await dev.Service.getInfo();
|
var info = await dev.Service.getInfo();
|
||||||
var uri = info.serverUri;
|
var uri = info.serverUri;
|
||||||
uri = uri.replace(path: p.join(uri.path, 'ws'));
|
uri = uri.replace(path: p.join(uri.path, 'ws'));
|
||||||
if (uri.scheme == 'https')
|
if (uri.scheme == 'https') {
|
||||||
uri = uri.replace(scheme: 'wss');
|
uri = uri.replace(scheme: 'wss');
|
||||||
else
|
} else {
|
||||||
uri = uri.replace(scheme: 'ws');
|
uri = uri.replace(scheme: 'ws');
|
||||||
|
}
|
||||||
_client = await vm.vmServiceConnectUri(uri.toString());
|
_client = await vm.vmServiceConnectUri(uri.toString());
|
||||||
_vmachine ??= await _client.getVM();
|
_vmachine ??= await _client.getVM();
|
||||||
_mainIsolate ??= _vmachine.isolates.first;
|
_mainIsolate ??= _vmachine.isolates.first;
|
||||||
|
@ -192,7 +196,9 @@ class HotReloader {
|
||||||
//.transform(new _Debounce(new Duration(seconds: 1)))
|
//.transform(new _Debounce(new Duration(seconds: 1)))
|
||||||
.listen(_handleWatchEvent);
|
.listen(_handleWatchEvent);
|
||||||
|
|
||||||
while (_requestQueue.isNotEmpty) await _handle(_requestQueue.removeFirst());
|
while (_requestQueue.isNotEmpty) {
|
||||||
|
await _handle(_requestQueue.removeFirst());
|
||||||
|
}
|
||||||
var server = _io = await HttpServer.bind(address ?? '127.0.0.1', port ?? 0);
|
var server = _io = await HttpServer.bind(address ?? '127.0.0.1', port ?? 0);
|
||||||
server.listen(handleRequest);
|
server.listen(handleRequest);
|
||||||
|
|
||||||
|
@ -278,12 +284,14 @@ class HotReloader {
|
||||||
} else if (path is Uri) {
|
} else if (path is Uri) {
|
||||||
if (path.scheme == 'package') {
|
if (path.scheme == 'package') {
|
||||||
var uri = await Isolate.resolvePackageUri(path);
|
var uri = await Isolate.resolvePackageUri(path);
|
||||||
if (uri != null)
|
if (uri != null) {
|
||||||
await _listenToStat(uri.toFilePath());
|
await _listenToStat(uri.toFilePath());
|
||||||
else
|
} else {
|
||||||
await _listenToStat(path.toFilePath());
|
await _listenToStat(path.toFilePath());
|
||||||
} else
|
}
|
||||||
|
} else {
|
||||||
await _listenToStat(path.toFilePath());
|
await _listenToStat(path.toFilePath());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
throw ArgumentError(
|
throw ArgumentError(
|
||||||
'Hot reload paths must be a FileSystemEntity, a Uri, a String or a Glob. You provided: $path');
|
'Hot reload paths must be a FileSystemEntity, a Uri, a String or a Glob. You provided: $path');
|
||||||
|
@ -305,8 +313,9 @@ class HotReloader {
|
||||||
} else if (stat.type == FileSystemEntityType.directory) {
|
} else if (stat.type == FileSystemEntityType.directory) {
|
||||||
var dir = Directory(path);
|
var dir = Directory(path);
|
||||||
if (!await dir.exists()) return null;
|
if (!await dir.exists()) return null;
|
||||||
} else
|
} else {
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
var watcher = Watcher(path);
|
var watcher = Watcher(path);
|
||||||
|
|
||||||
|
@ -357,7 +366,7 @@ class HotReloader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_handleWatchEvent(WatchEvent e, [bool hot = true]) async {
|
void _handleWatchEvent(WatchEvent e, [bool hot = true]) async {
|
||||||
_logInfo('${e.path} changed. Reloading server...\n');
|
_logInfo('${e.path} changed. Reloading server...\n');
|
||||||
await _killServer();
|
await _killServer();
|
||||||
_server = null;
|
_server = null;
|
||||||
|
@ -373,7 +382,9 @@ class HotReloader {
|
||||||
|
|
||||||
var s = await _generateServer();
|
var s = await _generateServer();
|
||||||
_server = s;
|
_server = s;
|
||||||
while (_requestQueue.isNotEmpty) await _handle(_requestQueue.removeFirst());
|
while (_requestQueue.isNotEmpty) {
|
||||||
|
await _handle(_requestQueue.removeFirst());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,23 +1,30 @@
|
||||||
name: angel_hot
|
name: angel_hot
|
||||||
description: Supports hot reloading/hot code push of Angel servers on file changes.
|
description: Supports hot reloading/hot code push of Angel servers on file changes.
|
||||||
version: 2.0.6
|
version: 3.0.0
|
||||||
author: Tobe O <thosakwe@gmail.com>
|
author: Tobe O <thosakwe@gmail.com>
|
||||||
homepage: https://github.com/angel-dart/hot
|
homepage: https://github.com/angel-dart/hot
|
||||||
|
publish_to: none
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=2.10.0 <2.12.0"
|
sdk: ">=2.10.0 <3.0.0"
|
||||||
dependencies:
|
dependencies:
|
||||||
angel_framework: #^2.0.0-alpha
|
angel_framework:
|
||||||
path: ../framework
|
git:
|
||||||
|
url: https://github.com/dukefirehawk/angel.git
|
||||||
|
ref: sdk-2.12.x
|
||||||
|
path: packages/framework
|
||||||
angel_websocket: #^2.0.0-alpha
|
angel_websocket: #^2.0.0-alpha
|
||||||
path: ../websocket
|
git:
|
||||||
|
url: https://github.com/dukefirehawk/angel.git
|
||||||
|
ref: sdk-2.12.x
|
||||||
|
path: packages/websocket
|
||||||
charcode: ^1.0.0
|
charcode: ^1.0.0
|
||||||
glob: ^1.0.0
|
glob: ^2.0.0
|
||||||
html_builder: ^1.0.0
|
html_builder: ^1.0.0
|
||||||
io: ^0.3.2
|
io: ^1.0.0
|
||||||
path: ^1.0.0
|
path: ^1.0.0
|
||||||
vm_service_lib: ^0.3.5
|
vm_service_lib: ^3.22.2+1
|
||||||
watcher: ^0.9.0
|
watcher: ^1.0.0
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
http: ^0.12.0
|
http: ^0.13.0
|
||||||
logging: ^0.11.0
|
logging: ^1.0.0
|
||||||
pedantic: ^1.0.0
|
pedantic: ^1.0.0
|
||||||
|
|
Loading…
Reference in a new issue