Skip to content

Commit 62ee0c1

Browse files
authored
chore(cube): Add script to simplify development environment setup (#8329)
1 parent 2913e1e commit 62ee0c1

File tree

2 files changed

+164
-0
lines changed

2 files changed

+164
-0
lines changed

CONTRIBUTING.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,14 @@ Cube.is written in a mixture of JavaScript, TypeScript, and Rust. TypeScript and
101101
11. Run `yarn link @cubejs-backend/server-core` in your project directory.
102102
12. Run `yarn dev` to start your testing project and verify changes.
103103

104+
Instead of running all of the above commands manually you can use the `dev_env_setup.sh` script:
105+
106+
1. Clone the Cube repository, `git clone https://github.com/cube-js/cube`.
107+
2. Navigate to your working projects directory and run `/path/to/cube/repo/dev_env_setup.sh`. The script will
108+
ask you some questions and run all the required commands. In case you decide to create a new testing project,
109+
it will be created in the current directory (that is why you probably don't want to run this script within
110+
cube repo directory).
111+
104112
### Debugging with WebStorm
105113

106114
1. Follow all the steps from the previous section. Make sure that the `yarn tsc:watch` daemon is running in the background.

dev_env_setup.sh

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
CURRENT_DIR=$(pwd)
6+
SCRIPT_DIR=$(dirname "$(realpath "$0")")
7+
8+
# Change to the cube repo directory
9+
cd "$SCRIPT_DIR"
10+
11+
# Step 1: Run yarn install in the root directory
12+
echo "Running 'yarn install' in the root directory..."
13+
yarn install
14+
15+
# Step 2: Run yarn build in the root directory
16+
echo "Running 'yarn build' in the root directory..."
17+
yarn build
18+
19+
# Step 3: Run yarn build in packages/cubejs-playground
20+
echo "Running 'yarn build' in packages/cubejs-playground..."
21+
cd packages/cubejs-playground
22+
yarn build
23+
cd ../..
24+
25+
# Step 4: Run yarn tsc for the first time
26+
echo "Running 'yarn tsc --build'..."
27+
yarn tsc
28+
29+
# Step 5: List available drivers and ask user to select
30+
echo "Listing available drivers..."
31+
available_drivers=$(ls packages | grep "driver")
32+
33+
PS3='Please select the drivers you want to use (enter number, then press Enter): '
34+
35+
# Display drivers without the prefix "cubejs-"
36+
select selected_driver in $(echo "$available_drivers" | sed 's/cubejs-//') "Finish selection"
37+
do
38+
if [[ "$selected_driver" == "Finish selection" ]]; then
39+
break
40+
fi
41+
selected_drivers+=("$selected_driver")
42+
echo "Selected drivers: ${selected_drivers[*]}"
43+
done
44+
45+
# Step 6-7: Run yarn link and yarn install in packages/cubejs-<pkg>
46+
for driver in "${selected_drivers[@]}"
47+
do
48+
echo "Linking and installing dependencies for $driver..."
49+
cd "packages/cubejs-$driver"
50+
yarn link
51+
yarn install
52+
cd ../..
53+
done
54+
55+
# Step 8: Run yarn link @cubejs-backend/<pkg> in packages/cubejs-server-core
56+
cd packages/cubejs-server-core
57+
for driver in "${selected_drivers[@]}"
58+
do
59+
echo "Linking @cubejs-backend/$driver in packages/cubejs-server-core..."
60+
yarn link @cubejs-backend/"$driver"
61+
done
62+
cd ../..
63+
64+
# Step 9: Run yarn link in packages/cubejs-server-core
65+
echo "Running 'yarn link' in packages/cubejs-server-core..."
66+
cd packages/cubejs-server-core
67+
yarn link
68+
cd ../..
69+
70+
# Change back to the original directory
71+
cd "$CURRENT_DIR"
72+
73+
# Step 10: Ask user if they want to create a new test project
74+
read -p "Do you want to create a new test project? (yes/no, default: yes): " CREATE_PROJECT
75+
CREATE_PROJECT=${CREATE_PROJECT:-yes}
76+
77+
if [[ "$CREATE_PROJECT" == "yes" || "$CREATE_PROJECT" == "y" ]]; then
78+
read -p "Enter the application name: " APP_NAME
79+
80+
# List of available database types (hardcoded for now as of https://cube.dev/docs/reference/cli)
81+
db_types=("postgres" "mysql" "athena" "mongodb" "bigquery" "redshift" "mssql" "clickhouse" "snowflake" "presto" "druid")
82+
83+
echo "Listing available database types..."
84+
PS3='Please select the database type: '
85+
select DB_TYPE in "${db_types[@]}"
86+
do
87+
if [[ -n "$DB_TYPE" ]]; then
88+
break
89+
else
90+
echo "Invalid selection. Please try again."
91+
fi
92+
done
93+
94+
# Create new project using cubejs-cli
95+
echo "Creating new project with name $APP_NAME and database type $DB_TYPE..."
96+
npx cubejs-cli create "$APP_NAME" -d "$DB_TYPE"
97+
98+
# Step 11: Run yarn link @cubejs-backend/server-core in your project directory
99+
echo "Linking @cubejs-backend/server-core in the project directory..."
100+
cd "$APP_NAME"
101+
yarn link @cubejs-backend/server-core
102+
cd ../
103+
else
104+
echo "Ok. No problem!"
105+
echo "You need to run 'yarn link @cubejs-backend/server-core' in your project directory manually"
106+
fi
107+
108+
# Step 11: Ask user if they plan to make changes to Rust code
109+
read -p "Do you plan to make changes to Rust code? (yes/no, default: no): " RUST_CHANGES
110+
RUST_CHANGES=${RUST_CHANGES:-no}
111+
112+
if [[ "$RUST_CHANGES" == "yes" || "$RUST_CHANGES" == "y" ]]; then
113+
# Run yarn link:dev in the script directory
114+
cd "$SCRIPT_DIR"
115+
echo "Running 'yarn link:dev' in the root directory..."
116+
yarn link:dev
117+
118+
if [[ "$CREATE_PROJECT" == "yes" || "$CREATE_PROJECT" == "y" ]]; then
119+
dev_pkgs=("@cubejs-backend/shared"
120+
"@cubejs-backend/cloud"
121+
"@cubejs-backend/native"
122+
"@cubejs-backend/server"
123+
"@cubejs-backend/server-core"
124+
"@cubejs-backend/api-gateway"
125+
"@cubejs-backend/schema-compiler"
126+
"@cubejs-backend/query-orchestrator"
127+
"@cubejs-backend/athena-driver"
128+
"@cubejs-backend/duckdb-driver"
129+
"@cubejs-backend/bigquery-driver"
130+
"@cubejs-backend/postgres-driver"
131+
"@cubejs-backend/databricks-jdbc-driver"
132+
"@cubejs-backend/mssql-driver"
133+
"@cubejs-backend/clickhouse-driver"
134+
"@cubejs-backend/snowflake-driver"
135+
"@cubejs-backend/cubestore-driver"
136+
"@cubejs-backend/templates"
137+
"@cubejs-client/core"
138+
"@cubejs-client/ws-transport"
139+
"@cubejs-client/playground"
140+
)
141+
142+
cd "$CURRENT_DIR/$APP_NAME"
143+
echo "Linking dev packages in $APP_NAME project..."
144+
145+
for pkg in "${dev_pkgs[@]}"
146+
do
147+
echo "Linking $pkg..."
148+
yarn link "$pkg"
149+
done
150+
else
151+
echo "Don't forget to link packages that you plan to modify inside your project!"
152+
fi
153+
fi
154+
155+
echo "All steps completed successfully!"
156+
echo "Run 'yarn dev' to start your testing project and verify changes."

0 commit comments

Comments
 (0)