2017-07-06 23:40:45 +02:00
|
|
|
// Copyright 2017 Google Inc. Use of this source code is governed by an
|
|
|
|
// MIT-style license that can be found in the LICENSE file or at
|
|
|
|
// https://opensource.org/licenses/MIT.
|
|
|
|
|
|
|
|
import 'dart:async';
|
|
|
|
import 'dart:io';
|
|
|
|
|
2017-07-07 02:36:15 +02:00
|
|
|
import 'package:stream_channel/stream_channel.dart';
|
2017-07-06 23:40:45 +02:00
|
|
|
import 'package:test/test.dart';
|
|
|
|
|
2017-07-07 02:36:15 +02:00
|
|
|
hybridMain(StreamChannel channel) async {
|
2017-07-06 23:40:45 +02:00
|
|
|
if (!new Directory("build/npm").existsSync()) {
|
|
|
|
throw "NPM package is not build. Run pub run grinder npm_package.";
|
|
|
|
}
|
|
|
|
|
|
|
|
var lastModified = new DateTime(0);
|
|
|
|
var entriesToCheck = new Directory("lib").listSync(recursive: true).toList()
|
2017-07-07 02:36:15 +02:00
|
|
|
..add(new File("pubspec.lock"));
|
2017-07-06 23:40:45 +02:00
|
|
|
for (var entry in entriesToCheck) {
|
2017-07-07 02:36:15 +02:00
|
|
|
if (entry is File) {
|
|
|
|
var entryLastModified = entry.lastModifiedSync();
|
|
|
|
if (lastModified.isBefore(entryLastModified)) {
|
|
|
|
lastModified = entryLastModified;
|
|
|
|
}
|
|
|
|
}
|
2017-07-06 23:40:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (lastModified
|
|
|
|
.isAfter(new File("build/npm/package.json").lastModifiedSync())) {
|
|
|
|
throw "NPM package is out-of-date. Run pub run grinder npm_package.";
|
|
|
|
}
|
|
|
|
|
|
|
|
channel.sink.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Ensures that the NPM package is compiled and up-to-date.
|
|
|
|
///
|
|
|
|
/// This is safe to call even outside the Dart VM.k
|
|
|
|
Future ensureNpmPackage() {
|
|
|
|
var channel = spawnHybridUri("ensure_npm_package.dart");
|
|
|
|
return channel.stream.toList();
|
|
|
|
}
|