Skip to content

Commit

Permalink
Revert "RMET-3315 :: Hook :: ODC :: Sound as a resource (#88)"
Browse files Browse the repository at this point in the history
This reverts commit eaa56cf.

# Conflicts:
#	CHANGELOG.md
  • Loading branch information
OS-ricardomoreirasilva committed Apr 12, 2024
1 parent b7f4510 commit 268e148
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 26 deletions.
4 changes: 0 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

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)

## 2.1.0

- Fix: Make `cleanUp` hook only run after all sound files are copied successfully. (https://outsystemsrd.atlassian.net/browse/RMET-3326)
Expand Down
31 changes: 21 additions & 10 deletions hooks/unzipSound.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,35 @@ module.exports = function(context) {
let soundFolderPath = platformConfig.getSoundDestinationFolder();
soundFolderPath = path.join(context.opts.projectRoot, soundFolderPath);

let zipFile = utils.getFileName(sourcePath, "sounds", ".zip");

let soundZipFile = path.join(sourcePath, constants.soundZipFile);
let promises = [];

if(zipFile != ""){
let soundZipFilePath = path.join(sourcePath, zipFile);
let zip = new AdmZip(soundZipFilePath);
let zipFolder = sourcePath + "/sounds"
zip.extractAllTo(zipFolder, true);
if(utils.checkIfFileOrFolderExists(soundZipFile)){
let zip = new AdmZip(soundZipFile);
zip.extractAllTo(sourcePath, 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"

promises = copyWavFiles(platformConfig, zipFolder, soundFolderPath, defer)

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)
}
}
return promises.length > 0 ? q.all(promises) : defer.resolve();
}
28 changes: 16 additions & 12 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 "platforms/android/app/src/main/assets/www";
return "www";
}
},
ios: {
Expand All @@ -33,14 +33,6 @@ 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 @@ -69,7 +61,20 @@ function getPlatformConfigs(platform) {

function getPlatformSoundPath(context, platformConfig){
let projectRoot = context.opts.projectRoot;
return path.join(projectRoot, platformConfig.getWWWFolder());
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
}

function isCordovaAbove(context, version) {
Expand Down Expand Up @@ -111,6 +116,5 @@ module.exports = {
removeFolder,
isAndroid,
getAppName,
getPlatformSoundPath,
getFileName
getPlatformSoundPath
};

0 comments on commit 268e148

Please sign in to comment.