Commit cf811636 authored by Adam Barth's avatar Adam Barth

flutter run should run pub get automatically

This removes a step that can cause trouble.

Fixes #1904
parent 7a2c38ab
......@@ -12,7 +12,7 @@ import 'package:path/path.dart' as path;
import '../android/android.dart' as android;
import '../artifacts.dart';
import '../base/globals.dart';
import '../base/process.dart';
import '../dart/pub.dart';
import 'ios.dart';
class CreateCommand extends Command {
......@@ -70,39 +70,6 @@ All done! To run your application:
printStatus(message);
return 0;
}
Future<int> pubGet({
String directory: '',
bool skipIfAbsent: false
}) async {
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;
}
}
abstract class Template {
......
......@@ -11,6 +11,7 @@ import '../application_package.dart';
import '../base/common.dart';
import '../base/globals.dart';
import '../build_configuration.dart';
import '../dart/pub.dart';
import '../device.dart';
import '../flx.dart';
import '../runner/flutter_command.dart';
......@@ -68,11 +69,21 @@ class RunCommand extends RunCommandBase {
defaultsTo: false,
negatable: false,
help: 'Start in a paused mode and wait for a debugger to connect.');
argParser.addFlag('pub',
defaultsTo: true,
help: 'Whether to run "pub get" before running the app.');
argParser.addOption('debug-port',
defaultsTo: observatoryDefaultPort.toString(),
help: 'Listen to the given port for a debug connection.');
}
@override
Future<int> run() async {
if (argResults['pub'])
await pubGet();
return await super.run();
}
@override
Future<int> runInProject() async {
printTrace('Downloading toolchain.');
......
// 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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment