My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more

How do you handle very long NPM scripts?

Rafal Wilinski's photo
Rafal Wilinski
·Jun 23, 2016

My NPM scripts are getting very long, for example if I'd like to kill all docker containers of my project, remove images and volumes and rebuild everything form scratch it goes like this:

docker ps | grep my_project | tr -s ' ' | cut -d ' ' -f2 | xargs docker kill &&
docker images | grep my_project | tr -s ' ' | cut -d ' ' -f2 | xargs docker rmi -f &&
docker volume ls | tr -s ' ' | cut -d ' ' -f2 |xargs docker volume rm && 
docker-compose rm -f &&
docker-compose build && 
docker-compose up

That's way to much for one line. I'm thinking about moving this code to separate .sh file and point NPM to execute that file. What do you think about that? What are your solutions?