Skip to content

Commit

Permalink
add blacklight-query bin
Browse files Browse the repository at this point in the history
  • Loading branch information
dphiffer committed Sep 24, 2024
1 parent 074526e commit efd0522
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
26 changes: 26 additions & 0 deletions blacklight-query
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

set -o errexit
set -o pipefail
set -o nounset

dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

if [ -t 0 ]; then
# URLs are passed as an argument value
if (( $# != 1 )) ; then
echo "Usage: blacklight-query urls.txt"
echo "Usage: cat urls.txt | blacklight-query"
echo
echo "Please provide a list of URLs, where each URL is on its own line."
exit 1
fi
"$dir/node_modules/.bin/ts-node" --project "$dir/tsconfig.json" "$dir/src/main.ts" $1
else
# URLs are piped to stdin (and saved to urls.txt)
echo > urls.txt
while read -r line ; do
echo $line >> urls.txt
done
"$dir/node_modules/.bin/ts-node" --project "$dir/tsconfig.json" "$dir/src/main.ts" urls.txt
fi
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"name": "@themarkup/blacklight-query",
"version": "1.0.0",
"description": "A simple tool to generate Blacklight-Collector scans of a list of urls",
"main": "build/index.js",
"main": "src/main.ts",
"bin": "./blacklight-query",
"funding": {
"type": "individual",
"url": "https://themarkup.org/donate"
Expand Down
6 changes: 2 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ import { collect } from "@themarkup/blacklight-collector";
import { reportFailures } from "./utils";

// Gather URLs from input file
const urlsPath = join(__dirname, '../urls.txt');
const urlsPath = join(__dirname, '../', process.argv[2]);
if (!fs.existsSync(urlsPath)) {
console.log(
"Please create a file named 'urls.txt', containing a newline-separated list of urls to scan."
);
console.log(`Could not find ${urlsPath}.`);
exit();
}
const urls = fs.readFileSync(urlsPath, "utf8");
Expand Down

0 comments on commit efd0522

Please sign in to comment.