Skip to content

Instantly share code, notes, and snippets.

@utkuturunc
Last active November 5, 2019 16:02
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 utkuturunc/6ee4b9328f9652dd8252410b15fd0161 to your computer and use it in GitHub Desktop.
Save utkuturunc/6ee4b9328f9652dd8252410b15fd0161 to your computer and use it in GitHub Desktop.
Ugly script that lists all files imported from inside of the working directory
#!/usr/bin/env bash
folder=$(pwd)
files=$(find . -name "*.js" | grep -v node_modules | grep -v dist/ | grep -v build/)
for path in $files
do
levels=$(echo $path | sed 's;[^/];;g' | wc -c)
levels=$(($levels-2))
relative_imports=$(cat $path | grep import | sed -e "s/['\"; ]//g" | sed -n 's/import.*from//p' | grep / | grep -v lodash)
echo "----------------------------------------------------------------------"
echo "File $path"
for import in $relative_imports
do
cd $(dirname $path)
absoulte_import_path=$(echo "$(cd "$(dirname "$import")"; pwd)/$(basename "$import")")
if [ -z "$absoulte_import_path" ]
then
echo "No imports"
else
echo $absoulte_import_path
fi
cd $folder
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment