3

I am working on React projects, where components have the following file structure:

ComponentName/
├── ComponentName.jsx
├── possiblySomeOtherFiles.js/jsx
└── index.js

and index.js reexports ComponentName.jsx like so:

import ComponentName from './ComponentName'

export default ComponentName

I want to create a live template for this like so:

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

export default $COMPONENT_NAME$

How do I get the value of $COMPONENT_NAME$? I would like to get it from the name of the current directory, but can't figure out how to do that.

I tried setting the variable to groovyScript("_editor.getVirtualFile().getPath()") and groovyScript("new File('.').absolutePath") as hinted here, but both return:

groovy

/
lang / GroovyShell

Is this even possible as of now?

LazyOne
  • 158,824
  • 45
  • 388
  • 391
Michal Kurz
  • 1,592
  • 13
  • 41

1 Answers1

6

The following expression should do the thing:

groovyScript("_editor.getVirtualFile().getParent().getName()")

it works fine for me in Intellij IDEA, but not in Webstorm, because Groovy plugin is not bundled and can't be added to it:( Please follow WEB-28139 for updates

lena
  • 90,154
  • 11
  • 145
  • 150