Skip to content

Instantly share code, notes, and snippets.

@marcusoftnet
Created Aug 26, 2021
Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@marcusoftnet marcusoftnet commented Aug 26, 2021

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