diff options
| author | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-05-10 22:13:11 +0300 |
|---|---|---|
| committer | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-05-10 22:13:11 +0300 |
| commit | 414ba6688b1b04664fe54fc6569a6bf3495a4858 (patch) | |
| tree | 62b0b1890a077e585fc6a56dac0cdbd3a608f63e /tools/add-feature-template.sh | |
| parent | 6144f287685df57c8a68d286e3952dbdfec0abc5 (diff) | |
| download | it-kariera-exam-template-414ba6688b1b04664fe54fc6569a6bf3495a4858.tar it-kariera-exam-template-414ba6688b1b04664fe54fc6569a6bf3495a4858.tar.gz it-kariera-exam-template-414ba6688b1b04664fe54fc6569a6bf3495a4858.zip | |
Started work on script that adds preset files on a given feature; Implemented Data layer edits
Diffstat (limited to 'tools/add-feature-template.sh')
| -rwxr-xr-x | tools/add-feature-template.sh | 42 |
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 |
