diff --git a/hooks/unzipSound.js b/hooks/unzipSound.js index 98914b5b..7ae91aed 100644 --- a/hooks/unzipSound.js +++ b/hooks/unzipSound.js @@ -62,35 +62,24 @@ module.exports = function(context) { let soundFolderPath = platformConfig.getSoundDestinationFolder(); soundFolderPath = path.join(context.opts.projectRoot, soundFolderPath); - let soundZipFile = path.join(sourcePath, constants.soundZipFile); + let zipFile = utils.getFileName(sourcePath, "sounds", ".zip"); + let promises = []; - if(utils.checkIfFileOrFolderExists(soundZipFile)){ - let zip = new AdmZip(soundZipFile); - zip.extractAllTo(sourcePath, true); + + if(zipFile != ""){ + let soundZipFilePath = path.join(sourcePath, zipFile); + let zip = new AdmZip(soundZipFilePath); + let zipFolder = sourcePath + "/sounds" + zip.extractAllTo(zipFolder, true); let entriesNr = zip.getEntries().length; console.log(`FCM_LOG: Sound zip file has ${entriesNr} entries`); if(entriesNr == 0) { throw new Error (`OUTSYSTEMS_PLUGIN_ERROR: Sound zip file is empty, either delete it or add one or more files.`) } - - let zipFolder = sourcePath + "/sounds" - if(!utils.checkIfFileOrFolderExists(zipFolder)){ - console.log(`FCM_LOG: No new folder unzipping.`) - /** - * to deal with the following case: - * iOS + one file in zip + O11 - **/ - if(sourcePath != soundFolderPath){ - console.log(`FCM_LOG: ${sourcePath} != ${soundFolderPath} so we need to copy files.`) - promises = copyWavFiles(platformConfig, sourcePath, soundFolderPath, defer) - } else { - console.log(`FCM_LOG: ${sourcePath} == ${soundFolderPath} so we don't need to copy files.`) - } - } else { - promises = copyWavFiles(platformConfig, zipFolder, soundFolderPath, defer) - } + promises = copyWavFiles(platformConfig, zipFolder, soundFolderPath, defer) + } return promises.length > 0 ? q.all(promises) : defer.resolve(); } diff --git a/hooks/utilities.js b/hooks/utilities.js index 9fe5ff5f..33a49f9c 100644 --- a/hooks/utilities.js +++ b/hooks/utilities.js @@ -13,7 +13,7 @@ var constants = { return "platforms/android/app/src/main/res/raw"; }, getWWWFolder: function() { - return "www"; + return "platforms/android/app/src/main/assets/www"; } }, ios: { @@ -33,6 +33,14 @@ function checkIfFileOrFolderExists(path) { return fs.existsSync(path); } + +function getFileName(dir, searchString, withExtension){ + const files = fs.readdirSync(dir); + const matchingFiles = files.filter(file => file.includes(searchString) && file.endsWith(withExtension)); + // return true if there are matching files, false otherwise + return matchingFiles.length > 0 ?matchingFiles[0] : ""; +} + function removeFile(path){ fs.unlinkSync(path) } @@ -61,20 +69,7 @@ function getPlatformConfigs(platform) { function getPlatformSoundPath(context, platformConfig){ let projectRoot = context.opts.projectRoot; - let platformPath; - - if(platformConfig === constants.android){ - platformPath = path.join(projectRoot, `platforms/android/www`); - } else { - let appName = getAppName(context) - platformPath = path.join(projectRoot, `platforms/ios/${appName}/Resources/www`); - } - - if(!fs.existsSync(platformPath)){ - platformPath = path.join(projectRoot, platformConfig.getWWWFolder()); - } - - return platformPath + return path.join(projectRoot, platformConfig.getWWWFolder()); } function isCordovaAbove(context, version) { @@ -116,5 +111,6 @@ module.exports = { removeFolder, isAndroid, getAppName, - getPlatformSoundPath + getPlatformSoundPath, + getFileName }; \ No newline at end of file