From fde440342f2b2205982506891533f58db5418e64 Mon Sep 17 00:00:00 2001 From: Janos Hrubos <33330538+janoshrubos@users.noreply.github.com> Date: Tue, 26 Jan 2021 19:19:23 +0100 Subject: [PATCH] feat: warn invalid platform folders (#5463) * feat: handle empty platforms folder * chore: shorter warning message Co-authored-by: Igor Randjelovic * fix: platformDirectoryItemCount variable name * chore: explaining platformDirectoryItemCount check Co-authored-by: Igor Randjelovic Co-authored-by: Igor Randjelovic --- lib/controllers/platform-controller.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/controllers/platform-controller.ts b/lib/controllers/platform-controller.ts index 2203c1a56e..e0e2b99974 100644 --- a/lib/controllers/platform-controller.ts +++ b/lib/controllers/platform-controller.ts @@ -143,6 +143,23 @@ export class PlatformController implements IPlatformController { const hasPlatformDirectory = this.$fs.exists( path.join(projectData.platformsDir, platformName) ); + + if (hasPlatformDirectory) { + const platformDirectoryItemCount = this.$fs.readDirectory( + path.join(projectData.platformsDir, platformName) + ).length; + + // 5 is a magic number to approximate a valid platform folder + // any valid platform should contain at least 5 files + // we choose 5 to avoid false-positives due to system files like .DS_Store etc. + if (platformDirectoryItemCount <= 5) { + this.$logger.warn( + `The platforms/${platformName} folder appears to be invalid. If the build fails, run 'ns clean' and rebuild the app.`, + { wrapMessageWithBorders: true } + ); + } + } + const shouldAddNativePlatform = !nativePrepare || !nativePrepare.skipNativePrepare; const prepareInfo = this.$projectChangesService.getPrepareInfo(