Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Add lint-sprig script and missing games. #971

Merged
merged 1 commit into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions bin/lint-sprig
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/env bash
# lint-sprig
#
# Do some sanity checks on the sprig games.

metadata=games/metadata.json

if [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]; then
echo "Usage: $0 [games/<name>.js ...]" >&2;
cat <<EOF >&2

Perform sanity check on sprig games. Ensures js files in games directory are
represented in metadata file. Checks name for invalid characters. Suggests a
record to add to metadata if not present, pulling title and author from
javascript file. Checks for associated image file.

Does not read metadata to determine if it references files not present.
EOF
exit 2;
fi

if [[ $# -eq 0 ]]; then
files=$(echo games/*.js);
else
files="$@";
fi


err=0
for game in $files; do
name=$(basename "$game" .js);
if [[ ! "$name" =~ ^[a-zA-Z0-9_\-]+$ ]]; then
echo "warning: Unexpected character in file name '$game'." >&2;
err=1;
fi

if ! grep -c "$name" $metadata > /dev/null; then
echo "warning: '$name' for $game not present in $metadata." >&2;
if ! grep '@title' $game >&-; then
echo "error: no @title in $game";
title="$name";
else
title=$(grep '@title' $game | awk '{ print $2 }');
fi
if ! grep '@author' $game >&-; then
echo "error: no @author in $game";
author="N/A";
else
author=$(grep '@author' $game | awk '{ print $2 }');
fi
img="games/img/$name.png";
if [[ ! -f "$img" ]]; then
echo "warning: no '$img' image found for $game." >&2;
img="";
err=1;
fi
date=$(date +%Y-%m-%d);
echo "Suggested fix: add this record to $metadata." >&2;
cat <<EOF >&2
{
"filename": "$name.js",
"title": "$title",
"author": "$author",
"img": "$img",
"tags": [],
"addedOn": "$date"
},
EOF
err=1
fi

# img="games/img/$name.png"
# if [[ ! -f "$img" ]]; then
# echo "warning: expect image '$img' for $game." >&2;
# err=1
# fi
done

exit $err
26 changes: 25 additions & 1 deletion games/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2350,5 +2350,29 @@
"img": "",
"tags": [],
"addedOn": "2023-03-14"
}
},
{
"filename": "Alien_Attack.js",
"title": "Alien_Attack",
"author": "whatware",
"img": "games/img/Alien_Attack.png",
"tags": [],
"addedOn": "2023-03-15"
},
{
"filename": "ElfSokoban.js",
"title": "ElfSokoban",
"author": "Markonije",
"img": "",
"tags": [],
"addedOn": "2023-03-15"
},
{
"filename": "It_Is_Coming_Out!.js",
"title": "It_Is_Coming_Out!",
"author": "N/A",
"img": "games/img/It_Is_Coming_Out!.png",
"tags": [],
"addedOn": "2023-03-15"
},
]