From 4e460967225a2a864db52b96dc3062926757a8d8 Mon Sep 17 00:00:00 2001 From: Vahid Kaykhaei Date: Wed, 4 Dec 2024 12:09:10 +0100 Subject: [PATCH] Manually syncing internal and external repos --- .githooks/pre-commit | 39 ++++++++++++++++++++++++++++++++++++++ .github/workflows/main.yml | 25 ++++++++++++++++++++++++ .gitignore | 1 + .prettierrc | 6 ++++++ package-lock.json | 32 +++++++++++++++++++++++++++++++ package.json | 15 +++++++++++++++ phpcs.xml.dist | 23 ++++++++++++++++++++++ 7 files changed, 141 insertions(+) create mode 100755 .githooks/pre-commit create mode 100644 .github/workflows/main.yml create mode 100644 .prettierrc create mode 100644 package-lock.json create mode 100644 package.json create mode 100644 phpcs.xml.dist diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100755 index 00000000..8f7b5050 --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,39 @@ +#!/bin/bash + +# Get staged PHP files for PHP CodeSniffer +php_files=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.php$') +if [ -n "$php_files" ]; then + echo "Running PHP CodeSniffer on the following files:" + echo "$php_files" + + echo "$php_files" | xargs vendor/bin/phpcs -d memory_limit=512M --standard=phpcs.xml.dist + if [ $? -ne 0 ]; then + echo "PHP CodeSniffer failed. Please fix the errors." + exit 1 + fi +fi + +# Get staged CSS and JS files +css_files=$(git diff --cached --name-only --diff-filter=ACM | grep -E '^(css/.*\.css)$') +js_files=$(git diff --cached --name-only --diff-filter=ACM | grep -E '^(js/.*\.js)$') + +# Combine CSS and JS files into a single variable +all_files="$css_files $js_files" + +# Run Prettier if there are CSS or JS files +if [ -n "$all_files" ]; then + echo "Running Prettier on the following files:" + echo "$all_files" + + echo "$all_files" | xargs npx prettier --write + if [ $? -ne 0 ]; then + echo "Prettier failed. Please fix the formatting errors." + exit 1 + fi + + # Add formatted files back to the staged changes + echo "$all_files" | xargs git add +fi + +echo "All checks passed." +exit 0 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..9b92700e --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,25 @@ +name: Test + +on: + push: + branches: + - main + +jobs: + test-and-code-style: + runs-on: ubuntu-latest + strategy: + matrix: + php: [8.1] + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install dependencies + run: composer install --prefer-dist + + - name: Run tests + run: vendor/bin/phpunit --bootstrap __tests__/bootstrap.php __tests__ + + - name: Run PHPCS + run: vendor/bin/phpcs --standard=WordPress --extensions=php --ignore=vendor/ . diff --git a/.gitignore b/.gitignore index 0a2ff5c1..67e563bf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /vendor /build /js/lib/node_modules +/node_modules diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 00000000..a37dddd9 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,6 @@ +{ + "singleQuote": true, + "trailingComma": "all", + "tabWidth": 2, + "semi": true + } diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 00000000..cf17a5f3 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,32 @@ +{ + "name": "facebook-pixel-for-wordpress", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "facebook-pixel-for-wordpress", + "version": "1.0.0", + "license": "ISC", + "devDependencies": { + "prettier": "^3.3.3" + } + }, + "node_modules/prettier": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.3.3.tgz", + "integrity": "sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew==", + "dev": true, + "license": "MIT", + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 00000000..7fbd0895 --- /dev/null +++ b/package.json @@ -0,0 +1,15 @@ +{ + "name": "facebook-pixel-for-wordpress", + "version": "1.0.0", + "description": "Grow your business with Facebook for WordPress! This plugin will install a Facebook Pixel for your page so you can capture the actions people take when they interact with your page, such as Lead, ViewContent, AddToCart, InitiateCheckout and Purchase events. Version 2.0.0 also includes support for the Conversions API, which lets you send events directly from your page’s server so you can capture a more of these events when they happen. This can help you better understand your customer’s journey from the moment they show interest in your business to the moment they complete a conversion. You can use this information to create ad campaigns that are relevant to your audience. [Learn More](https://www.facebook.com/business/learn/facebook-ads-pixel)", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "GPL-2.0", + "devDependencies": { + "prettier": "^3.3.3" + } +} diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 00000000..29a11b47 --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,23 @@ + + + Coding standards for WordPress development. + + + ./ + + + vendor/* + node_modules/* + + + + + + + + + + + + +