#!/bin/bash # Service name for the TypeScript file. service_name="$1" file_name="cache.ts" # Code content to write to the file. code="import { revalidateTag } from \"next/cache\"; interface RevalidateProps { id?: string; } export const ${service_name}Cache = { tag: { byId(id: string) { return \`${service_name}-\${id}\`; }, }, revalidate({ id }: RevalidateProps): void { if (id) { revalidateTag(this.tag.byId(id)); } }, };" # Create the file in the current directory. file_path="./packages/lib/$service_name/$file_name" # Check if the file already exists. if [ -e "$file_path" ]; then echo "Error: File '$file_path' already exists." exit 1 fi # Create the file with the specified code. echo "$code" > "$file_path" echo "Created $file_path with the specified code."