mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Merge pull request #1917 from abarth/pub_get
flutter run should run pub get automatically
This commit is contained in:
commit
5a0edf9f0f
@ -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.');
|
||||
|
||||
47
packages/flutter_tools/lib/src/dart/pub.dart
Normal file
47
packages/flutter_tools/lib/src/dart/pub.dart
Normal file
@ -0,0 +1,47 @@
|
||||
// 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;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user