Commit 95fa9e3c authored by Devon Carew's avatar Devon Carew Committed by GitHub

Less chatty (#6213)

* make flutter create less chatty

* output generated file count; mention lib/main.dart
parent b00e6cda
...@@ -82,24 +82,27 @@ class CreateCommand extends FlutterCommand { ...@@ -82,24 +82,27 @@ class CreateCommand extends FlutterCommand {
Directory projectDir = new Directory(argResults.rest.first); Directory projectDir = new Directory(argResults.rest.first);
String dirPath = path.normalize(projectDir.absolute.path); String dirPath = path.normalize(projectDir.absolute.path);
String relativePath = path.relative(dirPath);
String projectName = _normalizeProjectName(path.basename(dirPath)); String projectName = _normalizeProjectName(path.basename(dirPath));
if (_validateProjectDir(dirPath) != null) { if (_validateProjectDir(dirPath) != null) {
printError(_validateProjectDir(dirPath)); printError(_validateProjectDir(dirPath));
return 1; return 1;
} }
if (_validateProjectName(projectName) != null) { if (_validateProjectName(projectName) != null) {
printError(_validateProjectName(projectName)); printError(_validateProjectName(projectName));
return 1; return 1;
} }
_renderTemplates( int generatedCount = _renderTemplates(
projectName, projectName,
argResults['description'], argResults['description'],
dirPath, dirPath,
flutterPackagesDirectory, flutterPackagesDirectory,
renderDriverTest: argResults['with-driver-test'] renderDriverTest: argResults['with-driver-test']
); );
printStatus('Wrote $generatedCount files.');
printStatus(''); printStatus('');
...@@ -119,8 +122,8 @@ class CreateCommand extends FlutterCommand { ...@@ -119,8 +122,8 @@ class CreateCommand extends FlutterCommand {
printStatus(''' printStatus('''
All done! In order to run your application, type: All done! In order to run your application, type:
\$ cd $dirPath \$ cd $relativePath
\$ flutter run \$ flutter run lib/main.dart
'''); ''');
} else { } else {
printStatus("You'll need to install additional components before you can run " printStatus("You'll need to install additional components before you can run "
...@@ -132,21 +135,21 @@ All done! In order to run your application, type: ...@@ -132,21 +135,21 @@ All done! In order to run your application, type:
printStatus(''); printStatus('');
printStatus("After installing components, run 'flutter doctor' in order to " printStatus("After installing components, run 'flutter doctor' in order to "
"re-validate your setup."); "re-validate your setup.");
printStatus("When complete, type 'flutter run' from the '$dirPath' " printStatus("When complete, type 'flutter run lib/main.dart' from the '$relativePath' "
"directory in order to launch your app."); "directory in order to launch your app.");
} }
return 0; return 0;
} }
void _renderTemplates(String projectName, String projectDescription, String dirPath, int _renderTemplates(String projectName, String projectDescription, String dirPath,
String flutterPackagesDirectory, { bool renderDriverTest: false }) { String flutterPackagesDirectory, { bool renderDriverTest: false }) {
new Directory(dirPath).createSync(recursive: true); new Directory(dirPath).createSync(recursive: true);
flutterPackagesDirectory = path.normalize(flutterPackagesDirectory); flutterPackagesDirectory = path.normalize(flutterPackagesDirectory);
flutterPackagesDirectory = _relativePath(from: dirPath, to: flutterPackagesDirectory); flutterPackagesDirectory = _relativePath(from: dirPath, to: flutterPackagesDirectory);
printStatus('Creating project ${path.basename(projectName)}:'); printStatus('Creating project ${path.relative(dirPath)}...');
Map<String, dynamic> templateContext = <String, dynamic>{ Map<String, dynamic> templateContext = <String, dynamic>{
'projectName': projectName, 'projectName': projectName,
...@@ -157,18 +160,22 @@ All done! In order to run your application, type: ...@@ -157,18 +160,22 @@ All done! In order to run your application, type:
'androidMinApiLevel': android.minApiLevel 'androidMinApiLevel': android.minApiLevel
}; };
int fileCount = 0;
if (renderDriverTest) if (renderDriverTest)
templateContext['withDriverTest?'] = <String, dynamic>{}; templateContext['withDriverTest?'] = <String, dynamic>{};
Template createTemplate = new Template.fromName('create'); Template createTemplate = new Template.fromName('create');
createTemplate.render(new Directory(dirPath), templateContext, fileCount += createTemplate.render(new Directory(dirPath), templateContext,
overwriteExisting: false); overwriteExisting: false);
if (renderDriverTest) { if (renderDriverTest) {
Template driverTemplate = new Template.fromName('driver'); Template driverTemplate = new Template.fromName('driver');
driverTemplate.render(new Directory(path.join(dirPath, 'test_driver')), fileCount += driverTemplate.render(new Directory(path.join(dirPath, 'test_driver')),
templateContext, overwriteExisting: false); templateContext, overwriteExisting: false);
} }
return fileCount;
} }
} }
......
...@@ -92,7 +92,7 @@ class Doctor { ...@@ -92,7 +92,7 @@ class Doctor {
if (!allGood) { if (!allGood) {
buffer.writeln(); buffer.writeln();
buffer.write('Run "flutter doctor" for information about installing additional components.'); buffer.writeln('Run "flutter doctor" for information about installing additional components.');
} }
return buffer.toString(); return buffer.toString();
......
...@@ -60,9 +60,10 @@ class Template { ...@@ -60,9 +60,10 @@ class Template {
Map<String /* relative */, String /* absolute source */> _templateFilePaths; Map<String /* relative */, String /* absolute source */> _templateFilePaths;
void render(Directory destination, Map<String, dynamic> context, int render(Directory destination, Map<String, dynamic> context,
{ bool overwriteExisting: true }) { { bool overwriteExisting: true }) {
destination.createSync(recursive: true); destination.createSync(recursive: true);
int fileCount = 0;
String destinationDirPath = destination.absolute.path; String destinationDirPath = destination.absolute.path;
...@@ -82,13 +83,15 @@ class Template { ...@@ -82,13 +83,15 @@ class Template {
printStatus(' $relativePathForLogging (overwritten)'); printStatus(' $relativePathForLogging (overwritten)');
} else { } else {
// The file exists but we cannot overwrite it, move on. // The file exists but we cannot overwrite it, move on.
printStatus(' $relativePathForLogging (existing - skipped)'); printTrace(' $relativePathForLogging (existing - skipped)');
return; return;
} }
} else { } else {
printStatus(' $relativePathForLogging'); printTrace(' $relativePathForLogging');
} }
fileCount++;
finalDestinationFile.createSync(recursive: true); finalDestinationFile.createSync(recursive: true);
File sourceFile = new File(absoluteSrcPath); File sourceFile = new File(absoluteSrcPath);
...@@ -118,6 +121,8 @@ class Template { ...@@ -118,6 +121,8 @@ class Template {
sourceFile.copySync(finalDestinationFile.path); sourceFile.copySync(finalDestinationFile.path);
}); });
return fileCount;
} }
} }
......
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