Skip to content

Commit 83695e6

Browse files
Merge branch 'master' into next
# Conflicts: # CHANGELOG.md
2 parents 6a88c18 + 51461f6 commit 83695e6

File tree

12 files changed

+1288
-39
lines changed

12 files changed

+1288
-39
lines changed

.vscode/README.devsetup.md

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
# Local Development Setup Guide - macOS/Ubuntu
2+
3+
## Prerequisites
4+
- macOS 10.15 or later / Ubuntu 22.04/24.04 LTS
5+
- Terminal access
6+
- Homebrew package manager
7+
8+
## Installation Steps
9+
10+
### 1. Install [Homebrew](https://brew.sh/) (if not installed) (macOS only)
11+
```bash
12+
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
13+
```
14+
15+
### 2. Install MongoDB
16+
17+
[macOS](https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-os-x/):
18+
19+
```bash
20+
brew tap mongodb/brew
21+
brew install mongodb-community
22+
brew services start mongodb-community
23+
```
24+
25+
[Ubuntu](https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-ubuntu/):
26+
27+
```bash
28+
# Install required packages
29+
sudo apt-get install -y gnupg curl unzip
30+
31+
# Import MongoDB public GPG key
32+
curl -fsSL https://www.mongodb.org/static/pgp/server-8.0.asc | \
33+
sudo gpg -o /usr/share/keyrings/mongodb-server-8.0.gpg \
34+
--dearmor
35+
36+
# Create list file for MongoDB
37+
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] https://repo.mongodb.org/apt/ubuntu noble/mongodb-org/8.0 multiverse" | \
38+
sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list
39+
40+
# Update and install MongoDB
41+
sudo apt-get update
42+
sudo apt-get install -y mongodb-org
43+
44+
# Start and enable MongoDB service
45+
sudo systemctl start mongod
46+
sudo systemctl enable mongod
47+
```
48+
49+
### 3. Install [Fast Node Manager (fnm)](https://github.com/Schniz/fnm) (if no Node.js version manager is installed)
50+
```bash
51+
curl -fsSL https://fnm.vercel.app/install | bash
52+
```
53+
54+
Add fnm to your shell configuration:
55+
56+
macOS:
57+
58+
```bash
59+
echo 'eval "$(fnm env --use-on-cd)"' >> ~/.zshrc
60+
source ~/.zshrc
61+
```
62+
Ubuntu:
63+
64+
```bash
65+
echo 'eval "$(fnm env --use-on-cd)"' >> ~/.bashrc
66+
source ~/.bashrc
67+
```
68+
69+
### 4. Install Node.js
70+
```bash
71+
fnm install 22
72+
fnm use 22
73+
```
74+
75+
Verify the installation:
76+
```bash
77+
node --version
78+
npm --version
79+
```
80+
81+
### 5. Run Development Setup Script
82+
83+
Copy the `devsetup.sh` script from `.vscode/devsetup.sh` to your project directory (script clones the repo automatically).
84+
1. Navigate to your project directory
85+
2. Make the setup script executable:
86+
```bash
87+
chmod +x ./devsetup.sh
88+
```
89+
90+
1. Run the setup script:
91+
```bash
92+
./devsetup.sh
93+
```
94+
95+
The script will:
96+
- Clone the repository
97+
- Install dependencies
98+
- Configure the development environment
99+
100+
### 6. Start the Development of Server/Client
101+
102+
Use the debug configuration(server/client) in VS Code to run the code.
103+
104+
By default client runs on `locahost:6001` and server runs on `localhost:3001`
105+
106+
107+
## Verification
108+
After installation, verify all components:
109+
110+
- MongoDB:
111+
112+
macOS:
113+
114+
```bash
115+
brew services list | grep mongodb
116+
```
117+
118+
Ubuntu:
119+
120+
```bash
121+
sudo systemctl status mongod
122+
```
123+
124+
- Node.js:
125+
```bash
126+
node --version
127+
```
128+
129+
## Troubleshooting
130+
- If MongoDB fails to start, try:
131+
132+
macOS:
133+
134+
```bash
135+
brew services restart mongodb-community
136+
```
137+
138+
Ubuntu:
139+
140+
```bash
141+
sudo systemctl restart mongod
142+
sudo systemctl status mongod
143+
```
144+
145+
- If the setup script fails, check the generated log file in the current directory named \`setup_YYYYMMDD_HHMMSS.log\`

.vscode/devsetup.sh

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
#!/bin/bash
2+
# shellcheck disable=SC2016,SC2086,SC2046
3+
4+
# Script configuration
5+
set -euo pipefail # Exit on error, undefined vars, and pipe failures
6+
trap 'echo "Error on line $LINENO. Exit code: $?"' ERR
7+
8+
# Configuration variables
9+
REPO_URL="[email protected]:Countly/countly-server.git"
10+
REPO_NAME="countly-community"
11+
BRANCH="master"
12+
LOG_FILE="community_setup_$(date +%Y%m%d_%H%M%S).log"
13+
DIR="$(pwd)/$REPO_NAME"
14+
15+
# Plugins that will be disabled by default
16+
DISABLED_PLUGINS=(
17+
"browser"
18+
"empty"
19+
"enterpriseinfo"
20+
"hooks"
21+
"ip_store"
22+
"ldap"
23+
"old-ui-compatibility"
24+
"push"
25+
"recaptcha"
26+
"tracker"
27+
"two-factor-auth"
28+
"vue-example"
29+
"white-labeling"
30+
)
31+
32+
# Logging function
33+
log() {
34+
local level=$1
35+
shift
36+
local message=$*
37+
local timestamp
38+
timestamp=$(date '+%Y-%m-%d %H:%M:%S')
39+
echo -e "${timestamp} [${level}] ${message}" | tee -a "$LOG_FILE"
40+
}
41+
42+
# Check if command exists
43+
command_exists() {
44+
command -v "$1" >/dev/null 2>&1
45+
}
46+
47+
# Prerequisites check
48+
check_prerequisites() {
49+
log "INFO" "Checking prerequisites..."
50+
51+
local prerequisites=(git node npm)
52+
for cmd in "${prerequisites[@]}"; do
53+
if ! command_exists "$cmd"; then
54+
log "ERROR" "Required command '$cmd' not found. Please install it and try again."
55+
exit 1
56+
fi
57+
done
58+
59+
# Create nodejs symlink if it doesn't exist and node is not already available as nodejs
60+
if ! command_exists nodejs && command_exists node; then
61+
log "INFO" "Creating nodejs symlink..."
62+
sudo ln -s "$(command -v node)" /usr/local/bin/nodejs || {
63+
log "WARNING" "Could not create nodejs symlink, but continuing as node is available"
64+
}
65+
fi
66+
67+
log "INFO" "All prerequisites verified"
68+
}
69+
70+
# Repository setup
71+
setup_repository() {
72+
log "INFO" "Setting up repository..."
73+
74+
if [ -d "$REPO_NAME" ]; then
75+
local answer
76+
read -r -p "Directory $REPO_NAME already exists. Backup (b), remove (r), or exit (e)? " answer
77+
case $answer in
78+
b|B)
79+
log "INFO" "Backing up existing directory..."
80+
mv "$REPO_NAME" "${REPO_NAME}_backup_$(date +%Y%m%d_%H%M%S)"
81+
;;
82+
r|R)
83+
log "INFO" "Removing existing directory..."
84+
rm -rf "$REPO_NAME"
85+
;;
86+
*)
87+
log "INFO" "Exiting as per user request"
88+
exit 0
89+
;;
90+
esac
91+
fi
92+
93+
git clone "$REPO_URL" "$REPO_NAME" || {
94+
log "ERROR" "Failed to clone repository. Please check your SSH key and repository access."
95+
exit 1
96+
}
97+
98+
cd "$REPO_NAME" || exit 1
99+
100+
# Git configuration
101+
git config --global --add safe.directory "$DIR"
102+
git config core.fileMode false
103+
git checkout "$BRANCH"
104+
105+
# Submodules setup if any
106+
log "INFO" "Setting up submodules..."
107+
git submodule status
108+
git pull
109+
git submodule init
110+
git submodule update
111+
}
112+
113+
# Configuration setup
114+
setup_configuration() {
115+
log "INFO" "Setting up configuration files..."
116+
117+
# Copy config files if they don't exist
118+
cp -n "$DIR/api/config.sample.js" "$DIR/api/config.js" || log "WARNING" "Skipping api config - file may already exist"
119+
cp -n "$DIR/plugins/plugins.default.json" "$DIR/plugins/plugins.json" || log "WARNING" "Skipping plugins config - file may already exist"
120+
cp -n "$DIR/frontend/express/config.sample.js" "$DIR/frontend/express/config.js" || log "WARNING" "Skipping express config - file may already exist"
121+
cp -n "$DIR/frontend/express/public/javascripts/countly/countly.config.sample.js" "$DIR/frontend/express/public/javascripts/countly/countly.config.js" || log "WARNING" "Skipping frontend config - file may already exist"
122+
123+
# Use platform-independent sed syntax
124+
if [[ "$OSTYPE" == "darwin"* ]]; then
125+
# macOS
126+
sed -i '' 's#countlyGlobal.path#"http://localhost:3001"#g' "$DIR/frontend/express/public/javascripts/countly/countly.config.js"
127+
sed -i '' 's/max_pool_size: 500/max_pool_size: 20/g' "$DIR/api/config.js"
128+
else
129+
# Linux and others
130+
sed -i 's#countlyGlobal.path#"http://localhost:3001"#g' "$DIR/frontend/express/public/javascripts/countly/countly.config.js"
131+
sed -i 's/max_pool_size: 500/max_pool_size: 20/g' "$DIR/api/config.js"
132+
fi
133+
}
134+
135+
# Plugin management
136+
manage_plugins() {
137+
log "INFO" "Managing plugins..."
138+
139+
PLUGIN_JS_PATH="$DIR/bin/commands/scripts/plugin.js"
140+
for dir in "$DIR/plugins"/*/; do
141+
plugin=$(basename "$dir")
142+
143+
# Using a for loop to check array membership
144+
is_disabled=0
145+
for disabled_plugin in "${DISABLED_PLUGINS[@]}"; do
146+
if [ "$plugin" = "$disabled_plugin" ]; then
147+
is_disabled=1
148+
break
149+
fi
150+
done
151+
152+
if [ "$is_disabled" -eq 1 ]; then
153+
log "INFO" "Disabling $plugin..."
154+
if node "$PLUGIN_JS_PATH" disable "$plugin"; then
155+
log "INFO" "Successfully disabled $plugin"
156+
else
157+
log "ERROR" "Failed to disable $plugin"
158+
fi
159+
else
160+
log "INFO" "Enabling $plugin..."
161+
if node "$PLUGIN_JS_PATH" enable "$plugin"; then
162+
log "INFO" "Successfully enabled $plugin"
163+
else
164+
log "ERROR" "Failed to enable $plugin"
165+
fi
166+
fi
167+
done
168+
}
169+
170+
# Main execution
171+
main() {
172+
log "INFO" "Starting community setup script..."
173+
174+
check_prerequisites
175+
setup_repository
176+
177+
# Set permissions - but don't fail if we don't have sudo
178+
sudo chmod -R 766 "$DIR" || {
179+
log "WARNING" "Could not set full permissions on $DIR. You may need to adjust permissions manually."
180+
}
181+
182+
# Install dependencies
183+
cd "$DIR" || exit 1
184+
npm install
185+
186+
setup_configuration
187+
manage_plugins
188+
189+
# build locales and sass
190+
npx grunt dist-all
191+
192+
log "INFO" "Community setup completed successfully!"
193+
log "INFO" "You can now start Countly by using the debugger"
194+
}
195+
196+
# Execute main function
197+
main

.vscode/disable_plugins.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
echo "Script started. Working directory: $(pwd)"
6+
echo "Received arguments: $*"
7+
8+
if [ -z "$1" ]; then
9+
echo "Error: No plugin names provided."
10+
exit 1
11+
fi
12+
13+
# Read the comma-separated list of plugin names
14+
IFS=',' read -ra PLUGINS <<< "$1"
15+
16+
# Get the path to the plugin.js script
17+
PLUGIN_JS_PATH="$(pwd)/bin/commands/scripts/plugin.js"
18+
19+
# Loop through each plugin name
20+
for plugin in "${PLUGINS[@]}"; do
21+
# Trim whitespace
22+
plugin=$(echo "$plugin" | xargs)
23+
24+
echo "Attempting to disable plugin: $plugin"
25+
26+
# Run the Node.js command for each plugin
27+
if node --preserve-symlinks --preserve-symlinks-main "$PLUGIN_JS_PATH" disable "$plugin"; then
28+
echo "Successfully disabled plugin: $plugin"
29+
else
30+
echo "Failed to disable plugin: $plugin"
31+
fi
32+
done
33+
34+
echo "Script completed."

.vscode/extensions.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"recommendations": [
3+
"dbaeumer.vscode-eslint",
4+
"github.vscode-pull-request-github",
5+
"eamodio.gitlens",
6+
"christian-kohler.npm-intellisense",
7+
"christian-kohler.path-intellisense",
8+
"ms-vscode-remote.remote-ssh",
9+
"ms-vscode-remote.remote-ssh-edit",
10+
"ms-vscode.remote-explorer",
11+
"syler.sass-indented",
12+
"vue.volar",
13+
"usernamehw.vscode-error-lens"
14+
]
15+
}

0 commit comments

Comments
 (0)