From e8a52726f79f955133f7a8013d2183a8c6f99da3 Mon Sep 17 00:00:00 2001 From: johancube Date: Mon, 4 Nov 2024 22:14:14 +0300 Subject: [PATCH 1/6] fix(dev_env_setup): use relative packages everywhere --- dev_env_setup.sh | 182 +++++++++++++++-------------------------------- 1 file changed, 56 insertions(+), 126 deletions(-) diff --git a/dev_env_setup.sh b/dev_env_setup.sh index 112812c4d9209..5912d36857c65 100755 --- a/dev_env_setup.sh +++ b/dev_env_setup.sh @@ -12,145 +12,75 @@ cd "$SCRIPT_DIR" echo "Running 'yarn install' in the root directory..." yarn install -# Step 2: Run yarn build in the root directory -echo "Running 'yarn build' in the root directory..." -yarn build - -# Step 3: Run yarn build in packages/cubejs-playground -echo "Running 'yarn build' in packages/cubejs-playground..." -cd packages/cubejs-playground -yarn build -cd ../.. - -# Step 4: Run yarn tsc for the first time -echo "Running 'yarn tsc --build'..." -yarn tsc - -# Step 5: List available drivers and ask user to select -echo "Listing available drivers..." -available_drivers=$(ls packages | grep "driver") - -PS3='Please select the drivers you want to use (enter number, then press Enter): ' +# Step 2: Build all packages in packages directory +echo "Building all packages..." +for package in packages/*; do + if [ -d "$package" ]; then + echo "Building $package..." + cd "$package" + if ! yarn build; then + echo "yarn build failed for $package, trying yarn tsc..." + yarn tsc || true # Continue even if tsc fails + fi + cd "$SCRIPT_DIR" + fi +done -# Display drivers without the prefix "cubejs-" -select selected_driver in $(echo "$available_drivers" | sed 's/cubejs-//') "Finish selection" -do - if [[ "$selected_driver" == "Finish selection" ]]; then - break +# Step 3: Link all packages +echo "Linking all packages..." +for package in packages/*; do + if [ -d "$package" ]; then + echo "Linking $package..." + cd "$package" + yarn link + cd "$SCRIPT_DIR" fi - selected_drivers+=("$selected_driver") - echo "Selected drivers: ${selected_drivers[*]}" done -# Step 6-7: Run yarn link and yarn install in packages/cubejs- -for driver in "${selected_drivers[@]}" -do - echo "Linking and installing dependencies for $driver..." - cd "packages/cubejs-$driver" - yarn link - yarn install - cd ../.. +# Step 4: Ask for application name and database type +read -p "Enter the application name: " APP_NAME + +# Get available database types from packages directory +db_types=() +for package in packages/cubejs-*-driver; do + if [ -d "$package" ]; then + db_name=$(basename "$package" | sed 's/cubejs-\(.*\)-driver/\1/') + db_types+=("$db_name") + fi done -# Step 8: Run yarn link @cubejs-backend/ in packages/cubejs-server-core -cd packages/cubejs-server-core -for driver in "${selected_drivers[@]}" +echo "Available database types:" +PS3='Please select the database type: ' +select DB_TYPE in "${db_types[@]}" do - echo "Linking @cubejs-backend/$driver in packages/cubejs-server-core..." - yarn link @cubejs-backend/"$driver" + if [[ -n "$DB_TYPE" ]]; then + break + else + echo "Invalid selection. Please try again." + fi done -cd ../.. - -# Step 9: Run yarn link in packages/cubejs-server-core -echo "Running 'yarn link' in packages/cubejs-server-core..." -cd packages/cubejs-server-core -yarn link -cd ../.. # Change back to the original directory cd "$CURRENT_DIR" -# Step 10: Ask user if they want to create a new test project -read -p "Do you want to create a new test project? (yes/no, default: yes): " CREATE_PROJECT -CREATE_PROJECT=${CREATE_PROJECT:-yes} - -if [[ "$CREATE_PROJECT" == "yes" || "$CREATE_PROJECT" == "y" ]]; then - read -p "Enter the application name: " APP_NAME - - # List of available database types (hardcoded for now as of https://cube.dev/docs/reference/cli) - db_types=("postgres" "mysql" "athena" "mongodb" "bigquery" "redshift" "mssql" "clickhouse" "snowflake" "presto" "druid") - - echo "Listing available database types..." - PS3='Please select the database type: ' - select DB_TYPE in "${db_types[@]}" - do - if [[ -n "$DB_TYPE" ]]; then - break - else - echo "Invalid selection. Please try again." - fi - done - - # Create new project using cubejs-cli - echo "Creating new project with name $APP_NAME and database type $DB_TYPE..." - npx cubejs-cli create "$APP_NAME" -d "$DB_TYPE" - - # Step 11: Run yarn link @cubejs-backend/server-core in your project directory - echo "Linking @cubejs-backend/server-core in the project directory..." - cd "$APP_NAME" - yarn link @cubejs-backend/server-core - cd ../ -else - echo "Ok. No problem!" - echo "You need to run 'yarn link @cubejs-backend/server-core' in your project directory manually" -fi - -# Step 11: Ask user if they plan to make changes to Rust code -read -p "Do you plan to make changes to Rust code? (yes/no, default: no): " RUST_CHANGES -RUST_CHANGES=${RUST_CHANGES:-no} +# Create new project using cubejs-cli +echo "Creating new project with name $APP_NAME and database type $DB_TYPE..." +node "$SCRIPT_DIR/packages/cubejs-cli/dist/src/index.js" create "$APP_NAME" -d "$DB_TYPE" -if [[ "$RUST_CHANGES" == "yes" || "$RUST_CHANGES" == "y" ]]; then - # Run yarn link:dev in the script directory - cd "$SCRIPT_DIR" - echo "Running 'yarn link:dev' in the root directory..." - yarn link:dev +# Step 5: Link all packages in the new project +echo "Linking packages in the new project..." +cd "$APP_NAME" - if [[ "$CREATE_PROJECT" == "yes" || "$CREATE_PROJECT" == "y" ]]; then - dev_pkgs=("@cubejs-backend/shared" - "@cubejs-backend/cloud" - "@cubejs-backend/native" - "@cubejs-backend/server" - "@cubejs-backend/server-core" - "@cubejs-backend/api-gateway" - "@cubejs-backend/schema-compiler" - "@cubejs-backend/query-orchestrator" - "@cubejs-backend/athena-driver" - "@cubejs-backend/duckdb-driver" - "@cubejs-backend/bigquery-driver" - "@cubejs-backend/postgres-driver" - "@cubejs-backend/databricks-jdbc-driver" - "@cubejs-backend/mssql-driver" - "@cubejs-backend/clickhouse-driver" - "@cubejs-backend/snowflake-driver" - "@cubejs-backend/cubestore-driver" - "@cubejs-backend/templates" - "@cubejs-client/core" - "@cubejs-client/ws-transport" - "@cubejs-client/playground" - ) - - cd "$CURRENT_DIR/$APP_NAME" - echo "Linking dev packages in $APP_NAME project..." - - for pkg in "${dev_pkgs[@]}" - do - echo "Linking $pkg..." - yarn link "$pkg" - done - else - echo "Don't forget to link packages that you plan to modify inside your project!" +for package in "$SCRIPT_DIR"/packages/*; do + if [ -d "$package" ]; then + package_name=$(node -p "require('$package/package.json').name") + echo "Linking $package_name..." + yarn link "$package_name" fi -fi +done -echo "All steps completed successfully!" -echo "Run 'yarn dev' to start your testing project and verify changes." +echo "Project setup completed!" +echo "You can now run 'yarn dev' in the $APP_NAME directory to start your project." + +# Change back to the original directory +cd "$CURRENT_DIR" From 8484296919e974b45f0fa8bafc860842b333672c Mon Sep 17 00:00:00 2001 From: johancube Date: Fri, 22 Nov 2024 17:21:10 +0300 Subject: [PATCH 2/6] fix: use rollup --- dev_env_setup.sh | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/dev_env_setup.sh b/dev_env_setup.sh index 5912d36857c65..ff09bd9176005 100755 --- a/dev_env_setup.sh +++ b/dev_env_setup.sh @@ -11,20 +11,8 @@ cd "$SCRIPT_DIR" # Step 1: Run yarn install in the root directory echo "Running 'yarn install' in the root directory..." yarn install - -# Step 2: Build all packages in packages directory echo "Building all packages..." -for package in packages/*; do - if [ -d "$package" ]; then - echo "Building $package..." - cd "$package" - if ! yarn build; then - echo "yarn build failed for $package, trying yarn tsc..." - yarn tsc || true # Continue even if tsc fails - fi - cd "$SCRIPT_DIR" - fi -done +yarn build # Step 3: Link all packages echo "Linking all packages..." From c89f86d08b07c46e68dcbc2d96dcfb790f0b83cc Mon Sep 17 00:00:00 2001 From: johancube Date: Fri, 22 Nov 2024 17:21:18 +0300 Subject: [PATCH 3/6] fix: remove link:dev --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index c7acadf038b33..825fbfde747f3 100644 --- a/package.json +++ b/package.json @@ -23,8 +23,7 @@ "tsc": "tsc --build", "tsc:watch": "tsc --build --watch", "clean": "rimraf packages/*/{tsconfig.tsbuildinfo,lib,dist}", - "postinstall": "lerna link", - "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" + "postinstall": "lerna link" }, "author": "Cube Dev, Inc.", "dependencies": { From 47ebb82e92d397a6cbbb8e112ac9b1bca0020d84 Mon Sep 17 00:00:00 2001 From: johancube Date: Fri, 22 Nov 2024 18:00:22 +0300 Subject: [PATCH 4/6] =?UTF-8?q?fix:=20don=E2=80=99t=20show=20=E2=80=9Cbase?= =?UTF-8?q?=E2=80=9D=20driver?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dev_env_setup.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dev_env_setup.sh b/dev_env_setup.sh index ff09bd9176005..fd22f0e59a3ec 100755 --- a/dev_env_setup.sh +++ b/dev_env_setup.sh @@ -33,7 +33,9 @@ db_types=() for package in packages/cubejs-*-driver; do if [ -d "$package" ]; then db_name=$(basename "$package" | sed 's/cubejs-\(.*\)-driver/\1/') - db_types+=("$db_name") + if [ "$db_name" != "base" ]; then + db_types+=("$db_name") + fi fi done From 11271a58bbf75b0e05ce5c4588f237690a0e2272 Mon Sep 17 00:00:00 2001 From: johancube Date: Fri, 22 Nov 2024 21:20:21 +0300 Subject: [PATCH 5/6] feat: version 2 --- dev-env.sh | 198 +++++++++++++++++++++++++++++++++++++++++++++++ dev_env_setup.sh | 76 ------------------ 2 files changed, 198 insertions(+), 76 deletions(-) create mode 100755 dev-env.sh delete mode 100755 dev_env_setup.sh diff --git a/dev-env.sh b/dev-env.sh new file mode 100755 index 0000000000000..d5637e28ce6c4 --- /dev/null +++ b/dev-env.sh @@ -0,0 +1,198 @@ +#!/bin/bash + +set -e + +CURRENT_DIR=$(pwd) +SCRIPT_DIR=$(dirname "$(realpath "$0")") + +# Function to install dependencies in root +install_root_dependencies() { + echo "Running 'yarn install' in the root directory..." + cd "$SCRIPT_DIR" + yarn install +} + +# Function to build all packages +build_packages() { + echo "Building all packages..." + cd "$SCRIPT_DIR" + for package in packages/*; do + if [ -d "$package" ]; then + echo "Building $package..." + cd "$package" + if ! yarn build; then + echo "yarn build failed for $package, trying yarn tsc..." + yarn tsc || true + fi + cd "$SCRIPT_DIR" + fi + done +} + +# Function to create yarn links for all packages +link_packages() { + echo "Linking all packages..." + cd "$SCRIPT_DIR" + for package in packages/*; do + if [ -d "$package" ]; then + echo "Linking $package..." + cd "$package" + yarn link + cd "$SCRIPT_DIR" + fi + done +} + +# Function to get available database types +get_db_types() { + cd "$SCRIPT_DIR" + db_types=() + for package in packages/cubejs-*-driver; do + if [ -d "$package" ]; then + db_name=$(basename "$package" | sed 's/cubejs-\(.*\)-driver/\1/') + if [ "$db_name" != "base" ]; then + db_types+=("$db_name") + fi + fi + done + echo "${db_types[@]}" +} + +# Function to create new project +create_project() { + local app_name=$1 + local db_type=$2 + + # If app_name is not provided, ask for it + if [ -z "$app_name" ]; then + read -p "Enter the application name: " app_name + fi + + # If db_type is not provided, show selection menu + if [ -z "$db_type" ]; then + # Get available database types + readarray -t db_types < <(get_db_types) + + echo "Available database types:" + PS3='Please select the database type: ' + select DB_TYPE in "${db_types[@]}" + do + if [[ -n "$DB_TYPE" ]]; then + db_type=$DB_TYPE + break + else + echo "Invalid selection. Please try again." + fi + done + fi + + cd "$CURRENT_DIR" + echo "Creating new project with name $app_name and database type $db_type..." + node "$SCRIPT_DIR/packages/cubejs-cli/dist/src/index.js" create "$app_name" -d "$db_type" +} + +# Function to link packages to new project +link_project_packages() { + local app_name=$1 + + echo "Linking packages in the new project..." + cd "$CURRENT_DIR/$app_name" + for package in "$SCRIPT_DIR"/packages/*; do + if [ -d "$package" ]; then + package_name=$(node -p "require('$package/package.json').name") + echo "Linking $package_name..." + yarn link "$package_name" + fi + done +} + +# Main execution function +wizard() { + local app_name=$1 + local db_type=$2 + + install_root_dependencies + build_packages + link_packages + create_project "$app_name" "$db_type" + link_project_packages "$app_name" + + echo "Project setup completed!" + echo "You can now run 'yarn dev' in the $app_name directory to start your project." +} + +# Function to show help +show_help() { + echo "Development environment setup script for Cube" + echo "" + echo "Usage: ./dev-env.sh [arguments]" + echo "" + echo "Commands:" + echo " install Install dependencies in root directory" + echo " Usage: ./dev-env.sh install" + echo "" + echo " build Build all packages" + echo " Usage: ./dev-env.sh build" + echo "" + echo " drivers List available database drivers" + echo " Usage: ./dev-env.sh drivers" + echo "" + echo " create Create a new project" + echo " Usage: ./dev-env.sh create [app_name] [db_type]" + echo " If arguments are omitted, will ask interactively" + echo "" + echo " link Link all packages and link them to a project" + echo " Usage: ./dev-env.sh link [app_name]" + echo "" + echo " wizard Run all steps (install, build, link, create project)" + echo " Usage: ./dev-env.sh wizard [app_name] [db_type]" + echo "" + echo "Options:" + echo " -h, --help Show this help message" + echo "" + echo "Examples:" + echo " ./dev-env.sh create my-app postgres" + echo " ./dev-env.sh wizard my-app" + echo " ./dev-env.sh link my-app" +} + +command=$1 + +# Show help if no command provided +if [ -z "$command" ]; then + show_help + exit 0 +fi + +case "$command" in + "install") + install_root_dependencies + ;; + "build") + build_packages + ;; + "link") + link_packages + link_project_packages "$1" + ;; + "drivers") + get_db_types + ;; + "create") + create_project "$1" "$2" + ;; + "wizard") + wizard "$1" "$2" + ;; + "-h"|"--help"|"help") + show_help + ;; + *) + echo "Error: Unknown command '$command'" + echo "" + show_help + exit 1 + ;; +esac + +cd "$CURRENT_DIR" diff --git a/dev_env_setup.sh b/dev_env_setup.sh deleted file mode 100755 index fd22f0e59a3ec..0000000000000 --- a/dev_env_setup.sh +++ /dev/null @@ -1,76 +0,0 @@ -#!/bin/bash - -set -e - -CURRENT_DIR=$(pwd) -SCRIPT_DIR=$(dirname "$(realpath "$0")") - -# Change to the cube repo directory -cd "$SCRIPT_DIR" - -# Step 1: Run yarn install in the root directory -echo "Running 'yarn install' in the root directory..." -yarn install -echo "Building all packages..." -yarn build - -# Step 3: Link all packages -echo "Linking all packages..." -for package in packages/*; do - if [ -d "$package" ]; then - echo "Linking $package..." - cd "$package" - yarn link - cd "$SCRIPT_DIR" - fi -done - -# Step 4: Ask for application name and database type -read -p "Enter the application name: " APP_NAME - -# Get available database types from packages directory -db_types=() -for package in packages/cubejs-*-driver; do - if [ -d "$package" ]; then - db_name=$(basename "$package" | sed 's/cubejs-\(.*\)-driver/\1/') - if [ "$db_name" != "base" ]; then - db_types+=("$db_name") - fi - fi -done - -echo "Available database types:" -PS3='Please select the database type: ' -select DB_TYPE in "${db_types[@]}" -do - if [[ -n "$DB_TYPE" ]]; then - break - else - echo "Invalid selection. Please try again." - fi -done - -# Change back to the original directory -cd "$CURRENT_DIR" - -# Create new project using cubejs-cli -echo "Creating new project with name $APP_NAME and database type $DB_TYPE..." -node "$SCRIPT_DIR/packages/cubejs-cli/dist/src/index.js" create "$APP_NAME" -d "$DB_TYPE" - -# Step 5: Link all packages in the new project -echo "Linking packages in the new project..." -cd "$APP_NAME" - -for package in "$SCRIPT_DIR"/packages/*; do - if [ -d "$package" ]; then - package_name=$(node -p "require('$package/package.json').name") - echo "Linking $package_name..." - yarn link "$package_name" - fi -done - -echo "Project setup completed!" -echo "You can now run 'yarn dev' in the $APP_NAME directory to start your project." - -# Change back to the original directory -cd "$CURRENT_DIR" From 9faad45ecff62b263f35916b2c4db18b824fed90 Mon Sep 17 00:00:00 2001 From: johancube Date: Mon, 25 Nov 2024 14:02:54 +0300 Subject: [PATCH 6/6] fix: rename --- dev-env.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/dev-env.sh b/dev-env.sh index d5637e28ce6c4..518e6d0d9ae89 100755 --- a/dev-env.sh +++ b/dev-env.sh @@ -107,7 +107,7 @@ link_project_packages() { } # Main execution function -wizard() { +setup() { local app_name=$1 local db_type=$2 @@ -144,15 +144,16 @@ show_help() { echo " link Link all packages and link them to a project" echo " Usage: ./dev-env.sh link [app_name]" echo "" - echo " wizard Run all steps (install, build, link, create project)" - echo " Usage: ./dev-env.sh wizard [app_name] [db_type]" + echo " setup Run all steps (install, build, link, create project)" + echo " Usage: ./dev-env.sh setup [app_name] [db_type]" + echo " If arguments are omitted, will ask interactively" echo "" echo "Options:" echo " -h, --help Show this help message" echo "" echo "Examples:" echo " ./dev-env.sh create my-app postgres" - echo " ./dev-env.sh wizard my-app" + echo " ./dev-env.sh setup my-app" echo " ./dev-env.sh link my-app" } @@ -181,8 +182,8 @@ case "$command" in "create") create_project "$1" "$2" ;; - "wizard") - wizard "$1" "$2" + "setup") + setup "$1" "$2" ;; "-h"|"--help"|"help") show_help