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