Skip to content

Instantly share code, notes, and snippets.

@marcusoftnet
Created August 26, 2021 12:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcusoftnet/39c0e9a3076765fd0da4b572f91e7e75 to your computer and use it in GitHub Desktop.
Save marcusoftnet/39c0e9a3076765fd0da4b572f91e7e75 to your computer and use it in GitHub Desktop.
Bash challenge from real life - part I; which licenses are used in all our code, including dependencies
#!/usr/bin/env zsh
# The challenge is to understand which licenses we are indirectly including, by just getting a list of tool and license
# I'm thinking to post process this later, summarizing, sorting and aggregating in Google Sheets.
# For now I just want to get a list
# This assumest that all relevant repositories to be local directory in the current folder.
## Part I - install all dependencies for all repositories (i.e. all subfolders one level deep from .)
find . -maxdepth 1 -type d \( ! -name . \) -exec bash -c "cd '{}' && npm i --silent" \;
## Part II find the license field in all files
## I'm not too happy about this as i get some files that are not package.json
grep -r '"license"' . > ~/temp/allLicenses.txt
@marcusoftnet
Copy link
Author

Here's a better version that actually only checks the package.json files

#!/usr/bin/env zsh


# The challenge is to understand which licenses we are indirectly including, by just getting a list of tool and license
# I'm thinking to post process this later, summarizing, sorting and aggregating in Google Sheets.
# For now I just want to get a list

# This assumes that all relevant repositories to be local directory in the current folder.

## Part I - install all dependencies for all repositories (i.e. all subfolders one level deep from .)
find . -maxdepth 1 -type d \( ! -name . \) -exec bash -c "cd '{}' && npm i --silent" \;

## Part II find the license field in all package.json files
find ./ -type f -name "package.json" -print0 | xargs -0 grep -i '"license"' > ~/temp/allLicenses.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment