
const path = require('path');
const fs = require('fs');
module.exports = async function (ctx) {
    var platformRoot = path.resolve(__dirname, '../src-cordova/platforms/android');
    var gradleFiles = [path.join(platformRoot, 'build.gradle'),path.join(platformRoot,'app/build.gradle'),path.join(platformRoot,'CordovaLib/build.gradle')];
    gradleFiles.map((f)=>{
        let data = fs.readFileSync(f, 'utf-8')
        if(data.indexOf('https://maven.google.com')>=0){
            data = data.replace(/https\:\/\/maven\.google\.com/g,'https://maven.aliyun.com/nexus/content/groups/public/')
            fs.writeFileSync(f,data)
        }
    })

    let data = fs.readFileSync(gradleFiles[0],'utf-8');
    if(data.indexOf('google()') == -1){
        data = data.replace(/jcenter\(\)/g,'jcenter()\r\t\tgoogle()')
        fs.writeFileSync(gradleFiles[0],data)
    }

    console.log("======修改 build.gradle mirror")
}
