1
1
package org .nativescript .staticbindinggenerator ;
2
2
3
3
import org .apache .commons .io .FileUtils ;
4
+ import org .apache .commons .io .IOUtils ;
4
5
import org .json .JSONArray ;
5
6
import org .json .JSONException ;
6
7
import org .json .JSONObject ;
11
12
12
13
import java .io .File ;
13
14
import java .io .IOException ;
15
+ import java .io .InputStream ;
14
16
import java .io .PrintWriter ;
15
17
import java .nio .charset .Charset ;
18
+ import java .nio .file .Path ;
16
19
import java .nio .file .Paths ;
17
20
import java .util .ArrayList ;
18
21
import java .util .List ;
@@ -112,6 +115,10 @@ private static void validateInput() throws IOException {
112
115
113
116
List <DataRow > inputFile = Generator .getRows (SBG_INPUT_FILE );
114
117
inputDir = new File (inputFile .get (0 ).getRow ());
118
+ Path assetsInternalDirPath = inputDir .getParentFile ().toPath ().resolve ("internal" );
119
+ extractResource (assetsInternalDirPath .resolve ("ts_helpers.js" ), "ts_helpers.js" );
120
+ extractResource (assetsInternalDirPath .resolve ("livesync.js" ), "livesync.js" );
121
+
115
122
webpackWorkersExcludePath = Paths .get (inputDir .getAbsolutePath (), "__worker-chunks.json" ).toString ();
116
123
117
124
if (!inputDir .exists () || !inputDir .isDirectory ()) {
@@ -132,7 +139,9 @@ private static void validateInput() throws IOException {
132
139
* This output file should contain all the information needed to generate java counterparts to the traversed js classes.
133
140
* */
134
141
private static void runJsParser () {
135
- String parserPath = Paths .get (System .getProperty ("user.dir" ), "jsparser" , "js_parser.js" ).toString ();
142
+ Path jsParserPath = Paths .get (System .getProperty ("user.dir" ), "jsparser" , "js_parser.js" );
143
+ extractResource (jsParserPath , "js_parser.js" );
144
+ String parserPath = jsParserPath .toString ();
136
145
NodeJSProcess nodeJSProcess = new NodeJSProcessImpl (new ProcessExecutorImpl (), new EnvironmentVariablesReaderImpl ());
137
146
int exitCode = nodeJSProcess .runScript (parserPath );
138
147
@@ -141,6 +150,40 @@ private static void runJsParser() {
141
150
}
142
151
}
143
152
153
+ private static void extractResource (Path savePath , String resourceName ) {
154
+ File jsParserFile = savePath .toFile ();
155
+ if (!jsParserFile .exists ()) {
156
+ try {
157
+ jsParserFile .getParentFile ().mkdirs ();
158
+ jsParserFile .createNewFile ();
159
+ InputStream source = Main .class .getResourceAsStream ("/" + resourceName );
160
+ if (source == null ) {
161
+ throw new RuntimeException (resourceName + " not found in resources" );
162
+ }
163
+ FileUtils .copyInputStreamToFile (source , jsParserFile );
164
+ } catch (IOException e ) {
165
+ throw new RuntimeException (e );
166
+ }
167
+ }
168
+ }
169
+
170
+ private static void maybeExtractJsParserSource (Path jsParserPath ) {
171
+ File jsParserFile = jsParserPath .toFile ();
172
+ if (!jsParserFile .exists ()) {
173
+ try {
174
+ jsParserFile .getParentFile ().mkdirs ();
175
+ jsParserFile .createNewFile ();
176
+ InputStream source = Main .class .getResourceAsStream ("/js_parser.js" );
177
+ if (source == null ) {
178
+ throw new RuntimeException ("js_parser.js not found in resources" );
179
+ }
180
+ FileUtils .copyInputStreamToFile (source , jsParserFile );
181
+ } catch (IOException e ) {
182
+ throw new RuntimeException (e );
183
+ }
184
+ }
185
+ }
186
+
144
187
private static Boolean rootTraversed = false ;
145
188
146
189
private static void traverseDirectory (File currentDir , boolean traverseExplicitly ) throws IOException , JSONException {
0 commit comments