Batch install dependencies in all subfolder-organised projects

As a lecturer ICT I have to correct the work our students make. Therefor I collect all solutions and put them in a subfolder-organised structure on disk: per student I create a subfolder and put their solution into that folder(*).

$ tree -L 1
.
├── student1
├── student2
├── ...
└── studentN

As – from the 2nd year on – most of our projects use some sort of dependency manager I often found myself manually cding into folders and running the command to install the dependencies.

Today I knocked up a one-liner to install all PHP dependencies (using Composer) in subfolder-organised projects. My first attempt was pretty awful, yet with a hint by Frank I eventually cleaned it up:

find . -name composer.json -maxdepth 2 -execdir composer install \;

With some minor modifications the command can also be used to installing dependencies using npm:

find . -name package.json -maxdepth 2 -execdir npm install \;

(*) actually, a handy app created by a colleague of mine bash script I wrote does this automatically for me, but that’s not the gist of this post

Did this help you out? Like what you see?
Consider donating.

I don’t run ads on my blog nor do I do this for profit. A donation however would always put a smile on my face though. Thanks!

☕️ Buy me a Coffee ($3)

Published by Bramus!

Bramus is a frontend web developer from Belgium, working as a Chrome Developer Relations Engineer at Google. From the moment he discovered view-source at the age of 14 (way back in 1997), he fell in love with the web and has been tinkering with it ever since (more …)

Unless noted otherwise, the contents of this post are licensed under the Creative Commons Attribution 4.0 License and code samples are licensed under the MIT License

Join the Conversation

4 Comments

  1. That One Line is Worth A Cup of Coffee – with Extra Cream !! 🙂
    Thanks – You Saved My Fingers and My Sanity

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.