Skip to content

feat: embedding into iOS host projects #5769

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/commands/add-platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import { injector } from "../common/yok";

export class AddPlatformCommand
extends ValidatePlatformCommandBase
implements ICommand {
implements ICommand
{
public allowedParameters: ICommandParameter[] = [];

constructor(
Expand All @@ -36,7 +37,8 @@ export class AddPlatformCommand
await this.$platformCommandHelper.addPlatforms(
args,
this.$projectData,
this.$options.frameworkPath
this.$options.frameworkPath,
this.$options.nativeHost
);
}

Expand Down
1 change: 1 addition & 0 deletions lib/controllers/prepare-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ export class PrepareController extends EventEmitter {
"package.json"
);
} else {
console.log("!!!!! VM: proj root: " + platformData.projectRoot);
packagePath = path.join(
platformData.projectRoot,
"app",
Expand Down
4 changes: 4 additions & 0 deletions lib/data/build-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class IOSBuildData extends BuildData implements IiOSBuildData {
public mobileProvisionData: any;
public buildForAppStore: boolean;
public iCloudContainerEnvironment: string;
public nativeHost: string;

constructor(projectDir: string, platform: string, data: any) {
super(projectDir, platform, data);
Expand All @@ -40,6 +41,7 @@ export class IOSBuildData extends BuildData implements IiOSBuildData {
this.mobileProvisionData = data.mobileProvisionData;
this.buildForAppStore = data.buildForAppStore;
this.iCloudContainerEnvironment = data.iCloudContainerEnvironment;
this.nativeHost = data.nativeHost;
}
}

Expand All @@ -51,6 +53,7 @@ export class AndroidBuildData extends BuildData {
public androidBundle: boolean;
public gradlePath: string;
public gradleArgs: string;
public nativeHost: string;

constructor(projectDir: string, platform: string, data: any) {
super(projectDir, platform, data);
Expand All @@ -62,5 +65,6 @@ export class AndroidBuildData extends BuildData {
this.androidBundle = data.androidBundle || data.aab;
this.gradlePath = data.gradlePath;
this.gradleArgs = data.gradleArgs;
this.nativeHost = data.nativeHost;
}
}
2 changes: 2 additions & 0 deletions lib/data/prepare-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export class PrepareData extends ControllerDataBase {
public env: any;
public watch?: boolean;
public watchNative: boolean = true;
public nativeHost?: string;

constructor(public projectDir: string, public platform: string, data: any) {
super(projectDir, platform, data);
Expand Down Expand Up @@ -36,6 +37,7 @@ export class PrepareData extends ControllerDataBase {
if (_.isBoolean(data.watchNative)) {
this.watchNative = data.watchNative;
}
this.nativeHost = data.nativeHost;
}
}

Expand Down
10 changes: 9 additions & 1 deletion lib/declarations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,11 @@ interface IAndroidBundleOptions {
interface IAndroidOptions {
gradlePath: string;
gradleArgs: string;
nativeHost: string;
}

interface IIOSOptions {
nativeHost: string;
}

interface ITypingsOptions {
Expand All @@ -603,6 +608,7 @@ interface IOptions
IProvision,
ITeamIdentifier,
IAndroidOptions,
IIOSOptions,
IAndroidReleaseOptions,
IAndroidBundleOptions,
INpmInstallConfigurationOptions,
Expand Down Expand Up @@ -1009,6 +1015,7 @@ interface IXcprojService {
* @return {string} The full path to the xcodeproj
*/
getXcodeprojPath(projectData: IProjectData, projectRoot: string): string;
findXcodeProject(dir: string): string;
}

/**
Expand Down Expand Up @@ -1216,7 +1223,8 @@ interface IPlatformCommandHelper {
addPlatforms(
platforms: string[],
projectData: IProjectData,
frameworkPath?: string
frameworkPath?: string,
nativeHost?: string
): Promise<void>;
cleanPlatforms(
platforms: string[],
Expand Down
1 change: 1 addition & 0 deletions lib/definitions/platform.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ interface ICheckEnvironmentRequirementsOutput {

interface IAddPlatformData extends IControllerDataBase {
frameworkPath?: string;
nativeHost?: string;
}

interface IPlatformController {
Expand Down
18 changes: 10 additions & 8 deletions lib/helpers/platform-command-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
IPlatformCommandHelper,
IPackageInstallationManager,
IUpdatePlatformOptions,
IOptions,
} from "../declarations";
import { IPlatformsDataService, IPlatformData } from "../definitions/platform";
import { IFileSystem, IErrors } from "../common/declarations";
Expand All @@ -21,6 +22,7 @@ export class PlatformCommandHelper implements IPlatformCommandHelper {
private $fs: IFileSystem,
private $errors: IErrors,
private $logger: ILogger,
private $options: IOptions,
private $mobileHelper: Mobile.IMobileHelper,
private $packageInstallationManager: IPackageInstallationManager,
private $pacoteService: IPacoteService,
Expand All @@ -34,7 +36,8 @@ export class PlatformCommandHelper implements IPlatformCommandHelper {
public async addPlatforms(
platforms: string[],
projectData: IProjectData,
frameworkPath: string
frameworkPath: string,
nativeHost?: string
): Promise<void> {
const platformsDir = projectData.platformsDir;
this.$fs.ensureDirectoryExists(platformsDir);
Expand All @@ -56,6 +59,7 @@ export class PlatformCommandHelper implements IPlatformCommandHelper {
projectDir: projectData.projectDir,
platform,
frameworkPath,
nativeHost,
});
}
}
Expand Down Expand Up @@ -102,10 +106,9 @@ export class PlatformCommandHelper implements IPlatformCommandHelper {
}

try {
const platformDir = path.join(
projectData.platformsDir,
platform.toLowerCase()
);
const platformDir = this.$options.nativeHost
? this.$options.nativeHost
: path.join(projectData.platformsDir, platform.toLowerCase());
this.$fs.deleteDirectory(platformDir);
await this.$packageInstallationManager.uninstall(
platformData.frameworkPackageName,
Expand Down Expand Up @@ -210,9 +213,8 @@ export class PlatformCommandHelper implements IPlatformCommandHelper {
platform,
projectData
);
const prepareInfo = this.$projectChangesService.getPrepareInfo(
platformData
);
const prepareInfo =
this.$projectChangesService.getPrepareInfo(platformData);
if (!prepareInfo) {
return true;
}
Expand Down
1 change: 1 addition & 0 deletions lib/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ export class Options {
},
gradlePath: { type: OptionType.String, hasSensitiveValue: false },
gradleArgs: { type: OptionType.String, hasSensitiveValue: false },
nativeHost: { type: OptionType.String, hasSensitiveValue: false },
aab: { type: OptionType.Boolean, hasSensitiveValue: false },
performance: { type: OptionType.Object, hasSensitiveValue: true },
appleApplicationSpecificPassword: {
Expand Down
91 changes: 48 additions & 43 deletions lib/services/android-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,12 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
);
}
if (projectData && projectData.platformsDir) {
const projectRoot = path.join(
projectData.platformsDir,
AndroidProjectService.ANDROID_PLATFORM_NAME
);
const projectRoot = this.$options.nativeHost
? this.$options.nativeHost
: path.join(
projectData.platformsDir,
AndroidProjectService.ANDROID_PLATFORM_NAME
);

const appDestinationDirectoryArr = [
projectRoot,
Expand Down Expand Up @@ -266,10 +268,11 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
platformData: IPlatformData,
projectData: IProjectData
): string {
const currentPlatformData: IDictionary<any> = this.$projectDataService.getRuntimePackage(
projectData.projectDir,
<constants.PlatformTypes>platformData.platformNameLowerCase
);
const currentPlatformData: IDictionary<any> =
this.$projectDataService.getRuntimePackage(
projectData.projectDir,
<constants.PlatformTypes>platformData.platformNameLowerCase
);

return currentPlatformData && currentPlatformData[constants.VERSION_STRING];
}
Expand All @@ -281,9 +284,10 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
public getAppResourcesDestinationDirectoryPath(
projectData: IProjectData
): string {
const appResourcesDirStructureHasMigrated = this.$androidResourcesMigrationService.hasMigrated(
projectData.getAppResourcesDirectoryPath()
);
const appResourcesDirStructureHasMigrated =
this.$androidResourcesMigrationService.hasMigrated(
projectData.getAppResourcesDirectoryPath()
);

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

const checkEnvironmentRequirementsOutput = await this.$platformEnvironmentRequirements.checkEnvironmentRequirements(
{
const checkEnvironmentRequirementsOutput =
await this.$platformEnvironmentRequirements.checkEnvironmentRequirements({
platform: this.getPlatformData(projectData).normalizedPlatformName,
projectDir: projectData.projectDir,
options,
notConfiguredEnvOptions,
}
);
});

this.$androidToolsInfo.validateInfo({
showWarningsAsErrors: true,
Expand Down Expand Up @@ -358,14 +361,14 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
}

private getResDestinationDir(projectData: IProjectData): string {
const appResourcesDirStructureHasMigrated = this.$androidResourcesMigrationService.hasMigrated(
projectData.getAppResourcesDirectoryPath()
);
const appResourcesDirStructureHasMigrated =
this.$androidResourcesMigrationService.hasMigrated(
projectData.getAppResourcesDirectoryPath()
);

if (appResourcesDirStructureHasMigrated) {
const appResourcesDestinationPath = this.getUpdatedAppResourcesDestinationDirPath(
projectData
);
const appResourcesDestinationPath =
this.getUpdatedAppResourcesDestinationDirPath(projectData);
return path.join(
appResourcesDestinationPath,
constants.MAIN_DIR,
Expand Down Expand Up @@ -413,13 +416,13 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
public async interpolateData(projectData: IProjectData): Promise<void> {
// Interpolate the apilevel and package
this.interpolateConfigurationFile(projectData);
const appResourcesDirectoryPath = projectData.getAppResourcesDirectoryPath();
const appResourcesDirectoryPath =
projectData.getAppResourcesDirectoryPath();

let stringsFilePath: string;

const appResourcesDestinationDirectoryPath = this.getAppResourcesDestinationDirectoryPath(
projectData
);
const appResourcesDestinationDirectoryPath =
this.getAppResourcesDestinationDirectoryPath(projectData);
if (
this.$androidResourcesMigrationService.hasMigrated(
appResourcesDirectoryPath
Expand Down Expand Up @@ -479,8 +482,8 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
}

public interpolateConfigurationFile(projectData: IProjectData): void {
const manifestPath = this.getPlatformData(projectData)
.configurationFilePath;
const manifestPath =
this.getPlatformData(projectData).configurationFilePath;
shell.sed(
"-i",
/__PACKAGE__/,
Expand Down Expand Up @@ -521,9 +524,8 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
AndroidProjectService.MIN_RUNTIME_VERSION_WITH_GRADLE
)
) {
const platformLowercase = this.getPlatformData(
projectData
).normalizedPlatformName.toLowerCase();
const platformLowercase =
this.getPlatformData(projectData).normalizedPlatformName.toLowerCase();
await removePlatforms([platformLowercase.split("@")[0]]);
await addPlatform(platformLowercase);
return false;
Expand Down Expand Up @@ -585,9 +587,10 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
projectData: IProjectData
): void {
const appResourcesDirectoryPath = projectData.appResourcesDirectoryPath;
const appResourcesDirStructureHasMigrated = this.$androidResourcesMigrationService.hasMigrated(
appResourcesDirectoryPath
);
const appResourcesDirStructureHasMigrated =
this.$androidResourcesMigrationService.hasMigrated(
appResourcesDirectoryPath
);
let originalAndroidManifestFilePath;

if (appResourcesDirStructureHasMigrated) {
Expand Down Expand Up @@ -628,17 +631,17 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
const projectAppResourcesPath = projectData.getAppResourcesDirectoryPath(
projectData.projectDir
);
const platformsAppResourcesPath = this.getAppResourcesDestinationDirectoryPath(
projectData
);
const platformsAppResourcesPath =
this.getAppResourcesDestinationDirectoryPath(projectData);

this.cleanUpPreparedResources(projectData);

this.$fs.ensureDirectoryExists(platformsAppResourcesPath);

const appResourcesDirStructureHasMigrated = this.$androidResourcesMigrationService.hasMigrated(
projectAppResourcesPath
);
const appResourcesDirStructureHasMigrated =
this.$androidResourcesMigrationService.hasMigrated(
projectAppResourcesPath
);
if (appResourcesDirStructureHasMigrated) {
this.$fs.copyFile(
path.join(
Expand Down Expand Up @@ -745,10 +748,12 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
projectData: IProjectData,
dependencies: IDependencyData[]
): IDependencyData[] {
const platformDir = path.join(
projectData.platformsDir,
AndroidProjectService.ANDROID_PLATFORM_NAME
);
const platformDir = this.$options.nativeHost
? this.$options.nativeHost
: path.join(
projectData.platformsDir,
AndroidProjectService.ANDROID_PLATFORM_NAME
);
const dependenciesJsonPath = path.join(
platformDir,
constants.DEPENDENCIES_JSON_NAME
Expand Down
Loading