Skip to content

Commit

Permalink
feat: assume sound file is a resource
Browse files Browse the repository at this point in the history
- for ODC, this means the name won't be exact so we need filter the files by a search string
- unzipping files always to a specific folder name (sounds)
  • Loading branch information
OS-martacarlos committed Apr 9, 2024
1 parent db30be7 commit 6445169
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The changes documented here do not include those from the original repository.

## [Unreleased]

- Feat: Deal with `sounds` as a resource in ODC. (https://outsystemsrd.atlassian.net/browse/RMET-3315)
- Fix: Make `cleanUp` hook only run after all sound files are copied successfully. (https://outsystemsrd.atlassian.net/browse/RMET-3326)
- Chore: Update cordova hooks with new OutSystems specific errors. (https://outsystemsrd.atlassian.net/browse/RMET-3302)
- Chore: Update `FirebaseMessaging` iOS pod to version `10.23.0`. This includes the Privacy Manifest (https://outsystemsrd.atlassian.net/browse/RMET-3274).
Expand Down
31 changes: 10 additions & 21 deletions hooks/unzipSound.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
17 changes: 14 additions & 3 deletions hooks/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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)
}
Expand Down Expand Up @@ -63,6 +71,7 @@ function getPlatformSoundPath(context, platformConfig){
let projectRoot = context.opts.projectRoot;
let platformPath;

/**
if(platformConfig === constants.android){
platformPath = path.join(projectRoot, `platforms/android/www`);
} else {
Expand All @@ -71,8 +80,9 @@ function getPlatformSoundPath(context, platformConfig){
}
if(!fs.existsSync(platformPath)){
*/
platformPath = path.join(projectRoot, platformConfig.getWWWFolder());
}
// }

return platformPath
}
Expand Down Expand Up @@ -116,5 +126,6 @@ module.exports = {
removeFolder,
isAndroid,
getAppName,
getPlatformSoundPath
getPlatformSoundPath,
getFileName
};

0 comments on commit 6445169

Please sign in to comment.