Skip to content

Commit ab356c8

Browse files
committed
refactor javascript files collecting task in ASBG
1 parent 3ee5c96 commit ab356c8

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

android-static-binding-generator/project/build.gradle

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@ def jsParserP = "$projectDir/parser/js_parser.js"
1515
def jsFilesParametersP = "$projectDir/jsFilesParameters.txt"
1616

1717
def webpackWorkersExcludePath = "$projectDir/../../src/main/assets/app/__worker-chunks.json"
18-
def webpackWorkersExcludesList;
18+
def webpackWorkersExcludesList = [];
1919

2020
def workersExcludeFile = file(webpackWorkersExcludePath);
21-
def filterWorkerFiles = false;
2221
if (workersExcludeFile.exists()) {
23-
filterWorkerFiles = true;
24-
webpackWorkersExcludesList = new JsonSlurper().parseText(workersExcludeFile.text)
22+
// in case the file exists but is malformed
23+
try {
24+
webpackWorkersExcludesList = new JsonSlurper().parseText(workersExcludeFile.text)
25+
} catch (all) {
26+
println "Malformed workers exclude file at ${webpackWorkersExcludePath}"
27+
}
2528
}
2629

27-
28-
//def absoluteOutDir = new File("./outDir")//project.outDir
29-
3030
def absoluteOutDir;
3131
if (project.hasProperty("outDir")) {
3232
absoluteOutDir = project.outDir;
@@ -123,15 +123,7 @@ traverseDirectory = { dir, traverseExplicitly ->
123123

124124
currentDir.eachFile(FileType.FILES) { File f ->
125125
def currFile = f.getAbsolutePath();
126-
if (currFile.substring(currFile.length() - 3, currFile.length()).equals(".js")) {
127-
// Read __worker-chunks.json file containing a list of webpacked workers
128-
// ignore worker scripts, so as to not attempt to generate bindings for them
129-
if (filterWorkerFiles) {
130-
if (webpackWorkersExcludesList.any{element -> file(element).getAbsolutePath() == currFile}) {
131-
return
132-
}
133-
}
134-
126+
if (isJsFile(currFile) && !isWorkerScript(currFile)) {
135127
inputJsFiles.add(currFile)
136128
}
137129
}
@@ -141,6 +133,15 @@ traverseDirectory = { dir, traverseExplicitly ->
141133
}
142134
}
143135

136+
def isJsFile = { fileName -> return fileName.substring(fileName.length() - 3, fileName.length()).equals(".js")
137+
}
138+
139+
def isWorkerScript = { fileName ->
140+
// Read __worker-chunks.json file containing a list of webpacked workers
141+
// ignore worker scripts, so as to not attempt to generate bindings for them
142+
return webpackWorkersExcludesList.any{element -> file(element).getAbsolutePath() == fileName}
143+
}
144+
144145
task traverseJsFilesArgs << { //(jsCodeDir, bindingsFilePath, interfaceNamesFilePath, jsParserPath, jsFilesParameter) {
145146
jsCodeAbsolutePath = jsCodeDir;
146147
inputJsFiles = new LinkedList<String>();

0 commit comments

Comments
 (0)