def extractRegexesFromJS(jsFile): """Extract regexes from this JS file. Returns a libLF.SimpleFileWithRegexes object. """ # Extract cmd = "'{}' '{}'".format(regexExtractor, jsFile) out = libLF.chkcmd(cmd) # Object-ify sfwr = libLF.SimpleFileWithRegexes() sfwr.initFromNDJSON(out) return sfwr
def runExtractor(sourceFile, extractor, registry): libLF.log('Extracting regexes from {} using {}'.format( sourceFile['name'], extractor)) # Any special invocation recipe? if extractor.endswith(".jar"): invocationPrefix = "java -jar" else: invocationPrefix = "" try: # Extract cmd = "{} '{}' '{}' 2>/dev/null".format(invocationPrefix, extractor, sourceFile['name']) out = libLF.chkcmd(cmd) try: sfwr = libLF.SimpleFileWithRegexes() sfwr.initFromNDJSON(out) if not sfwr.couldParse: libLF.log('Could not parse: {}'.format(sourceFile['name'])) # TODO ruList = libLF.sfwrToRegexUsageList(sfwr) ruList = [] for regex in sfwr.regexes: ru = libLF.RegexUsage() basePath = os.path.basename(sourceFile['name']) ru.initFromRaw(regex['pattern'], regex['flags'], None, None, sourceFile['name'], basePath) ruList.append(ru) libLF.log('Got {} regexes from {}'.format(len(ruList), sourceFile['name'])) return ruList except KeyboardInterrupt: raise except Exception as err: libLF.log( 'Error converting output from SFWR to RU: {}\n {}'.format( out, err)) except KeyboardInterrupt: raise except BaseException as err: libLF.log('Error extracting regexes from {} using {}: {}'.format( sourceFile['name'], extractor, err))
def transpile(tsSrc, jsDest): """Transpile TypeScript: from tsSrc into jsDest""" # ./node_modules/.bin/babel --out-file /tmp/x.js --presets @babel/preset-typescript test/apps/Hitchhiker/client/src/store.ts cmd = "'{}' '{}' > '{}'".format(transpiler, tsSrc, jsDest) libLF.chkcmd(cmd)