-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
61 changed files
with
10,868 additions
and
8 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,53 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const xml2js = require('xml2js'); | ||
const Q = require('q'); | ||
|
||
const PLUGIN_ID = "cordova-plugin-measure"; | ||
const androidPlatformRoot = "./platforms/android/"; | ||
|
||
const deferral = Q.defer(); | ||
|
||
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{ | ||
removeKotlinSourceFiles(); | ||
deferral.resolve(); | ||
}catch(e){ | ||
let msg = e.toString(); | ||
console.dir(e); | ||
deferral.reject(msg); | ||
return deferral.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,59 @@ | ||
const fs = require('fs'); | ||
const xml2js = require('xml2js'); | ||
const Q = require('q'); | ||
|
||
const PLUGIN_ID = "cordova-plugin-measure"; | ||
const gradlePath = './platforms/android/app/build.gradle'; // cordova-android@7+ path | ||
|
||
const deferral = Q.defer(); | ||
|
||
function addSupport(){ | ||
let defaultArgs = { | ||
kotlin_version: '\text.kotlin_version = "latest.integration"\n\t', | ||
kotlin_android: 'apply plugin: "kotlin-android"', | ||
classpath: ' \t\tclasspath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"' | ||
}; | ||
const pluginXML = fs.readFileSync('./plugins/'+PLUGIN_ID+'/plugin.xml').toString(); | ||
const gradle = fs.readFileSync(gradlePath).toString(); | ||
let text = gradle; | ||
const parser = new xml2js.Parser(); | ||
parser.parseString(pluginXML, (error, config) => { | ||
if (error) return; | ||
if (!config.plugin.hasOwnProperty('platform')) return; | ||
for (let x of config.plugin.platform) | ||
if (x['$'].name === 'android') { | ||
if (x['$'].hasOwnProperty('kotlin')) defaultArgs.kotlin_version = `\text.kotlin_version = "${x['$'].kotlin}"\n\t`; | ||
if (x.hasOwnProperty('apply-plugin')) defaultArgs.apply_plugin = x['apply-plugin']; | ||
break; | ||
} | ||
if (!gradle.match(/ext.kotlin_version/g)) append(defaultArgs.kotlin_version, /buildscript(\s*)\{\s*/g); | ||
if (!gradle.match(/kotlin-gradle-plugin/g)) append(defaultArgs.classpath, /classpath\s+(['"])[\w.:]+(['"])/g); | ||
if (!gradle.match(/apply\s+plugin(\s*:\s*)(['"])kotlin-android(['"])/g)) append(defaultArgs.kotlin_android); | ||
if (defaultArgs.apply_plugin) | ||
for (let x of defaultArgs.apply_plugin) { | ||
const reg = new RegExp(`apply\\s+plugin(\\s*:\\s*)(['"])${x}(['"])`, 'g'); | ||
if (!gradle.match(reg)) append(`apply plugin: "${x}"`); | ||
} | ||
}); | ||
|
||
function append(edit, reg) { | ||
if (reg === undefined) reg = /com.android.application['"]/g; | ||
const pos = text.search(reg); | ||
const len = text.match(reg)[0].length; | ||
const header = text.substring(0, pos + len); | ||
const footer = text.substring(pos + len); | ||
text = header + '\n' + edit + footer; | ||
} | ||
|
||
fs.writeFileSync(gradlePath, text); | ||
} | ||
module.exports = function(ctx) { | ||
try{ | ||
addSupport(); | ||
deferral.resolve(); | ||
}catch(e){ | ||
let msg = e.toString(); | ||
deferral.reject(msg); | ||
return deferral.promise; | ||
} | ||
}; |
Oops, something went wrong.