Commit f6a2477d authored by Chinmay Garde's avatar Chinmay Garde

Always generate legal UTIs for project identifiers.

parent 9ed4e417
...@@ -98,6 +98,7 @@ abstract class Template { ...@@ -98,6 +98,7 @@ abstract class Template {
void generateInto(Directory dir, String flutterPackagePath) { void generateInto(Directory dir, String flutterPackagePath) {
String dirPath = path.normalize(dir.absolute.path); String dirPath = path.normalize(dir.absolute.path);
String projectName = _normalizeProjectName(path.basename(dirPath)); String projectName = _normalizeProjectName(path.basename(dirPath));
String projectIdentifier = _createProjectIdentifier(path.basename(dirPath));
printStatus('Creating ${path.basename(projectName)}...'); printStatus('Creating ${path.basename(projectName)}...');
dir.createSync(recursive: true); dir.createSync(recursive: true);
...@@ -108,6 +109,7 @@ abstract class Template { ...@@ -108,6 +109,7 @@ abstract class Template {
String contents = files[filePath]; String contents = files[filePath];
Map m = <String, String>{ Map m = <String, String>{
'projectName': projectName, 'projectName': projectName,
'projectIdentifier': projectIdentifier,
'description': description, 'description': description,
'flutterPackagePath': relativeFlutterPackagePath 'flutterPackagePath': relativeFlutterPackagePath
}; };
...@@ -150,6 +152,14 @@ String _normalizeProjectName(String name) { ...@@ -150,6 +152,14 @@ String _normalizeProjectName(String name) {
return name; return name;
} }
String _createProjectIdentifier(String 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]+");
name = name.replaceAll(disallowed, '');
name = name.length == 0 ? 'untitled' : name;
return 'com.yourcompany.${name}';
}
const String _analysis_options = r''' const String _analysis_options = r'''
analyzer: analyzer:
exclude: exclude:
...@@ -244,7 +254,7 @@ class FlutterDemoState extends State { ...@@ -244,7 +254,7 @@ class FlutterDemoState extends State {
final String _apkManifest = ''' final String _apkManifest = '''
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.{{projectName}}" package="{{projectIdentifier}}"
android:versionCode="1" android:versionCode="1"
android:versionName="0.0.1"> android:versionName="0.0.1">
......
...@@ -173,7 +173,7 @@ final String _infoPlistInitialContents = ''' ...@@ -173,7 +173,7 @@ final String _infoPlistInitialContents = '''
<key>CFBundleExecutable</key> <key>CFBundleExecutable</key>
<string>Runner</string> <string>Runner</string>
<key>CFBundleIdentifier</key> <key>CFBundleIdentifier</key>
<string>com.example.{{projectName}}</string> <string>{{projectIdentifier}}</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