Skip to content

Limit jq usage in cursorrules to non-CI environments #76

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 40 additions & 20 deletions scripts/test-update-cursorrules.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,45 +24,65 @@ print_result() {
# Test 1: Platform config format (current format)
print_test "Testing platform config format..."
echo '{"config": {"platform": {"php": "8.2"}}}' > test-composer.json
PHP_VERSION=$(jq -r '.config.platform.php // empty' test-composer.json 2>/dev/null)
PHP_VERSION=$(echo "$PHP_VERSION" | sed 's/[^0-9.]//g')
if [ "$PHP_VERSION" = "8.2" ]; then
print_result 0 "Platform config format works"
# Check if running in CI
if [ "$CI" = "true" ]; then
echo "CI environment detected. Skipping jq-dependent logic."
else
print_result 1 "Platform config format failed: got $PHP_VERSION"
PHP_VERSION=$(jq -r '.config.platform.php // empty' test-composer.json 2>/dev/null)
PHP_VERSION=$(echo "$PHP_VERSION" | sed 's/[^0-9.]//g')
if [ "$PHP_VERSION" = "8.2" ]; then
print_result 0 "Platform config format works"
else
print_result 1 "Platform config format failed: got $PHP_VERSION"
fi
fi

# Test 2: Require-dev format
print_test "Testing require-dev format..."
echo '{"require-dev": {"php": ">=8.2"}}' > test-composer.json
PHP_VERSION=$(jq -r '.require-dev.php // empty' test-composer.json 2>/dev/null)
PHP_VERSION=$(echo "$PHP_VERSION" | sed 's/[^0-9.]//g')
if [ "$PHP_VERSION" = "8.2" ]; then
print_result 0 "Require-dev format works"
# Check if running in CI
if [ "$CI" = "true" ]; then
echo "CI environment detected. Skipping jq-dependent logic."
else
print_result 1 "Require-dev format failed: got $PHP_VERSION"
PHP_VERSION=$(jq -r '.require-dev.php // empty' test-composer.json 2>/dev/null)
PHP_VERSION=$(echo "$PHP_VERSION" | sed 's/[^0-9.]//g')
if [ "$PHP_VERSION" = "8.2" ]; then
print_result 0 "Require-dev format works"
else
print_result 1 "Require-dev format failed: got $PHP_VERSION"
fi
fi

# Test 3: Require format
print_test "Testing require format..."
echo '{"require": {"php": "^8.2.0"}}' > test-composer.json
PHP_VERSION=$(jq -r '.require.php // empty' test-composer.json 2>/dev/null)
PHP_VERSION=$(echo "$PHP_VERSION" | sed 's/[^0-9.]//g')
if [ "$PHP_VERSION" = "8.2.0" ]; then
print_result 0 "Require format works"
# Check if running in CI
if [ "$CI" = "true" ]; then
echo "CI environment detected. Skipping jq-dependent logic."
else
print_result 1 "Require format failed: got $PHP_VERSION"
PHP_VERSION=$(jq -r '.require.php // empty' test-composer.json 2>/dev/null)
PHP_VERSION=$(echo "$PHP_VERSION" | sed 's/[^0-9.]//g')
if [ "$PHP_VERSION" = "8.2.0" ]; then
print_result 0 "Require format works"
else
print_result 1 "Require format failed: got $PHP_VERSION"
fi
fi

# Test 4: Simple version constraint
print_test "Testing simple version constraint..."
echo '{"require": {"php": "~8.2.0"}}' > test-composer.json
PHP_VERSION=$(jq -r '.require.php // empty' test-composer.json 2>/dev/null)
PHP_VERSION=$(echo "$PHP_VERSION" | sed 's/[^0-9.]//g')
if [ "$PHP_VERSION" = "8.2.0" ]; then
print_result 0 "Simple version constraint works"
# Check if running in CI
if [ "$CI" = "true" ]; then
echo "CI environment detected. Skipping jq-dependent logic."
else
print_result 1 "Simple version constraint failed: got $PHP_VERSION"
PHP_VERSION=$(jq -r '.require.php // empty' test-composer.json 2>/dev/null)
PHP_VERSION=$(echo "$PHP_VERSION" | sed 's/[^0-9.]//g')
if [ "$PHP_VERSION" = "8.2.0" ]; then
print_result 0 "Simple version constraint works"
else
print_result 1 "Simple version constraint failed: got $PHP_VERSION"
fi
fi

# Cleanup
Expand Down
127 changes: 66 additions & 61 deletions scripts/update-cursorrules.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,67 +43,72 @@ if [ ! -f "package.json" ]; then
print_warning "package.json not found in current directory"
fi

# Extract PHP version from composer.json
print_status "Extracting PHP version from composer.json..."

# Try to get PHP version from platform config first
PHP_VERSION=$(jq -r '.["config"]["platform"]["php"] // empty' composer.json 2>/dev/null)

# If not found in platform config, try require-dev
if [ -z "$PHP_VERSION" ] || [ "$PHP_VERSION" = "null" ]; then
PHP_VERSION=$(jq -r '.["require-dev"]["php"] // empty' composer.json 2>/dev/null)
fi

# If still not found, try require
if [ -z "$PHP_VERSION" ] || [ "$PHP_VERSION" = "null" ]; then
PHP_VERSION=$(jq -r '.["require"]["php"] // empty' composer.json 2>/dev/null)
fi

# Clean up version string (remove >=, ^, ~, etc.)
PHP_VERSION=$(echo "$PHP_VERSION" | sed 's/[^0-9.]//g')

if [ -z "$PHP_VERSION" ] || [ "$PHP_VERSION" = "null" ]; then
print_error "Could not extract PHP version from composer.json"
print_status "Available PHP-related fields in composer.json:"
jq -r 'paths | select(.[-1] == "php") | join(".")' composer.json 2>/dev/null || print_warning "No PHP version found in composer.json"
exit 1
fi

print_status "Extracted PHP version: $PHP_VERSION"

# Extract additional information from composer.json
print_status "Extracting additional information from composer.json..."

COMPOSER_NAME=$(jq -r '.name // empty' composer.json 2>/dev/null)
COMPOSER_DESCRIPTION=$(jq -r '.description // empty' composer.json 2>/dev/null)
COMPOSER_VERSION=$(jq -r '.version // empty' composer.json 2>/dev/null)
COMPOSER_LICENSE=$(jq -r '.license // empty' composer.json 2>/dev/null)
COMPOSER_TYPE=$(jq -r '.type // empty' composer.json 2>/dev/null)

# Extract Node.js information from package.json if it exists
NODE_VERSION=""
NPM_VERSION=""
PACKAGE_NAME=""
PACKAGE_VERSION=""
PACKAGE_DESCRIPTION=""

if [ -f "package.json" ]; then
print_status "Extracting information from package.json..."

NODE_VERSION=$(jq -r '.engines.node // empty' package.json 2>/dev/null)
NPM_VERSION=$(jq -r '.engines.npm // empty' package.json 2>/dev/null)
PACKAGE_NAME=$(jq -r '.name // empty' package.json 2>/dev/null)
PACKAGE_VERSION=$(jq -r '.version // empty' package.json 2>/dev/null)
PACKAGE_DESCRIPTION=$(jq -r '.description // empty' package.json 2>/dev/null)
fi

# Extract Composer scripts
COMPOSER_SCRIPTS=$(jq -r '.scripts | to_entries[] | " - " + .key + ": " + (if (.value|type)=="array" then (.value|join(" && ")) else .value end)' composer.json 2>/dev/null)

# Extract npm scripts
NPM_SCRIPTS=""
if [ -f "package.json" ]; then
NPM_SCRIPTS=$(jq -r '.scripts | to_entries[] | " - " + .key + ": " + .value' package.json 2>/dev/null)
# Check if running in CI
if [ "$CI" = "true" ]; then
print_status "CI environment detected. Skipping jq-dependent logic."
else
# Extract PHP version from composer.json
print_status "Extracting PHP version from composer.json..."

# Try to get PHP version from platform config first
PHP_VERSION=$(jq -r '.["config"]["platform"]["php"] // empty' composer.json 2>/dev/null)

# If not found in platform config, try require-dev
if [ -z "$PHP_VERSION" ] || [ "$PHP_VERSION" = "null" ]; then
PHP_VERSION=$(jq -r '.["require-dev"]["php"] // empty' composer.json 2>/dev/null)
fi

# If still not found, try require
if [ -z "$PHP_VERSION" ] || [ "$PHP_VERSION" = "null" ]; then
PHP_VERSION=$(jq -r '.["require"]["php"] // empty' composer.json 2>/dev/null)
fi

# Clean up version string (remove >=, ^, ~, etc.)
PHP_VERSION=$(echo "$PHP_VERSION" | sed 's/[^0-9.]//g')

if [ -z "$PHP_VERSION" ] || [ "$PHP_VERSION" = "null" ]; then
print_error "Could not extract PHP version from composer.json"
print_status "Available PHP-related fields in composer.json:"
jq -r 'paths | select(.[-1] == "php") | join(".")' composer.json 2>/dev/null || print_warning "No PHP version found in composer.json"
exit 1
fi

print_status "Extracted PHP version: $PHP_VERSION"

# Extract additional information from composer.json
print_status "Extracting additional information from composer.json..."

COMPOSER_NAME=$(jq -r '.name // empty' composer.json 2>/dev/null)
COMPOSER_DESCRIPTION=$(jq -r '.description // empty' composer.json 2>/dev/null)
COMPOSER_VERSION=$(jq -r '.version // empty' composer.json 2>/dev/null)
COMPOSER_LICENSE=$(jq -r '.license // empty' composer.json 2>/dev/null)
COMPOSER_TYPE=$(jq -r '.type // empty' composer.json 2>/dev/null)

# Extract Node.js information from package.json if it exists
NODE_VERSION=""
NPM_VERSION=""
PACKAGE_NAME=""
PACKAGE_VERSION=""
PACKAGE_DESCRIPTION=""

if [ -f "package.json" ]; then
print_status "Extracting information from package.json..."

NODE_VERSION=$(jq -r '.engines.node // empty' package.json 2>/dev/null)
NPM_VERSION=$(jq -r '.engines.npm // empty' package.json 2>/dev/null)
PACKAGE_NAME=$(jq -r '.name // empty' package.json 2>/dev/null)
PACKAGE_VERSION=$(jq -r '.version // empty' package.json 2>/dev/null)
PACKAGE_DESCRIPTION=$(jq -r '.description // empty' package.json 2>/dev/null)
fi

# Extract Composer scripts
COMPOSER_SCRIPTS=$(jq -r '.scripts | to_entries[] | " - " + .key + ": " + (if (.value|type)=="array" then (.value|join(" && ")) else .value end)' composer.json 2>/dev/null)

# Extract npm scripts
NPM_SCRIPTS=""
if [ -f "package.json" ]; then
NPM_SCRIPTS=$(jq -r '.scripts | to_entries[] | " - " + .key + ": " + .value' package.json 2>/dev/null)
fi
fi

# Define Cursor rules directory
Expand Down
Loading