generates directive on `node_modules` directory

I'm trying to work out how to run npm install but only when the following is true: package.json has been updated OR node_modules directory doesn't exist. I can make the first condition work but not both. Many thanks!
2 Replies
pd93
pd933y ago
@leaanthony This is what sources and generates are for. You should be able to use them like this:
version: '3'

tasks:
node-modules:
sources:
- package.json
- package-lock.json
generates:
- node_modules/*
cmds:
- npm install
version: '3'

tasks:
node-modules:
sources:
- package.json
- package-lock.json
generates:
- node_modules/*
cmds:
- npm install
leaanthony
leaanthonyOP3y ago
Thanks for the quick reply @pd93. I thought I'd done this and it kept triggering anyway. Turns out i had a typo in the path and so it didn't find it. Would be an interesting addition to check the generates path after running to see if it actually did generate and if not, issue a warning. Anyway, happy to report it's working as expected 👍

Did you find this page helpful?