forked from NativeScript/nativescript-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathios-project-service.ts
1522 lines (1380 loc) · 43.3 KB
/
ios-project-service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import * as path from "path";
import * as shell from "shelljs";
import * as _ from "lodash";
import * as constants from "../constants";
import { Configurations } from "../common/constants";
import * as helpers from "../common/helpers";
import { attachAwaitDetach } from "../common/helpers";
import * as projectServiceBaseLib from "./platform-project-service-base";
import { PlistSession, Reporter } from "plist-merge-patch";
import { EOL } from "os";
const plist = require("plist");
import { IOSProvisionService } from "./ios-provision-service";
import { IOSEntitlementsService } from "./ios-entitlements-service";
import { IOSBuildData } from "../data/build-data";
import { IOSPrepareData } from "../data/prepare-data";
import { BUILD_XCCONFIG_FILE_NAME, IosProjectConstants } from "../constants";
import { hook } from "../common/helpers";
import {
IPlatformData,
IValidBuildOutputData,
IPlatformEnvironmentRequirements,
} from "../definitions/platform";
import {
IProjectData,
ICocoaPodsService,
IProjectDataService,
IIOSExtensionsService,
IIOSWatchAppService,
IIOSNativeTargetService,
IValidatePlatformOutput,
} from "../definitions/project";
import { IBuildData } from "../definitions/build";
import { IXcprojService, IXcconfigService, IOptions } from "../declarations";
import { IPluginData, IPluginsService } from "../definitions/plugins";
import {
IFileSystem,
IChildProcess,
IErrors,
IHostInfo,
IPlistParser,
ISysInfo,
IRelease,
} from "../common/declarations";
import { IInjector } from "../common/definitions/yok";
import { injector } from "../common/yok";
import { INotConfiguredEnvOptions } from "../common/definitions/commands";
import { IProjectChangesInfo } from "../definitions/project-changes";
interface INativeSourceCodeGroup {
name: string;
path: string;
files: string[];
}
const DevicePlatformSdkName = "iphoneos";
const SimulatorPlatformSdkName = "iphonesimulator";
const FRAMEWORK_EXTENSIONS = [".framework", ".xcframework"];
const getPlatformSdkName = (forDevice: boolean): string =>
forDevice ? DevicePlatformSdkName : SimulatorPlatformSdkName;
const getConfigurationName = (release: boolean): string =>
release ? Configurations.Release : Configurations.Debug;
export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServiceBase {
private static IOS_PROJECT_NAME_PLACEHOLDER = "__PROJECT_NAME__";
private static IOS_PLATFORM_NAME = "ios";
constructor(
$fs: IFileSystem,
private $childProcess: IChildProcess,
private $cocoapodsService: ICocoaPodsService,
private $errors: IErrors,
private $logger: ILogger,
private $injector: IInjector,
$projectDataService: IProjectDataService,
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
private $hostInfo: IHostInfo,
private $xcprojService: IXcprojService,
private $iOSProvisionService: IOSProvisionService,
private $iOSSigningService: IiOSSigningService,
private $pbxprojDomXcode: IPbxprojDomXcode,
private $xcode: IXcode,
private $iOSEntitlementsService: IOSEntitlementsService,
private $platformEnvironmentRequirements: IPlatformEnvironmentRequirements,
private $plistParser: IPlistParser,
private $xcconfigService: IXcconfigService,
private $xcodebuildService: IXcodebuildService,
private $iOSExtensionsService: IIOSExtensionsService,
private $iOSWatchAppService: IIOSWatchAppService,
private $iOSNativeTargetService: IIOSNativeTargetService,
private $sysInfo: ISysInfo,
private $tempService: ITempService
) {
super($fs, $projectDataService);
}
private _platformsDirCache: string = null;
private _platformData: IPlatformData = null;
public getPlatformData(projectData: IProjectData): IPlatformData {
if (!projectData && !this._platformData) {
throw new Error(
"First call of getPlatformData without providing projectData."
);
}
if (
projectData &&
projectData.platformsDir &&
this._platformsDirCache !== projectData.platformsDir
) {
const projectRoot = path.join(
projectData.platformsDir,
this.$devicePlatformsConstants.iOS.toLowerCase()
);
const runtimePackage = this.$projectDataService.getRuntimePackage(
projectData.projectDir,
constants.PlatformTypes.ios
);
this._platformData = {
frameworkPackageName: runtimePackage.name,
normalizedPlatformName: "iOS",
platformNameLowerCase: "ios",
appDestinationDirectoryPath: path.join(
projectRoot,
projectData.projectName
),
platformProjectService: <any>this,
projectRoot: projectRoot,
getBuildOutputPath: (options: IBuildData): string => {
const config = getConfigurationName(!options || options.release);
return path.join(
projectRoot,
constants.BUILD_DIR,
`${config}-${getPlatformSdkName(
!options || options.buildForDevice || options.buildForAppStore
)}`
);
},
getValidBuildOutputData: (
buildOptions: IBuildData
): IValidBuildOutputData => {
const forDevice =
!buildOptions ||
!!buildOptions.buildForDevice ||
!!buildOptions.buildForAppStore;
if (forDevice) {
const ipaFileName = _.find(
this.$fs.readDirectory(
this._platformData.getBuildOutputPath(buildOptions)
),
(entry) => path.extname(entry) === ".ipa"
);
return {
packageNames: [ipaFileName, `${projectData.projectName}.ipa`],
};
}
return {
packageNames: [
`${projectData.projectName}.app`,
`${projectData.projectName}.zip`,
],
};
},
frameworkDirectoriesExtensions: FRAMEWORK_EXTENSIONS,
frameworkDirectoriesNames: [
"Metadata",
"metadataGenerator",
"NativeScript",
"internal",
],
targetedOS: ["darwin"],
configurationFileName: constants.INFO_PLIST_FILE_NAME,
configurationFilePath: path.join(
projectRoot,
projectData.projectName,
projectData.projectName + `-${constants.INFO_PLIST_FILE_NAME}`
),
relativeToFrameworkConfigurationFilePath: path.join(
"__PROJECT_NAME__",
"__PROJECT_NAME__-Info.plist"
),
fastLivesyncFileExtensions: [
".tiff",
".tif",
".jpg",
"jpeg",
"gif",
".png",
".bmp",
".BMPf",
".ico",
".cur",
".xbm",
], // https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIImage_Class/
};
}
return this._platformData;
}
public async validateOptions(
projectId: string,
provision: true | string,
teamId: true | string
): Promise<boolean> {
if (provision && teamId) {
this.$errors.fail(
"The options --provision and --teamId are mutually exclusive."
);
}
if (provision === true) {
await this.$iOSProvisionService.listProvisions(projectId);
this.$errors.fail(
"Please provide provisioning profile uuid or name with the --provision option."
);
}
if (teamId === true) {
await this.$iOSProvisionService.listTeams();
this.$errors.fail(
"Please provide team id or team name with the --teamId options."
);
}
return true;
}
public getAppResourcesDestinationDirectoryPath(
projectData: IProjectData
): string {
return path.join(
this.getPlatformData(projectData).projectRoot,
projectData.projectName,
"Resources"
);
}
public async validate(
projectData: IProjectData,
options: IOptions,
notConfiguredEnvOptions?: INotConfiguredEnvOptions
): Promise<IValidatePlatformOutput> {
if (!this.$hostInfo.isDarwin) {
return;
}
const checkEnvironmentRequirementsOutput = await this.$platformEnvironmentRequirements.checkEnvironmentRequirements(
{
platform: this.getPlatformData(projectData).normalizedPlatformName,
projectDir: projectData.projectDir,
options,
notConfiguredEnvOptions,
}
);
if (
checkEnvironmentRequirementsOutput &&
checkEnvironmentRequirementsOutput.canExecute
) {
const xcodeWarning = await this.$sysInfo.getXcodeWarning();
if (xcodeWarning) {
this.$logger.warn(xcodeWarning);
}
}
return {
checkEnvironmentRequirementsOutput,
};
}
public async createProject(
frameworkDir: string,
frameworkVersion: string,
projectData: IProjectData
): Promise<void> {
this.$fs.ensureDirectoryExists(
path.join(
this.getPlatformData(projectData).projectRoot,
IOSProjectService.IOS_PROJECT_NAME_PLACEHOLDER
)
);
shell.cp(
"-R",
path.join(frameworkDir, "*"),
this.getPlatformData(projectData).projectRoot
);
}
//TODO: plamen5kov: revisit this method, might have unnecessary/obsolete logic
public async interpolateData(projectData: IProjectData): Promise<void> {
const projectRootFilePath = path.join(
this.getPlatformData(projectData).projectRoot,
IOSProjectService.IOS_PROJECT_NAME_PLACEHOLDER
);
// Starting with NativeScript for iOS 1.6.0, the project Info.plist file resides not in the platform project,
// but in the hello-world app template as a platform specific resource.
if (
this.$fs.exists(
path.join(
projectRootFilePath,
IOSProjectService.IOS_PROJECT_NAME_PLACEHOLDER + "-Info.plist"
)
)
) {
this.replaceFileName("-Info.plist", projectRootFilePath, projectData);
}
this.replaceFileName("-Prefix.pch", projectRootFilePath, projectData);
if (
this.$fs.exists(
path.join(
projectRootFilePath,
IOSProjectService.IOS_PROJECT_NAME_PLACEHOLDER + ".entitlements"
)
)
) {
this.replaceFileName(".entitlements", projectRootFilePath, projectData);
}
const xcschemeDirPath = path.join(
this.getPlatformData(projectData).projectRoot,
IOSProjectService.IOS_PROJECT_NAME_PLACEHOLDER +
IosProjectConstants.XcodeProjExtName,
"xcshareddata/xcschemes"
);
const xcschemeFilePath = path.join(
xcschemeDirPath,
IOSProjectService.IOS_PROJECT_NAME_PLACEHOLDER +
IosProjectConstants.XcodeSchemeExtName
);
if (this.$fs.exists(xcschemeFilePath)) {
this.$logger.debug(
"Found shared scheme at xcschemeFilePath, renaming to match project name."
);
this.$logger.debug("Checkpoint 0");
this.replaceFileContent(xcschemeFilePath, projectData);
this.$logger.debug("Checkpoint 1");
this.replaceFileName(
IosProjectConstants.XcodeSchemeExtName,
xcschemeDirPath,
projectData
);
this.$logger.debug("Checkpoint 2");
} else {
this.$logger.debug(
"Copying xcscheme from template not found at " + xcschemeFilePath
);
}
this.replaceFileName(
IosProjectConstants.XcodeProjExtName,
this.getPlatformData(projectData).projectRoot,
projectData
);
const pbxprojFilePath = this.getPbxProjPath(projectData);
this.replaceFileContent(pbxprojFilePath, projectData);
const internalDirPath = path.join(projectRootFilePath, "..", "internal");
const xcframeworksFilePath = path.join(internalDirPath, "XCFrameworks.zip");
if (this.$fs.exists(xcframeworksFilePath)) {
await this.$fs.unzip(xcframeworksFilePath, internalDirPath);
this.$fs.deleteFile(xcframeworksFilePath);
}
}
public interpolateConfigurationFile(projectData: IProjectData): void {
return undefined;
}
public async cleanProject(
projectRoot: string,
projectData: IProjectData
): Promise<void> {
return null;
}
public afterCreateProject(
projectRoot: string,
projectData: IProjectData
): void {
this.$fs.rename(
path.join(projectRoot, IOSProjectService.IOS_PROJECT_NAME_PLACEHOLDER),
path.join(projectRoot, projectData.projectName)
);
}
@hook("buildIOS")
public async buildProject(
projectRoot: string,
projectData: IProjectData,
buildData: IOSBuildData
): Promise<void> {
const platformData = this.getPlatformData(projectData);
const handler = (data: any) => {
this.emit(constants.BUILD_OUTPUT_EVENT_NAME, data);
};
if (buildData.buildForDevice) {
await this.$iOSSigningService.setupSigningForDevice(
projectRoot,
projectData,
buildData
);
await attachAwaitDetach(
constants.BUILD_OUTPUT_EVENT_NAME,
this.$childProcess,
handler,
this.$xcodebuildService.buildForDevice(
platformData,
projectData,
<any>buildData
)
);
} else if (buildData.buildForAppStore) {
await attachAwaitDetach(
constants.BUILD_OUTPUT_EVENT_NAME,
this.$childProcess,
handler,
this.$xcodebuildService.buildForAppStore(
platformData,
projectData,
<any>buildData
)
);
} else {
await attachAwaitDetach(
constants.BUILD_OUTPUT_EVENT_NAME,
this.$childProcess,
handler,
this.$xcodebuildService.buildForSimulator(
platformData,
projectData,
<any>buildData
)
);
}
this.validateApplicationIdentifier(projectData);
}
public isPlatformPrepared(
projectRoot: string,
projectData: IProjectData
): boolean {
return this.$fs.exists(
path.join(projectRoot, projectData.projectName, constants.APP_FOLDER_NAME)
);
}
public cleanDeviceTempFolder(deviceIdentifier: string): Promise<void> {
return Promise.resolve();
}
private async isDynamicFramework(frameworkPath: string): Promise<boolean> {
const frameworkName = path.basename(
frameworkPath,
path.extname(frameworkPath)
);
const isDynamicFrameworkBundle = async (bundlePath: string) => {
const frameworkBinaryPath = path.join(bundlePath, frameworkName);
const fileResult = (
await this.$childProcess.spawnFromEvent(
"file",
[frameworkBinaryPath],
"close"
)
).stdout;
const isDynamicallyLinked = _.includes(fileResult, "dynamically linked");
return isDynamicallyLinked;
};
if (path.extname(frameworkPath) === ".xcframework") {
let isDynamic = true;
const subDirs = this.$fs
.readDirectory(frameworkPath)
.filter((entry) =>
this.$fs.getFsStats(path.join(frameworkPath, entry)).isDirectory()
);
for (const subDir of subDirs) {
const singlePlatformFramework = path.join(
subDir,
frameworkName + ".framework"
);
if (this.$fs.exists(singlePlatformFramework)) {
isDynamic = await isDynamicFrameworkBundle(singlePlatformFramework);
break;
}
}
return isDynamic;
} else {
return await isDynamicFrameworkBundle(frameworkPath);
}
}
private async addFramework(
frameworkPath: string,
projectData: IProjectData
): Promise<void> {
if (!this.$hostInfo.isWindows) {
this.validateFramework(frameworkPath);
const project = this.createPbxProj(projectData);
const frameworkAddOptions: IXcode.Options = { customFramework: true };
if (await this.isDynamicFramework(frameworkPath)) {
frameworkAddOptions["embed"] = true;
frameworkAddOptions["sign"] = true;
}
const frameworkRelativePath =
"$(SRCROOT)/" +
this.getLibSubpathRelativeToProjectPath(frameworkPath, projectData);
project.addFramework(frameworkRelativePath, frameworkAddOptions);
this.savePbxProj(project, projectData);
}
}
private async addStaticLibrary(
staticLibPath: string,
projectData: IProjectData
): Promise<void> {
// Copy files to lib folder.
const libraryName = path.basename(staticLibPath, ".a");
const headersSubpath = path.join(
path.dirname(staticLibPath),
"include",
libraryName
);
// Add static library to project file and setup header search paths
const project = this.createPbxProj(projectData);
const relativeStaticLibPath = this.getLibSubpathRelativeToProjectPath(
staticLibPath,
projectData
);
project.addFramework(relativeStaticLibPath);
const relativeHeaderSearchPath = path.join(
this.getLibSubpathRelativeToProjectPath(headersSubpath, projectData)
);
project.addToHeaderSearchPaths({ relativePath: relativeHeaderSearchPath });
this.generateModulemap(headersSubpath, libraryName);
this.savePbxProj(project, projectData);
}
public async prepareProject(
projectData: IProjectData,
prepareData: IOSPrepareData
): Promise<void> {
const projectRoot = path.join(projectData.platformsDir, "ios");
const platformData = this.getPlatformData(projectData);
const resourcesDirectoryPath = projectData.getAppResourcesDirectoryPath();
const provision = prepareData && prepareData.provision;
const teamId = prepareData && prepareData.teamId;
if (provision) {
await this.$iOSSigningService.setupSigningFromProvision(
projectRoot,
projectData,
provision,
prepareData.mobileProvisionData
);
}
if (teamId) {
await this.$iOSSigningService.setupSigningFromTeam(
projectRoot,
projectData,
teamId
);
}
const project = this.createPbxProj(projectData);
const resources = project.pbxGroupByName("Resources");
if (resources) {
const references = project.pbxFileReferenceSection();
const xcodeProjectImages = _.map(<any[]>resources.children, (resource) =>
this.replace(references[resource.value].name)
);
this.$logger.trace("Images from Xcode project");
this.$logger.trace(xcodeProjectImages);
const appResourcesImages = this.$fs.readDirectory(
this.getAppResourcesDestinationDirectoryPath(projectData)
);
this.$logger.trace("Current images from App_Resources");
this.$logger.trace(appResourcesImages);
const imagesToAdd = _.difference(appResourcesImages, xcodeProjectImages);
this.$logger.trace(
`New images to add into xcode project: ${imagesToAdd.join(", ")}`
);
_.each(imagesToAdd, (image) =>
project.addResourceFile(
path.relative(
this.getPlatformData(projectData).projectRoot,
path.join(
this.getAppResourcesDestinationDirectoryPath(projectData),
image
)
)
)
);
const imagesToRemove = _.difference(
xcodeProjectImages,
appResourcesImages
);
this.$logger.trace(
`Images to remove from xcode project: ${imagesToRemove.join(", ")}`
);
_.each(imagesToRemove, (image) =>
project.removeResourceFile(
path.join(
this.getAppResourcesDestinationDirectoryPath(projectData),
image
)
)
);
this.savePbxProj(project, projectData);
const resourcesNativeCodePath = path.join(
resourcesDirectoryPath,
platformData.normalizedPlatformName,
constants.NATIVE_SOURCE_FOLDER
);
await this.prepareNativeSourceCode(
constants.TNS_NATIVE_SOURCE_GROUP_NAME,
resourcesNativeCodePath,
projectData
);
}
const pbxProjPath = this.getPbxProjPath(projectData);
this.$iOSWatchAppService.removeWatchApp({ pbxProjPath });
const addedWatchApp = await this.$iOSWatchAppService.addWatchAppFromPath({
watchAppFolderPath: path.join(
resourcesDirectoryPath,
platformData.normalizedPlatformName
),
projectData,
platformData,
pbxProjPath,
});
if (addedWatchApp) {
this.$logger.warn(
"The support for Apple Watch App is currently in Beta. For more information about the current development state and any known issues, please check the relevant GitHub issue: https://github.com/NativeScript/nativescript-cli/issues/4589"
);
}
}
public prepareAppResources(projectData: IProjectData): void {
const platformData = this.getPlatformData(projectData);
const projectAppResourcesPath = projectData.getAppResourcesDirectoryPath(
projectData.projectDir
);
const platformsAppResourcesPath = this.getAppResourcesDestinationDirectoryPath(
projectData
);
this.$fs.deleteDirectory(platformsAppResourcesPath);
this.$fs.ensureDirectoryExists(platformsAppResourcesPath);
this.$fs.copyFile(
path.join(
projectAppResourcesPath,
platformData.normalizedPlatformName,
"*"
),
platformsAppResourcesPath
);
this.$fs.deleteFile(
path.join(platformsAppResourcesPath, platformData.configurationFileName)
);
this.$fs.deleteFile(
path.join(platformsAppResourcesPath, constants.PODFILE_NAME)
);
this.$fs.deleteDirectory(
path.join(platformsAppResourcesPath, constants.NATIVE_SOURCE_FOLDER)
);
this.$fs.deleteDirectory(
path.join(platformsAppResourcesPath, constants.NATIVE_EXTENSION_FOLDER)
);
this.$fs.deleteDirectory(path.join(platformsAppResourcesPath, "watchapp"));
this.$fs.deleteDirectory(
path.join(platformsAppResourcesPath, "watchextension")
);
}
public async processConfigurationFilesFromAppResources(
projectData: IProjectData,
opts: IRelease
): Promise<void> {
await this.mergeInfoPlists(projectData, opts);
await this.$iOSEntitlementsService.merge(projectData);
await this.mergeProjectXcconfigFiles(projectData);
}
public ensureConfigurationFileInAppResources(): void {
return null;
}
private async mergeInfoPlists(
projectData: IProjectData,
buildOptions: IRelease
): Promise<void> {
const projectDir = projectData.projectDir;
const infoPlistPath = path.join(
projectData.appResourcesDirectoryPath,
this.getPlatformData(projectData).normalizedPlatformName,
this.getPlatformData(projectData).configurationFileName
);
this.ensureConfigurationFileInAppResources();
const reporterTraceMessage = "Info.plist:";
const reporter: Reporter = {
log: (txt: string) =>
this.$logger.trace(`${reporterTraceMessage} ${txt}`),
warn: (txt: string) =>
this.$logger.warn(`${reporterTraceMessage} ${txt}`),
};
const session = new PlistSession(reporter);
const makePatch = (plistPath: string) => {
if (!this.$fs.exists(plistPath)) {
this.$logger.trace("No plist found at: " + plistPath);
return;
}
this.$logger.trace("Schedule merge plist at: " + plistPath);
session.patch({
name: path.relative(projectDir, plistPath),
read: () => this.$fs.readText(plistPath),
});
};
const allPlugins = this.getAllProductionPlugins(projectData);
for (const plugin of allPlugins) {
const pluginInfoPlistPath = path.join(
plugin.pluginPlatformsFolderPath(IOSProjectService.IOS_PLATFORM_NAME),
this.getPlatformData(projectData).configurationFileName
);
makePatch(pluginInfoPlistPath);
}
makePatch(infoPlistPath);
if (projectData.projectIdentifiers && projectData.projectIdentifiers.ios) {
session.patch({
name: "CFBundleIdentifier from package.json nativescript.id",
read: () =>
`<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
</dict>
</plist>`,
});
}
if (
!buildOptions.release &&
projectData.projectIdentifiers &&
projectData.projectIdentifiers.ios
) {
session.patch({
name: "CFBundleURLTypes from package.json nativescript.id",
read: () =>
`<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>${projectData.projectIdentifiers.ios.replace(
/[^A-Za-z0-9]/g,
""
)}</string>
</array>
</dict>
</array>
</dict>
</plist>`,
});
}
const plistContent = session.build();
this.$logger.trace(
"Info.plist: Write to: " +
this.getPlatformData(projectData).configurationFilePath
);
this.$fs.writeFile(
this.getPlatformData(projectData).configurationFilePath,
plistContent
);
}
private getAllProductionPlugins(projectData: IProjectData): IPluginData[] {
return (<IPluginsService>(
this.$injector.resolve("pluginsService")
)).getAllProductionPlugins(
projectData,
this.getPlatformData(projectData).platformNameLowerCase
);
}
private replace(name: string): string {
if (_.startsWith(name, '"')) {
name = name.substr(1, name.length - 2);
}
return name.replace(/\\\"/g, '"');
}
private getLibSubpathRelativeToProjectPath(
targetPath: string,
projectData: IProjectData
): string {
const frameworkPath = path.relative(
this.getPlatformData(projectData).projectRoot,
targetPath
);
return frameworkPath;
}
private getPbxProjPath(projectData: IProjectData): string {
return path.join(
this.$xcprojService.getXcodeprojPath(
projectData,
this.getPlatformData(projectData).projectRoot
),
"project.pbxproj"
);
}
private createPbxProj(projectData: IProjectData): any {
const project = new this.$xcode.project(this.getPbxProjPath(projectData));
project.parseSync();
return project;
}
private savePbxProj(
project: any,
projectData: IProjectData,
omitEmptyValues?: boolean
): void {
return this.$fs.writeFile(
this.getPbxProjPath(projectData),
project.writeSync({ omitEmptyValues })
);
}
public async preparePluginNativeCode(
pluginData: IPluginData,
projectData: IProjectData,
opts?: any
): Promise<void> {
const pluginPlatformsFolderPath = pluginData.pluginPlatformsFolderPath(
IOSProjectService.IOS_PLATFORM_NAME
);
const sourcePath = path.join(pluginPlatformsFolderPath, "src");
await this.prepareNativeSourceCode(
pluginData.name,
sourcePath,
projectData
);
await this.prepareResources(
pluginPlatformsFolderPath,
pluginData,
projectData
);
await this.prepareFrameworks(
pluginPlatformsFolderPath,
pluginData,
projectData
);
await this.prepareStaticLibs(
pluginPlatformsFolderPath,
pluginData,
projectData
);
}
public async removePluginNativeCode(
pluginData: IPluginData,
projectData: IProjectData
): Promise<void> {
const pluginPlatformsFolderPath = pluginData.pluginPlatformsFolderPath(
IOSProjectService.IOS_PLATFORM_NAME
);
this.removeNativeSourceCode(
pluginPlatformsFolderPath,
pluginData,
projectData
);
this.removeFrameworks(pluginPlatformsFolderPath, pluginData, projectData);
this.removeStaticLibs(pluginPlatformsFolderPath, pluginData, projectData);
const projectRoot = this.getPlatformData(projectData).projectRoot;
this.$cocoapodsService.removePodfileFromProject(
pluginData.name,
this.$cocoapodsService.getPluginPodfilePath(pluginData),
projectData,
projectRoot
);
}
public async handleNativeDependenciesChange(
projectData: IProjectData,
opts: IRelease
): Promise<void> {
const platformData = this.getPlatformData(projectData);
const pluginsData = this.getAllProductionPlugins(projectData);
this.setProductBundleIdentifier(projectData);
await this.applyPluginsCocoaPods(pluginsData, projectData, platformData);
await this.$cocoapodsService.applyPodfileFromAppResources(
projectData,
platformData
);
await this.$cocoapodsService.applyPodfileArchExclusions(
projectData,
platformData
);
const projectPodfilePath = this.$cocoapodsService.getProjectPodfilePath(
platformData.projectRoot
);
if (this.$fs.exists(projectPodfilePath)) {
await this.$cocoapodsService.executePodInstall(
platformData.projectRoot,
this.$xcprojService.getXcodeprojPath(
projectData,
platformData.projectRoot
)
);
// The `pod install` command adds a new target to the .pbxproject. This target adds additional build phases to Xcode project.
// Some of these phases relies on env variables (like PODS_PODFILE_DIR_PATH or PODS_ROOT).
// These variables are produced from merge of pod's xcconfig file and project's xcconfig file.
// So the correct order is `pod install` to be executed before merging pod's xcconfig file.
await this.$cocoapodsService.mergePodXcconfigFile(
projectData,
platformData,
opts
);
}
const pbxProjPath = this.getPbxProjPath(projectData);
this.$iOSExtensionsService.removeExtensions({ pbxProjPath });
await this.addExtensions(projectData, pluginsData);
}
public beforePrepareAllPlugins(): Promise<void> {
return Promise.resolve();
}
public async checkForChanges(
changesInfo: IProjectChangesInfo,
prepareData: IOSPrepareData,
projectData: IProjectData
): Promise<void> {
const { provision, teamId } = prepareData;
const hasProvision = provision !== undefined;
const hasTeamId = teamId !== undefined;
if (hasProvision || hasTeamId) {
// Check if the native project's signing is set to the provided provision...
const pbxprojPath = this.getPbxProjPath(projectData);
if (this.$fs.exists(pbxprojPath)) {
const xcode = this.$pbxprojDomXcode.Xcode.open(pbxprojPath);
const signing = xcode.getSigning(projectData.projectName);
if (hasProvision) {
if (signing && signing.style === "Manual") {
for (const name in signing.configurations) {