WebStorm 实时模板:如何创建“从”实时模板导出默认值/如何获取当前文件夹名称?

Mic*_*urz 2 javascript intellij-idea live-templates webstorm reactjs

我正在研究 React 项目,其中组件具有以下文件结构:

ComponentName/
??? ComponentName.jsx
??? possiblySomeOtherFiles.js/jsx
??? index.js
Run Code Online (Sandbox Code Playgroud)

index.js 重新导出 ComponentName.jsx 像这样:

import ComponentName from './ComponentName'

export default ComponentName
Run Code Online (Sandbox Code Playgroud)

我想为此创建一个实时模板,如下所示:

import $COMPONENT_NAME$ from './$COMPONENT_NAME$'

export default $COMPONENT_NAME$
Run Code Online (Sandbox Code Playgroud)

我如何获得 的价值$COMPONENT_NAME$?我想从当前目录的名称中获取它,但无法弄清楚如何做到这一点。

我尝试将变量设置为groovyScript("_editor.getVirtualFile().getPath()")此处groovyScript("new File('.').absolutePath")提示,但都返回:

groovy

/
lang / GroovyShell
Run Code Online (Sandbox Code Playgroud)

到目前为止,这甚至可能吗?

len*_*ena 5

下面的表达式应该做的事情:

groovyScript("_editor.getVirtualFile().getParent().getName()")
Run Code Online (Sandbox Code Playgroud)

它在 Intellij IDEA 中对我来说很好,但在 Webstorm 中却没有,因为 Groovy 插件没有捆绑并且无法添加到它:( 请关注WEB-28139获取更新