-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenerate.sh
More file actions
67 lines (56 loc) · 2.12 KB
/
generate.sh
File metadata and controls
67 lines (56 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#! bin/bash
# Barrel Template
barrel_template() {
feature_name=$1
feature_name_lower=$(tr '[:upper:]' '[:lower:]' <<< ${feature_name:0})
printf "export * from './$feature_name_lower.component';\n"
}
# Typescript Template
typescript_template() {
feature_name=$1
feature_name_lower=$(tr '[:upper:]' '[:lower:]' <<< ${feature_name:0})
printf "import { Component, OnInit } from '@angular/core';
@Component({
selector: '$feature_name_lower',
templateUrl: 'app/$feature_name_lower/$feature_name_lower.component.html'
})
export class ${feature_name}Component implements OnInit {
message: string = 'This is ${feature_name}Component.';
constructor() {}
ngOnInit() {}
}\n"
}
# HTML Template
html_template() {
feature_name=$1
feature_name_lower=$(tr '[:upper:]' '[:lower:]' <<< ${feature_name:0})
printf "<section>
<p>{{message}}</p>
</section>\n"
}
# SASS Template
sass_template() {
feature_name=$1
feature_name_lower=$(tr '[:upper:]' '[:lower:]' <<< ${feature_name:0})
printf "/* <$feature_name_lower> (app/$feature_name_lower/$feature_name_lower.component.html/ts) */
$feature_name_lower {
}\n"
}
read -r -p "Name of feature to generate (PascalCase): " feature_name
feature_name_lower=$(tr '[:upper:]' '[:lower:]' <<< ${feature_name:0})
read -r -p "Create directory in src/app named $feature_name_lower and add .scss to src/scss/features? [y/N]" response
if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]]
then
mkdir -p src/app/$feature_name_lower
touch src/app/$feature_name_lower/$feature_name_lower.ts
touch src/app/$feature_name_lower/$feature_name_lower.component.ts
touch src/app/$feature_name_lower/$feature_name_lower.component.html
touch src/scss/features/_$feature_name_lower.scss
barrel_template $feature_name > src/app/$feature_name_lower/$feature_name_lower.ts
typescript_template $feature_name > src/app/$feature_name_lower/$feature_name_lower.component.ts
html_template $feature_name > src/app/$feature_name_lower/$feature_name_lower.component.html
sass_template $feature_name > src/scss/features/_$feature_name_lower.scss
echo "NOTE: Remember to import and declare your new component(s) in src/app/app.module.ts."
else
return 1
fi