Skip to content

Commit 06309b1

Browse files
committed
Merge pull request #1771 from NativeScript/kerezov/add-target-doctor
Add target to Podfile in tns doctor
2 parents c4f033b + 93d56ef commit 06309b1

File tree

6 files changed

+43
-4
lines changed

6 files changed

+43
-4
lines changed

lib/bootstrap.ts

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ $injector.require("projectService", "./services/project-service");
1111
$injector.require("androidProjectService", "./services/android-project-service");
1212
$injector.require("iOSProjectService", "./services/ios-project-service");
1313

14+
$injector.require("cocoapodsService", "./services/cocoapods-service");
15+
1416
$injector.require("projectTemplatesService", "./services/project-templates-service");
1517
$injector.require("projectNameService", "./services/project-name-service");
1618
$injector.require("tnsModulesService", "./services/tns-modules-service");

lib/definitions/project.d.ts

+16
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,19 @@ interface ITestExecutionService {
106106
startKarmaServer(platform: string): IFuture<void>;
107107
}
108108

109+
/**
110+
* Describes a service used to facilitate communication with CocoaPods
111+
*/
112+
interface ICocoaPodsService {
113+
/**
114+
* Get the header needed for the beginning of every Podfile
115+
* @param {string} targetName The name of the target (usually the same as the project's name).
116+
* @return {string} The header which needs to be placed at the beginning of a Podfile.
117+
*/
118+
getPodfileHeader(targetName: string): string;
119+
/**
120+
* Get the footer needed for the end of every Podfile
121+
* @return {string} The footer which needs to be placed at the end of a Podfile.
122+
*/
123+
getPodfileFooter(): string;
124+
}

lib/services/cocoapods-service.ts

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
///<reference path="../.d.ts"/>
2+
"use strict";
3+
4+
import {EOL} from "os";
5+
6+
export class CocoaPodsService implements ICocoaPodsService {
7+
public getPodfileHeader(targetName: string): string {
8+
return `use_frameworks!${EOL}${EOL}target "${targetName}" do${EOL}`;
9+
}
10+
11+
public getPodfileFooter(): string {
12+
return `${EOL}end`;
13+
}
14+
}
15+
16+
$injector.register("cocoapodsService", CocoaPodsService);

lib/services/doctor-service.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as helpers from "../common/helpers";
77
let clui = require("clui");
88

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

1819
constructor(private $analyticsService: IAnalyticsService,
1920
private $androidToolsInfo: IAndroidToolsInfo,
21+
private $cocoapodsService: ICocoaPodsService,
2022
private $hostInfo: IHostInfo,
2123
private $logger: ILogger,
2224
private $progressIndicator: IProgressIndicator,
@@ -187,7 +189,7 @@ class DoctorService implements IDoctorService {
187189
let iosDir = path.join(projDir, "node_modules", "tns-ios", "framework");
188190
this.$fs.writeFile(
189191
path.join(iosDir, "Podfile"),
190-
"pod 'AFNetworking', '~> 1.0'\n"
192+
`${this.$cocoapodsService.getPodfileHeader(DoctorService.PROJECT_NAME_PLACEHOLDER)}pod 'AFNetworking', '~> 1.0'${this.$cocoapodsService.getPodfileFooter()}`
191193
).wait();
192194

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

210-
return !(this.$fs.exists(path.join(iosDir, "__PROJECT_NAME__.xcworkspace")).wait());
212+
return !(this.$fs.exists(path.join(iosDir, `${DoctorService.PROJECT_NAME_PLACEHOLDER}.xcworkspace`)).wait());
211213
} catch (err) {
212214
this.$logger.trace(`verifyCocoaPods error: ${err}`);
213215
return true;

lib/services/ios-project-service.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
2727
constructor($projectData: IProjectData,
2828
$fs: IFileSystem,
2929
private $childProcess: IChildProcess,
30+
private $cocoapodsService: ICocoaPodsService,
3031
private $errors: IErrors,
3132
private $logger: ILogger,
3233
private $iOSEmulatorServices: Mobile.IEmulatorPlatformServices,
@@ -705,8 +706,8 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
705706
projectPodFileContent = this.$fs.exists(this.projectPodFilePath).wait() ? this.$fs.readText(this.projectPodFilePath).wait() : "";
706707

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

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

test/ios-project-service.ts

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {AndroidDeviceDiscovery} from "../lib/common/mobile/mobile-core/android-d
2525
import {PluginVariablesService} from "../lib/services/plugin-variables-service";
2626
import {PluginVariablesHelper} from "../lib/common/plugin-variables-helper";
2727
import {Utils} from "../lib/common/utils";
28+
import {CocoaPodsService} from "../lib/services/cocoapods-service";
2829
import { assert } from "chai";
2930
import temp = require("temp");
3031
temp.track();
@@ -48,6 +49,7 @@ function createTestInjector(projectPath: string, projectName: string): IInjector
4849
testInjector.register("hostInfo", HostInfoLib.HostInfo);
4950
testInjector.register("injector", testInjector);
5051
testInjector.register("iOSEmulatorServices", {});
52+
testInjector.register("cocoapodsService", CocoaPodsService);
5153
testInjector.register("iOSProjectService", iOSProjectServiceLib.IOSProjectService);
5254
testInjector.register("logger", LoggerLib.Logger);
5355
testInjector.register("options", OptionsLib.Options);

0 commit comments

Comments
 (0)