-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_create_project.sh
executable file
·128 lines (108 loc) · 3.86 KB
/
run_create_project.sh
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/bash
# Function to find the project root
find_project_root() {
local dir="$(cd "${1:-$(pwd)}" && pwd)" # Convert to absolute path
local root_files=("README.md" "LICENSE" "CONTRIBUTE.md" "CNAME")
while [[ "$dir" != "/" ]]; do
for file in "${root_files[@]}"; do
if [[ -f "$dir/$file" ]]; then
echo "$dir"
return 0
fi
done
dir=$(dirname "$dir") # Move one level up
done
echo "No project root found"
return 1
}
# Get the project root dynamically
project_root=$(find_project_root)
if [[ -z "$project_root" ]]; then
echo "Error: Project root not found."
exit 1
fi
# Check if the project name is provided as an argument
if [[ -n "$1" ]]; then
project_name="$1"
else
echo "Please provide a project name: ./run_create_project.sh myproject [theme] [base_directory]"
exit 1
fi
# Use the second argument as the theme, or default to 'default'
if [[ -n "$2" ]]; then
theme="$2"
else
theme="default"
fi
# Use the third argument as the base directory if provided, otherwise default to the 'projects' directory
if [[ -n "$3" ]]; then
base_dir="$3"
else
base_dir="$project_root/projects"
fi
# Define the target project directory
target_dir="$base_dir/$project_name"
# Ensure the base directory is created if it doesn't exist
if [[ ! -d "$base_dir" ]]; then
echo "Creating base directory '$base_dir'..."
mkdir -p "$base_dir"
fi
# Create the project directory if it doesn't already exist
if [[ -d "$target_dir" ]]; then
echo "Error: Directory '$target_dir' already exists. Exiting."
exit 1
else
echo "Creating project directory '$target_dir'..."
mkdir -p "$target_dir"
fi
# Define the source directory for components and templates
components_dir="$project_root/components/default"
template_file="$project_root/templates/template_default.html"
scripts_dir="$project_root/scripts"
# Copy template_default.html to the target project directory
if [[ -f "$template_file" ]]; then
cp "$template_file" "$target_dir/"
echo "Copied template_default.html to '$target_dir'."
else
echo "Error: template_default.html not found in '$template_file'."
exit 1
fi
# Replace the data-theme attribute in the template with the selected theme
sed -i "s/data-theme=\"\"/data-theme=\"$theme\"/" "$target_dir/template_default.html"
echo "Applied theme '$theme' to template_default.html."
# Copy all components from the components directory to the target project directory
if [[ -d "$components_dir" ]]; then
cp "$components_dir"/* "$target_dir/"
echo "Copied all default components to '$target_dir'."
else
echo "Error: Components directory '$components_dir' does not exist."
exit 1
fi
# Copy run_generate.sh to the project directory
run_generate_script="$scripts_dir/run_generate.sh"
if [[ -f "$run_generate_script" ]]; then
cp "$run_generate_script" "$target_dir/"
echo "Copied run_generate.sh to '$target_dir'."
else
echo "Error: run_generate.sh not found in '$scripts_dir'."
fi
# Copy run_add.sh to the project directory
run_add_script="$scripts_dir/run_add.sh"
if [[ -f "$run_add_script" ]]; then
cp "$run_add_script" "$target_dir/"
echo "Copied run_add.sh to '$target_dir'."
else
echo "Error: run_add.sh not found in '$scripts_dir'."
fi
# Copy run_serve.sh to the project directory
run_serve_script="$scripts_dir/run_serve.sh"
if [[ -f "$run_serve_script" ]]; then
cp "$run_serve_script" "$target_dir/"
echo "Copied run_serve.sh to '$target_dir'."
else
echo "Error: run_serve.sh not found in '$scripts_dir'."
fi
# Run the project generate script with the theme, passing the project directory as the first argument
echo "Running the generate script in the project directory..."
cd "$target_dir" && ./run_generate.sh "$target_dir" "$theme"
echo "Project setup complete with theme '$theme' in directory '$base_dir/$project_name'."