Skip to content

Commit 0fbadb5

Browse files
committed
Fix LiveSync when webpack plugin is used
1 parent 8655173 commit 0fbadb5

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

lib/services/platform-service.ts

+16-3
Original file line numberDiff line numberDiff line change
@@ -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,9 +711,22 @@ 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+
// 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
719+
if (!this.$fs.exists(platformData.configurationFilePath) && this.isPlatformInstalled(platform, projectData) && appFilesUpdaterOptions.bundle) {
720+
const tmpDirectoryPath = path.join(projectData.projectDir, "platforms", "tmp");
721+
this.$fs.deleteDirectory(tmpDirectoryPath);
722+
this.$fs.ensureDirectoryExists(tmpDirectoryPath);
723+
this.$fs.copyFile(path.join(platformData.appDestinationDirectoryPath, "*"), tmpDirectoryPath);
724+
await this.addPlatform(platform, platformTemplate, projectData, config, "", nativePrepare);
725+
this.$fs.copyFile(path.join(tmpDirectoryPath, "*"), platformData.appDestinationDirectoryPath);
726+
this.$fs.deleteDirectory(tmpDirectoryPath);
727+
return;
728+
}
729+
717730
if (!this.isPlatformInstalled(platform, projectData)) {
718731
await this.addPlatform(platform, platformTemplate, projectData, config, "", nativePrepare);
719732
} else {

0 commit comments

Comments
 (0)