dart-sass/test/ensure_npm_package.dart

45 lines
1.3 KiB
Dart
Raw Normal View History

// 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:convert';
import 'dart:io';
2017-07-07 02:36:15 +02:00
import 'package:stream_channel/stream_channel.dart';
import 'package:test/test.dart';
import 'package:yaml/yaml.dart';
2017-07-07 02:36:15 +02:00
hybridMain(StreamChannel channel) async {
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"));
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;
}
}
}
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();
}