flutter/packages/flutter_tools/lib/src/dart/pub.dart
Adam Barth cf8116368d flutter run should run pub get automatically
This removes a step that can cause trouble.

Fixes #1904
2016-02-16 11:16:34 -08:00

48 lines
1.5 KiB
Dart

// Copyright 2016 The Chromium Authors. 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:path/path.dart' as path;
import '../base/globals.dart';
import '../base/process.dart';
Future<int> pubGet({
String directory,
bool skipIfAbsent: false
}) async {
if (directory == null)
directory = Directory.current.path;
File pubSpecYaml = new File(path.join(directory, 'pubspec.yaml'));
File pubSpecLock = new File(path.join(directory, 'pubspec.lock'));
File dotPackages = new File(path.join(directory, '.packages'));
if (!pubSpecYaml.existsSync()) {
if (skipIfAbsent)
return 0;
printError('$directory: no pubspec.yaml found');
return 1;
}
if (!pubSpecLock.existsSync() || pubSpecYaml.lastModifiedSync().isAfter(pubSpecLock.lastModifiedSync())) {
printStatus("Running 'pub get' in '$directory'...");
int code = await runCommandAndStreamOutput(
<String>[sdkBinaryName('pub'), '--verbosity=warning', 'get'],
workingDirectory: directory
);
if (code != 0)
return code;
}
if ((pubSpecLock.existsSync() && pubSpecLock.lastModifiedSync().isAfter(pubSpecYaml.lastModifiedSync())) &&
(dotPackages.existsSync() && dotPackages.lastModifiedSync().isAfter(pubSpecYaml.lastModifiedSync())))
return 0;
printError('$directory: pubspec.yaml, pubspec.lock, and .packages are in an inconsistent state');
return 1;
}