Skip to content

Instantly share code, notes, and snippets.

@fatso83
Last active October 24, 2019 09:00
Show Gist options
  • Save fatso83/6d12d2afd0a2236daea712f7216d538f to your computer and use it in GitHub Desktop.
Save fatso83/6d12d2afd0a2236daea712f7216d538f to your computer and use it in GitHub Desktop.
#!/bin/bash
# Checks to see if the published NPM package has the files passed in as arguments
# Requirements: jq and npm
# `brew install jq` on macOS and `apt install jq` on Ubuntu
pkg=$(echo $(jq .name package.json)-$(jq .version package.json).tgz | sed 's/"//g')
files_to_check="$@"
main(){
npm pack > /dev/null 2>&1;
check_tarball_files $@
rm $pkg > /dev/null;
}
usage(){
cat << EOF
Usage: check-files-present [file1 [file2 [...]]]
Example. Want to see that 'lolex' contains two specific files:
check-files-present src/lolex-src.js package/lolex.js
EOF
exit 1
}
if [[ $# == 0 ]]; then
echo No file names given on command line
usage
fi
check_tarball_files(){
tarball_files=$(tar tf $pkg)
for f in $files_to_check; do
if !(echo $tarball_files | grep package/$f) > /dev/null; then
echo "Missing $f" && exit 1
fi
done
echo All files present: $files_to_check
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment