Skip to content

Commit 11271a5

Browse files
committed
feat: version 2
1 parent 47ebb82 commit 11271a5

File tree

2 files changed

+198
-76
lines changed

2 files changed

+198
-76
lines changed

dev-env.sh

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
CURRENT_DIR=$(pwd)
6+
SCRIPT_DIR=$(dirname "$(realpath "$0")")
7+
8+
# Function to install dependencies in root
9+
install_root_dependencies() {
10+
echo "Running 'yarn install' in the root directory..."
11+
cd "$SCRIPT_DIR"
12+
yarn install
13+
}
14+
15+
# Function to build all packages
16+
build_packages() {
17+
echo "Building all packages..."
18+
cd "$SCRIPT_DIR"
19+
for package in packages/*; do
20+
if [ -d "$package" ]; then
21+
echo "Building $package..."
22+
cd "$package"
23+
if ! yarn build; then
24+
echo "yarn build failed for $package, trying yarn tsc..."
25+
yarn tsc || true
26+
fi
27+
cd "$SCRIPT_DIR"
28+
fi
29+
done
30+
}
31+
32+
# Function to create yarn links for all packages
33+
link_packages() {
34+
echo "Linking all packages..."
35+
cd "$SCRIPT_DIR"
36+
for package in packages/*; do
37+
if [ -d "$package" ]; then
38+
echo "Linking $package..."
39+
cd "$package"
40+
yarn link
41+
cd "$SCRIPT_DIR"
42+
fi
43+
done
44+
}
45+
46+
# Function to get available database types
47+
get_db_types() {
48+
cd "$SCRIPT_DIR"
49+
db_types=()
50+
for package in packages/cubejs-*-driver; do
51+
if [ -d "$package" ]; then
52+
db_name=$(basename "$package" | sed 's/cubejs-\(.*\)-driver/\1/')
53+
if [ "$db_name" != "base" ]; then
54+
db_types+=("$db_name")
55+
fi
56+
fi
57+
done
58+
echo "${db_types[@]}"
59+
}
60+
61+
# Function to create new project
62+
create_project() {
63+
local app_name=$1
64+
local db_type=$2
65+
66+
# If app_name is not provided, ask for it
67+
if [ -z "$app_name" ]; then
68+
read -p "Enter the application name: " app_name
69+
fi
70+
71+
# If db_type is not provided, show selection menu
72+
if [ -z "$db_type" ]; then
73+
# Get available database types
74+
readarray -t db_types < <(get_db_types)
75+
76+
echo "Available database types:"
77+
PS3='Please select the database type: '
78+
select DB_TYPE in "${db_types[@]}"
79+
do
80+
if [[ -n "$DB_TYPE" ]]; then
81+
db_type=$DB_TYPE
82+
break
83+
else
84+
echo "Invalid selection. Please try again."
85+
fi
86+
done
87+
fi
88+
89+
cd "$CURRENT_DIR"
90+
echo "Creating new project with name $app_name and database type $db_type..."
91+
node "$SCRIPT_DIR/packages/cubejs-cli/dist/src/index.js" create "$app_name" -d "$db_type"
92+
}
93+
94+
# Function to link packages to new project
95+
link_project_packages() {
96+
local app_name=$1
97+
98+
echo "Linking packages in the new project..."
99+
cd "$CURRENT_DIR/$app_name"
100+
for package in "$SCRIPT_DIR"/packages/*; do
101+
if [ -d "$package" ]; then
102+
package_name=$(node -p "require('$package/package.json').name")
103+
echo "Linking $package_name..."
104+
yarn link "$package_name"
105+
fi
106+
done
107+
}
108+
109+
# Main execution function
110+
wizard() {
111+
local app_name=$1
112+
local db_type=$2
113+
114+
install_root_dependencies
115+
build_packages
116+
link_packages
117+
create_project "$app_name" "$db_type"
118+
link_project_packages "$app_name"
119+
120+
echo "Project setup completed!"
121+
echo "You can now run 'yarn dev' in the $app_name directory to start your project."
122+
}
123+
124+
# Function to show help
125+
show_help() {
126+
echo "Development environment setup script for Cube"
127+
echo ""
128+
echo "Usage: ./dev-env.sh <command> [arguments]"
129+
echo ""
130+
echo "Commands:"
131+
echo " install Install dependencies in root directory"
132+
echo " Usage: ./dev-env.sh install"
133+
echo ""
134+
echo " build Build all packages"
135+
echo " Usage: ./dev-env.sh build"
136+
echo ""
137+
echo " drivers List available database drivers"
138+
echo " Usage: ./dev-env.sh drivers"
139+
echo ""
140+
echo " create Create a new project"
141+
echo " Usage: ./dev-env.sh create [app_name] [db_type]"
142+
echo " If arguments are omitted, will ask interactively"
143+
echo ""
144+
echo " link Link all packages and link them to a project"
145+
echo " Usage: ./dev-env.sh link [app_name]"
146+
echo ""
147+
echo " wizard Run all steps (install, build, link, create project)"
148+
echo " Usage: ./dev-env.sh wizard [app_name] [db_type]"
149+
echo ""
150+
echo "Options:"
151+
echo " -h, --help Show this help message"
152+
echo ""
153+
echo "Examples:"
154+
echo " ./dev-env.sh create my-app postgres"
155+
echo " ./dev-env.sh wizard my-app"
156+
echo " ./dev-env.sh link my-app"
157+
}
158+
159+
command=$1
160+
161+
# Show help if no command provided
162+
if [ -z "$command" ]; then
163+
show_help
164+
exit 0
165+
fi
166+
167+
case "$command" in
168+
"install")
169+
install_root_dependencies
170+
;;
171+
"build")
172+
build_packages
173+
;;
174+
"link")
175+
link_packages
176+
link_project_packages "$1"
177+
;;
178+
"drivers")
179+
get_db_types
180+
;;
181+
"create")
182+
create_project "$1" "$2"
183+
;;
184+
"wizard")
185+
wizard "$1" "$2"
186+
;;
187+
"-h"|"--help"|"help")
188+
show_help
189+
;;
190+
*)
191+
echo "Error: Unknown command '$command'"
192+
echo ""
193+
show_help
194+
exit 1
195+
;;
196+
esac
197+
198+
cd "$CURRENT_DIR"

dev_env_setup.sh

Lines changed: 0 additions & 76 deletions
This file was deleted.

0 commit comments

Comments
 (0)