Skip to content

Commit ae823c9

Browse files
authored
fix(dev_env_setup): use relative packages everywhere (#8910)
* fix(dev_env_setup): use relative packages everywhere * fix: use rollup * fix: remove link:dev * fix: don’t show “base” driver * feat: version 2 * fix: rename
1 parent 98b5013 commit ae823c9

File tree

3 files changed

+200
-158
lines changed

3 files changed

+200
-158
lines changed

dev-env.sh

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
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+
setup() {
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 " setup Run all steps (install, build, link, create project)"
148+
echo " Usage: ./dev-env.sh setup [app_name] [db_type]"
149+
echo " If arguments are omitted, will ask interactively"
150+
echo ""
151+
echo "Options:"
152+
echo " -h, --help Show this help message"
153+
echo ""
154+
echo "Examples:"
155+
echo " ./dev-env.sh create my-app postgres"
156+
echo " ./dev-env.sh setup my-app"
157+
echo " ./dev-env.sh link my-app"
158+
}
159+
160+
command=$1
161+
162+
# Show help if no command provided
163+
if [ -z "$command" ]; then
164+
show_help
165+
exit 0
166+
fi
167+
168+
case "$command" in
169+
"install")
170+
install_root_dependencies
171+
;;
172+
"build")
173+
build_packages
174+
;;
175+
"link")
176+
link_packages
177+
link_project_packages "$1"
178+
;;
179+
"drivers")
180+
get_db_types
181+
;;
182+
"create")
183+
create_project "$1" "$2"
184+
;;
185+
"setup")
186+
setup "$1" "$2"
187+
;;
188+
"-h"|"--help"|"help")
189+
show_help
190+
;;
191+
*)
192+
echo "Error: Unknown command '$command'"
193+
echo ""
194+
show_help
195+
exit 1
196+
;;
197+
esac
198+
199+
cd "$CURRENT_DIR"

dev_env_setup.sh

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

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
"tsc": "tsc --build",
2424
"tsc:watch": "tsc --build --watch",
2525
"clean": "rimraf packages/*/{tsconfig.tsbuildinfo,lib,dist}",
26-
"postinstall": "lerna link",
27-
"link:dev": "cd ./packages/cubejs-backend-shared && yarn link && cd ../cubejs-backend-cloud && yarn link && cd ../cubejs-backend-native && yarn link && cd ../cubejs-server && yarn link && cd ../cubejs-server-core && yarn link && cd ../cubejs-api-gateway && yarn link && cd ../cubejs-schema-compiler && yarn link && cd ../cubejs-query-orchestrator && yarn link && cd ../cubejs-athena-driver && yarn link && cd ../cubejs-duckdb-driver && yarn link && cd ../cubejs-bigquery-driver && yarn link && cd ../cubejs-postgres-driver && yarn link && cd ../cubejs-databricks-jdbc-driver && yarn link && cd ../cubejs-mssql-driver && yarn link && cd ../cubejs-clickhouse-driver && yarn link && cd ../cubejs-snowflake-driver && yarn link && cd ../cubejs-cubestore-driver && yarn link && cd ../cubejs-templates && yarn link && cd ../cubejs-client-core && yarn link && cd ../cubejs-client-ws-transport && yarn link && cd ../cubejs-playground && yarn link"
26+
"postinstall": "lerna link"
2827
},
2928
"author": "Cube Dev, Inc.",
3029
"dependencies": {

0 commit comments

Comments
 (0)