Webstorm: Best Practice for automatically copying files to multiple destinations before launching

Our web application has a fixed directory structure, which contains several redundant files. Unfortunately this structure can not be changed and this directory structure must in place, as soon as our web application starts (i.e. when we trigger run/debug from within WebStorm).

Example (bold = redundant)


root / folderA / hello.js
root / folderA / somespecial.js
root / folderA / css / styling.css
root / folderB / hello.js
root / folderB / myBstuff.js
root / folderB / css / styling.css
root / folderC / css / styling.css

 

Because I do not want to have these redundant files in my Git repository (they would be independent then), I am looking for a way where I can open my repository (without the redundant) files in WebStorm, this would look like this ...

root / folderA / hello.js
root / folderA / somespecial.js
root / folderA / css / styling.css

root / folderB / myBstuff.js


...and you see the redundant files in folderB and folderC are not there initially.

Now, in WebStorm I must be able

  1. to initially trigger a job (external tool/job written by me?) which copies the 'source' files to its destination path. These copies should not be marked as project files, if this is possible, so that I do not accidentally edit the copies later in WebStorm
  2. to copy an edited 'source' file to its destination path(s) when it gets saved

I learned that the second point (copying when saved) might be achieved by a custom File Watcher (https://www.jetbrains.com/help/webstorm/using-file-watchers.html ).

But maybe there's a solution which could combine both points. "Artifacts" (https://www.jetbrains.com/help/idea/working-with-artifacts.html ) sounded promising, but this feature doesn't seem to be available in WebStorm. Maybe a possible solution would be to build such an Artifact on my own (that would be a solution that would satisfy the first point, but I would have to trigger it every time I save a file, too, to satisfy the second point).

Does anyone have a neat solution or some ideas/thoughts? Thank you!

 

 

2 comments

You can use shell scripts written by you - they can be set up as external tools/file watchers, or use some Gulp/Grunt tasks for this (https://www.npmjs.com/package/gulp-copy, for example)

 

>These copies should not be marked as project files, if this is possible

You can exclude certain files from project using patterns - see https://www.jetbrains.com/help/webstorm/2017.2/directories.html, Exclude files

0

Thanks for the hints.

I will take a look at Gulp, maybe that's easier than a shell script.

Also good to know that I can use patterns to exclude certain files. However, maybe it will be easier to to copy everthing into a new destination directory, and this will become the launch directory, i.e. I could work with this...

root / .idea
root
/ folderA / hello.js
root / folderA / somespecial.js
root / folderA / css / styling.css
root / folderB / myBstuff.js

...and before launching I start my job, which will generate this:

launch / folderA / hello.js
launch / folderA / somespecial.js
launch / folderA / css / styling.css
launch / folderB / hello.js
launch / folderB / myBstuff.js
launch / folderB / css / styling.css
launch / folderC / css / styling.css

That's maybe what an Artifact build would do, with the exception that I will have to do this on my own.

0

Please sign in to leave a comment.