diff --git a/lib/definitions/plugins.d.ts b/lib/definitions/plugins.d.ts index 99c50b7893..24926cd12a 100644 --- a/lib/definitions/plugins.d.ts +++ b/lib/definitions/plugins.d.ts @@ -12,6 +12,8 @@ interface IPluginsService { */ getDependenciesFromPackageJson(projectDir: string): IPackageJsonDepedenciesResult; validate(platformData: IPlatformData, projectData: IProjectData): Promise; + preparePluginNativeCode(pluginData: IPluginData, platform: string, projectData: IProjectData): Promise; + convertToPluginData(cacheData: any, projectDir: string): IPluginData; } interface IPackageJsonDepedenciesResult { diff --git a/lib/services/platform-service.ts b/lib/services/platform-service.ts index 8b92bc5a19..f1a3bd5b94 100644 --- a/lib/services/platform-service.ts +++ b/lib/services/platform-service.ts @@ -39,7 +39,8 @@ export class PlatformService extends EventEmitter implements IPlatformService { private $npm: INodePackageManager, private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants, private $projectChangesService: IProjectChangesService, - private $analyticsService: IAnalyticsService) { + private $analyticsService: IAnalyticsService, + private $nodeModulesDependenciesBuilder: INodeModulesDependenciesBuilder) { super(); } @@ -223,13 +224,17 @@ export class PlatformService extends EventEmitter implements IPlatformService { let platformData = this.$platformsData.getPlatformData(platform, projectData); await this.$pluginsService.validate(platformData, projectData); + const bundle = appFilesUpdaterOptions.bundle; + await this.ensurePlatformInstalled(platform, platformTemplate, projectData, config); - let changesInfo = this.$projectChangesService.checkForChanges(platform, projectData, { bundle: appFilesUpdaterOptions.bundle, release: appFilesUpdaterOptions.release, provision: config.provision }); + let changesInfo = this.$projectChangesService.checkForChanges(platform, projectData, { bundle, release: appFilesUpdaterOptions.release, provision: config.provision }); this.$logger.trace("Changes info in prepare platform:", changesInfo); if (changesInfo.hasChanges) { await this.cleanProject(platform, appFilesUpdaterOptions, platformData, projectData); + } + if (changesInfo.hasChanges || bundle) { await this.preparePlatformCore(platform, appFilesUpdaterOptions, projectData, config, changesInfo, filesToSync); this.$projectChangesService.savePrepareInfo(platform, projectData); } else { @@ -302,6 +307,16 @@ export class PlatformService extends EventEmitter implements IPlatformService { if (!changesInfo || changesInfo.modulesChanged) { await this.copyTnsModules(platform, projectData); + } else if (appFilesUpdaterOptions.bundle) { + let dependencies = this.$nodeModulesDependenciesBuilder.getProductionDependencies(projectData.projectDir); + for (let dependencyKey in dependencies) { + const dependency = dependencies[dependencyKey]; + let isPlugin = !!dependency.nativescript; + if (isPlugin) { + let pluginData = this.$pluginsService.convertToPluginData(dependency, projectData.projectDir); + await this.$pluginsService.preparePluginNativeCode(pluginData, platform, projectData); + } + } } let directoryPath = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME); diff --git a/lib/services/plugins-service.ts b/lib/services/plugins-service.ts index c1fae529f9..df436d5e9d 100644 --- a/lib/services/plugins-service.ts +++ b/lib/services/plugins-service.ts @@ -139,7 +139,7 @@ export class PluginsService implements IPluginsService { this.$projectFilesManager.processPlatformSpecificFiles(pluginScriptsDestinationPath, platform); } - private async preparePluginNativeCode(pluginData: IPluginData, platform: string, projectData: IProjectData): Promise { + public async preparePluginNativeCode(pluginData: IPluginData, platform: string, projectData: IProjectData): Promise { let platformData = this.$platformsData.getPlatformData(platform, projectData); pluginData.pluginPlatformsFolderPath = (_platform: string) => path.join(pluginData.fullPath, "platforms", _platform); @@ -228,7 +228,7 @@ export class PluginsService implements IPluginsService { }; } - private convertToPluginData(cacheData: any, projectDir: string): IPluginData { + public convertToPluginData(cacheData: any, projectDir: string): IPluginData { let pluginData: any = {}; pluginData.name = cacheData.name; pluginData.version = cacheData.version; diff --git a/test/platform-commands.ts b/test/platform-commands.ts index 9c5b8ee2d9..63288c0261 100644 --- a/test/platform-commands.ts +++ b/test/platform-commands.ts @@ -96,6 +96,7 @@ function createTestInjector() { testInjector.register("injector", testInjector); testInjector.register("hooksService", stubs.HooksServiceStub); testInjector.register("staticConfig", StaticConfigLib.StaticConfig); + testInjector.register("nodeModulesDependenciesBuilder", {}); testInjector.register('platformService', PlatformServiceLib.PlatformService); testInjector.register('errors', ErrorsNoFailStub); testInjector.register('logger', stubs.LoggerStub); diff --git a/test/platform-service.ts b/test/platform-service.ts index d8898f0b26..e4ce0e5352 100644 --- a/test/platform-service.ts +++ b/test/platform-service.ts @@ -30,6 +30,7 @@ function createTestInjector() { testInjector.register('platformService', PlatformServiceLib.PlatformService); testInjector.register('errors', stubs.ErrorsStub); testInjector.register('logger', stubs.LoggerStub); + testInjector.register("nodeModulesDependenciesBuilder", {}); testInjector.register('npmInstallationManager', stubs.NpmInstallationManagerStub); testInjector.register('projectData', stubs.ProjectDataStub); testInjector.register('platformsData', stubs.PlatformsDataStub);