Last active
October 31, 2023 07:45
-
-
Save rotimi-best/7bd7e4ebda09a68ff0a1dc8ae6fa0009 to your computer and use it in GitHub Desktop.
Revisions
-
rotimi-best renamed this gist
Oct 31, 2023 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
rotimi-best created this gist
Oct 31, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,39 @@ #!/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."