2015-11-18 20:17:39 +00:00
|
|
|
import org.apache.tools.ant.taskdefs.condition.Os
|
|
|
|
|
2015-10-19 13:32:02 +00:00
|
|
|
def config = project.hasProperty("react") ? project.react : [];
|
|
|
|
|
|
|
|
def bundleAssetName = config.bundleAssetName ?: "index.android.bundle"
|
|
|
|
def entryFile = config.entryFile ?: "index.android.js"
|
|
|
|
|
|
|
|
// because elvis operator
|
|
|
|
def elvisFile(thing) {
|
|
|
|
return thing ? file(thing) : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
def reactRoot = elvisFile(config.root) ?: file("../../")
|
|
|
|
def jsBundleDirDebug = elvisFile(config.jsBundleDirDebug) ?:
|
|
|
|
file("$buildDir/intermediates/assets/debug")
|
|
|
|
def jsBundleDirRelease = elvisFile(config.jsBundleDirRelease) ?:
|
|
|
|
file("$buildDir/intermediates/assets/release")
|
|
|
|
def resourcesDirDebug = elvisFile(config.resourcesDirDebug) ?:
|
|
|
|
file("$buildDir/intermediates/res/merged/debug")
|
|
|
|
def resourcesDirRelease = elvisFile(config.resourcesDirRelease) ?:
|
|
|
|
file("$buildDir/intermediates/res/merged/release")
|
|
|
|
def inputExcludes = config.inputExcludes ?: ["android/**", "ios/**"]
|
|
|
|
|
|
|
|
def jsBundleFileDebug = file("$jsBundleDirDebug/$bundleAssetName")
|
|
|
|
def jsBundleFileRelease = file("$jsBundleDirRelease/$bundleAssetName")
|
|
|
|
|
|
|
|
task bundleDebugJsAndAssets(type: Exec) {
|
|
|
|
// create dirs if they are not there (e.g. the "clean" task just ran)
|
|
|
|
doFirst {
|
|
|
|
jsBundleDirDebug.mkdirs()
|
|
|
|
resourcesDirDebug.mkdirs()
|
|
|
|
}
|
|
|
|
|
|
|
|
// set up inputs and outputs so gradle can cache the result
|
|
|
|
inputs.files fileTree(dir: reactRoot, excludes: inputExcludes)
|
|
|
|
outputs.dir jsBundleDirDebug
|
|
|
|
outputs.dir resourcesDirDebug
|
|
|
|
|
|
|
|
// set up the call to the react-native cli
|
|
|
|
workingDir reactRoot
|
2015-11-18 20:17:39 +00:00
|
|
|
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
|
|
|
|
commandLine "cmd", "/c", "react-native", "bundle", "--platform", "android", "--dev", "true", "--entry-file",
|
|
|
|
entryFile, "--bundle-output", jsBundleFileDebug, "--assets-dest", resourcesDirDebug
|
|
|
|
} else {
|
|
|
|
commandLine "react-native", "bundle", "--platform", "android", "--dev", "true", "--entry-file",
|
2015-10-19 13:32:02 +00:00
|
|
|
entryFile, "--bundle-output", jsBundleFileDebug, "--assets-dest", resourcesDirDebug
|
2015-11-18 20:17:39 +00:00
|
|
|
}
|
2015-10-19 13:32:02 +00:00
|
|
|
|
|
|
|
enabled config.bundleInDebug ?: false
|
|
|
|
}
|
|
|
|
|
|
|
|
task bundleReleaseJsAndAssets(type: Exec) {
|
|
|
|
// create dirs if they are not there (e.g. the "clean" task just ran)
|
|
|
|
doFirst {
|
|
|
|
jsBundleDirRelease.mkdirs()
|
|
|
|
resourcesDirRelease.mkdirs()
|
|
|
|
}
|
|
|
|
|
|
|
|
// set up inputs and outputs so gradle can cache the result
|
|
|
|
inputs.files fileTree(dir: reactRoot, excludes: inputExcludes)
|
|
|
|
outputs.dir jsBundleDirRelease
|
|
|
|
outputs.dir resourcesDirRelease
|
|
|
|
|
|
|
|
// set up the call to the react-native cli
|
|
|
|
workingDir reactRoot
|
2015-11-18 20:17:39 +00:00
|
|
|
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
|
|
|
|
commandLine "cmd","/c", "react-native", "bundle", "--platform", "android", "--dev", "false", "--entry-file",
|
2015-10-19 13:32:02 +00:00
|
|
|
entryFile, "--bundle-output", jsBundleFileRelease, "--assets-dest", resourcesDirRelease
|
2015-11-18 20:17:39 +00:00
|
|
|
} else {
|
|
|
|
commandLine "react-native", "bundle", "--platform", "android", "--dev", "false", "--entry-file",
|
|
|
|
entryFile, "--bundle-output", jsBundleFileRelease, "--assets-dest", resourcesDirRelease
|
|
|
|
}
|
2015-10-19 13:32:02 +00:00
|
|
|
|
|
|
|
enabled config.bundleInRelease ?: true
|
|
|
|
}
|
|
|
|
|
2016-01-07 17:32:46 +00:00
|
|
|
void runBefore(String dependentTaskName, Task task) {
|
|
|
|
Task dependentTask = tasks.findByPath(dependentTaskName);
|
|
|
|
if (dependentTask != null) {
|
|
|
|
dependentTask.dependsOn task
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-19 13:32:02 +00:00
|
|
|
gradle.projectsEvaluated {
|
2016-01-07 17:32:46 +00:00
|
|
|
|
2015-10-19 13:32:02 +00:00
|
|
|
// hook bundleDebugJsAndAssets into the android build process
|
2016-01-07 17:32:46 +00:00
|
|
|
|
2015-10-19 13:32:02 +00:00
|
|
|
bundleDebugJsAndAssets.dependsOn mergeDebugResources
|
|
|
|
bundleDebugJsAndAssets.dependsOn mergeDebugAssets
|
2016-01-07 17:32:46 +00:00
|
|
|
|
|
|
|
runBefore('processArmeabi-v7aDebugResources', bundleDebugJsAndAssets)
|
|
|
|
runBefore('processX86DebugResources', bundleDebugJsAndAssets)
|
|
|
|
runBefore('processUniversalDebugResources', bundleDebugJsAndAssets)
|
|
|
|
runBefore('processDebugResources', bundleDebugJsAndAssets)
|
2015-10-19 13:32:02 +00:00
|
|
|
|
|
|
|
// hook bundleReleaseJsAndAssets into the android build process
|
2016-01-07 17:32:46 +00:00
|
|
|
|
2015-10-19 13:32:02 +00:00
|
|
|
bundleReleaseJsAndAssets.dependsOn mergeReleaseResources
|
|
|
|
bundleReleaseJsAndAssets.dependsOn mergeReleaseAssets
|
2016-01-07 17:32:46 +00:00
|
|
|
|
|
|
|
runBefore('processArmeabi-v7aReleaseResources', bundleReleaseJsAndAssets)
|
|
|
|
runBefore('processX86ReleaseResources', bundleReleaseJsAndAssets)
|
|
|
|
runBefore('processUniversalReleaseResources', bundleReleaseJsAndAssets)
|
|
|
|
runBefore('processReleaseResources', bundleReleaseJsAndAssets)
|
|
|
|
|
2015-10-19 13:32:02 +00:00
|
|
|
}
|