I want to keep my sources up to date and in case they have Node.js package manager and/or Bower in use, install those.
This is rather trivial once certain requirements are set:
- Source codes are synced via Git, thus directory
.git
is present - Node.js dependencies are listed in
package.json
- Bower dependencies are listed in
bower.json
The examples shown below can easily be adjusted to work with other similar tools.
All the examples use the -maxdepth
parameter with value 3
which means that measured from the current directory,
three sub levels are searched.
Sync source code
The following one line command will look for .git
directory and for those directories that under it is found,
resets the state to the latest known commit, pulls all changes from the server repository,
including other branch information and finally sets the currently used branch to be master
.
find . -maxdepth 3 -type d -name '.git' -printf '\n%h\n' \
-exec sh -c '(cd {}/.. && git pull --all)' ';'
Install Node.js dependencies
The following one liner installs the NPM dependencies that are listed in the package.json
which is present in case
the project is Node.js based.
find . -maxdepth 3 -type f -name 'package.json' -printf '\n%h\n' \
-exec sh -c '(cd $(dirname {}) && npm install)' ';'
Install Bower dependencies
Almost exactly the same with the previous installation procedure, the Bower dependencies are installed
if the directory contains a file called bower.json
.
find . -maxdepth 3 -type f -name 'bower.json' -printf '\n%h\n' \
-exec sh -c '(cd $(dirname {}) && bower install)' ';'