Skip to content

Commit 98c7066

Browse files
authored
feat(ios): embedding into host Swift projects (#5769)
1 parent 7287f60 commit 98c7066

20 files changed

+2242
-888
lines changed

lib/commands/add-platform.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import { injector } from "../common/yok";
1212

1313
export class AddPlatformCommand
1414
extends ValidatePlatformCommandBase
15-
implements ICommand {
15+
implements ICommand
16+
{
1617
public allowedParameters: ICommandParameter[] = [];
1718

1819
constructor(
@@ -36,7 +37,8 @@ export class AddPlatformCommand
3637
await this.$platformCommandHelper.addPlatforms(
3738
args,
3839
this.$projectData,
39-
this.$options.frameworkPath
40+
this.$options.frameworkPath,
41+
this.$options.nativeHost
4042
);
4143
}
4244

lib/controllers/prepare-controller.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ export class PrepareController extends EventEmitter {
476476
"package.json"
477477
);
478478
} else {
479+
console.log("!!!!! VM: proj root: " + platformData.projectRoot);
479480
packagePath = path.join(
480481
platformData.projectRoot,
481482
"app",

lib/data/build-data.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export class IOSBuildData extends BuildData implements IiOSBuildData {
3131
public mobileProvisionData: any;
3232
public buildForAppStore: boolean;
3333
public iCloudContainerEnvironment: string;
34+
public nativeHost: string;
3435

3536
constructor(projectDir: string, platform: string, data: any) {
3637
super(projectDir, platform, data);
@@ -40,6 +41,7 @@ export class IOSBuildData extends BuildData implements IiOSBuildData {
4041
this.mobileProvisionData = data.mobileProvisionData;
4142
this.buildForAppStore = data.buildForAppStore;
4243
this.iCloudContainerEnvironment = data.iCloudContainerEnvironment;
44+
this.nativeHost = data.nativeHost;
4345
}
4446
}
4547

@@ -51,6 +53,7 @@ export class AndroidBuildData extends BuildData {
5153
public androidBundle: boolean;
5254
public gradlePath: string;
5355
public gradleArgs: string;
56+
public nativeHost: string;
5457

5558
constructor(projectDir: string, platform: string, data: any) {
5659
super(projectDir, platform, data);
@@ -62,5 +65,6 @@ export class AndroidBuildData extends BuildData {
6265
this.androidBundle = data.androidBundle || data.aab;
6366
this.gradlePath = data.gradlePath;
6467
this.gradleArgs = data.gradleArgs;
68+
this.nativeHost = data.nativeHost;
6569
}
6670
}

lib/data/prepare-data.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export class PrepareData extends ControllerDataBase {
77
public env: any;
88
public watch?: boolean;
99
public watchNative: boolean = true;
10+
public nativeHost?: string;
1011

1112
constructor(public projectDir: string, public platform: string, data: any) {
1213
super(projectDir, platform, data);
@@ -36,6 +37,7 @@ export class PrepareData extends ControllerDataBase {
3637
if (_.isBoolean(data.watchNative)) {
3738
this.watchNative = data.watchNative;
3839
}
40+
this.nativeHost = data.nativeHost;
3941
}
4042
}
4143

lib/declarations.d.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,11 @@ interface IAndroidBundleOptions {
581581
interface IAndroidOptions {
582582
gradlePath: string;
583583
gradleArgs: string;
584+
nativeHost: string;
585+
}
586+
587+
interface IIOSOptions {
588+
nativeHost: string;
584589
}
585590

586591
interface ITypingsOptions {
@@ -603,6 +608,7 @@ interface IOptions
603608
IProvision,
604609
ITeamIdentifier,
605610
IAndroidOptions,
611+
IIOSOptions,
606612
IAndroidReleaseOptions,
607613
IAndroidBundleOptions,
608614
INpmInstallConfigurationOptions,
@@ -1009,6 +1015,7 @@ interface IXcprojService {
10091015
* @return {string} The full path to the xcodeproj
10101016
*/
10111017
getXcodeprojPath(projectData: IProjectData, projectRoot: string): string;
1018+
findXcodeProject(dir: string): string;
10121019
}
10131020

10141021
/**
@@ -1216,7 +1223,8 @@ interface IPlatformCommandHelper {
12161223
addPlatforms(
12171224
platforms: string[],
12181225
projectData: IProjectData,
1219-
frameworkPath?: string
1226+
frameworkPath?: string,
1227+
nativeHost?: string
12201228
): Promise<void>;
12211229
cleanPlatforms(
12221230
platforms: string[],

lib/definitions/platform.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ interface ICheckEnvironmentRequirementsOutput {
118118

119119
interface IAddPlatformData extends IControllerDataBase {
120120
frameworkPath?: string;
121+
nativeHost?: string;
121122
}
122123

123124
interface IPlatformController {

lib/helpers/platform-command-helper.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
IPlatformCommandHelper,
1010
IPackageInstallationManager,
1111
IUpdatePlatformOptions,
12+
IOptions,
1213
} from "../declarations";
1314
import { IPlatformsDataService, IPlatformData } from "../definitions/platform";
1415
import { IFileSystem, IErrors } from "../common/declarations";
@@ -21,6 +22,7 @@ export class PlatformCommandHelper implements IPlatformCommandHelper {
2122
private $fs: IFileSystem,
2223
private $errors: IErrors,
2324
private $logger: ILogger,
25+
private $options: IOptions,
2426
private $mobileHelper: Mobile.IMobileHelper,
2527
private $packageInstallationManager: IPackageInstallationManager,
2628
private $pacoteService: IPacoteService,
@@ -34,7 +36,8 @@ export class PlatformCommandHelper implements IPlatformCommandHelper {
3436
public async addPlatforms(
3537
platforms: string[],
3638
projectData: IProjectData,
37-
frameworkPath: string
39+
frameworkPath: string,
40+
nativeHost?: string
3841
): Promise<void> {
3942
const platformsDir = projectData.platformsDir;
4043
this.$fs.ensureDirectoryExists(platformsDir);
@@ -56,6 +59,7 @@ export class PlatformCommandHelper implements IPlatformCommandHelper {
5659
projectDir: projectData.projectDir,
5760
platform,
5861
frameworkPath,
62+
nativeHost,
5963
});
6064
}
6165
}
@@ -102,10 +106,9 @@ export class PlatformCommandHelper implements IPlatformCommandHelper {
102106
}
103107

104108
try {
105-
const platformDir = path.join(
106-
projectData.platformsDir,
107-
platform.toLowerCase()
108-
);
109+
const platformDir = this.$options.nativeHost
110+
? this.$options.nativeHost
111+
: path.join(projectData.platformsDir, platform.toLowerCase());
109112
this.$fs.deleteDirectory(platformDir);
110113
await this.$packageInstallationManager.uninstall(
111114
platformData.frameworkPackageName,
@@ -210,9 +213,8 @@ export class PlatformCommandHelper implements IPlatformCommandHelper {
210213
platform,
211214
projectData
212215
);
213-
const prepareInfo = this.$projectChangesService.getPrepareInfo(
214-
platformData
215-
);
216+
const prepareInfo =
217+
this.$projectChangesService.getPrepareInfo(platformData);
216218
if (!prepareInfo) {
217219
return true;
218220
}

lib/options.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ export class Options {
227227
},
228228
gradlePath: { type: OptionType.String, hasSensitiveValue: false },
229229
gradleArgs: { type: OptionType.String, hasSensitiveValue: false },
230+
nativeHost: { type: OptionType.String, hasSensitiveValue: false },
230231
aab: { type: OptionType.Boolean, hasSensitiveValue: false },
231232
performance: { type: OptionType.Object, hasSensitiveValue: true },
232233
appleApplicationSpecificPassword: {

lib/services/android-project-service.ts

Lines changed: 48 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,12 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
164164
);
165165
}
166166
if (projectData && projectData.platformsDir) {
167-
const projectRoot = path.join(
168-
projectData.platformsDir,
169-
AndroidProjectService.ANDROID_PLATFORM_NAME
170-
);
167+
const projectRoot = this.$options.nativeHost
168+
? this.$options.nativeHost
169+
: path.join(
170+
projectData.platformsDir,
171+
AndroidProjectService.ANDROID_PLATFORM_NAME
172+
);
171173

172174
const appDestinationDirectoryArr = [
173175
projectRoot,
@@ -266,10 +268,11 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
266268
platformData: IPlatformData,
267269
projectData: IProjectData
268270
): string {
269-
const currentPlatformData: IDictionary<any> = this.$projectDataService.getRuntimePackage(
270-
projectData.projectDir,
271-
<constants.PlatformTypes>platformData.platformNameLowerCase
272-
);
271+
const currentPlatformData: IDictionary<any> =
272+
this.$projectDataService.getRuntimePackage(
273+
projectData.projectDir,
274+
<constants.PlatformTypes>platformData.platformNameLowerCase
275+
);
273276

274277
return currentPlatformData && currentPlatformData[constants.VERSION_STRING];
275278
}
@@ -281,9 +284,10 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
281284
public getAppResourcesDestinationDirectoryPath(
282285
projectData: IProjectData
283286
): string {
284-
const appResourcesDirStructureHasMigrated = this.$androidResourcesMigrationService.hasMigrated(
285-
projectData.getAppResourcesDirectoryPath()
286-
);
287+
const appResourcesDirStructureHasMigrated =
288+
this.$androidResourcesMigrationService.hasMigrated(
289+
projectData.getAppResourcesDirectoryPath()
290+
);
287291

288292
if (appResourcesDirStructureHasMigrated) {
289293
return this.getUpdatedAppResourcesDestinationDirPath(projectData);
@@ -300,14 +304,13 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
300304
this.validatePackageName(projectData.projectIdentifiers.android);
301305
this.validateProjectName(projectData.projectName);
302306

303-
const checkEnvironmentRequirementsOutput = await this.$platformEnvironmentRequirements.checkEnvironmentRequirements(
304-
{
307+
const checkEnvironmentRequirementsOutput =
308+
await this.$platformEnvironmentRequirements.checkEnvironmentRequirements({
305309
platform: this.getPlatformData(projectData).normalizedPlatformName,
306310
projectDir: projectData.projectDir,
307311
options,
308312
notConfiguredEnvOptions,
309-
}
310-
);
313+
});
311314

312315
this.$androidToolsInfo.validateInfo({
313316
showWarningsAsErrors: true,
@@ -358,14 +361,14 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
358361
}
359362

360363
private getResDestinationDir(projectData: IProjectData): string {
361-
const appResourcesDirStructureHasMigrated = this.$androidResourcesMigrationService.hasMigrated(
362-
projectData.getAppResourcesDirectoryPath()
363-
);
364+
const appResourcesDirStructureHasMigrated =
365+
this.$androidResourcesMigrationService.hasMigrated(
366+
projectData.getAppResourcesDirectoryPath()
367+
);
364368

365369
if (appResourcesDirStructureHasMigrated) {
366-
const appResourcesDestinationPath = this.getUpdatedAppResourcesDestinationDirPath(
367-
projectData
368-
);
370+
const appResourcesDestinationPath =
371+
this.getUpdatedAppResourcesDestinationDirPath(projectData);
369372
return path.join(
370373
appResourcesDestinationPath,
371374
constants.MAIN_DIR,
@@ -413,13 +416,13 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
413416
public async interpolateData(projectData: IProjectData): Promise<void> {
414417
// Interpolate the apilevel and package
415418
this.interpolateConfigurationFile(projectData);
416-
const appResourcesDirectoryPath = projectData.getAppResourcesDirectoryPath();
419+
const appResourcesDirectoryPath =
420+
projectData.getAppResourcesDirectoryPath();
417421

418422
let stringsFilePath: string;
419423

420-
const appResourcesDestinationDirectoryPath = this.getAppResourcesDestinationDirectoryPath(
421-
projectData
422-
);
424+
const appResourcesDestinationDirectoryPath =
425+
this.getAppResourcesDestinationDirectoryPath(projectData);
423426
if (
424427
this.$androidResourcesMigrationService.hasMigrated(
425428
appResourcesDirectoryPath
@@ -479,8 +482,8 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
479482
}
480483

481484
public interpolateConfigurationFile(projectData: IProjectData): void {
482-
const manifestPath = this.getPlatformData(projectData)
483-
.configurationFilePath;
485+
const manifestPath =
486+
this.getPlatformData(projectData).configurationFilePath;
484487
shell.sed(
485488
"-i",
486489
/__PACKAGE__/,
@@ -521,9 +524,8 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
521524
AndroidProjectService.MIN_RUNTIME_VERSION_WITH_GRADLE
522525
)
523526
) {
524-
const platformLowercase = this.getPlatformData(
525-
projectData
526-
).normalizedPlatformName.toLowerCase();
527+
const platformLowercase =
528+
this.getPlatformData(projectData).normalizedPlatformName.toLowerCase();
527529
await removePlatforms([platformLowercase.split("@")[0]]);
528530
await addPlatform(platformLowercase);
529531
return false;
@@ -585,9 +587,10 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
585587
projectData: IProjectData
586588
): void {
587589
const appResourcesDirectoryPath = projectData.appResourcesDirectoryPath;
588-
const appResourcesDirStructureHasMigrated = this.$androidResourcesMigrationService.hasMigrated(
589-
appResourcesDirectoryPath
590-
);
590+
const appResourcesDirStructureHasMigrated =
591+
this.$androidResourcesMigrationService.hasMigrated(
592+
appResourcesDirectoryPath
593+
);
591594
let originalAndroidManifestFilePath;
592595

593596
if (appResourcesDirStructureHasMigrated) {
@@ -628,17 +631,17 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
628631
const projectAppResourcesPath = projectData.getAppResourcesDirectoryPath(
629632
projectData.projectDir
630633
);
631-
const platformsAppResourcesPath = this.getAppResourcesDestinationDirectoryPath(
632-
projectData
633-
);
634+
const platformsAppResourcesPath =
635+
this.getAppResourcesDestinationDirectoryPath(projectData);
634636

635637
this.cleanUpPreparedResources(projectData);
636638

637639
this.$fs.ensureDirectoryExists(platformsAppResourcesPath);
638640

639-
const appResourcesDirStructureHasMigrated = this.$androidResourcesMigrationService.hasMigrated(
640-
projectAppResourcesPath
641-
);
641+
const appResourcesDirStructureHasMigrated =
642+
this.$androidResourcesMigrationService.hasMigrated(
643+
projectAppResourcesPath
644+
);
642645
if (appResourcesDirStructureHasMigrated) {
643646
this.$fs.copyFile(
644647
path.join(
@@ -745,10 +748,12 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
745748
projectData: IProjectData,
746749
dependencies: IDependencyData[]
747750
): IDependencyData[] {
748-
const platformDir = path.join(
749-
projectData.platformsDir,
750-
AndroidProjectService.ANDROID_PLATFORM_NAME
751-
);
751+
const platformDir = this.$options.nativeHost
752+
? this.$options.nativeHost
753+
: path.join(
754+
projectData.platformsDir,
755+
AndroidProjectService.ANDROID_PLATFORM_NAME
756+
);
752757
const dependenciesJsonPath = path.join(
753758
platformDir,
754759
constants.DEPENDENCIES_JSON_NAME

0 commit comments

Comments
 (0)