aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rwxr-xr-xtools/add-feature-template.sh42
1 files changed, 42 insertions, 0 deletions
diff --git a/tools/add-feature-template.sh b/tools/add-feature-template.sh
new file mode 100755
index 0000000..9a24bf6
--- /dev/null
+++ b/tools/add-feature-template.sh
@@ -0,0 +1,42 @@
+#!/bin/bash
+
+if [ -z "$1" ] || [ -z "$2" ]; then
+ echo "No name supplied!"
+ exit
+fi
+
+project_name="$1"
+feature_name="$2"
+features=("${@:3}")
+
+if [ -z features ]; then
+ features=("string Name")
+fi
+
+#=== Add to Data layer
+dir="../$project_name/Data"
+
+# Create the Feature.cs DB model class
+cat > $dir/$feature_name.cs<< FILE
+using System;
+
+namespace $project_name.Data.Models {
+ public class $feature_name {
+ $(
+ for feature in "${features[@]}"; do
+ echo -e "\r\t\tpublic $feature { get; set; }"
+ done
+ )
+ }
+}
+FILE
+
+# Add the DbSet of the Feature to DbContext
+dbset="public DbSet<$feature_name> ${feature_name}s { get; set; }"
+dbcontext_path="$dir/${project_name}Context.cs"
+
+if grep -Fq "DbSet" $dbcontext_path; then
+ sed -z -i "s/.*DbSet[^\n]*\n/&\t\t$dbset\n/" $dbcontext_path
+else
+ sed -i "11 i \\\t\t$dbset\n" $dbcontext_path
+fi