Skip to content
Prev Previous commit
Next Next commit
*Rename androidHost to nativeHost
*add js package to xcodeproj folder
  • Loading branch information
tdermendjiev committed Oct 9, 2023
commit 49c33f508efeb8b595a34852100b34db516d77c6
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
6 changes: 4 additions & 2 deletions lib/data/build-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,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 @@ -38,6 +39,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 @@ -49,7 +51,7 @@ export class AndroidBuildData extends BuildData {
public androidBundle: boolean;
public gradlePath: string;
public gradleArgs: string;
public androidHost: string;
public nativeHost: string;

constructor(projectDir: string, platform: string, data: any) {
super(projectDir, platform, data);
Expand All @@ -61,6 +63,6 @@ export class AndroidBuildData extends BuildData {
this.androidBundle = data.androidBundle || data.aab;
this.gradlePath = data.gradlePath;
this.gradleArgs = data.gradleArgs;
this.androidHost = data.androidHost;
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
11 changes: 9 additions & 2 deletions lib/declarations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,11 @@ interface IAndroidBundleOptions {
interface IAndroidOptions {
gradlePath: string;
gradleArgs: string;
androidHost: string;
nativeHost: string;
}

interface IIOSOptions {
nativeHost: string;
}

interface ITypingsOptions {
Expand All @@ -604,6 +608,7 @@ interface IOptions
IProvision,
ITeamIdentifier,
IAndroidOptions,
IIOSOptions,
IAndroidReleaseOptions,
IAndroidBundleOptions,
INpmInstallConfigurationOptions,
Expand Down Expand Up @@ -1001,6 +1006,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 @@ -1208,7 +1214,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
8 changes: 5 additions & 3 deletions lib/helpers/platform-command-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,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 @@ -58,6 +59,7 @@ export class PlatformCommandHelper implements IPlatformCommandHelper {
projectDir: projectData.projectDir,
platform,
frameworkPath,
nativeHost,
});
}
}
Expand Down Expand Up @@ -104,8 +106,8 @@ export class PlatformCommandHelper implements IPlatformCommandHelper {
}

try {
const platformDir = this.$options.androidHost
? this.$options.androidHost
const platformDir = this.$options.nativeHost
? this.$options.nativeHost
: path.join(projectData.platformsDir, platform.toLowerCase());
this.$fs.deleteDirectory(platformDir);
await this.$packageInstallationManager.uninstall(
Expand Down
2 changes: 1 addition & 1 deletion lib/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ export class Options {
},
gradlePath: { type: OptionType.String, hasSensitiveValue: false },
gradleArgs: { type: OptionType.String, hasSensitiveValue: false },
androidHost: { 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
8 changes: 4 additions & 4 deletions lib/services/android-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
);
}
if (projectData && projectData.platformsDir) {
const projectRoot = this.$options.androidHost
? this.$options.androidHost
const projectRoot = this.$options.nativeHost
? this.$options.nativeHost
: path.join(
projectData.platformsDir,
AndroidProjectService.ANDROID_PLATFORM_NAME
Expand Down Expand Up @@ -748,8 +748,8 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
projectData: IProjectData,
dependencies: IDependencyData[]
): IDependencyData[] {
const platformDir = this.$options.androidHost
? this.$options.androidHost
const platformDir = this.$options.nativeHost
? this.$options.nativeHost
: path.join(
projectData.platformsDir,
AndroidProjectService.ANDROID_PLATFORM_NAME
Expand Down
4 changes: 2 additions & 2 deletions lib/services/assets-generation/assets-generation-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class AssetsGenerationService implements IAssetsGenerationService {
public async generateIcons(
resourceGenerationData: IResourceGenerationData
): Promise<void> {
if (this.$options.androidHost) {
if (this.$options.nativeHost) {
return;
}

Expand All @@ -59,7 +59,7 @@ export class AssetsGenerationService implements IAssetsGenerationService {
public async generateSplashScreens(
splashesGenerationData: IResourceGenerationData
): Promise<void> {
if (this.$options.androidHost) {
if (this.$options.nativeHost) {
return;
}

Expand Down
29 changes: 24 additions & 5 deletions lib/services/ios-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
private $logger: ILogger,
private $injector: IInjector,
$projectDataService: IProjectDataService,
private $options: IOptions,
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
private $hostInfo: IHostInfo,
private $xcprojService: IXcprojService,
Expand Down Expand Up @@ -120,10 +121,13 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
projectData.platformsDir &&
this._platformsDirCache !== projectData.platformsDir
) {
const projectRoot = path.join(
projectData.platformsDir,
this.$devicePlatformsConstants.iOS.toLowerCase()
);
const projectRoot = this.$options.nativeHost
? this.$options.nativeHost
: path.join(
projectData.platformsDir,
this.$devicePlatformsConstants.iOS.toLowerCase()
);

const runtimePackage = this.$projectDataService.getRuntimePackage(
projectData.projectDir,
constants.PlatformTypes.ios
Expand Down Expand Up @@ -564,11 +568,17 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
projectData: IProjectData,
prepareData: IOSPrepareData
): Promise<void> {
const projectRoot = path.join(projectData.platformsDir, "ios");
const projectRoot = this.$options.nativeHost
? this.$options.nativeHost
: path.join(
projectData.platformsDir,
this.$devicePlatformsConstants.iOS.toLowerCase()
);
const platformData = this.getPlatformData(projectData);

const pluginsData = this.getAllProductionPlugins(projectData);
const pbxProjPath = this.getPbxProjPath(projectData);

this.$iOSExtensionsService.removeExtensions({ pbxProjPath });
await this.addExtensions(projectData, pluginsData);

Expand Down Expand Up @@ -860,6 +870,15 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
}

private getPbxProjPath(projectData: IProjectData): string {
if (this.$options.nativeHost) {
let xcodeProjectPath = this.$xcprojService.findXcodeProject(
this.$options.nativeHost
);
if (!xcodeProjectPath) {
this.$errors.fail("Xcode project not found at the specified directory");
}
return path.join(xcodeProjectPath, "project.pbxproj");
}
return path.join(
this.$xcprojService.getXcodeprojPath(
projectData,
Expand Down
9 changes: 6 additions & 3 deletions lib/services/platform/add-platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export class AddPlatformService implements IAddPlatformService {
private $analyticsService: IAnalyticsService // private $tempService: ITempService
) {}

public async addProjectHost() {}

public async addPlatformSafe(
projectData: IProjectData,
platformData: IPlatformData,
Expand Down Expand Up @@ -183,14 +185,15 @@ export class AddPlatformService implements IAddPlatformService {
frameworkDirPath: string,
frameworkVersion: string
): Promise<void> {
const platformDir = this.$options.androidHost
? this.$options.androidHost
//here we should use ios OR android
const platformDir = this.$options.nativeHost
? this.$options.nativeHost
: path.join(
projectData.platformsDir,
platformData.normalizedPlatformName.toLowerCase()
);
this.$fs.deleteDirectory(platformDir);

//if iosHost - dont create project
await platformData.platformProjectService.createProject(
path.resolve(frameworkDirPath),
frameworkVersion,
Expand Down
2 changes: 1 addition & 1 deletion lib/services/platform/prepare-native-platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class PrepareNativePlatformService
await this.cleanProject(platformData, { release });
}

if (!this.$options.androidHost) {
if (!this.$options.nativeHost) {
platformData.platformProjectService.prepareAppResources(projectData);
}

Expand Down
6 changes: 4 additions & 2 deletions lib/services/webpack/webpack-compiler-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,11 @@ export class WebpackCompilerService
cwd: projectData.projectDir,
stdio,
};
if (this.$options.androidHost) {

if (this.$options.nativeHost) {
options.env = {
USER_PROJECT_PLATFORMS_ANDROID: this.$options.androidHost,
USER_PROJECT_PLATFORMS_ANDROID: this.$options.nativeHost,
USER_PROJECT_PLATFORMS_IOS: this.$options.nativeHost,
};
}
const childProcess = this.$childProcess.spawn(
Expand Down
18 changes: 18 additions & 0 deletions lib/services/xcproj-service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as path from "path";
import * as fs from "fs";
import { IosProjectConstants } from "../constants";
import { IXcprojService } from "../declarations";
import { IProjectData } from "../definitions/project";
Expand All @@ -15,6 +16,23 @@ class XcprojService implements IXcprojService {
projectData.projectName + IosProjectConstants.XcodeProjExtName
);
}

public findXcodeProject(dir: string): string {
const filesAndDirs = fs.readdirSync(dir);

for (let i = 0; i < filesAndDirs.length; i++) {
const fullPath = path.join(dir, filesAndDirs[i]);

if (
fs.statSync(fullPath).isDirectory() &&
filesAndDirs[i].endsWith(".xcodeproj")
) {
return fullPath;
}
}

return null;
}
}

injector.register("xcprojService", XcprojService);