I was looking for a way to streamline the process of setting up project structures for my projects so that I could utilize ALE linting and fixing without any hassle. After trying out one method, I'm confident that there must be a more efficient solution available. In general, the steps involved are:
- create package.json
- install all necessary packages with npm
- for eslint:
- create .eslintrc.{json,js,yaml}
- install plugins and set rules
- integrate plugins like airbnb, prettier, etc.
- repeat these steps for each new project
While I understand that using -g
with npm can install packages globally, placing the .eslintrc.json
in my home folder prevents VIM from loading the desired plugins (like airbnb, prettier) since there is no node_modules folder within the project directory.
To tackle this issue, I decided to create a template folder that contains everything mentioned above and copied that structure to the folder where I work on my .html
, .css
, .js
, or .json
files as an autocmd
from VIM.
This snippet shows a portion of my .vimrc
:
autocmd FileType javascript,json,css,html silent exec '! '.$HOME.'/Documents/eslint-template/prepare.sh
And this is what my prepare.sh
looks like:
$ cat Documents/eslint-template/prepare.sh
#!/bin/bash
echo Preparing environment...
templateFolder=$HOME/Documents/eslint-template
files=( $templateFolder/{.,}* )
for file in ${files[@]}; do
[ "$(basename $0)" == "$(basename $file)" ] && continue
destFile=$PWD/$(basename $file)
diff -q $file $destFile > /dev/null 2>&1 ||
cp -r $file $PWD/
done
rsync -azz --delete $templateFolder/node_modules/ node_modules/ > /dev/null 2>&1
echo Preparation completed!
After some tweaking and testing, the process seems to be working smoothly (although further tests will be conducted). However, it takes around 10 to 15 seconds to open a simple .html
file due to the need to copy the entire node_modules structure from the template to the new project. Even with the -zz
option from rsync, running it from within VIM appears to be slower compared to running it directly from the terminal.
With that in mind, I would like to explore other alternatives for achieving this task more efficiently. So, what other options are available?