From 95fa9e3c5539c0004d17346c32563356aa640427 Mon Sep 17 00:00:00 2001 From: Devon Carew Date: Wed, 5 Oct 2016 08:26:17 -0700 Subject: [PATCH] Less chatty (#6213) * make flutter create less chatty * output generated file count; mention lib/main.dart --- .../lib/src/commands/create.dart | 23 ++++++++++++------- packages/flutter_tools/lib/src/doctor.dart | 2 +- packages/flutter_tools/lib/src/template.dart | 11 ++++++--- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/packages/flutter_tools/lib/src/commands/create.dart b/packages/flutter_tools/lib/src/commands/create.dart index 1fcfd7eda8..d09c19be93 100644 --- a/packages/flutter_tools/lib/src/commands/create.dart +++ b/packages/flutter_tools/lib/src/commands/create.dart @@ -82,24 +82,27 @@ class CreateCommand extends FlutterCommand { Directory projectDir = new Directory(argResults.rest.first); String dirPath = path.normalize(projectDir.absolute.path); + String relativePath = path.relative(dirPath); String projectName = _normalizeProjectName(path.basename(dirPath)); if (_validateProjectDir(dirPath) != null) { printError(_validateProjectDir(dirPath)); return 1; } + if (_validateProjectName(projectName) != null) { printError(_validateProjectName(projectName)); return 1; } - _renderTemplates( + int generatedCount = _renderTemplates( projectName, argResults['description'], dirPath, flutterPackagesDirectory, renderDriverTest: argResults['with-driver-test'] ); + printStatus('Wrote $generatedCount files.'); printStatus(''); @@ -119,8 +122,8 @@ class CreateCommand extends FlutterCommand { printStatus(''' All done! In order to run your application, type: - \$ cd $dirPath - \$ flutter run + \$ cd $relativePath + \$ flutter run lib/main.dart '''); } else { 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: printStatus(''); printStatus("After installing components, run 'flutter doctor' in order to " "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."); } return 0; } - void _renderTemplates(String projectName, String projectDescription, String dirPath, + int _renderTemplates(String projectName, String projectDescription, String dirPath, String flutterPackagesDirectory, { bool renderDriverTest: false }) { new Directory(dirPath).createSync(recursive: true); flutterPackagesDirectory = path.normalize(flutterPackagesDirectory); flutterPackagesDirectory = _relativePath(from: dirPath, to: flutterPackagesDirectory); - printStatus('Creating project ${path.basename(projectName)}:'); + printStatus('Creating project ${path.relative(dirPath)}...'); Map templateContext = { 'projectName': projectName, @@ -157,18 +160,22 @@ All done! In order to run your application, type: 'androidMinApiLevel': android.minApiLevel }; + int fileCount = 0; + if (renderDriverTest) templateContext['withDriverTest?'] = {}; Template createTemplate = new Template.fromName('create'); - createTemplate.render(new Directory(dirPath), templateContext, + fileCount += createTemplate.render(new Directory(dirPath), templateContext, overwriteExisting: false); if (renderDriverTest) { 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); } + + return fileCount; } } diff --git a/packages/flutter_tools/lib/src/doctor.dart b/packages/flutter_tools/lib/src/doctor.dart index 3f351b0f01..11c311b6d4 100644 --- a/packages/flutter_tools/lib/src/doctor.dart +++ b/packages/flutter_tools/lib/src/doctor.dart @@ -92,7 +92,7 @@ class Doctor { if (!allGood) { 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(); diff --git a/packages/flutter_tools/lib/src/template.dart b/packages/flutter_tools/lib/src/template.dart index f244baf40e..e306d169d3 100644 --- a/packages/flutter_tools/lib/src/template.dart +++ b/packages/flutter_tools/lib/src/template.dart @@ -60,9 +60,10 @@ class Template { Map _templateFilePaths; - void render(Directory destination, Map context, + int render(Directory destination, Map context, { bool overwriteExisting: true }) { destination.createSync(recursive: true); + int fileCount = 0; String destinationDirPath = destination.absolute.path; @@ -82,13 +83,15 @@ class Template { printStatus(' $relativePathForLogging (overwritten)'); } else { // The file exists but we cannot overwrite it, move on. - printStatus(' $relativePathForLogging (existing - skipped)'); + printTrace(' $relativePathForLogging (existing - skipped)'); return; } } else { - printStatus(' $relativePathForLogging'); + printTrace(' $relativePathForLogging'); } + fileCount++; + finalDestinationFile.createSync(recursive: true); File sourceFile = new File(absoluteSrcPath); @@ -118,6 +121,8 @@ class Template { sourceFile.copySync(finalDestinationFile.path); }); + + return fileCount; } }