Adding gulp to your list of tools seems rather unnecessary if all you want to do is delete a folder(s) via an npm script in a cross-platform way. For a lightweight solution consider the following two solutions instead:
Solution 1
Take a look at rimraf, it's described as:
The UNIX command rm -rf for node.
Usage
cd to your project directory and run the following command:
npm install rimraf --save-dev
Change your clean script in package.json to the following:
"scripts": {
"clean": "rimraf lib",
...
},
Delete the clean:windows script from your package.json as that's now redundant.
Note I've not had great success with it when installing it as a local dependency, hence I use solution two below. However you may have greater success - so it's worth a try.
Solution 2
The following solution utilizes the shelljs rm command which is analogous to the Unix rm -rf command except it's for node - hence it's a cross platform equivalent.
The following steps shows how this can be achieved:
cd to your project directory and install shelljs by running the following command:
npm install shelljs --save-dev
Create a custom node script as follows, let's name the file clean.js:
const shell = require('shelljs');
process.argv.slice(2).forEach(function(_path) {
shell.rm('-rf', _path);
});
and save it to a hidden directory called .scripts in the projects root directory. For example:
.
├── .scripts
│ └── clean.js
├── lib
│ └── ...
├── node_modules
│ └── ...
├── package.json
├── src
│ └── ...
└── ...
Replace your clean script in package.json to the following:
"scripts": {
"clean": "node .scripts/clean lib",
...
},
You can also pass multiple path arguments to clean.js too. For example:
"scripts": {
"clean": "node .scripts/clean lib another/folder/path foo/bar",
...
},
Filepaths are handled too. For example:
"scripts": {
"clean": "node .scripts/clean path/to/quux.js",
...
},
Delete the clean:windows script from your package.json as that's now redundant.
Notes
clean.js utilizes nodes built-in process.argv to obtain an array of command line arguments passed to Node when the script was invoked.
We then slice() the array of arguments from index 2 to ensure that we only include the folder/file path arguments (e.g. lib).
Finally we loop over each folder path in the array using forEach() and invoke shell.rm('-rf', _path); in each turn of the loop to delete the asset.
Edit / Update:
An alternative cross-platform solution, (which wasn't available when originally posting this answer), is to utilize the shx package, which is described as:
shx is a wrapper around ShellJS Unix commands, providing an easy solution for simple Unix-like, cross-platform commands in npm package scripts
Run the following command to install shx:
npm i -D shx
Then redefine your clean script in package.json as follows:
"scripts": {
"clean": "shx rm -rf lib"
}
node script.jsto run the ShellJS commands.