Huuums/vscode-folder-templates

Append to existing file

AndrewCraswell opened this issue · 3 comments

I'm generating folder templates into a react project and wondering how to append code to an existing file, in the case where I need to add the new component to a barrel file. For example

/src
  /components
    index.ts
    /MyComponent
      MyComponent.tsx
      index.ts

In my scenario, my template generated the MyComponent folder. But what I'd like to do is append the following to my /src/components/index.ts file:

export * from "./[FTName]";

This way when I import any component, I can just do the following:

import { MyComponent } from "src/components";

Currently I'm already aliasing the src/components file so that it's just as simple as this:

import { MyComponent } from "$components";

Unfortunately that isn't possible at the moment. But it is something that i would be willing to add.

This is most likely going to be linked with #89 due to the nature of the static path of your src/components/index.ts file.

If you have any suggestion or rough idea how a configuration for this functionality could look like I'd be happy if you could share it.

Hey @AndrewCraswell,

it took a long while but better late than never I finally got around to publish this functionality. Feel free to have a look at this example. https://github.com/Huuums/vscode-folder-templates/tree/master/examples/Append%20Text%20to%20Existing%20File

This should provide the functionality you're looking for

Woohoo! This is great! Can't wait to start using this on all my projects :)