@@ -263,7 +263,7 @@ export class PlatformService extends EventEmitter implements IPlatformService {
263
263
this . $errors . failWithoutHelp ( `Unable to install dependencies. Make sure your package.json is valid and all dependencies are correct. Error is: ${ err . message } ` ) ;
264
264
}
265
265
266
- await this . ensurePlatformInstalled ( platform , platformTemplate , projectData , config , nativePrepare ) ;
266
+ await this . ensurePlatformInstalled ( platform , platformTemplate , projectData , config , appFilesUpdaterOptions , nativePrepare ) ;
267
267
268
268
const bundle = appFilesUpdaterOptions . bundle ;
269
269
const nativePlatformStatus = ( nativePrepare && nativePrepare . skipNativePrepare ) ? constants . NativePlatformStatus . requiresPlatformAdd : constants . NativePlatformStatus . requiresPrepare ;
@@ -603,7 +603,7 @@ export class PlatformService extends EventEmitter implements IPlatformService {
603
603
604
604
@helpers . hook ( 'cleanApp' )
605
605
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 ) ;
607
607
608
608
const platformData = this . $platformsData . getPlatformData ( platformInfo . platform , platformInfo . projectData ) ;
609
609
const appDestinationDirectoryPath = path . join ( platformData . appDestinationDirectoryPath , constants . APP_FOLDER_NAME ) ;
@@ -711,14 +711,27 @@ export class PlatformService extends EventEmitter implements IPlatformService {
711
711
}
712
712
}
713
713
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 > {
715
715
let requiresNativePlatformAdd = false ;
716
716
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
+
717
731
if ( ! this . isPlatformInstalled ( platform , projectData ) ) {
718
732
await this . addPlatform ( platform , platformTemplate , projectData , config , "" , nativePrepare ) ;
719
733
} else {
720
734
const shouldAddNativePlatform = ! nativePrepare || ! nativePrepare . skipNativePrepare ;
721
- const prepareInfo = this . $projectChangesService . getPrepareInfo ( platform , projectData ) ;
722
735
// 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.
723
736
requiresNativePlatformAdd = prepareInfo && prepareInfo . nativePlatformStatus === constants . NativePlatformStatus . requiresPlatformAdd ;
724
737
if ( requiresNativePlatformAdd && shouldAddNativePlatform ) {
0 commit comments