-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathfixAndroid.js
More file actions
66 lines (61 loc) · 2.25 KB
/
fixAndroid.js
File metadata and controls
66 lines (61 loc) · 2.25 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
//@flow
'use strict'
const chalk = require('chalk')
const fs = require('fs')
function replaceKeyword(content) {
content = content.split(/compile\s/).join('implementation ')
content = content.split('compile("').join('implementation("')
content = content.split('compile(').join('implementation(')
content = content
.split(/androidTestCompile\s/)
.join('androidTestImplementation ')
content = content.split(/testCompile\s/).join('testImplementation ')
content = content.split(/debugCompile\s/).join('debugImplementation ')
content = content.split(/testApi\s/).join('testImplementation ')
content = content.split(/provided\s/).join('compileOnly ')
return content
}
function processGradle() {
console.log(chalk.green.bold('####################################'))
console.log(
chalk.green.bold('#') +
chalk.black.bold(' Upgrade All Android build.gradle ') +
chalk.green.bold('#')
)
console.log(chalk.green.bold('####################################\n'))
if (!fs.existsSync('./node_modules')) {
console.log(chalk.red.bold('node_modules directory does not exists'))
return
}
const dirs = fs.readdirSync('./node_modules')
const subDirs = []
dirs.forEach(dir => {
let exists = fs.existsSync(`./node_modules/${dir}/android/build.gradle`)
if (exists) {
subDirs.push(`./node_modules/${dir}/android/build.gradle`)
}
exists = fs.existsSync(`./node_modules/${dir}/ReactAndroid/build.gradle`)
if (exists) {
subDirs.push(`./node_modules/${dir}/ReactAndroid/build.gradle`)
}
exists = fs.existsSync(`./node_modules/${dir}/src/android/build.gradle`)
if (exists) {
subDirs.push(`./node_modules/${dir}/src/android/build.gradle`)
}
exists = fs.existsSync(`./node_modules/${dir}/lib/android/build.gradle`)
if (exists) {
subDirs.push(`./node_modules/${dir}/lib/android/build.gradle`)
}
exists = fs.existsSync(`./node_modules/${dir}/android/app/build.gradle`)
if (exists) {
subDirs.push(`./node_modules/${dir}/android/app/build.gradle`)
}
})
subDirs.forEach(gradle => {
fs.writeFileSync(gradle, replaceKeyword(fs.readFileSync(gradle).toString()))
console.log(chalk.green.bold('Processed file: ') + gradle)
})
}
setImmediate(() => {
processGradle()
})