Skip to content

Commit

Permalink
Add target to Podfile in tns doctor
Browse files Browse the repository at this point in the history
CocoaPods 1.0.0 and later requires a target for which the Podfile will install. We already add such a target when preparing the Podfile for projects - extract logic and reuse it in the doctor service.
  • Loading branch information
TsvetanMilanov committed May 19, 2016
1 parent c4f033b commit 9696dcc
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 5 deletions.
2 changes: 2 additions & 0 deletions lib/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ $injector.require("projectService", "./services/project-service");
$injector.require("androidProjectService", "./services/android-project-service");
$injector.require("iOSProjectService", "./services/ios-project-service");

$injector.require("cocoapodsService", "./services/cocoapods-service");

$injector.require("projectTemplatesService", "./services/project-templates-service");
$injector.require("projectNameService", "./services/project-name-service");
$injector.require("tnsModulesService", "./services/tns-modules-service");
Expand Down
16 changes: 16 additions & 0 deletions lib/definitions/project.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,19 @@ interface ITestExecutionService {
startKarmaServer(platform: string): IFuture<void>;
}

/**
* Describes a service used to facilitate communication with CocoaPods
*/
interface ICocoaPodsService {
/**
* Get the header needed for the beginning of every Podfile
* @param {string} targetName The name of the target (usually the same as the project's name).
* @return {string} The header which needs to be placed at the beginning of a Podfile.
*/
getPodfileHeader(targetName: string): string;
/**
* Get the footer needed for the end of every Podfile
* @return {string} The footer which needs to be placed at the end of a Podfile.
*/
getPodfileFooter(): string;
}
16 changes: 16 additions & 0 deletions lib/services/cocoapods-service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
///<reference path="../.d.ts"/>
"use strict";

import {EOL} from "os";

export class CocoaPodsService implements ICocoaPodsService {
public getPodfileHeader(targetName: string): string {
return `use_frameworks!${EOL}${EOL}target "${targetName}" do${EOL}`;
}

public getPodfileFooter(): string {
return `${EOL}end`;
}
}

$injector.register("cocoapodsService", CocoaPodsService);
6 changes: 4 additions & 2 deletions lib/services/doctor-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as helpers from "../common/helpers";
let clui = require("clui");

class DoctorService implements IDoctorService {
private static PROJECT_NAME_PLACEHOLDER = "__PROJECT_NAME__";
private static MIN_SUPPORTED_POD_VERSION = "0.38.2";
private static DarwinSetupScriptLocation = path.join(__dirname, "..", "..", "setup", "mac-startup-shell-script.sh");
private static DarwinSetupDocsLink = "https://docs.nativescript.org/start/ns-setup-os-x";
Expand All @@ -17,6 +18,7 @@ class DoctorService implements IDoctorService {

constructor(private $analyticsService: IAnalyticsService,
private $androidToolsInfo: IAndroidToolsInfo,
private $cocoapodsService: ICocoaPodsService,
private $hostInfo: IHostInfo,
private $logger: ILogger,
private $progressIndicator: IProgressIndicator,
Expand Down Expand Up @@ -187,7 +189,7 @@ class DoctorService implements IDoctorService {
let iosDir = path.join(projDir, "node_modules", "tns-ios", "framework");
this.$fs.writeFile(
path.join(iosDir, "Podfile"),
"pod 'AFNetworking', '~> 1.0'\n"
`${this.$cocoapodsService.getPodfileHeader(DoctorService.PROJECT_NAME_PLACEHOLDER)}pod 'AFNetworking', '~> 1.0'${this.$cocoapodsService.getPodfileFooter()}`
).wait();

spinner.message("Verifying CocoaPods. This may take some time, please be patient.");
Expand All @@ -207,7 +209,7 @@ class DoctorService implements IDoctorService {
return true;
}

return !(this.$fs.exists(path.join(iosDir, "__PROJECT_NAME__.xcworkspace")).wait());
return !(this.$fs.exists(path.join(iosDir, `${DoctorService.PROJECT_NAME_PLACEHOLDER}.xcworkspace`)).wait());
} catch (err) {
this.$logger.trace(`verifyCocoaPods error: ${err}`);
return true;
Expand Down
7 changes: 4 additions & 3 deletions lib/services/ios-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
constructor($projectData: IProjectData,
$fs: IFileSystem,
private $childProcess: IChildProcess,
private $cocoapodsService: ICocoaPodsService,
private $errors: IErrors,
private $logger: ILogger,
private $iOSEmulatorServices: Mobile.IEmulatorPlatformServices,
Expand Down Expand Up @@ -705,10 +706,10 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
projectPodFileContent = this.$fs.exists(this.projectPodFilePath).wait() ? this.$fs.readText(this.projectPodFilePath).wait() : "";

if (!~projectPodFileContent.indexOf(pluginPodFilePreparedContent)) {
let podFileHeader = `use_frameworks!${os.EOL}${os.EOL}target "${this.$projectData.projectName}" do${os.EOL}`,
podFileFooter = `${os.EOL}end`;
let podFileHeader = this.$cocoapodsService.getPodfileHeader(this.$projectData.projectName),
podFileFooter = this.$cocoapodsService.getPodfileFooter();

if (_.startsWith(projectPodFileContent, podFileHeader)) {
if (_.startsWith(projectPodFileContent, podFileHeader)) {
projectPodFileContent = projectPodFileContent.substr(podFileHeader.length);
}

Expand Down

0 comments on commit 9696dcc

Please sign in to comment.