Skip to content

Commit

Permalink
chore: add pnpm move-function command
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Jul 12, 2024
1 parent baf937d commit d7bea7a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 8 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
],
"scripts": {
"add-function": "bash ./scripts/add-function.sh",
"move-function": "bash ./scripts/move-function.sh",
"bench": "vitest bench",
"build": "tsup --clean",
"dev": "tsup --clean --watch --sourcemap",
Expand Down
46 changes: 38 additions & 8 deletions scripts/move-function.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,51 @@ IFS="/" read -r GROUP FUNC <<< "$1"
DEST="$2"
DEST_FUNC="$FUNC"

print_help() {
echo "Usage: $0 <group/func> <dest | dest/dest_func>"
exit 1
}

# If FUNC is empty, throw an error
if [ -z "$FUNC" ]; then
echo "ERROR: Function is required\n"
print_help
fi

# If DEST is empty, throw an error
if [ -z "$DEST" ]; then
echo "ERROR: Destination is required\n"
print_help
fi

# If DEST contains /, update DEST_FUNC and DEST.
if [[ "$DEST" == */* ]]; then
IFS="/" read -r DEST DEST_FUNC <<< "$DEST"
fi

mkdir -p "src/$DEST"
git mv "src/$GROUP/$FUNC.ts" "src/$DEST/$DEST_FUNC.ts"
# Source file
if [ -f "src/$GROUP/$FUNC.ts" ]; then
mkdir -p "src/$DEST"
git mv "src/$GROUP/$FUNC.ts" "src/$DEST/$DEST_FUNC.ts"
fi

mkdir -p "docs/$DEST"
git mv "docs/$GROUP/$FUNC.mdx" "docs/$DEST/$DEST_FUNC.mdx"
# Documentation file
if [ -f "docs/$GROUP/$FUNC.mdx" ]; then
mkdir -p "docs/$DEST"
git mv "docs/$GROUP/$FUNC.mdx" "docs/$DEST/$DEST_FUNC.mdx"
fi

mkdir -p "benchmarks/$DEST"
git mv "benchmarks/$GROUP/$FUNC.bench.ts" "benchmarks/$DEST/$DEST_FUNC.bench.ts"
# Benchmark file
if [ -f "benchmarks/$GROUP/$FUNC.bench.ts" ]; then
mkdir -p "benchmarks/$DEST"
git mv "benchmarks/$GROUP/$FUNC.bench.ts" "benchmarks/$DEST/$DEST_FUNC.bench.ts"
fi

mkdir -p "tests/$DEST"
git mv "tests/$GROUP/$FUNC.test.ts" "tests/$DEST/$DEST_FUNC.test.ts"
# Test file
if [ -f "tests/$GROUP/$FUNC.test.ts" ]; then
mkdir -p "tests/$DEST"
git mv "tests/$GROUP/$FUNC.test.ts" "tests/$DEST/$DEST_FUNC.test.ts"
fi

# Update src/mod.ts
echo "WARNING: You need to update src/mod.ts to export \"$DEST/$DEST_FUNC.ts\""

0 comments on commit d7bea7a

Please sign in to comment.