Scenario:
I am currently configuring a prepublishOnly
hook in NPM. This hook is designed to remove the "lib" folder, transpile the typescript source files into a new lib folder, and then execute the tests.
The issue at hand:
There are two individuals responsible for publishing the NPM packages, each using a different operating system (Windows / Mac). Due to this difference, the commands used to delete folders vary between the two OSs.
"scripts": {
"build": "tsc",
"clean": "rm -rf lib",
"clean:windows": "if exist lib rmdir /s /q lib",
"lint": "tslint --project tsconfig.json --format stylish src/**/*.ts",
"format": "prettier --write \"**/*.ts\""
},
"husky": {
"hooks": {
"pre-push": "npm run clean:windows && npm run build && npm run test"
}
},
The query being posed:
Is there a method to conditionally execute NPM scripts based on the operating system being used? Alternatively, is there a command that can be utilized to remove folders across both Windows and Mac?