#!/bin/bash

# the same script is in common/scripts/clean-command-state.sh but we need local copy because of working SDK mirroring

# This script, `clean-command-state.sh`, is designed to clean up the temporary files generated by the Rush build tool in your project.
# It's typically called as part of a cleanup or reset process, often defined in the `scripts` section of a `package.json` file.

# In the context of a Rush project, this script is useful for cleaning up temporary files generated during the build process,
# while preserving certain important files like `shrinkwrap-deps.json`.

# By calling this script from a "clean" command in your `package.json`, you can easily reset your project to a clean state before build called.

# Define an array of file names to exclude
exclude_files=("shrinkwrap-deps.json" "another-file.txt")

# Create a find command
find_cmd="find \"$(pwd)/.rush/temp\" -type f"

# Add each file to the find command
for file in "${exclude_files[@]}"; do
    find_cmd+=" ! -name '$file'"
done

# Add the delete action to the find command
find_cmd+=" -delete"

# Run the find command
eval "$find_cmd"
