Skip to content

Commit 300f21f

Browse files
Fatmejasssonpet
Fatme
authored andcommitted
Merge pull request #1038 from NativeScript/fatme/fix-emulate-after-livesync
Fix emulate-livesync-emulate
2 parents b306852 + b131e7c commit 300f21f

File tree

8 files changed

+57
-39
lines changed

8 files changed

+57
-39
lines changed

lib/commands/create-project.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class ProjectCommandParameter implements ICommandParameter {
1414
}
1515

1616
if (value.toUpperCase() === "APP") {
17-
this.$logger.warn("You cannot build aplications named 'app' in Xcode. Consider creating a project with different name.");
17+
this.$logger.warn("You cannot build applications named 'app' in Xcode. Consider creating a project with different name.");
1818
}
1919

2020
return this.$projectNameValidator.validate(value);

lib/definitions/project.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ interface IPlatformProjectService {
5353
removePluginNativeCode(pluginData: IPluginData): IFuture<void>;
5454
afterPrepareAllPlugins(): IFuture<void>;
5555
getAppResourcesDestinationDirectoryPath(): IFuture<string>;
56-
deploy(device: Mobile.IDevice, appIdentifier: string): IFuture<void>;
56+
deploy(deviceIdentifier: string): IFuture<void>;
5757
}
5858

5959
interface IAndroidProjectPropertiesManager {

lib/services/android-project-service.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Future = require("fibers/future");
66
import * as constants from "../constants";
77
import * as semver from "semver";
88
import * as projectServiceBaseLib from "./platform-project-service-base";
9+
import * as androidDebugBridgePath from "../common/mobile/android/android-debug-bridge";
910

1011
class AndroidProjectService extends projectServiceBaseLib.PlatformProjectServiceBase implements IPlatformProjectService {
1112
private static VALUES_DIRNAME = "values";
@@ -28,7 +29,8 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
2829
$projectData: IProjectData,
2930
$projectDataService: IProjectDataService,
3031
private $sysInfo: ISysInfo,
31-
private $mobileHelper: Mobile.IMobileHelper) {
32+
private $mobileHelper: Mobile.IMobileHelper,
33+
private $injector: IInjector) {
3234
super($fs, $projectData, $projectDataService);
3335
this._androidProjectPropertiesManagers = Object.create(null);
3436
}
@@ -285,10 +287,11 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
285287
return Future.fromResult();
286288
}
287289

288-
public deploy(device: Mobile.IAndroidDevice, appIdentifier: string): IFuture<void> {
290+
public deploy(deviceIdentifier: string): IFuture<void> {
289291
return (() => {
290-
let deviceRootPath = `/data/local/tmp/${appIdentifier}`;
291-
device.adb.executeShellCommand(["rm", "-rf", this.$mobileHelper.buildDevicePath(deviceRootPath, "fullsync"),
292+
let adb = this.$injector.resolve(androidDebugBridgePath.AndroidDebugBridge, { identifier: deviceIdentifier });
293+
let deviceRootPath = `/data/local/tmp/${this.$projectData.projectId}`;
294+
adb.executeShellCommand(["rm", "-rf", this.$mobileHelper.buildDevicePath(deviceRootPath, "fullsync"),
292295
this.$mobileHelper.buildDevicePath(deviceRootPath, "sync"),
293296
this.$mobileHelper.buildDevicePath(deviceRootPath, "removedsync")]).wait();
294297
}).future<void>()();

lib/services/ios-project-service.ts

+41-29
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
212212
}).future<void>()();
213213
}
214214

215-
public deploy(device: Mobile.IDevice, appIdentifier: string): IFuture<void> {
215+
public deploy(deviceIdentifier: string): IFuture<void> {
216216
return Future.fromResult();
217217
}
218218

@@ -349,8 +349,12 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
349349
return path.join(this.platformData.projectRoot, "Podfile");
350350
}
351351

352-
private get projectXcconfigFilePath(): string {
353-
return path.join(this.platformData.appDestinationDirectoryPath, "build.xcconfig");
352+
private get pluginsDebugXcconfigFilePath(): string {
353+
return path.join(this.platformData.projectRoot, "plugins-debug.xcconfig");
354+
}
355+
356+
private get pluginsReleaseXcconfigFilePath(): string {
357+
return path.join(this.platformData.projectRoot, "plugins-release.xcconfig");
354358
}
355359

356360
private replace(name: string): string {
@@ -389,7 +393,6 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
389393
this.prepareFrameworks(pluginPlatformsFolderPath, pluginData).wait();
390394
this.prepareStaticLibs(pluginPlatformsFolderPath, pluginData).wait();
391395
this.prepareCocoapods(pluginPlatformsFolderPath).wait();
392-
this.prepareXcconfigFile(pluginPlatformsFolderPath).wait();
393396
}).future<void>()();
394397
}
395398

@@ -400,7 +403,6 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
400403
this.removeFrameworks(pluginPlatformsFolderPath, pluginData).wait();
401404
this.removeStaticLibs(pluginPlatformsFolderPath, pluginData).wait();
402405
this.removeCocoapods(pluginPlatformsFolderPath).wait();
403-
this.removeXcconfigFile(pluginPlatformsFolderPath).wait();
404406
}).future<void>()();
405407
}
406408

@@ -433,6 +435,8 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
433435

434436
this.executePodInstall().wait();
435437
}
438+
439+
this.regeneratePluginsXcconfigFile().wait();
436440
}).future<void>()();
437441
}
438442

@@ -535,16 +539,6 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
535539
}).future<void>()();
536540
}
537541

538-
private prepareXcconfigFile(pluginPlatformsFolderPath: string): IFuture<void> {
539-
return (() => {
540-
let pluginXcconfigFilePath = path.join(pluginPlatformsFolderPath, "build.xcconfig");
541-
if(this.$fs.exists(pluginXcconfigFilePath).wait()) {
542-
let contentToWrite = this.buildXcconfigContent(pluginXcconfigFilePath);
543-
this.$fs.appendFile(this.projectXcconfigFilePath, contentToWrite).wait();
544-
}
545-
}).future<void>()();
546-
}
547-
548542
private removeFrameworks(pluginPlatformsFolderPath: string, pluginData: IPluginData): IFuture<void> {
549543
return (() => {
550544
let project = this.createPbxProj();
@@ -588,18 +582,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
588582
} else {
589583
this.$fs.writeFile(this.projectPodFilePath, projectPodFileContent).wait();
590584
}
591-
}
592-
}).future<void>()();
593-
}
594585

595-
private removeXcconfigFile(pluginPlatformsFolderPath: string): IFuture<void> {
596-
return (() => {
597-
let pluginXcconfigFilePath = path.join(pluginPlatformsFolderPath, "build.xcconfig");
598-
if(this.$fs.exists(pluginXcconfigFilePath).wait()) {
599-
let projectXcconfigFileContent = this.$fs.readText(this.projectXcconfigFilePath).wait();
600-
let contentToRemove = this.buildXcconfigContent(pluginXcconfigFilePath);
601-
projectXcconfigFileContent = helpers.stringReplaceAll(projectXcconfigFileContent, contentToRemove, "");
602-
this.$fs.writeFile(this.projectXcconfigFilePath, projectXcconfigFileContent).wait();
603586
}
604587
}).future<void>()();
605588
}
@@ -624,9 +607,38 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
624607
this.$fs.writeFile(path.join(headersFolderPath, "module.modulemap"), modulemap).wait();
625608
}
626609

627-
private buildXcconfigContent(xcconfigFilePath: string): string {
628-
let relativePluginXcconfigFilePath = path.relative(path.dirname(this.projectXcconfigFilePath), xcconfigFilePath);
629-
return `${os.EOL}#include "${relativePluginXcconfigFilePath}"${os.EOL}`;
610+
private mergeXcconfigFiles(pluginFile: string, projectFile: string): IFuture<void> {
611+
return (() => {
612+
if (!this.$fs.exists(projectFile).wait()) {
613+
this.$fs.writeFile(projectFile, "").wait();
614+
}
615+
616+
let mergeScript = `require 'xcodeproj'; Xcodeproj::Config.new('${projectFile}').merge(Xcodeproj::Config.new('${pluginFile}')).save_as(Pathname.new('${projectFile}'))`;
617+
this.$childProcess.exec(`ruby -e "${mergeScript}"`).wait();
618+
}).future<void>()();
619+
}
620+
621+
private regeneratePluginsXcconfigFile(): IFuture<void> {
622+
return (() => {
623+
this.$fs.deleteFile(this.pluginsDebugXcconfigFilePath).wait();
624+
this.$fs.deleteFile(this.pluginsReleaseXcconfigFilePath).wait();
625+
626+
let allPlugins: IPluginData[] = (<IPluginsService>this.$injector.resolve("pluginsService")).getAllInstalledPlugins().wait();
627+
for (let plugin of allPlugins) {
628+
let pluginPlatformsFolderPath = plugin.pluginPlatformsFolderPath(IOSProjectService.IOS_PLATFORM_NAME);
629+
let pluginXcconfigFilePath = path.join(pluginPlatformsFolderPath, "build.xcconfig");
630+
if (this.$fs.exists(pluginXcconfigFilePath).wait()) {
631+
this.mergeXcconfigFiles(pluginXcconfigFilePath, this.pluginsDebugXcconfigFilePath).wait();
632+
this.mergeXcconfigFiles(pluginXcconfigFilePath, this.pluginsReleaseXcconfigFilePath).wait();
633+
}
634+
}
635+
636+
let podFolder = path.join(this.platformData.projectRoot, "Pods/Target Support Files/Pods/");
637+
if (this.$fs.exists(podFolder).wait()) {
638+
this.mergeXcconfigFiles(path.join(this.platformData.projectRoot, "Pods/Target Support Files/Pods/Pods.debug.xcconfig"), this.pluginsDebugXcconfigFilePath).wait();
639+
this.mergeXcconfigFiles(path.join(this.platformData.projectRoot, "Pods/Target Support Files/Pods/Pods.release.xcconfig"), this.pluginsReleaseXcconfigFilePath).wait();
640+
}
641+
}).future<void>()();
630642
}
631643
}
632644

lib/services/platform-service.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ export class PlatformService implements IPlatformService {
276276
this.$devicesServices.initialize({platform: platform, deviceId: this.$options.device}).wait();
277277
let action = (device: Mobile.IDevice): IFuture<void> => {
278278
return (() => {
279-
platformData.platformProjectService.deploy(device, this.$projectData.projectId).wait();
279+
platformData.platformProjectService.deploy(device.deviceInfo.identifier).wait();
280280
device.deploy(packageFile, this.$projectData.projectId).wait();
281281

282282
if (!this.$options.justlaunch) {
@@ -301,6 +301,9 @@ export class PlatformService implements IPlatformService {
301301
emulatorServices.checkAvailability().wait();
302302
emulatorServices.checkDependencies().wait();
303303

304+
let emulatorId = emulatorServices.getEmulatorId().wait();
305+
platformData.platformProjectService.deploy(emulatorId).wait();
306+
304307
if(!this.$options.availableDevices) {
305308
this.buildPlatform(platform, buildConfig).wait();
306309

lib/services/plugins-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ export class PluginsService implements IPluginsService {
201201

202202
public getAllInstalledPlugins(): IFuture<IPluginData[]> {
203203
return (() => {
204-
let nodeModules = this.getAllInstalledModules().wait();
204+
let nodeModules = this.getAllInstalledModules().wait().map(nodeModuleData => this.convertToPluginData(nodeModuleData));
205205
return _.filter(nodeModules, nodeModuleData => nodeModuleData && nodeModuleData.isPlugin);
206206
}).future<IPluginData[]>()();
207207
}

test/stubs.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ export class PlatformProjectServiceStub implements IPlatformProjectService {
325325
afterPrepareAllPlugins(): IFuture<void> {
326326
return Future.fromResult();
327327
}
328-
deploy(device: Mobile.IAndroidDevice, appIdentifier: string): IFuture<void> {
328+
deploy(deviceIdentifier: string): IFuture<void> {
329329
return Future.fromResult();
330330
}
331331
}

0 commit comments

Comments
 (0)