Class JSXIntrinsicTranspiler
java.lang.Object
org.nustaq.kontraktor.webapp.transpiler.JSXIntrinsicTranspiler
- All Implemented Interfaces:
TranspilerHook
public class JSXIntrinsicTranspiler extends Object implements TranspilerHook
transpiles jsx without requiring babel.
-
Field Summary
Fields Modifier and Type Field Description protected booleanautoJNPMstatic booleanBUNDLE_NODE_ALWAYSprotected booleandevprotected StringglobalPrologueprotected booleanhmrprotected JNPMConfigjnpmConfigprotected StringjnpmConfigFileprotected JNPMConfigjnpmConfigFileCachedprotected FilejnpmNodeModulesDirprotected Map<String,File>nodeDirResolveCacheprotected Map<String,File>nodeTopLevelImportsprotected List<WatchedFile>readFilesprotected TimeStampedFileCache<JSXGenerator.ParseResult>transpiledCachestatic booleanUSE_CUSTOM_RELOADFUNprotected FileWatcherwatcher -
Constructor Summary
Constructors Constructor Description JSXIntrinsicTranspiler(boolean dev) -
Method Summary
Modifier and Type Method Description JSXIntrinsicTranspilerautoJNPM(boolean b)automatically import unknown modules via jnpmJSXIntrinsicTranspilerconfigureJNPM(String nodeModulesDir, String pathToJNPMConfigKsonFile)JSXIntrinsicTranspilerconfigureJNPM(String nodeModulesDir, JNPMConfig config)protected StringconstructLibName(File f, FileResolver resolver)JSXIntrinsicTranspilerdev(boolean dev)JSXIntrinsicTranspilerfalseFile(File falseFile)protected StringgenerateCommonJSEnd(File f, JSXGenerator.ParseResult result, FileResolver resolver)protected StringgenerateCommonJSPrologue(File f, JSXGenerator.ParseResult result, FileResolver resolver)protected StringgenerateImportEnd(JSXGenerator.ParseResult result, FileResolver resolver)protected StringgenerateImportPrologue(JSXGenerator.ParseResult result, FileResolver resolver)protected JNPMConfiggetConfig()StringgetGlobalPrologue()protected StringgetHMRFunWrapper()protected StringgetHMRReloadFun()protected StringgetInitialShims()static StringgetLookupLibName(String required)JSXIntrinsicTranspilerglobalPrologue(String globalPrologue)JSXIntrinsicTranspilerhmr(boolean hmr)enable hot module reloading, requires exposure of FileWatcher as a json websocket actor like: .websocket("/hotreloading", FileWatcher.get()) .serType(SerializerType.JsonNoRef) .buildWebsocket()static booleanisNotInNodeModules(File f)JSXIntrinsicTranspilerjnpmConfig(JNPMConfig jnpmConfig)JSXIntrinsicTranspilerjnpmConfigFile(String jnpmConfigFile)JSXIntrinsicTranspilerjnpmConfigFileCached(JNPMConfig jnpmConfigFileCached)JSXIntrinsicTranspilerjnpmNodeModulesDir(File jnpmNodeModulesDir)JSXIntrinsicTranspilernodeModulesDir(File jnpmNodeModulesDir)protected byte[]processJSX(boolean dev, File f, FileResolver resolver, Map<String,Object> alreadyResolved)JSXIntrinsicTranspilerreadFiles(List<WatchedFile> readFiles)byte[]transpile(File f)indicates a file is being accessed. in dev mode this is called always (so its up to the implementation to check for filedate/modification).byte[]transpile(File f, FileResolver resolver, Map<String,Object> alreadyResolved)byte[]updateJSX(File f, FileResolver resolver)JSXIntrinsicTranspilerwatcher(FileWatcher watcher)
-
Field Details
-
BUNDLE_NODE_ALWAYS
public static boolean BUNDLE_NODE_ALWAYS -
dev
protected boolean dev -
jnpmNodeModulesDir
-
autoJNPM
protected boolean autoJNPM -
jnpmConfig
-
jnpmConfigFile
-
jnpmConfigFileCached
-
readFiles
-
nodeTopLevelImports
-
watcher
-
transpiledCache
-
nodeDirResolveCache
-
hmr
protected boolean hmr -
globalPrologue
-
USE_CUSTOM_RELOADFUN
public static boolean USE_CUSTOM_RELOADFUN
-
-
Constructor Details
-
JSXIntrinsicTranspiler
public JSXIntrinsicTranspiler(boolean dev)
-
-
Method Details
-
transpile
Description copied from interface:TranspilerHookindicates a file is being accessed. in dev mode this is called always (so its up to the implementation to check for filedate/modification). In order to run an external transpiler, just run transpilation synchronous such that the given file is updated and return null. Alternatively an implementation might choose to just transpile dynamically and directly return byte[]. NOTE: transpilation is static. this means in production mode it will be called once on first resource access.- Specified by:
transpilein interfaceTranspilerHook- Parameters:
f- - the file being accessed (after resourcepath resolvment)- Returns:
- either (transpiled) file content or null. Should throw an exception in case an error occured during transpile.
- Throws:
TranspileException
-
globalPrologue
-
getGlobalPrologue
-
transpile
- Specified by:
transpilein interfaceTranspilerHook
-
updateJSX
-
processJSX
protected byte[] processJSX(boolean dev, File f, FileResolver resolver, Map<String,Object> alreadyResolved) -
isNotInNodeModules
-
getLookupLibName
-
getConfig
-
generateCommonJSPrologue
protected String generateCommonJSPrologue(File f, JSXGenerator.ParseResult result, FileResolver resolver) -
generateCommonJSEnd
protected String generateCommonJSEnd(File f, JSXGenerator.ParseResult result, FileResolver resolver) -
generateImportEnd
-
generateImportPrologue
-
constructLibName
-
getInitialShims
-
getHMRFunWrapper
-
getHMRReloadFun
-
nodeModulesDir
-
configureJNPM
public JSXIntrinsicTranspiler configureJNPM(String nodeModulesDir, String pathToJNPMConfigKsonFile) -
configureJNPM
-
autoJNPM
automatically import unknown modules via jnpm- Parameters:
b-- Returns:
-
dev
-
jnpmNodeModulesDir
-
jnpmConfig
-
jnpmConfigFile
-
jnpmConfigFileCached
-
readFiles
-
watcher
-
hmr
enable hot module reloading, requires exposure of FileWatcher as a json websocket actor like: .websocket("/hotreloading", FileWatcher.get()) .serType(SerializerType.JsonNoRef) .buildWebsocket()- Parameters:
hmr-- Returns:
-
falseFile
-