| 
									
										
										
										
											2021-04-10 03:18:32 +02:00
										 |  |  | import {lstatSync, readdirSync} from "fs"; | 
					
						
							| 
									
										
										
										
											2021-04-22 03:30:46 +02:00
										 |  |  | import * as https from "https"; | 
					
						
							| 
									
										
										
										
											2021-04-10 03:18:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | export default class ScriptUtils { | 
					
						
							|  |  |  |     public static readDirRecSync(path): string[] { | 
					
						
							|  |  |  |         const result = [] | 
					
						
							|  |  |  |         for (const entry of readdirSync(path)) { | 
					
						
							|  |  |  |             const fullEntry = path + "/" + entry | 
					
						
							|  |  |  |             const stats = lstatSync(fullEntry) | 
					
						
							|  |  |  |             if (stats.isDirectory()) { | 
					
						
							|  |  |  |                 // Subdirectory
 | 
					
						
							|  |  |  |                 // @ts-ignore
 | 
					
						
							|  |  |  |                 result.push(...ScriptUtils.readDirRecSync(fullEntry)) | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 result.push(fullEntry) | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return result; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-04-22 03:30:46 +02:00
										 |  |  |      | 
					
						
							|  |  |  |     public static DownloadJSON(url, continuation : (parts : string []) => void){ | 
					
						
							|  |  |  |         https.get(url, (res) => { | 
					
						
							|  |  |  |             console.log("Got response!") | 
					
						
							|  |  |  |             const parts : string[] = [] | 
					
						
							|  |  |  |             res.setEncoding('utf8'); | 
					
						
							|  |  |  |             res.on('data', function (chunk) { | 
					
						
							|  |  |  |                 // @ts-ignore
 | 
					
						
							|  |  |  |                 parts.push(chunk) | 
					
						
							|  |  |  |             }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             res.addListener('end', function () { | 
					
						
							|  |  |  |                 continuation(parts) | 
					
						
							|  |  |  |             }); | 
					
						
							|  |  |  |         }) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public static sleep(ms) { | 
					
						
							|  |  |  |         return new Promise((resolve) => { | 
					
						
							|  |  |  |             console.debug("Sleeping for", ms) | 
					
						
							|  |  |  |             setTimeout(resolve, ms); | 
					
						
							|  |  |  |             | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-10 03:18:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | } |