From 93b31a41df493ad2887d67d0d2f317a2211cc1fd Mon Sep 17 00:00:00 2001 From: Devon Carew Date: Fri, 4 Mar 2016 18:56:26 -0800 Subject: [PATCH] fix flutter create --- .../lib/src/commands/create.dart | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/packages/flutter_tools/lib/src/commands/create.dart b/packages/flutter_tools/lib/src/commands/create.dart index d13f9cac05..8e6fc399da 100644 --- a/packages/flutter_tools/lib/src/commands/create.dart +++ b/packages/flutter_tools/lib/src/commands/create.dart @@ -128,21 +128,19 @@ All done! In order to run your application, type: void _renderTemplates(String projectName, String dirPath, String flutterPackagesDirectory, { bool renderDriverTest: false }) { - String relativePackagesDirectory = path.relative( - flutterPackagesDirectory, - from: path.join(dirPath, 'pubspec.yaml') - ); + new Directory(dirPath).createSync(recursive: true); + + flutterPackagesDirectory = path.normalize(flutterPackagesDirectory); + flutterPackagesDirectory = _relativePath(from: dirPath, to: flutterPackagesDirectory); printStatus('Creating project ${path.basename(projectName)}:'); - new Directory(dirPath).createSync(recursive: true); - Map templateContext = { 'projectName': projectName, 'androidIdentifier': _createAndroidIdentifier(projectName), 'iosIdentifier': _createUTIIdentifier(projectName), 'description': description, - 'flutterPackagesDirectory': relativePackagesDirectory, + 'flutterPackagesDirectory': flutterPackagesDirectory, 'androidMinApiLevel': android.minApiLevel }; @@ -211,3 +209,11 @@ String _validateProjectName(String projectName) { return null; } + +String _relativePath({ String from, String to }) { + String result = path.relative(to, from: from); + // `path.relative()` doesn't always return a correct result: dart-lang/path#12. + if (FileSystemEntity.isDirectorySync(path.join(from, result))) + return result; + return to; +}