diff --git a/hooks/cleanUp.js b/hooks/cleanUp.js
index dd17b0ac..d3a92369 100644
--- a/hooks/cleanUp.js
+++ b/hooks/cleanUp.js
@@ -8,14 +8,23 @@ var constants = {
};
module.exports = function(context) {
- var platform = context.opts.plugin.platform;
- var platformConfig = utils.getPlatformConfigs(platform);
+ let cordovaAbove8 = utils.isCordovaAbove(context, 8);
+ let defer;
+ if (cordovaAbove8) {
+ defer = require("q").defer();
+ } else {
+ defer = context.requireCordovaModule("q").defer();
+ }
+
+ let platform = context.opts.platforms[0];
+ let platformConfig = utils.getPlatformConfigs(platform);
+
if (!platformConfig) {
utils.handleError("Invalid platform", defer);
}
- var sourcePath = platformConfig.getSoundSourceFolder();
- var soundFolderPath = path.join(sourcePath, constants.soundFolder);
+ let sourcePath = utils.getPlatformSoundPath(context, platformConfig)
+ let soundFolderPath = path.join(sourcePath, constants.soundFolder);
if(utils.checkIfFileOrFolderExists(soundFolderPath)){
utils.removeFolder(soundFolderPath);
diff --git a/hooks/installDependencies.js b/hooks/installDependencies.js
deleted file mode 100644
index d227623e..00000000
--- a/hooks/installDependencies.js
+++ /dev/null
@@ -1,27 +0,0 @@
-var utils = require('./utilities');
-
-module.exports = function (context) {
- var cordovaAbove8 = utils.isCordovaAbove(context, 8);
- var child_process;
- var deferral;
-
- if (cordovaAbove8) {
- child_process = require('child_process');
- deferral = require('q').defer();
- } else {
- child_process = context.requireCordovaModule('child_process');
- deferral = context.requireCordovaModule('q').defer();
- }
-
- var output = child_process.exec('npm install', {cwd: __dirname}, function (error) {
- if (error !== null) {
- console.log('exec error: ' + error);
- deferral.reject('npm installation failed');
- }
- else {
- deferral.resolve();
- }
- });
-
- return deferral.promise;
-};
\ No newline at end of file
diff --git a/hooks/package.json b/hooks/package.json
deleted file mode 100644
index bfb1d2fd..00000000
--- a/hooks/package.json
+++ /dev/null
@@ -1,5 +0,0 @@
-{
- "dependencies": {
- "adm-zip": "0.4.11"
- }
-}
\ No newline at end of file
diff --git a/hooks/unzipSound.js b/hooks/unzipSound.js
index c168a01e..edde0fd1 100644
--- a/hooks/unzipSound.js
+++ b/hooks/unzipSound.js
@@ -1,6 +1,6 @@
"use strict";
-var path = require("path");
+let path = require("path");
var utils = require("./utilities");
var AdmZip = require("adm-zip");
@@ -15,6 +15,7 @@ function copyWavFiles(platformConfig, source, dest, defer) {
return file.endsWith(platformConfig.soundFileExtension) == true;
});
+ console.log("Nr of sound files in zip: ", filteredFiles.length)
copyFiles(filteredFiles, source, dest, defer)
}
@@ -28,56 +29,53 @@ function copyFiles(files, source, dest, defer){
utils.createOrCheckIfFolderExists(dest);
}
- for(var i = 0; i < files.length; i++) {
- var filePath = path.join(source, files[i]);
- var destFilePath = path.join(dest, files[i]);
+ for(const element of files) {
+ let filePath = path.join(source, element);
+ let destFilePath = path.join(dest, element);
utils.copyFromSourceToDestPath(defer, filePath, destFilePath);
}
}
module.exports = function(context) {
- var cordovaAbove8 = utils.isCordovaAbove(context, 8);
- var defer;
+ let cordovaAbove8 = utils.isCordovaAbove(context, 8);
+ let defer;
if (cordovaAbove8) {
defer = require("q").defer();
} else {
defer = context.requireCordovaModule("q").defer();
}
- var platform = context.opts.plugin.platform;
- var platformConfig = utils.getPlatformConfigs(platform);
+ let platform = context.opts.platforms[0];
+ let platformConfig = utils.getPlatformConfigs(platform);
if (!platformConfig) {
utils.handleError("Invalid platform", defer);
}
- var sourcePath = platformConfig.getSoundSourceFolder();
- var soundFolderPath = platformConfig.getSoundDestinationFolder();
+ let sourcePath = utils.getPlatformSoundPath(context, platformConfig)
+ let soundFolderPath = platformConfig.getSoundDestinationFolder();
- var soundZipFile = path.join(sourcePath, constants.soundZipFile);
+ let soundZipFile = path.join(sourcePath, constants.soundZipFile);
if(utils.checkIfFileOrFolderExists(soundZipFile)){
- var zip = new AdmZip(soundZipFile);
+ let zip = new AdmZip(soundZipFile);
zip.extractAllTo(sourcePath, true);
- var entriesNr = zip.getEntries().length;
- console.log("Number of entries in zip file: ", entriesNr);
+ let entriesNr = zip.getEntries().length;
if(entriesNr == 0) {
utils.handleError("Sound zip file is empty, either delete it or add one or more files", defer);
return
}
- var zipFolder = sourcePath + "/sounds"
+ let zipFolder = sourcePath + "/sounds"
if(!utils.checkIfFileOrFolderExists(zipFolder)){
- if(utils.isAndroid(platform))
- copyWavFiles(platformConfig, sourcePath, soundFolderPath, defer)
- } else {
- var files = utils.getFilesFromPath(zipFolder);
- copyFiles(files, zipFolder, soundFolderPath, defer)
+ copyWavFiles(platformConfig, sourcePath, soundFolderPath, defer)
+ } else {
+ copyWavFiles(platformConfig, zipFolder, soundFolderPath, defer)
}
- utils.removeFile(soundZipFile);
+ //utils.removeFile(soundZipFile);
}
}
diff --git a/hooks/utilities.js b/hooks/utilities.js
index 401fc681..dc507749 100644
--- a/hooks/utilities.js
+++ b/hooks/utilities.js
@@ -7,12 +7,12 @@ var constants = {
platforms: "platforms",
android: {
platform: "android",
- wwwFolder: "assets/www",
+ wwwFolder: "www",
soundFileExtension: ".wav",
getSoundDestinationFolder: function() {
return "platforms/android/app/src/main/res/raw";
},
- getSoundSourceFolder: function() {
+ getWWWFolder: function() {
return "www";
}
},
@@ -21,10 +21,10 @@ var constants = {
wwwFolder: "www",
soundFileExtension: ".wav",
getSoundDestinationFolder: function() {
- return "www";
+ return "platforms/ios/www";
},
- getSoundSourceFolder: function() {
- return "www";
+ getWWWFolder: function() {
+ return "platforms/ios/www";
}
}
};
@@ -44,7 +44,7 @@ function removeFile(path){
}
function removeFolder(path){
- fs.rmdirSync(path, { recursive: true })
+ fs.rmSync(path, { recursive: true })
}
function getFilesFromPath(path) {
@@ -65,6 +65,24 @@ 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
+}
+
function isCordovaAbove(context, version) {
let cordovaVersion = context.opts.cordova.version;
let sp = cordovaVersion.split('.');
@@ -87,6 +105,12 @@ function isAndroid(platform){
return platform === constants.android.platform
}
+function getAppName(context) {
+ let ConfigParser = context.requireCordovaModule("cordova-lib").configparser;
+ let config = new ConfigParser("config.xml");
+ return config.name();
+}
+
module.exports = {
isCordovaAbove,
handleError,
@@ -97,5 +121,7 @@ module.exports = {
checkIfFileOrFolderExists,
removeFile,
removeFolder,
- isAndroid
+ isAndroid,
+ getAppName,
+ getPlatformSoundPath
};
\ No newline at end of file
diff --git a/package.json b/package.json
index 809ed0ea..1c1c9ef5 100644
--- a/package.json
+++ b/package.json
@@ -14,5 +14,8 @@
"android"
]
},
- "engines": []
+ "engines": [],
+ "dependencies": {
+ "adm-zip": "0.4.11"
+ }
}
diff --git a/plugin.xml b/plugin.xml
index 851d200b..96a983d3 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -8,9 +8,10 @@
-
-
-
+
+
+
+