Skip to content

Commit

Permalink
Consistency with Xcode-generated projects
Browse files Browse the repository at this point in the history
  • Loading branch information
dpogue committed Sep 16, 2018
1 parent ce32ce8 commit af22be3
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 47 deletions.
4 changes: 2 additions & 2 deletions bin/lib/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ function copyTemplateFiles (project_path, project_name, project_template_dir, pa
shell.mv('-f', path.join(r, '__PROJECT_NAME__-Prefix.pch'), path.join(r, project_name + '-Prefix.pch'));
shell.mv('-f', path.join(r, 'gitignore'), path.join(r, '.gitignore'));

/* replace __PROJECT_NAME__ and --ID-- with ACTIVITY and ID strings, respectively, in:
/* replace __PROJECT_NAME__ and __PROJECT_ID__ with ACTIVITY and ID strings, respectively, in:
*
* - ./__PROJECT_NAME__.xcodeproj/project.pbxproj
* - ./__PROJECT_NAME__/Classes/AppDelegate.h
Expand All @@ -155,14 +155,14 @@ function copyTemplateFiles (project_path, project_name, project_template_dir, pa

var project_name_esc = project_name.replace(/&/g, '\\&');
shell.sed('-i', /__PROJECT_NAME__/g, project_name_esc, path.join(r + '.xcodeproj', 'project.pbxproj'));
shell.sed('-i', /__PROJECT_ID__/g, package_name, path.join(r + '.xcodeproj', 'project.pbxproj'));
shell.sed('-i', /__PROJECT_NAME__/g, project_name_esc, path.join(r, 'Classes', 'AppDelegate.h'));
shell.sed('-i', /__PROJECT_NAME__/g, project_name_esc, path.join(r, 'Classes', 'AppDelegate.m'));
shell.sed('-i', /__PROJECT_NAME__/g, project_name_esc, path.join(r, 'Classes', 'MainViewController.h'));
shell.sed('-i', /__PROJECT_NAME__/g, project_name_esc, path.join(r, 'Classes', 'MainViewController.m'));
shell.sed('-i', /__PROJECT_NAME__/g, project_name_esc, path.join(r, 'main.m'));
shell.sed('-i', /__PROJECT_NAME__/g, project_name_esc, path.join(r, project_name + '-Info.plist'));
shell.sed('-i', /__PROJECT_NAME__/g, project_name_esc, path.join(r, project_name + '-Prefix.pch'));
shell.sed('-i', /--ID--/g, package_name, path.join(r, project_name + '-Info.plist'));
}

function AbsParentPath (_path) {
Expand Down
20 changes: 8 additions & 12 deletions bin/templates/project/__PROJECT_NAME__/__PROJECT_NAME__-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,33 @@
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<string>en_US</string>
<key>CFBundleDisplayName</key>
<string>${PRODUCT_NAME}</string>
<string>$(PRODUCT_NAME)</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIcons</key>
<dict/>
<key>CFBundleIcons~ipad</key>
<dict/>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>--ID--</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSMainNibFile</key>
<string></string>
<key>NSMainNibFile~ipad</key>
<string></string>
<key>UIRequiresFullScreen</key>
<true/>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
Expand All @@ -45,7 +43,5 @@
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIRequiresFullScreen</key>
<true/>
</dict>
</plist>
10 changes: 6 additions & 4 deletions bin/templates/project/__TEMP__.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
};
};
};
buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "__NON-CLI__" */;
buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "__PROJECT_NAME__" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
hasScannedForEncodings = 1;
Expand Down Expand Up @@ -322,8 +322,9 @@
INFOPLIST_FILE = "__PROJECT_NAME__/__PROJECT_NAME__-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "__PROJECT_ID__";
PRODUCT_NAME = "$(TARGET_NAME)";
TARGETED_DEVICE_FAMILY = "1,2";
PRODUCT_NAME = "__PROJECT_NAME__";
};
name = Debug;
};
Expand All @@ -344,8 +345,9 @@
INFOPLIST_FILE = "__PROJECT_NAME__/__PROJECT_NAME__-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "__PROJECT_ID__";
PRODUCT_NAME = "$(TARGET_NAME)";
TARGETED_DEVICE_FAMILY = "1,2";
PRODUCT_NAME = "__PROJECT_NAME__";
};
name = Release;
};
Expand Down Expand Up @@ -441,7 +443,7 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
C01FCF4E08A954540054247B /* Build configuration list for PBXProject "__NON-CLI__" */ = {
C01FCF4E08A954540054247B /* Build configuration list for PBXProject "__PROJECT_NAME__" */ = {
isa = XCConfigurationList;
buildConfigurations = (
C01FCF4F08A954540054247B /* Debug */,
Expand Down
32 changes: 21 additions & 11 deletions bin/templates/scripts/cordova/lib/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ function updateProject (platformConfig, locations) {
// because node and shell scripts handles unicode symbols differently
// We need to normalize the name to NFD form since iOS uses NFD unicode form
var name = unorm.nfd(platformConfig.name());
var pkg = platformConfig.getAttribute('ios-CFBundleIdentifier') || platformConfig.packageName();
var version = platformConfig.version();
var displayName = platformConfig.shortName && platformConfig.shortName();

Expand All @@ -198,7 +197,6 @@ function updateProject (platformConfig, locations) {
// Update package id (bundle id)
var plistFile = path.join(locations.xcodeCordovaProj, originalName + '-Info.plist');
var infoPlist = plist.parse(fs.readFileSync(plistFile, 'utf8'));
infoPlist['CFBundleIdentifier'] = pkg;

// Update version (bundle version)
infoPlist['CFBundleShortVersionString'] = version;
Expand All @@ -224,10 +222,14 @@ function updateProject (platformConfig, locations) {
handleOrientationSettings(platformConfig, infoPlist);
updateProjectPlistForLaunchStoryboard(platformConfig, infoPlist);

var info_contents = plist.build(infoPlist);
/* eslint-disable no-tabs */
// Write out the plist file with the same formatting as Xcode does
var info_contents = plist.build(infoPlist, { indent: ' ', offset: -1 });
/* eslint-enable no-tabs */

info_contents = info_contents.replace(/<string>[\s\r\n]*<\/string>/g, '<string></string>');
fs.writeFileSync(plistFile, info_contents, 'utf-8');
events.emit('verbose', 'Wrote out iOS Bundle Identifier "' + pkg + '" and iOS Bundle Version "' + version + '" to ' + plistFile);
events.emit('verbose', 'Wrote out iOS Bundle Version "' + version + '" to ' + plistFile);

return handleBuildSettings(platformConfig, locations, infoPlist).then(function () {
if (name === originalName) {
Expand Down Expand Up @@ -274,23 +276,31 @@ function handleOrientationSettings (platformConfig, infoPlist) {
}

function handleBuildSettings (platformConfig, locations, infoPlist) {
var pkg = platformConfig.getAttribute('ios-CFBundleIdentifier') || platformConfig.packageName();
var targetDevice = parseTargetDevicePreference(platformConfig.getPreference('target-device', 'ios'));
var deploymentTarget = platformConfig.getPreference('deployment-target', 'ios');
var needUpdatedBuildSettingsForLaunchStoryboard = checkIfBuildSettingsNeedUpdatedForLaunchStoryboard(platformConfig, infoPlist);
var swiftVersion = platformConfig.getPreference('SwiftVersion', 'ios');

// no build settings provided and we don't need to update build settings for launch storyboards,
// then we don't need to parse and update .pbxproj file
if (!targetDevice && !deploymentTarget && !needUpdatedBuildSettingsForLaunchStoryboard && !swiftVersion) {
return Q();
}

var proj = new xcode.project(locations.pbxproj); /* eslint new-cap : 0 */

try {
proj.parseSync();
} catch (err) {
return Q.reject(new CordovaError('Could not parse project.pbxproj: ' + err));
return Q.reject(new CordovaError('Could not parse ' + locations.pbxproj + ': ' + err));
}

var origPkg = proj.getBuildProperty('PRODUCT_BUNDLE_IDENTIFIER');

// no build settings provided and we don't need to update build settings for launch storyboards,
// then we don't need to parse and update .pbxproj file
if (origPkg === pkg && !targetDevice && !deploymentTarget && !needUpdatedBuildSettingsForLaunchStoryboard && !swiftVersion) {
return Q();
}

if (origPkg !== pkg) {
events.emit('verbose', 'Set PRODUCT_BUNDLE_IDENTIFIER to ' + pkg + '.');
proj.updateBuildProperty('PRODUCT_BUNDLE_IDENTIFIER', pkg);
}

if (targetDevice) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
0207DA581B56EA530066E2B4 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0207DA571B56EA530066E2B4 /* Images.xcassets */; };
1D3623260D0F684500981E51 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D3623250D0F684500981E51 /* AppDelegate.m */; };
1D60589B0D05DD56006BFB54 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; };
301BF552109A68D80062928A /* libCordova.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 301BF535109A57CC0062928A /* libCordova.a */; };
301BF552109A68D80062928A /* libCordova.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 301BF535109A57CC0062928A /* libCordova.a */; settings = {ATTRIBUTES = (Required, ); }; };
302D95F114D2391D003F00A1 /* MainViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 302D95EF14D2391D003F00A1 /* MainViewController.m */; };
302D95F214D2391D003F00A1 /* MainViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 302D95F014D2391D003F00A1 /* MainViewController.xib */; };
3047A5121AB8059700498E2A /* build-debug.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 3047A50F1AB8059700498E2A /* build-debug.xcconfig */; };
Expand All @@ -33,6 +33,13 @@
remoteGlobalIDString = D2AAC07D0554694100DB518D;
remoteInfo = CordovaLib;
};
907D8123214C687600058A10 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 301BF52D109A57CC0062928A /* CordovaLib.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = C0C01EB21E3911D50056E6CB;
remoteInfo = Cordova;
};
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
Expand All @@ -54,8 +61,8 @@
8D1107310486CEB800E47090 /* SampleApp-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "SampleApp-Info.plist"; path = "SampleApp/SampleApp-Info.plist"; plistStructureDefinitionIdentifier = "com.apple.xcode.plist.structure-definition.iphone.info-plist"; sourceTree = SOURCE_ROOT; };
EB87FDF31871DA8E0020F90C /* www */ = {isa = PBXFileReference; lastKnownFileType = folder; name = www; path = ../../www; sourceTree = "<group>"; };
EB87FDF41871DAF40020F90C /* config.xml */ = {isa = PBXFileReference; lastKnownFileType = text.xml; name = config.xml; path = ../../config.xml; sourceTree = "<group>"; };
F840E1F0165FE0F500CFE078 /* config.xml */ = {isa = PBXFileReference; lastKnownFileType = text.xml; name = config.xml; path = "SampleApp/config.xml"; sourceTree = "<group>"; };
ED33DF2A687741AEAF9F8254 /* Bridging-Header.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "Bridging-Header.h"; path = "Bridging-Header.h"; sourceTree = "<group>"; };
F840E1F0165FE0F500CFE078 /* config.xml */ = {isa = PBXFileReference; lastKnownFileType = text.xml; name = config.xml; path = "SampleApp/config.xml"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -142,6 +149,7 @@
isa = PBXGroup;
children = (
301BF535109A57CC0062928A /* libCordova.a */,
907D8124214C687600058A10 /* Cordova.framework */,
);
name = Products;
sourceTree = "<group>";
Expand Down Expand Up @@ -201,7 +209,12 @@
29B97313FDCFA39411CA2CEA /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 510;
LastUpgradeCheck = 0510;
TargetAttributes = {
1D6058900D05DD3D006BFB54 = {
ProvisioningStyle = Automatic;
};
};
};
buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "__NON-CLI__" */;
compatibilityVersion = "Xcode 3.2";
Expand Down Expand Up @@ -230,6 +243,13 @@
remoteRef = 301BF534109A57CC0062928A /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
907D8124214C687600058A10 /* Cordova.framework */ = {
isa = PBXReferenceProxy;
fileType = wrapper.framework;
path = Cordova.framework;
remoteRef = 907D8123214C687600058A10 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
/* End PBXReferenceProxy section */

/* Begin PBXResourcesBuildPhase section */
Expand Down Expand Up @@ -304,8 +324,9 @@
INFOPLIST_FILE = "SampleApp/SampleApp-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
TARGETED_DEVICE_FAMILY = "1,2";
PRODUCT_BUNDLE_IDENTIFIER = "com.example.friendstring";
PRODUCT_NAME = "SampleApp";
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
};
Expand All @@ -326,8 +347,9 @@
INFOPLIST_FILE = "SampleApp/SampleApp-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
TARGETED_DEVICE_FAMILY = "1,2";
PRODUCT_BUNDLE_IDENTIFIER = "com.example.friendstring";
PRODUCT_NAME = "SampleApp";
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
};
Expand All @@ -337,15 +359,30 @@
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = c99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_THUMB_SUPPORT = NO;
GCC_VERSION = "";
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
Expand All @@ -363,15 +400,29 @@
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = c99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_THUMB_SUPPORT = NO;
GCC_VERSION = "";
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
Expand All @@ -394,7 +445,7 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
C01FCF4E08A954540054247B /* Build configuration list for PBXProject "__NON-CLI__" */ = {
C01FCF4E08A954540054247B /* Build configuration list for PBXProject "SampleApp" */ = {
isa = XCConfigurationList;
buildConfigurations = (
C01FCF4F08A954540054247B /* Debug */,
Expand Down
Loading

0 comments on commit af22be3

Please sign in to comment.