on-uninstall.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. const fs = require('fs');
  2. const path = require('path');
  3. const xml2js = require('xml2js');
  4. const PLUGIN_ID = "cordova-plugin-semsx-launcher";
  5. const androidPlatformRoot = "./platforms/android/";
  6. let deferral;
  7. function removeKotlinSourceFiles(){
  8. const pluginXML = fs.readFileSync('./plugins/'+PLUGIN_ID+'/plugin.xml').toString();
  9. const parser = new xml2js.Parser();
  10. parser.parseString(pluginXML, (error, config) => {
  11. if (error) return;
  12. if (!config.plugin.hasOwnProperty('platform')) return;
  13. for (let platform of config.plugin.platform)
  14. if (platform['$'].name === 'android') {
  15. if (platform.hasOwnProperty('source-file')){
  16. let sourceFiles = platform['source-file'];
  17. for(let sourceFile of sourceFiles){
  18. if (sourceFile['$'].hasOwnProperty('src')){
  19. let src = sourceFile['$']['src'];
  20. if(src.match(/\.kt/)){
  21. let srcParts = src.split('/');
  22. let filename = srcParts[srcParts.length - 1];
  23. let filepath = sourceFile['$']['target-dir'];
  24. filepath = androidPlatformRoot+filepath+'/'+filename;
  25. if(fs.existsSync(path.resolve(filepath))){
  26. fs.unlinkSync(filepath);
  27. console.log("Removed Kotlin source file: "+filepath);
  28. }
  29. }
  30. }
  31. }
  32. }
  33. break;
  34. }
  35. });
  36. }
  37. module.exports = function(ctx) {
  38. try{
  39. deferral = ctx.requireCordovaModule('q').defer();
  40. removeKotlinSourceFiles();
  41. deferral.resolve();
  42. }catch(e){
  43. let msg = e.toString();
  44. console.dir(e);
  45. deferral.reject(msg);
  46. return deferral.promise;
  47. }
  48. };