From c2530662a8e0dc0a4535717863340fd6d16f8598 Mon Sep 17 00:00:00 2001 From: Vladimir Mutafov Date: Tue, 2 Jan 2024 15:40:48 +0200 Subject: [PATCH 1/2] feat: support android embedding --- lib/controllers/prepare-controller.ts | 18 +-- lib/data/build-data.ts | 2 + lib/declarations.d.ts | 2 + lib/helpers/platform-command-helper.ts | 26 ++-- lib/options.ts | 12 +- lib/project-data.ts | 12 +- lib/providers/project-files-provider.ts | 2 +- lib/services/android-plugin-build-service.ts | 29 ++++- lib/services/android-project-service.ts | 113 +++++++++--------- .../assets-generation-service.ts | 12 +- lib/services/files-hash-service.ts | 11 +- ...android-device-livesync-sockets-service.ts | 6 +- .../livesync/android-livesync-service.ts | 10 +- lib/services/livesync/ios-livesync-service.ts | 15 ++- .../platform-livesync-service-base.ts | 57 ++++----- lib/services/log-source-map-service.ts | 4 +- lib/services/platform/add-platform-service.ts | 13 +- .../prepare-native-platform-service.ts | 16 ++- lib/services/plugins-service.ts | 9 +- lib/services/project-changes-service.ts | 10 ++ lib/services/project-data-service.ts | 5 +- .../webpack/webpack-compiler-service.ts | 39 +++++- package-lock.json | 28 +++++ vendor/gradle-plugin/build.gradle | 27 ++++- vendor/gradle-plugin/settings.gradle | 16 ++- 25 files changed, 338 insertions(+), 156 deletions(-) diff --git a/lib/controllers/prepare-controller.ts b/lib/controllers/prepare-controller.ts index 8c22fe3e61..5dc846e4d5 100644 --- a/lib/controllers/prepare-controller.ts +++ b/lib/controllers/prepare-controller.ts @@ -22,7 +22,7 @@ import { TrackActionNames, WEBPACK_COMPILATION_COMPLETE, } from "../constants"; -import { IWatchIgnoreListService } from "../declarations"; +import { IOptions, IWatchIgnoreListService } from "../declarations"; import { INodeModulesDependenciesBuilder, IPlatformController, @@ -59,6 +59,7 @@ export class PrepareController extends EventEmitter { public $hooksService: IHooksService, private $fs: IFileSystem, private $logger: ILogger, + private $options: IOptions, private $mobileHelper: Mobile.IMobileHelper, private $nodeModulesDependenciesBuilder: INodeModulesDependenciesBuilder, private $platformsDataService: IPlatformsDataService, @@ -134,10 +135,13 @@ export class PrepareController extends EventEmitter { projectData: IProjectData ): Promise { await this.$projectService.ensureAppResourcesExist(projectData.projectDir); - await this.$platformController.addPlatformIfNeeded( - prepareData, - projectData - ); + if (!this.$options.androidHost) { + await this.$platformController.addPlatformIfNeeded( + prepareData, + projectData + ); + } + await this.trackRuntimeVersion(prepareData.platform, projectData); this.$logger.info("Preparing project..."); @@ -476,9 +480,9 @@ export class PrepareController extends EventEmitter { } else { packagePath = path.join( platformData.projectRoot, - "app", + this.$options.androidHostModule, "src", - "main", + this.$options.androidHost ? "nativescript" : "main", "assets", "app", "package.json" diff --git a/lib/data/build-data.ts b/lib/data/build-data.ts index 87af14d166..e47b9d2e3b 100644 --- a/lib/data/build-data.ts +++ b/lib/data/build-data.ts @@ -49,6 +49,7 @@ export class AndroidBuildData extends BuildData { public androidBundle: boolean; public gradlePath: string; public gradleArgs: string; + public androidHost: string; constructor(projectDir: string, platform: string, data: any) { super(projectDir, platform, data); @@ -60,5 +61,6 @@ export class AndroidBuildData extends BuildData { this.androidBundle = data.androidBundle || data.aab; this.gradlePath = data.gradlePath; this.gradleArgs = data.gradleArgs; + this.androidHost = data.androidHost; } } diff --git a/lib/declarations.d.ts b/lib/declarations.d.ts index 9f627a9202..b8af37a2a2 100644 --- a/lib/declarations.d.ts +++ b/lib/declarations.d.ts @@ -581,6 +581,8 @@ interface IAndroidBundleOptions { interface IAndroidOptions { gradlePath: string; gradleArgs: string; + androidHost: string; + androidHostModule: string; } interface ITypingsOptions { diff --git a/lib/helpers/platform-command-helper.ts b/lib/helpers/platform-command-helper.ts index 1218d08790..d2d34036c7 100644 --- a/lib/helpers/platform-command-helper.ts +++ b/lib/helpers/platform-command-helper.ts @@ -9,6 +9,7 @@ import { IPlatformCommandHelper, IPackageInstallationManager, IUpdatePlatformOptions, + IOptions, } from "../declarations"; import { IPlatformsDataService, IPlatformData } from "../definitions/platform"; import { IFileSystem, IErrors } from "../common/declarations"; @@ -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, @@ -36,6 +38,11 @@ export class PlatformCommandHelper implements IPlatformCommandHelper { projectData: IProjectData, frameworkPath: string ): Promise { + if (this.$options.androidHost) { + this.$logger.info("Ignoring platform add becuase of --android-host flag"); + return; + } + const platformsDir = projectData.platformsDir; this.$fs.ensureDirectoryExists(platformsDir); @@ -82,6 +89,13 @@ export class PlatformCommandHelper implements IPlatformCommandHelper { platforms: string[], projectData: IProjectData ): Promise { + if (this.$options.androidHost) { + this.$logger.info( + "Ignoring platform remove becuase of --android-host flag" + ); + return; + } + for (const platform of platforms) { this.$platformValidationService.validatePlatformInstalled( platform, @@ -102,10 +116,9 @@ export class PlatformCommandHelper implements IPlatformCommandHelper { } try { - const platformDir = path.join( - projectData.platformsDir, - platform.toLowerCase() - ); + const platformDir = this.$options.androidHost + ? this.$options.androidHost + : path.join(projectData.platformsDir, platform.toLowerCase()); this.$fs.deleteDirectory(platformDir); await this.$packageInstallationManager.uninstall( platformData.frameworkPackageName, @@ -210,9 +223,8 @@ export class PlatformCommandHelper implements IPlatformCommandHelper { platform, projectData ); - const prepareInfo = this.$projectChangesService.getPrepareInfo( - platformData - ); + const prepareInfo = + this.$projectChangesService.getPrepareInfo(platformData); if (!prepareInfo) { return true; } diff --git a/lib/options.ts b/lib/options.ts index 26451d8264..53ae5ead93 100644 --- a/lib/options.ts +++ b/lib/options.ts @@ -10,6 +10,7 @@ import { ISettingsService, } from "./common/declarations"; import { injector } from "./common/yok"; +import { APP_FOLDER_NAME } from "./constants"; export class Options { private static DASHED_OPTION_REGEX = /(.+?)([A-Z])(.*)/; private static NONDASHED_OPTION_REGEX = /(.+?)[-]([a-zA-Z])(.*)/; @@ -221,6 +222,12 @@ export class Options { }, gradlePath: { type: OptionType.String, hasSensitiveValue: false }, gradleArgs: { type: OptionType.String, hasSensitiveValue: false }, + androidHost: { type: OptionType.String, hasSensitiveValue: false }, + androidHostModule: { + type: OptionType.String, + hasSensitiveValue: false, + default: APP_FOLDER_NAME, + }, aab: { type: OptionType.Boolean, hasSensitiveValue: false }, performance: { type: OptionType.Object, hasSensitiveValue: true }, appleApplicationSpecificPassword: { @@ -422,9 +429,8 @@ export class Options { this.$settingsService.setSettings({ profileDir: this.argv.profileDir, }); - this.argv.profileDir = this.argv[ - "profile-dir" - ] = this.$settingsService.getProfileDir(); + this.argv.profileDir = this.argv["profile-dir"] = + this.$settingsService.getProfileDir(); // if justlaunch is set, it takes precedence over the --watch flag and the default true value if (this.argv.justlaunch) { diff --git a/lib/project-data.ts b/lib/project-data.ts index f8bee9a09c..a8631d694a 100644 --- a/lib/project-data.ts +++ b/lib/project-data.ts @@ -217,11 +217,10 @@ export class ProjectData implements IProjectData { appResourcesDir, this.$devicePlatformsConstants.Android ); - const androidManifestDir = this.$androidResourcesMigrationService.hasMigrated( - appResourcesDir - ) - ? path.join(androidDirPath, constants.SRC_DIR, constants.MAIN_DIR) - : androidDirPath; + const androidManifestDir = + this.$androidResourcesMigrationService.hasMigrated(appResourcesDir) + ? path.join(androidDirPath, constants.SRC_DIR, constants.MAIN_DIR) + : androidDirPath; return path.join(androidManifestDir, constants.MANIFEST_FILE_NAME); } @@ -244,7 +243,8 @@ export class ProjectData implements IProjectData { } public getAppResourcesDirectoryPath(projectDir?: string): string { - const appResourcesRelativePath = this.getAppResourcesRelativeDirectoryPath(); + const appResourcesRelativePath = + this.getAppResourcesRelativeDirectoryPath(); return this.resolveToProjectDir(appResourcesRelativePath, projectDir); } diff --git a/lib/providers/project-files-provider.ts b/lib/providers/project-files-provider.ts index 1f3337f906..553e5241ab 100644 --- a/lib/providers/project-files-provider.ts +++ b/lib/providers/project-files-provider.ts @@ -54,7 +54,7 @@ export class ProjectFilesProvider extends ProjectFilesProviderBase { ); mappedFilePath = path.join( platformData.appDestinationDirectoryPath, - constants.APP_FOLDER_NAME, + this.$options.androidHostModule, relativePath ); } diff --git a/lib/services/android-plugin-build-service.ts b/lib/services/android-plugin-build-service.ts index 0ba08ec83c..b3301e6d0a 100644 --- a/lib/services/android-plugin-build-service.ts +++ b/lib/services/android-plugin-build-service.ts @@ -15,6 +15,7 @@ import { INodePackageManager, IAndroidToolsInfo, IWatchIgnoreListService, + IOptions, } from "../declarations"; import { IPlatformsDataService } from "../definitions/platform"; import { IProjectData, IProjectDataService } from "../definitions/project"; @@ -37,6 +38,7 @@ import { IInjector } from "../common/definitions/yok"; import { injector } from "../common/yok"; import * as _ from "lodash"; import { resolvePackageJSONPath } from "@rigor789/resolve-package-path"; +import { cwd } from "process"; export class AndroidPluginBuildService implements IAndroidPluginBuildService { private get $platformsDataService(): IPlatformsDataService { @@ -47,6 +49,7 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService { private $fs: IFileSystem, private $childProcess: IChildProcess, private $hostInfo: IHostInfo, + private $options: IOptions, private $androidToolsInfo: IAndroidToolsInfo, private $logger: ILogger, private $packageManager: INodePackageManager, @@ -803,6 +806,7 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService { `-PappPath=${this.$projectData.getAppDirectoryPath()}`, `-PappResourcesPath=${this.$projectData.getAppResourcesDirectoryPath()}`, ]; + if (pluginBuildSettings.gradleArgs) { localArgs.push(pluginBuildSettings.gradleArgs); } @@ -811,11 +815,28 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService { localArgs.push("--quiet"); } + const opts: any = { + cwd: pluginBuildSettings.pluginDir, + stdio: "inherit", + }; + + if (this.$options.androidHost) { + opts.env = { + USER_PROJECT_PLATFORMS_ANDROID: path.resolve( + cwd(), + this.$options.androidHost + ), // TODO: couldn't `androidHost` have an absolute path already? + ...process.env, // TODO: any other way to pass automatically the current process.env? + }; + } + try { - await this.$childProcess.spawnFromEvent(gradlew, localArgs, "close", { - cwd: pluginBuildSettings.pluginDir, - stdio: "inherit", - }); + await this.$childProcess.spawnFromEvent( + gradlew, + localArgs, + "close", + opts + ); } catch (err) { this.$errors.fail( `Failed to build plugin ${pluginBuildSettings.pluginName} : \n${err}` diff --git a/lib/services/android-project-service.ts b/lib/services/android-project-service.ts index 71335ef5b6..10ce7a633a 100644 --- a/lib/services/android-project-service.ts +++ b/lib/services/android-project-service.ts @@ -164,28 +164,30 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject ); } if (projectData && projectData.platformsDir) { - const projectRoot = path.join( - projectData.platformsDir, - AndroidProjectService.ANDROID_PLATFORM_NAME - ); + const projectRoot = this.$options.androidHost + ? this.$options.androidHost + : path.join( + projectData.platformsDir, + AndroidProjectService.ANDROID_PLATFORM_NAME + ); const appDestinationDirectoryArr = [ projectRoot, - constants.APP_FOLDER_NAME, + this.$options.androidHostModule, constants.SRC_DIR, constants.MAIN_DIR, constants.ASSETS_DIR, ]; const configurationsDirectoryArr = [ projectRoot, - constants.APP_FOLDER_NAME, + this.$options.androidHostModule, constants.SRC_DIR, constants.MAIN_DIR, constants.MANIFEST_FILE_NAME, ]; const deviceBuildOutputArr = [ projectRoot, - constants.APP_FOLDER_NAME, + this.$options.androidHostModule, constants.BUILD_DIR, constants.OUTPUTS_DIR, constants.APK_DIR, @@ -208,7 +210,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject if (buildOptions.androidBundle) { return path.join( projectRoot, - constants.APP_FOLDER_NAME, + this.$options.androidHostModule, constants.BUILD_DIR, constants.OUTPUTS_DIR, constants.BUNDLE_DIR @@ -227,8 +229,8 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject if (buildOptions.androidBundle) { return { packageNames: [ - `${constants.APP_FOLDER_NAME}${constants.AAB_EXTENSION_NAME}`, - `${constants.APP_FOLDER_NAME}-${buildMode}${constants.AAB_EXTENSION_NAME}`, + `${this.$options.androidHostModule}${constants.AAB_EXTENSION_NAME}`, + `${this.$options.androidHostModule}-${buildMode}${constants.AAB_EXTENSION_NAME}`, ], }; } @@ -238,11 +240,11 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject `${packageName}-${buildMode}${constants.APK_EXTENSION_NAME}`, `${projectData.projectName}-${buildMode}${constants.APK_EXTENSION_NAME}`, `${projectData.projectName}${constants.APK_EXTENSION_NAME}`, - `${constants.APP_FOLDER_NAME}-${buildMode}${constants.APK_EXTENSION_NAME}`, + `${this.$options.androidHostModule}-${buildMode}${constants.APK_EXTENSION_NAME}`, ], regexes: [ new RegExp( - `(${packageName}|${constants.APP_FOLDER_NAME})-.*-(${Configurations.Debug}|${Configurations.Release})(-unsigned)?${constants.APK_EXTENSION_NAME}`, + `(${packageName}|${this.$options.androidHostModule})-.*-(${Configurations.Debug}|${Configurations.Release})(-unsigned)?${constants.APK_EXTENSION_NAME}`, "i" ), ], @@ -266,10 +268,11 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject platformData: IPlatformData, projectData: IProjectData ): string { - const currentPlatformData: IDictionary = this.$projectDataService.getRuntimePackage( - projectData.projectDir, - platformData.platformNameLowerCase - ); + const currentPlatformData: IDictionary = + this.$projectDataService.getRuntimePackage( + projectData.projectDir, + platformData.platformNameLowerCase + ); return currentPlatformData && currentPlatformData[constants.VERSION_STRING]; } @@ -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); @@ -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, @@ -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, @@ -413,13 +416,13 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject public async interpolateData(projectData: IProjectData): Promise { // 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 @@ -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__/, @@ -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; @@ -568,7 +570,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject return this.$fs.exists( path.join( this.getPlatformData(projectData).appDestinationDirectoryPath, - constants.APP_FOLDER_NAME + this.$options.androidHostModule ) ); } @@ -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) { @@ -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( @@ -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.androidHost + ? this.$options.androidHost + : path.join( + projectData.platformsDir, + AndroidProjectService.ANDROID_PLATFORM_NAME + ); const dependenciesJsonPath = path.join( platformDir, constants.DEPENDENCIES_JSON_NAME @@ -874,7 +879,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject projectData: IProjectData ): string { const resourcePath: string[] = [ - constants.APP_FOLDER_NAME, + this.$options.androidHostModule, constants.SRC_DIR, constants.MAIN_DIR, constants.RESOURCES_DIR, @@ -890,7 +895,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject projectData: IProjectData ): string { const resourcePath: string[] = [ - constants.APP_FOLDER_NAME, + this.$options.androidHostModule, constants.SRC_DIR, ]; diff --git a/lib/services/assets-generation/assets-generation-service.ts b/lib/services/assets-generation/assets-generation-service.ts index 01177c3704..b7e380965e 100644 --- a/lib/services/assets-generation/assets-generation-service.ts +++ b/lib/services/assets-generation/assets-generation-service.ts @@ -4,6 +4,7 @@ import { exported } from "../../common/decorators"; import { AssetConstants } from "../../constants"; import { IAssetsGenerationService, + IOptions, IResourceGenerationData, } from "../../declarations"; import { @@ -34,13 +35,18 @@ export class AssetsGenerationService implements IAssetsGenerationService { constructor( private $logger: ILogger, private $projectDataService: IProjectDataService, - private $fs: IFileSystem + private $fs: IFileSystem, + private $options: IOptions ) {} @exported("assetsGenerationService") public async generateIcons( resourceGenerationData: IResourceGenerationData ): Promise { + if (this.$options.androidHost) { + return; + } + this.$logger.info("Generating icons ..."); await this.generateImagesForDefinitions( resourceGenerationData, @@ -53,6 +59,10 @@ export class AssetsGenerationService implements IAssetsGenerationService { public async generateSplashScreens( splashesGenerationData: IResourceGenerationData ): Promise { + if (this.$options.androidHost) { + return; + } + this.$logger.info("Generating splash screens ..."); await this.generateImagesForDefinitions( splashesGenerationData, diff --git a/lib/services/files-hash-service.ts b/lib/services/files-hash-service.ts index a29881f227..23ad8124d8 100644 --- a/lib/services/files-hash-service.ts +++ b/lib/services/files-hash-service.ts @@ -1,15 +1,20 @@ import { executeActionByChunks } from "../common/helpers"; import { DEFAULT_CHUNK_SIZE } from "../common/constants"; -import { APP_FOLDER_NAME, HASHES_FILE_NAME } from "../constants"; +import { HASHES_FILE_NAME } from "../constants"; import * as path from "path"; import * as _ from "lodash"; import { IFilesHashService } from "../definitions/files-hash-service"; import { IPlatformData } from "../definitions/platform"; import { IFileSystem, IStringDictionary } from "../common/declarations"; import { injector } from "../common/yok"; +import { IOptions } from "../declarations"; export class FilesHashService implements IFilesHashService { - constructor(private $fs: IFileSystem, private $logger: ILogger) {} + constructor( + private $fs: IFileSystem, + private $logger: ILogger, + private $options: IOptions + ) {} public async generateHashes(files: string[]): Promise { const result: IStringDictionary = {}; @@ -37,7 +42,7 @@ export class FilesHashService implements IFilesHashService { ): Promise { const appFilesPath = path.join( platformData.appDestinationDirectoryPath, - APP_FOLDER_NAME + this.$options.androidHostModule ); const files = this.$fs.enumerateFilesInDirectorySync(appFilesPath); const hashes = await this.generateHashes(files); diff --git a/lib/services/livesync/android-device-livesync-sockets-service.ts b/lib/services/livesync/android-device-livesync-sockets-service.ts index 14dc23693a..59867ea0b0 100644 --- a/lib/services/livesync/android-device-livesync-sockets-service.ts +++ b/lib/services/livesync/android-device-livesync-sockets-service.ts @@ -1,5 +1,4 @@ import { AndroidDeviceLiveSyncServiceBase } from "./android-device-livesync-service-base"; -import { APP_FOLDER_NAME } from "../../constants"; import { LiveSyncPaths } from "../../common/constants"; import { AndroidLivesyncTool } from "./android-livesync-tool"; import * as path from "path"; @@ -19,7 +18,8 @@ export class AndroidDeviceSocketsLiveSyncService extends AndroidDeviceLiveSyncServiceBase implements IAndroidNativeScriptDeviceLiveSyncService, - INativeScriptDeviceLiveSyncService { + INativeScriptDeviceLiveSyncService +{ private livesyncTool: IAndroidLivesyncTool; private static STATUS_UPDATE_INTERVAL = 10000; private static MINIMAL_VERSION_LONG_LIVING_CONNECTION = "0.2.0"; @@ -279,7 +279,7 @@ export class AndroidDeviceSocketsLiveSyncService ); const projectFilesPath = path.join( platformData.appDestinationDirectoryPath, - APP_FOLDER_NAME + this.$options.androidHostModule ); if (!this.livesyncTool.hasConnection()) { await this.livesyncTool.connect({ diff --git a/lib/services/livesync/android-livesync-service.ts b/lib/services/livesync/android-livesync-service.ts index 366c121cb0..8ff185ca0d 100644 --- a/lib/services/livesync/android-livesync-service.ts +++ b/lib/services/livesync/android-livesync-service.ts @@ -13,10 +13,12 @@ import { } from "../../common/declarations"; import { IInjector } from "../../common/definitions/yok"; import { injector } from "../../common/yok"; +import { IOptions } from "../../declarations"; export class AndroidLiveSyncService extends PlatformLiveSyncServiceBase - implements IPlatformLiveSyncService { + implements IPlatformLiveSyncService +{ private static MIN_SOCKETS_LIVESYNC_RUNTIME_VERSION = "4.2.0-2018-07-20-02"; constructor( protected $platformsDataService: IPlatformsDataService, @@ -24,14 +26,16 @@ export class AndroidLiveSyncService private $injector: IInjector, $devicePathProvider: IDevicePathProvider, $fs: IFileSystem, - $logger: ILogger + $logger: ILogger, + $options: IOptions ) { super( $fs, $logger, $platformsDataService, $projectFilesManager, - $devicePathProvider + $devicePathProvider, + $options ); } diff --git a/lib/services/livesync/ios-livesync-service.ts b/lib/services/livesync/ios-livesync-service.ts index 6ea6b6e2e1..2ead95e8ac 100644 --- a/lib/services/livesync/ios-livesync-service.ts +++ b/lib/services/livesync/ios-livesync-service.ts @@ -13,10 +13,12 @@ import { import { IInjector } from "../../common/definitions/yok"; import { injector } from "../../common/yok"; import { ITempService } from "../../definitions/temp-service"; +import { IOptions } from "../../declarations"; export class IOSLiveSyncService extends PlatformLiveSyncServiceBase - implements IPlatformLiveSyncService { + implements IPlatformLiveSyncService +{ constructor( protected $fs: IFileSystem, protected $platformsDataService: IPlatformsDataService, @@ -24,14 +26,16 @@ export class IOSLiveSyncService private $injector: IInjector, private $tempService: ITempService, $devicePathProvider: IDevicePathProvider, - $logger: ILogger + $logger: ILogger, + $options: IOptions ) { super( $fs, $logger, $platformsDataService, $projectFilesManager, - $devicePathProvider + $devicePathProvider, + $options ); } @@ -59,9 +63,8 @@ export class IOSLiveSyncService }); this.$logger.trace("Creating zip file: " + tempZip); - const filesToTransfer = this.$fs.enumerateFilesInDirectorySync( - projectFilesPath - ); + const filesToTransfer = + this.$fs.enumerateFilesInDirectorySync(projectFilesPath); await this.$fs.zipFiles(tempZip, filesToTransfer, (res) => { return path.join(APP_FOLDER_NAME, path.relative(projectFilesPath, res)); diff --git a/lib/services/livesync/platform-livesync-service-base.ts b/lib/services/livesync/platform-livesync-service-base.ts index 099334c0df..20d03f15eb 100644 --- a/lib/services/livesync/platform-livesync-service-base.ts +++ b/lib/services/livesync/platform-livesync-service-base.ts @@ -12,18 +12,19 @@ import { IProjectFilesManager, } from "../../common/declarations"; import { color } from "../../color"; +import { IOptions } from "../../declarations"; export abstract class PlatformLiveSyncServiceBase { - private _deviceLiveSyncServicesCache: IDictionary< - INativeScriptDeviceLiveSyncService - > = {}; + private _deviceLiveSyncServicesCache: IDictionary = + {}; constructor( protected $fs: IFileSystem, protected $logger: ILogger, protected $platformsDataService: IPlatformsDataService, protected $projectFilesManager: IProjectFilesManager, - private $devicePathProvider: IDevicePathProvider + private $devicePathProvider: IDevicePathProvider, + private $options: IOptions ) {} public getDeviceLiveSyncService( @@ -35,9 +36,8 @@ export abstract class PlatformLiveSyncServiceBase { device.deviceInfo.platform, projectData ); - const frameworkVersion = platformData.platformProjectService.getFrameworkVersion( - projectData - ); + const frameworkVersion = + platformData.platformProjectService.getFrameworkVersion(projectData); const key = getHash( `${device.deviceInfo.identifier}${projectData.projectIdentifiers[platform]}${projectData.projectDir}${frameworkVersion}` ); @@ -135,14 +135,15 @@ export abstract class PlatformLiveSyncServiceBase { const projectFilesPath = path.join( platformData.appDestinationDirectoryPath, - APP_FOLDER_NAME - ); - const localToDevicePaths = await this.$projectFilesManager.createLocalToDevicePaths( - deviceAppData, - projectFilesPath, - null, - [] + this.$options.androidHostModule ); + const localToDevicePaths = + await this.$projectFilesManager.createLocalToDevicePaths( + deviceAppData, + projectFilesPath, + null, + [] + ); const modifiedFilesData = await this.transferFiles( deviceAppData, localToDevicePaths, @@ -200,14 +201,15 @@ export abstract class PlatformLiveSyncServiceBase { ); const projectFilesPath = path.join( platformData.appDestinationDirectoryPath, - APP_FOLDER_NAME - ); - const localToDevicePaths = await this.$projectFilesManager.createLocalToDevicePaths( - deviceAppData, - projectFilesPath, - existingFiles, - [] + this.$options.androidHostModule ); + const localToDevicePaths = + await this.$projectFilesManager.createLocalToDevicePaths( + deviceAppData, + projectFilesPath, + existingFiles, + [] + ); modifiedLocalToDevicePaths.push(...localToDevicePaths); modifiedLocalToDevicePaths = await this.transferFiles( deviceAppData, @@ -235,12 +237,13 @@ export abstract class PlatformLiveSyncServiceBase { platformData.appDestinationDirectoryPath, APP_FOLDER_NAME ); - const localToDevicePaths = await this.$projectFilesManager.createLocalToDevicePaths( - deviceAppData, - projectFilesPath, - mappedFiles, - [] - ); + const localToDevicePaths = + await this.$projectFilesManager.createLocalToDevicePaths( + deviceAppData, + projectFilesPath, + mappedFiles, + [] + ); modifiedLocalToDevicePaths.push(...localToDevicePaths); await deviceLiveSyncService.removeFiles( diff --git a/lib/services/log-source-map-service.ts b/lib/services/log-source-map-service.ts index 39d6012a53..e0431e8da5 100644 --- a/lib/services/log-source-map-service.ts +++ b/lib/services/log-source-map-service.ts @@ -20,6 +20,7 @@ import { } from "../common/declarations"; import { IInjector } from "../common/definitions/yok"; import { injector } from "../common/yok"; +import { IOptions } from "../declarations"; interface IParsedMessage { filePath?: string; @@ -53,6 +54,7 @@ export class LogSourceMapService implements Mobile.ILogSourceMapService { private $fs: IFileSystem, private $projectDataService: IProjectDataService, private $injector: IInjector, + private $options: IOptions, private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants, private $logger: ILogger ) { @@ -191,7 +193,7 @@ export class LogSourceMapService implements Mobile.ILogSourceMapService { ): IFileLocation { const fileLocation = path.join( this.getFilesLocation(platform, projectData), - APP_FOLDER_NAME + this.$options.androidHostModule ); if (parsedLine && parsedLine.filePath) { diff --git a/lib/services/platform/add-platform-service.ts b/lib/services/platform/add-platform-service.ts index 138063f4d3..fa1ec5cc78 100644 --- a/lib/services/platform/add-platform-service.ts +++ b/lib/services/platform/add-platform-service.ts @@ -13,13 +13,14 @@ import { import { IProjectData } from "../../definitions/project"; //IProjectDataService import { IAnalyticsService, IFileSystem } from "../../common/declarations"; import { injector } from "../../common/yok"; -import { IPackageManager } from "../../declarations"; +import { IOptions, IPackageManager } from "../../declarations"; import { ITerminalSpinnerService } from "../../definitions/terminal-spinner-service"; export class AddPlatformService implements IAddPlatformService { constructor( private $fs: IFileSystem, private $logger: ILogger, + private $options: IOptions, // private $pacoteService: IPacoteService, // private $projectDataService: IProjectDataService, private $packageManager: IPackageManager, @@ -182,10 +183,12 @@ export class AddPlatformService implements IAddPlatformService { frameworkDirPath: string, frameworkVersion: string ): Promise { - const platformDir = path.join( - projectData.platformsDir, - platformData.normalizedPlatformName.toLowerCase() - ); + const platformDir = this.$options.androidHost + ? this.$options.androidHost + : path.join( + projectData.platformsDir, + platformData.normalizedPlatformName.toLowerCase() + ); this.$fs.deleteDirectory(platformDir); await platformData.platformProjectService.createProject( diff --git a/lib/services/platform/prepare-native-platform-service.ts b/lib/services/platform/prepare-native-platform-service.ts index 10e59ab563..2c2c05e4c3 100644 --- a/lib/services/platform/prepare-native-platform-service.ts +++ b/lib/services/platform/prepare-native-platform-service.ts @@ -6,14 +6,17 @@ import { IProjectData } from "../../definitions/project"; import { IMetadataFilteringService } from "../../definitions/metadata-filtering-service"; import { IHooksService } from "../../common/declarations"; import { injector } from "../../common/yok"; +import { IOptions } from "../../declarations"; export class PrepareNativePlatformService - implements IPrepareNativePlatformService { + implements IPrepareNativePlatformService +{ constructor( public $hooksService: IHooksService, private $nodeModulesBuilder: INodeModulesBuilder, private $projectChangesService: IProjectChangesService, - private $metadataFilteringService: IMetadataFilteringService + private $metadataFilteringService: IMetadataFilteringService, + private $options: IOptions ) {} @performanceLog() @@ -45,7 +48,9 @@ export class PrepareNativePlatformService await this.cleanProject(platformData, { release }); } - platformData.platformProjectService.prepareAppResources(projectData); + if (!this.$options.androidHost) { + platformData.platformProjectService.prepareAppResources(projectData); + } if (hasChangesRequirePrepare) { await platformData.platformProjectService.prepareProject( @@ -98,9 +103,8 @@ export class PrepareNativePlatformService return; } - const previousPrepareInfo = this.$projectChangesService.getPrepareInfo( - platformData - ); + const previousPrepareInfo = + this.$projectChangesService.getPrepareInfo(platformData); if ( !previousPrepareInfo || previousPrepareInfo.nativePlatformStatus !== diff --git a/lib/services/plugins-service.ts b/lib/services/plugins-service.ts index 46c45b23ec..747b02b937 100644 --- a/lib/services/plugins-service.ts +++ b/lib/services/plugins-service.ts @@ -787,7 +787,7 @@ This framework comes from ${dependencyName} plugin, which is installed multiple ); const pluginDestinationPath = path.join( platformData.appDestinationDirectoryPath, - constants.APP_FOLDER_NAME, + this.$options.androidHostModule, "tns_modules" ); await action( @@ -860,6 +860,9 @@ This framework comes from ${dependencyName} plugin, which is installed multiple private getAllPluginsNativeHashes( pathToPluginsBuildFile: string ): IDictionary { + if (this.$options.androidHost) { + return {}; // TODO: force rebuild plugins for now until we decide where to put .ns-plugins-build-data.json when embedding + } let data: IDictionary = {}; if (this.$fs.exists(pathToPluginsBuildFile)) { data = this.$fs.readJson(pathToPluginsBuildFile); @@ -874,6 +877,10 @@ This framework comes from ${dependencyName} plugin, which is installed multiple currentPluginNativeHashes: IStringDictionary; allPluginsNativeHashes: IDictionary; }): void { + if (this.$options.androidHost) { + return; // TODO: force rebuild plugins for now until we decide where to put .ns-plugins-build-data.json when embedding + } + opts.allPluginsNativeHashes[opts.pluginData.name] = opts.currentPluginNativeHashes; this.$fs.writeJson( diff --git a/lib/services/project-changes-service.ts b/lib/services/project-changes-service.ts index edb9b2593d..d17066da42 100644 --- a/lib/services/project-changes-service.ts +++ b/lib/services/project-changes-service.ts @@ -23,6 +23,7 @@ import { } from "../definitions/project-changes"; import * as _ from "lodash"; import { injector } from "../common/yok"; +import { IOptions } from "../declarations"; const prepareInfoFileName = ".nsprepareinfo"; @@ -62,6 +63,7 @@ export class ProjectChangesService implements IProjectChangesService { private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants, private $fs: IFileSystem, private $logger: ILogger, + private $options: IOptions, public $hooksService: IHooksService, private $nodeModulesDependenciesBuilder: INodeModulesDependenciesBuilder ) {} @@ -223,6 +225,10 @@ export class ProjectChangesService implements IProjectChangesService { } public getPrepareInfo(platformData: IPlatformData): IPrepareInfo { + if (this.$options.androidHost) { + return null; // TODO: always prepare for now until we decide where to keep the .nsprepareinfo file when embedding + } + const prepareInfoFilePath = this.getPrepareInfoFilePath(platformData); let prepareInfo: IPrepareInfo = null; if (this.$fs.exists(prepareInfoFilePath)) { @@ -245,6 +251,10 @@ export class ProjectChangesService implements IProjectChangesService { await this.ensurePrepareInfo(platformData, projectData, prepareData); } + if (this.$options.androidHost) { + return null; // TODO: do not save for now until we decide where to keep the .nsprepareinfo file when embedding + } + const prepareInfoFilePath = this.getPrepareInfoFilePath(platformData); this.$fs.writeJson(prepareInfoFilePath, this._prepareInfo); } diff --git a/lib/services/project-data-service.ts b/lib/services/project-data-service.ts index abc917c424..112ec05d16 100644 --- a/lib/services/project-data-service.ts +++ b/lib/services/project-data-service.ts @@ -246,9 +246,8 @@ export class ProjectDataService implements IProjectDataService { // ignore } - const content = this.getImageDefinitions()[ - useLegacy ? "android_legacy" : "android" - ]; + const content = + this.getImageDefinitions()[useLegacy ? "android_legacy" : "android"]; return { icons: this.getAndroidAssetSubGroup(content.icons, basePath), diff --git a/lib/services/webpack/webpack-compiler-service.ts b/lib/services/webpack/webpack-compiler-service.ts index 4590fbc895..f4378a0e1a 100644 --- a/lib/services/webpack/webpack-compiler-service.ts +++ b/lib/services/webpack/webpack-compiler-service.ts @@ -163,10 +163,18 @@ export class WebpackCompilerService }; } const files = result.emittedFiles.map((file: string) => - path.join(platformData.appDestinationDirectoryPath, "app", file) + path.join( + platformData.appDestinationDirectoryPath, + this.$options.androidHostModule, + file + ) ); const fallbackFiles = result.fallbackFiles.map((file: string) => - path.join(platformData.appDestinationDirectoryPath, "app", file) + path.join( + platformData.appDestinationDirectoryPath, + this.$options.androidHostModule, + file + ) ); const data = { @@ -342,10 +350,21 @@ export class WebpackCompilerService } const stdio = prepareData.watch ? ["ipc"] : "inherit"; - const childProcess = this.$childProcess.spawn(process.execPath, args, { + const options: { [key: string]: any } = { cwd: projectData.projectDir, stdio, - }); + }; + if (this.$options.androidHost) { + options.env = { + USER_PROJECT_PLATFORMS_ANDROID: this.$options.androidHost, + USER_PROJECT_PLATFORMS_ANDROID_MODULE: this.$options.androidHostModule, + }; + } + const childProcess = this.$childProcess.spawn( + process.execPath, + args, + options + ); this.webpackProcesses[platformData.platformNameLowerCase] = childProcess; await this.$cleanupService.addKillProcess(childProcess.pid.toString()); @@ -553,10 +572,18 @@ export class WebpackCompilerService this.$logger.trace("Webpack build done!"); const files = message.data.emittedAssets.map((asset: string) => - path.join(platformData.appDestinationDirectoryPath, "app", asset) + path.join( + platformData.appDestinationDirectoryPath, + this.$options.androidHostModule, + asset + ) ); const staleFiles = message.data.staleAssets.map((asset: string) => - path.join(platformData.appDestinationDirectoryPath, "app", asset) + path.join( + platformData.appDestinationDirectoryPath, + this.$options.androidHostModule, + asset + ) ); // extract last hash from emitted filenames diff --git a/package-lock.json b/package-lock.json index a90298e2f3..1763e4855a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1833,6 +1833,15 @@ "node": ">=14" } }, + "node_modules/@pkgjs/parseargs": { + "version": "0.11.0", + "resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz", + "integrity": "sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==", + "optional": true, + "engines": { + "node": ">=14" + } + }, "node_modules/@prettier/plugin-xml": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/@prettier/plugin-xml/-/plugin-xml-2.2.0.tgz", @@ -2243,6 +2252,20 @@ "form-data": "^4.0.0" } }, + "node_modules/@types/node-fetch/node_modules/form-data": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.1.tgz", + "integrity": "sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==", + "dev": true, + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/@types/normalize-package-data": { "version": "2.4.3", "resolved": "https://registry.npmjs.org/@types/normalize-package-data/-/normalize-package-data-2.4.3.tgz", @@ -8668,6 +8691,11 @@ "resolved": "https://registry.npmjs.org/json-parse-even-better-errors/-/json-parse-even-better-errors-2.3.1.tgz", "integrity": "sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w==" }, + "node_modules/meow/node_modules/json-parse-even-better-errors": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/json-parse-even-better-errors/-/json-parse-even-better-errors-2.3.1.tgz", + "integrity": "sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w==" + }, "node_modules/meow/node_modules/locate-path": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", diff --git a/vendor/gradle-plugin/build.gradle b/vendor/gradle-plugin/build.gradle index 38092efde4..9778f33d62 100644 --- a/vendor/gradle-plugin/build.gradle +++ b/vendor/gradle-plugin/build.gradle @@ -8,8 +8,27 @@ apply plugin: 'kotlin-android' apply plugin: 'kotlin-parcelize' buildscript { + // project.ext.USER_PROJECT_ROOT = "$rootDir/../../.." + project.ext.PLATFORMS_ANDROID = "platforms/android" + project.ext.PLUGIN_NAME = "{{pluginName}}" + + def USER_PROJECT_ROOT_FROM_ENV = System.getenv('USER_PROJECT_ROOT'); + if (USER_PROJECT_ROOT_FROM_ENV != null && !USER_PROJECT_ROOT_FROM_ENV.equals("")) { + project.ext.USER_PROJECT_ROOT = USER_PROJECT_ROOT_FROM_ENV; + } else { + project.ext.USER_PROJECT_ROOT = "$rootDir/../../../" + } + + def USER_PROJECT_PLATFORMS_ANDROID_FROM_ENV = System.getenv('USER_PROJECT_PLATFORMS_ANDROID'); + if (USER_PROJECT_PLATFORMS_ANDROID_FROM_ENV != null && !USER_PROJECT_PLATFORMS_ANDROID_FROM_ENV.equals("")) { + project.ext.USER_PROJECT_PLATFORMS_ANDROID = USER_PROJECT_PLATFORMS_ANDROID_FROM_ENV; + } else { + project.ext.USER_PROJECT_PLATFORMS_ANDROID = project.ext.USER_PROJECT_ROOT + PLATFORMS_ANDROID + } + + def getDepPlatformDir = { dep -> - file("${project.ext.USER_PROJECT_ROOT}/${project.ext.PLATFORMS_ANDROID}/${dep.directory}/$PLATFORMS_ANDROID") + file("${project.ext.USER_PROJECT_PLATFORMS_ANDROID}/${dep.directory}/$PLATFORMS_ANDROID") } def computeKotlinVersion = { -> project.hasProperty("kotlinVersion") ? kotlinVersion : "1.8.20" } def kotlinVersion = computeKotlinVersion() @@ -29,12 +48,8 @@ buildscript { project.ext.getDepPlatformDir = getDepPlatformDir project.ext.outLogger = services.get(StyledTextOutputFactory).create("colouredOutputLogger") - project.ext.USER_PROJECT_ROOT = "$rootDir/../../.." - project.ext.PLATFORMS_ANDROID = "platforms/android" - project.ext.PLUGIN_NAME = "{{pluginName}}" - // the build script will not work with previous versions of the CLI (3.1 or earlier) - def dependenciesJson = file("${project.ext.USER_PROJECT_ROOT}/${project.ext.PLATFORMS_ANDROID}/dependencies.json") + def dependenciesJson = file("${project.ext.USER_PROJECT_PLATFORMS_ANDROID}/dependencies.json") def appDependencies = new JsonSlurper().parseText(dependenciesJson.text) def pluginData = appDependencies.find { it.name == project.ext.PLUGIN_NAME } project.ext.nativescriptDependencies = appDependencies.findAll{pluginData.dependencies.contains(it.name)} diff --git a/vendor/gradle-plugin/settings.gradle b/vendor/gradle-plugin/settings.gradle index ac173898e3..82d60e2d88 100644 --- a/vendor/gradle-plugin/settings.gradle +++ b/vendor/gradle-plugin/settings.gradle @@ -1,16 +1,26 @@ import groovy.json.JsonSlurper -def USER_PROJECT_ROOT = "$rootDir/../../../" +// def USER_PROJECT_ROOT = "$rootDir/../../../" def PLATFORMS_ANDROID = "platforms/android" def PLUGIN_NAME = "{{pluginName}}" -def dependenciesJson = file("${USER_PROJECT_ROOT}/${PLATFORMS_ANDROID}/dependencies.json") +def USER_PROJECT_PLATFORMS_ANDROID +def USER_PROJECT_PLATFORMS_ANDROID_FROM_ENV = System.getenv('USER_PROJECT_PLATFORMS_ANDROID'); +if (USER_PROJECT_PLATFORMS_ANDROID_FROM_ENV != null && !USER_PROJECT_PLATFORMS_ANDROID_FROM_ENV.equals("")) { + USER_PROJECT_PLATFORMS_ANDROID = USER_PROJECT_PLATFORMS_ANDROID_FROM_ENV; +} else { + USER_PROJECT_PLATFORMS_ANDROID = "$rootDir/../../../platforms/android" +} + +System.out.println("!!!!! VM: USER_PROJECT_PLATFORMS_ANDROID: " + USER_PROJECT_PLATFORMS_ANDROID); + +def dependenciesJson = file("${USER_PROJECT_PLATFORMS_ANDROID}/dependencies.json") def appDependencies = new JsonSlurper().parseText(dependenciesJson.text) def pluginData = appDependencies.find { it.name == PLUGIN_NAME } def nativescriptDependencies = appDependencies.findAll{pluginData.name == it.name} def getDepPlatformDir = { dep -> - file("$USER_PROJECT_ROOT/$PLATFORMS_ANDROID/${dep.directory}/$PLATFORMS_ANDROID") + file("$USER_PROJECT_PLATFORMS_ANDROID/${dep.directory}/$PLATFORMS_ANDROID") } def applyIncludeSettingsGradlePlugin = { From 8453205ecda6fd2c4ef0d16d59ea0d5aa73dce27 Mon Sep 17 00:00:00 2001 From: Nathan Walker Date: Tue, 28 May 2024 10:24:19 -0700 Subject: [PATCH 2/2] feat: use nativeHost for all platforms --- lib/controllers/prepare-controller.ts | 6 +++--- lib/providers/project-files-provider.ts | 2 +- lib/services/files-hash-service.ts | 2 +- .../livesync/android-device-livesync-sockets-service.ts | 2 +- lib/services/livesync/platform-livesync-service-base.ts | 4 ++-- lib/services/log-source-map-service.ts | 2 +- lib/services/plugins-service.ts | 6 +++--- lib/services/project-changes-service.ts | 4 ++-- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/controllers/prepare-controller.ts b/lib/controllers/prepare-controller.ts index 329f50fb14..2cebc5ff38 100644 --- a/lib/controllers/prepare-controller.ts +++ b/lib/controllers/prepare-controller.ts @@ -135,7 +135,7 @@ export class PrepareController extends EventEmitter { projectData: IProjectData ): Promise { await this.$projectService.ensureAppResourcesExist(projectData.projectDir); - if (!this.$options.androidHost) { + if (!this.$options.nativeHost) { await this.$platformController.addPlatformIfNeeded( prepareData, projectData @@ -483,9 +483,9 @@ export class PrepareController extends EventEmitter { console.log("!!!!! VM: proj root: " + platformData.projectRoot); packagePath = path.join( platformData.projectRoot, - this.$options.androidHostModule, + this.$options.nativeHostModule, "src", - this.$options.androidHost ? "nativescript" : "main", + this.$options.nativeHost ? "nativescript" : "main", "assets", "app", "package.json" diff --git a/lib/providers/project-files-provider.ts b/lib/providers/project-files-provider.ts index 553e5241ab..6ce80f787f 100644 --- a/lib/providers/project-files-provider.ts +++ b/lib/providers/project-files-provider.ts @@ -54,7 +54,7 @@ export class ProjectFilesProvider extends ProjectFilesProviderBase { ); mappedFilePath = path.join( platformData.appDestinationDirectoryPath, - this.$options.androidHostModule, + this.$options.nativeHostModule, relativePath ); } diff --git a/lib/services/files-hash-service.ts b/lib/services/files-hash-service.ts index 23ad8124d8..50758e4533 100644 --- a/lib/services/files-hash-service.ts +++ b/lib/services/files-hash-service.ts @@ -42,7 +42,7 @@ export class FilesHashService implements IFilesHashService { ): Promise { const appFilesPath = path.join( platformData.appDestinationDirectoryPath, - this.$options.androidHostModule + this.$options.nativeHostModule ); const files = this.$fs.enumerateFilesInDirectorySync(appFilesPath); const hashes = await this.generateHashes(files); diff --git a/lib/services/livesync/android-device-livesync-sockets-service.ts b/lib/services/livesync/android-device-livesync-sockets-service.ts index 59867ea0b0..037145b05a 100644 --- a/lib/services/livesync/android-device-livesync-sockets-service.ts +++ b/lib/services/livesync/android-device-livesync-sockets-service.ts @@ -279,7 +279,7 @@ export class AndroidDeviceSocketsLiveSyncService ); const projectFilesPath = path.join( platformData.appDestinationDirectoryPath, - this.$options.androidHostModule + this.$options.nativeHostModule ); if (!this.livesyncTool.hasConnection()) { await this.livesyncTool.connect({ diff --git a/lib/services/livesync/platform-livesync-service-base.ts b/lib/services/livesync/platform-livesync-service-base.ts index 20d03f15eb..37293cf7ba 100644 --- a/lib/services/livesync/platform-livesync-service-base.ts +++ b/lib/services/livesync/platform-livesync-service-base.ts @@ -135,7 +135,7 @@ export abstract class PlatformLiveSyncServiceBase { const projectFilesPath = path.join( platformData.appDestinationDirectoryPath, - this.$options.androidHostModule + this.$options.nativeHostModule ); const localToDevicePaths = await this.$projectFilesManager.createLocalToDevicePaths( @@ -201,7 +201,7 @@ export abstract class PlatformLiveSyncServiceBase { ); const projectFilesPath = path.join( platformData.appDestinationDirectoryPath, - this.$options.androidHostModule + this.$options.nativeHostModule ); const localToDevicePaths = await this.$projectFilesManager.createLocalToDevicePaths( diff --git a/lib/services/log-source-map-service.ts b/lib/services/log-source-map-service.ts index 62b640346b..df119c398d 100644 --- a/lib/services/log-source-map-service.ts +++ b/lib/services/log-source-map-service.ts @@ -202,7 +202,7 @@ export class LogSourceMapService implements Mobile.ILogSourceMapService { ): IFileLocation { const fileLocation = path.join( this.getFilesLocation(platform, projectData), - this.$options.androidHostModule + this.$options.nativeHostModule ); if (parsedLine && parsedLine.filePath) { diff --git a/lib/services/plugins-service.ts b/lib/services/plugins-service.ts index bc79e466d8..e8defc5178 100644 --- a/lib/services/plugins-service.ts +++ b/lib/services/plugins-service.ts @@ -803,7 +803,7 @@ This framework comes from ${dependencyName} plugin, which is installed multiple ); const pluginDestinationPath = path.join( platformData.appDestinationDirectoryPath, - this.$options.androidHostModule, + this.$options.nativeHostModule, "tns_modules" ); await action( @@ -876,7 +876,7 @@ This framework comes from ${dependencyName} plugin, which is installed multiple private getAllPluginsNativeHashes( pathToPluginsBuildFile: string ): IDictionary { - if (this.$options.androidHost) { + if (this.$options.nativeHost) { return {}; // TODO: force rebuild plugins for now until we decide where to put .ns-plugins-build-data.json when embedding } let data: IDictionary = {}; @@ -893,7 +893,7 @@ This framework comes from ${dependencyName} plugin, which is installed multiple currentPluginNativeHashes: IStringDictionary; allPluginsNativeHashes: IDictionary; }): void { - if (this.$options.androidHost) { + if (this.$options.nativeHost) { return; // TODO: force rebuild plugins for now until we decide where to put .ns-plugins-build-data.json when embedding } diff --git a/lib/services/project-changes-service.ts b/lib/services/project-changes-service.ts index 2ab52dbb28..10ada01108 100644 --- a/lib/services/project-changes-service.ts +++ b/lib/services/project-changes-service.ts @@ -237,7 +237,7 @@ export class ProjectChangesService implements IProjectChangesService { } public getPrepareInfo(platformData: IPlatformData): IPrepareInfo { - if (this.$options.androidHost) { + if (this.$options.nativeHost) { return null; // TODO: always prepare for now until we decide where to keep the .nsprepareinfo file when embedding } @@ -263,7 +263,7 @@ export class ProjectChangesService implements IProjectChangesService { await this.ensurePrepareInfo(platformData, projectData, prepareData); } - if (this.$options.androidHost) { + if (this.$options.nativeHost) { return null; // TODO: do not save for now until we decide where to keep the .nsprepareinfo file when embedding }