@@ -263,7 +263,7 @@ export class PlatformService extends EventEmitter implements IPlatformService {
263263 this . $errors . failWithoutHelp ( `Unable to install dependencies. Make sure your package.json is valid and all dependencies are correct. Error is: ${ err . message } ` ) ;
264264 }
265265
266- await this . ensurePlatformInstalled ( platform , platformTemplate , projectData , config , nativePrepare ) ;
266+ await this . ensurePlatformInstalled ( platform , platformTemplate , projectData , config , appFilesUpdaterOptions , nativePrepare ) ;
267267
268268 const bundle = appFilesUpdaterOptions . bundle ;
269269 const nativePlatformStatus = ( nativePrepare && nativePrepare . skipNativePrepare ) ? constants . NativePlatformStatus . requiresPlatformAdd : constants . NativePlatformStatus . requiresPrepare ;
@@ -603,7 +603,7 @@ export class PlatformService extends EventEmitter implements IPlatformService {
603603
604604 @helpers . hook ( 'cleanApp' )
605605 public async cleanDestinationApp ( platformInfo : IPreparePlatformInfo ) : Promise < void > {
606- await this . ensurePlatformInstalled ( platformInfo . platform , platformInfo . platformTemplate , platformInfo . projectData , platformInfo . config , platformInfo . nativePrepare ) ;
606+ await this . ensurePlatformInstalled ( platformInfo . platform , platformInfo . platformTemplate , platformInfo . projectData , platformInfo . config , platformInfo . appFilesUpdaterOptions , platformInfo . nativePrepare ) ;
607607
608608 const platformData = this . $platformsData . getPlatformData ( platformInfo . platform , platformInfo . projectData ) ;
609609 const appDestinationDirectoryPath = path . join ( platformData . appDestinationDirectoryPath , constants . APP_FOLDER_NAME ) ;
@@ -711,14 +711,27 @@ export class PlatformService extends EventEmitter implements IPlatformService {
711711 }
712712 }
713713
714- public async ensurePlatformInstalled ( platform : string , platformTemplate : string , projectData : IProjectData , config : IPlatformOptions , nativePrepare ?: INativePrepare ) : Promise < void > {
714+ public async ensurePlatformInstalled ( platform : string , platformTemplate : string , projectData : IProjectData , config : IPlatformOptions , appFilesUpdaterOptions : IAppFilesUpdaterOptions , nativePrepare ?: INativePrepare ) : Promise < void > {
715715 let requiresNativePlatformAdd = false ;
716716
717+ const platformData = this . $platformsData . getPlatformData ( platform , projectData ) ;
718+ const prepareInfo = this . $projectChangesService . getPrepareInfo ( platform , projectData ) ;
719+ // In case when no platform is added and webpack plugin is started it produces files in platforms folder. In this case {N} CLI needs to add platform and keeps the already produced files from webpack
720+ if ( appFilesUpdaterOptions . bundle && this . isPlatformInstalled ( platform , projectData ) && ! this . $fs . exists ( platformData . configurationFilePath ) && ( ! prepareInfo || ! prepareInfo . nativePlatformStatus || prepareInfo . nativePlatformStatus !== constants . NativePlatformStatus . alreadyPrepared ) ) {
721+ const tmpDirectoryPath = path . join ( projectData . projectDir , "platforms" , "tmp" ) ;
722+ this . $fs . deleteDirectory ( tmpDirectoryPath ) ;
723+ this . $fs . ensureDirectoryExists ( tmpDirectoryPath ) ;
724+ this . $fs . copyFile ( path . join ( platformData . appDestinationDirectoryPath , "*" ) , tmpDirectoryPath ) ;
725+ await this . addPlatform ( platform , platformTemplate , projectData , config , "" , nativePrepare ) ;
726+ this . $fs . copyFile ( path . join ( tmpDirectoryPath , "*" ) , platformData . appDestinationDirectoryPath ) ;
727+ this . $fs . deleteDirectory ( tmpDirectoryPath ) ;
728+ return ;
729+ }
730+
717731 if ( ! this . isPlatformInstalled ( platform , projectData ) ) {
718732 await this . addPlatform ( platform , platformTemplate , projectData , config , "" , nativePrepare ) ;
719733 } else {
720734 const shouldAddNativePlatform = ! nativePrepare || ! nativePrepare . skipNativePrepare ;
721- const prepareInfo = this . $projectChangesService . getPrepareInfo ( platform , projectData ) ;
722735 // In case there's no prepare info, it means only platform add had been executed. So we've come from CLI and we do not need to prepare natively.
723736 requiresNativePlatformAdd = prepareInfo && prepareInfo . nativePlatformStatus === constants . NativePlatformStatus . requiresPlatformAdd ;
724737 if ( requiresNativePlatformAdd && shouldAddNativePlatform ) {
0 commit comments