A Tip for Using npm Package del
npm package del allows one to delete files and folders with JavaScript. When using the glob pattern **
, it matches all children and the parent itself.
Here is the example given in the project README:
So this won't work:
del.sync(['public/assets/**', '!public/assets/goat.png']);
You have to explicitly ignore the parent directories too:
del.sync(['public/assets/**', '!public/assets', '!public/assets/goat.png']);
Alternatively, you may use **/*
, which matches all children but without the parent.
So for the given example, you can write
del.sync(['public/assets/**/*', '!public/assets/goat.png']);