Commit 4c569195 authored by Devon Carew's avatar Devon Carew

clean the project names used for flutter create

parent f3561d80
...@@ -13,6 +13,21 @@ String calculateSha(File file) { ...@@ -13,6 +13,21 @@ String calculateSha(File file) {
return CryptoUtils.bytesToHex(sha1.close()); return CryptoUtils.bytesToHex(sha1.close());
} }
/// Convert `foo_bar` to `fooBar`.
String camelCase(String str) {
int index = str.indexOf('_');
while (index != -1 && index < str.length - 2) {
str = str.substring(0, index) +
str.substring(index + 1, index + 2).toUpperCase() +
str.substring(index + 2);
index = str.indexOf('_');
}
return str;
}
/// Return the plural of the given word (`cat(s)`).
String pluralize(String word, int count) => count == 1 ? word : word + 's';
/// A class to maintain a list of items, fire events when items are added or /// A class to maintain a list of items, fire events when items are added or
/// removed, and calculate a diff of changes when a new list of items is /// removed, and calculate a diff of changes when a new list of items is
/// available. /// available.
......
...@@ -10,6 +10,7 @@ import 'package:path/path.dart' as path; ...@@ -10,6 +10,7 @@ import 'package:path/path.dart' as path;
import '../android/android.dart' as android; import '../android/android.dart' as android;
import '../artifacts.dart'; import '../artifacts.dart';
import '../base/utils.dart';
import '../dart/pub.dart'; import '../dart/pub.dart';
import '../globals.dart'; import '../globals.dart';
import '../template.dart'; import '../template.dart';
...@@ -87,8 +88,10 @@ class CreateCommand extends Command { ...@@ -87,8 +88,10 @@ class CreateCommand extends Command {
_renderTemplates(projectName, dirPath, flutterPackagesDirectory, _renderTemplates(projectName, dirPath, flutterPackagesDirectory,
renderDriverTest: argResults['with-driver-test']); renderDriverTest: argResults['with-driver-test']);
printStatus('');
if (argResults['pub']) { if (argResults['pub']) {
int code = await pubGet(directory: projectDir.path); int code = await pubGet(directory: dirPath);
if (code != 0) if (code != 0)
return code; return code;
} }
...@@ -103,7 +106,7 @@ class CreateCommand extends Command { ...@@ -103,7 +106,7 @@ class CreateCommand extends Command {
printStatus(''' printStatus('''
All done! In order to run your application, type: All done! In order to run your application, type:
\$ cd ${projectDir.path} \$ cd $dirPath
\$ flutter run \$ flutter run
'''); ''');
} else { } else {
...@@ -116,7 +119,7 @@ All done! In order to run your application, type: ...@@ -116,7 +119,7 @@ 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 '${projectDir.path}' " printStatus("When complete, type 'flutter run' from the '$dirPath' "
"directory in order to launch your app."); "directory in order to launch your app.");
} }
...@@ -125,7 +128,6 @@ All done! In order to run your application, type: ...@@ -125,7 +128,6 @@ All done! In order to run your application, type:
void _renderTemplates(String projectName, String dirPath, void _renderTemplates(String projectName, String dirPath,
String flutterPackagesDirectory, { bool renderDriverTest: false }) { String flutterPackagesDirectory, { bool renderDriverTest: false }) {
String projectIdentifier = _createProjectIdentifier(path.basename(dirPath));
String relativeFlutterPackagesDirectory = path.relative(flutterPackagesDirectory, from: dirPath); String relativeFlutterPackagesDirectory = path.relative(flutterPackagesDirectory, from: dirPath);
printStatus('Creating project ${path.basename(projectName)}:'); printStatus('Creating project ${path.basename(projectName)}:');
...@@ -134,7 +136,8 @@ All done! In order to run your application, type: ...@@ -134,7 +136,8 @@ All done! In order to run your application, type:
Map templateContext = <String, dynamic>{ Map templateContext = <String, dynamic>{
'projectName': projectName, 'projectName': projectName,
'projectIdentifier': projectIdentifier, 'androidIdentifier': _createAndroidIdentifier(projectName),
'iosIdentifier': _createUTIIdentifier(projectName),
'description': description, 'description': description,
'flutterPackagesDirectory': relativeFlutterPackagesDirectory, 'flutterPackagesDirectory': relativeFlutterPackagesDirectory,
'androidMinApiLevel': android.minApiLevel 'androidMinApiLevel': android.minApiLevel
...@@ -163,11 +166,15 @@ String _normalizeProjectName(String name) { ...@@ -163,11 +166,15 @@ String _normalizeProjectName(String name) {
return name; return name;
} }
String _createProjectIdentifier(String name) { String _createAndroidIdentifier(String name) {
return 'com.yourcompany.${camelCase(name)}';
}
String _createUTIIdentifier(String name) {
// Create a UTI (https://en.wikipedia.org/wiki/Uniform_Type_Identifier) from a base name // Create a UTI (https://en.wikipedia.org/wiki/Uniform_Type_Identifier) from a base name
RegExp disallowed = new RegExp(r"[^a-zA-Z0-9\-.\u0080-\uffff]+"); RegExp disallowed = new RegExp(r"[^a-zA-Z0-9\-.\u0080-\uffff]+");
name = name.replaceAll(disallowed, ''); name = camelCase(name).replaceAll(disallowed, '');
name = name.length == 0 ? 'untitled' : name; name = name.isEmpty ? 'untitled' : name;
return 'com.yourcompany.$name'; return 'com.yourcompany.$name';
} }
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
import 'dart:async'; import 'dart:async';
import '../base/utils.dart';
import '../device.dart'; import '../device.dart';
import '../globals.dart'; import '../globals.dart';
import '../runner/flutter_command.dart'; import '../runner/flutter_command.dart';
...@@ -38,5 +39,3 @@ class DevicesCommand extends FlutterCommand { ...@@ -38,5 +39,3 @@ class DevicesCommand extends FlutterCommand {
return 0; return 0;
} }
} }
String pluralize(String word, int count) => count == 1 ? word : word + 's';
...@@ -9,6 +9,7 @@ import 'package:path/path.dart' as path; ...@@ -9,6 +9,7 @@ import 'package:path/path.dart' as path;
import '../application_package.dart'; import '../application_package.dart';
import '../base/common.dart'; import '../base/common.dart';
import '../base/utils.dart';
import '../build_configuration.dart'; import '../build_configuration.dart';
import '../dart/pub.dart'; import '../dart/pub.dart';
import '../device.dart'; import '../device.dart';
...@@ -17,7 +18,6 @@ import '../globals.dart'; ...@@ -17,7 +18,6 @@ import '../globals.dart';
import '../runner/flutter_command.dart'; import '../runner/flutter_command.dart';
import '../toolchain.dart'; import '../toolchain.dart';
import 'apk.dart'; import 'apk.dart';
import 'devices.dart';
import 'install.dart'; import 'install.dart';
/// Given the value of the --target option, return the path of the Dart file /// Given the value of the --target option, return the path of the Dart file
......
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="{{projectIdentifier}}" package="{{androidIdentifier}}"
android:versionCode="1" android:versionCode="1"
android:versionName="0.0.1"> android:versionName="0.0.1">
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
<key>CFBundleExecutable</key> <key>CFBundleExecutable</key>
<string>Runner</string> <string>Runner</string>
<key>CFBundleIdentifier</key> <key>CFBundleIdentifier</key>
<string>{{projectIdentifier}}</string> <string>{{iosIdentifier}}</string>
<key>CFBundleInfoDictionaryVersion</key> <key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string> <string>6.0</string>
<key>CFBundleName</key> <key>CFBundleName</key>
......
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