-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RMET-2378 Cloud Messaging Plugin - Hook for sound files (#52)
* feat: first version of hook to copy sound files References: https://outsystemsrd.atlassian.net/browse/RMET-2378 * chore: save current progress * refactor: remove comment * refactor: remove unnecessary code from hook References: https://outsystemsrd.atlassian.net/browse/RMET-2378 * refactor: remove unnecessary functions References: https://outsystemsrd.atlassian.net/browse/RMET-2378 * chore: update libs References: https://outsystemsrd.atlassian.net/browse/RMET-2378 * chore: update changelog * refactor: replace var with let * refactor: replace var with let * refactor: use let instead of var * chore: update lib version
- Loading branch information
1 parent
04f9b1f
commit de58b46
Showing
6 changed files
with
136 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
"use strict"; | ||
|
||
var path = require("path"); | ||
var utils = require("./utilities"); | ||
|
||
module.exports = function(context) { | ||
let cordovaAbove8 = utils.isCordovaAbove(context, 8); | ||
let defer; | ||
if (cordovaAbove8) { | ||
defer = require("q").defer(); | ||
} else { | ||
defer = context.requireCordovaModule("q").defer(); | ||
} | ||
|
||
let platform = context.opts.plugin.platform; | ||
let platformConfig = utils.getPlatformConfigs(platform); | ||
if (!platformConfig) { | ||
utils.handleError("Invalid platform", defer); | ||
} | ||
|
||
let sourceFolderPath = platformConfig.getSoundSourceFolder() | ||
let destFolderPath = platformConfig.getSoundDestinationFolder() | ||
|
||
if(!utils.checkIfFolderExists(destFolderPath)) { | ||
utils.createOrCheckIfFolderExists(destFolderPath) | ||
} | ||
|
||
let files = utils.getFilesFromPath(sourceFolderPath); | ||
if (!files) { | ||
utils.handleError("No directory found", defer); | ||
} | ||
else { | ||
let filteredFiles = files.filter(function(file){ | ||
return file.endsWith(platformConfig.soundFileExtension) == true; | ||
}); | ||
|
||
filteredFiles.forEach(function (f) { | ||
let filePath = path.join(sourceFolderPath, f); | ||
let destFilePath = path.join(destFolderPath, f); | ||
utils.copyFromSourceToDestPath(defer, filePath, destFilePath); | ||
}); | ||
} | ||
|
||
return defer.promise; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
"use strict" | ||
|
||
var path = require("path"); | ||
var fs = require("fs"); | ||
|
||
var utils = require("./utils"); | ||
|
||
var constants = { | ||
platforms: "platforms", | ||
android: { | ||
platform: "android", | ||
wwwFolder: "assets/www", | ||
soundFileExtension: ".wav", | ||
getSoundDestinationFolder: function() { | ||
return "platforms/android/app/src/main/res/raw"; | ||
}, | ||
getSoundSourceFolder: function() { | ||
return "platforms/android/app/src/main/assets/www"; | ||
} | ||
} | ||
}; | ||
|
||
function handleError(errorMessage, defer) { | ||
console.log(errorMessage); | ||
defer.reject(); | ||
} | ||
|
||
function checkIfFolderExists(path) { | ||
return fs.existsSync(path); | ||
} | ||
|
||
function getFilesFromPath(path) { | ||
return fs.readdirSync(path); | ||
} | ||
|
||
function createOrCheckIfFolderExists(path) { | ||
if (!fs.existsSync(path)) { | ||
fs.mkdirSync(path); | ||
} | ||
} | ||
|
||
function getPlatformConfigs(platform) { | ||
if (platform === constants.android.platform) { | ||
return constants.android; | ||
} else if (platform === constants.ios.platform) { | ||
return constants.ios; | ||
} | ||
} | ||
|
||
function isCordovaAbove(context, version) { | ||
let cordovaVersion = context.opts.cordova.version; | ||
console.log(cordovaVersion); | ||
let sp = cordovaVersion.split('.'); | ||
return parseInt(sp[0]) >= version; | ||
} | ||
|
||
|
||
function copyFromSourceToDestPath(defer, sourcePath, destPath) { | ||
fs.createReadStream(sourcePath).pipe(fs.createWriteStream(destPath)) | ||
.on("close", function (err) { | ||
defer.resolve(); | ||
}) | ||
.on("error", function (err) { | ||
console.log(err); | ||
defer.reject(); | ||
}); | ||
} | ||
|
||
module.exports = { | ||
isCordovaAbove, | ||
handleError, | ||
getPlatformConfigs, | ||
copyFromSourceToDestPath, | ||
getFilesFromPath, | ||
createOrCheckIfFolderExists, | ||
checkIfFolderExists | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = { | ||
getAppName: function (context) { | ||
let ConfigParser = context.requireCordovaModule("cordova-lib").configparser; | ||
let config = new ConfigParser("config.xml"); | ||
return config.name(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters