forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
/
architecture.gradle
88 lines (71 loc) · 2.42 KB
/
architecture.gradle
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
def codegenDir = "$rootDir/packages/react-native-codegen";
def codegenGenerateSchemaCli = "$codegenDir/lib/cli/combine/combine-js-to-schema-cli.js";
def codegenGenerateNativeModuleSpecsCli = "$rootDir/scripts/generate-native-modules-specs-cli.js";
def schemaFile = "schema.json";
// TODO: Consider building Gradle plugin instead.
/**
* The config is derived from app-level `project.react`.
*/
ext.generateNativeArtifactsFromJavaScript = { Map config ->
def nodeExecutableAndArgs = config.nodeExecutableAndArgs ?: ["node"];
def jsRootDir = config.jsRootDir ?: config.root;
if (!config.enableCodegen) {
return;
}
// 1. Create build dir
def generatedSrcDir = file("$buildDir/generated/source/codegen");
// 2. Produce schema from JS files.
task generateCodegenSchemaFromJavaScript(type: Exec) {
doFirst {
generatedSrcDir.deleteDir()
generatedSrcDir.mkdirs()
}
def schemaOutputFile = file("$generatedSrcDir/$schemaFile");
inputs.files fileTree(dir: codegenDir)
inputs.files fileTree(dir: jsRootDir)
outputs.file(schemaOutputFile)
def execCommands = ["yarn"] + nodeExecutableAndArgs + [
codegenGenerateSchemaCli,
"$schemaOutputFile",
jsRootDir,
];
commandLine execCommands
ext.schema = {
schemaOutputFile
}
}
// 3. Generate Java code from schema
task generateCodegenArtifactsFromSchema(dependsOn: 'generateCodegenSchemaFromJavaScript', type: Exec) {
def generatedSchema = tasks.generateCodegenSchemaFromJavaScript.schema();
def javaPackageName = config.codegenJavaPackageName ?: "com.facebook.fbreact.specs.beta";
def javaPackageDir = javaPackageName.replace(".", "/");
def outputDir = file("$generatedSrcDir/java/$javaPackageDir");
inputs.files fileTree(dir: codegenDir)
inputs.files generatedSchema
outputs.dir(outputDir)
def execCommands = ["yarn"] + nodeExecutableAndArgs + [
codegenGenerateNativeModuleSpecsCli,
"android",
"$generatedSchema",
"$outputDir",
];
commandLine execCommands
}
// 4. add deps + srcs
preBuild.dependsOn generateCodegenArtifactsFromSchema
android {
sourceSets {
main {
java {
srcDirs += "$generatedSrcDir/java"
}
}
}
}
}