-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from jxhnx/feat/add-wordpress-template
feat: add wordpress template
- Loading branch information
Showing
25 changed files
with
1,648 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"project_name": "My Awesome Project", | ||
"repo_name": "{{ cookiecutter.project_name.lower()|replace(' ', '-')|replace('_', '-')|replace('.', '-')|trim() }}", | ||
"description": "Awesome project description.", | ||
"author_name": "John Hoffmann", | ||
"open_source_license": [ | ||
"MIT", | ||
"BSD", | ||
"GPLv3", | ||
"Apache Software License 2.0", | ||
"Not open source" | ||
], | ||
"ci_tool": ["None", "Gitlab", "Github"], | ||
"__default_code_formatter_print_width": "140", | ||
"code_formatter_print_width": "{{ cookiecutter.__default_code_formatter_print_width }}", | ||
"wordpress_coding_standards": ["strict", "relaxed"], | ||
"git_init": false, | ||
"__prompts__": { | ||
"code_formatter_print_width": "code_formatter_print_width (recommended: 0/120/140)" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
import os | ||
import shutil | ||
import subprocess | ||
|
||
import requests | ||
|
||
TERMINATOR = "\x1b[0m" | ||
WARNING = "\x1b[1;33m [WARNING]: " | ||
INFO = "\x1b[1;33m [INFO]: " | ||
HINT = "\x1b[3;33m" | ||
SUCCESS = "\x1b[1;32m [SUCCESS]: " | ||
|
||
|
||
def yes(value): | ||
return str(value).lower() not in ["n", "0", "false", "f", "no", "off"] | ||
|
||
|
||
def remove_open_source_files(): | ||
file_names = ["LICENSE"] | ||
for file_name in file_names: | ||
os.remove(file_name) | ||
|
||
|
||
def remove_gplv3_files(): | ||
file_names = ["COPYING"] | ||
for file_name in file_names: | ||
os.remove(file_name) | ||
|
||
|
||
def remove_dotgitlabciyml_file(): | ||
os.remove(".gitlab-ci.yml") | ||
|
||
|
||
def remove_bitbucketpipelinesyml_file(): | ||
os.remove("bitbucket-pipelines.yml") | ||
|
||
|
||
def remove_dotgithub_folder(): | ||
shutil.rmtree(".github") | ||
|
||
|
||
def generate_gitignore(): | ||
print(INFO + "Fetching recent .gitignore rules..." + TERMINATOR) | ||
|
||
rules = ["dotenv", "windows", "macos", "linux", "wordpress"] | ||
url = "https://www.toptal.com/developers/gitignore/api/" + ",".join(rules) | ||
|
||
try: | ||
response = requests.get(url) | ||
response.raise_for_status() | ||
except requests.exceptions.RequestException as e: | ||
print(WARNING + f"Error: {e}, using cached .gitignore" + TERMINATOR) | ||
return None | ||
|
||
custom_header = f"""###################################################### | ||
# Custom / project-specific .gitignore | ||
###################################################### | ||
# Wordpress | ||
/wordpress/* | ||
!/wordpress/wp-content/ | ||
/wordpress/wp-content/* | ||
!/wordpress/wp-content/themes | ||
/wordpress/wp-content/themes/* | ||
!/wordpress/wp-content/themes/my-theme | ||
# CI | ||
/vendor | ||
/node_modules | ||
# Moving data | ||
/data | ||
###################################################### | ||
# Generated .gitignore for {", ".join(rules)} | ||
###################################################### | ||
""" | ||
|
||
combined_gitignore = custom_header + "\n" + response.text | ||
|
||
with open(".gitignore", "w") as gitignore_file: | ||
gitignore_file.write(combined_gitignore) | ||
|
||
|
||
def run_pre_commit_subprocess(): | ||
print(INFO + "Run pre-commit..." + TERMINATOR) | ||
subprocess.call(["git", "init", "-b", "main"]) | ||
subprocess.call(["git", "add", "*"]) | ||
subprocess.call(["pre-commit", "run", "--all-files"]) | ||
subprocess.call(["rm", "-rf", ".git"]) | ||
|
||
|
||
def run_initial_git_commit_subprocess(): | ||
print(INFO + "Initializing git repository..." + TERMINATOR) | ||
subprocess.call(["git", "init", "-b", "main"]) | ||
subprocess.call(["git", "add", "*"]) | ||
subprocess.call(["git", "commit", "-m", "Initial commit"]) | ||
|
||
|
||
def main(): | ||
if "{{ cookiecutter.open_source_license }}" == "Not open source": | ||
remove_open_source_files() | ||
|
||
if "{{ cookiecutter.open_source_license }}" != "GPLv3": | ||
remove_gplv3_files() | ||
|
||
if "{{ cookiecutter.ci_tool }}" != "Gitlab": | ||
remove_dotgitlabciyml_file() | ||
|
||
if "{{ cookiecutter.ci_tool }}" != "Github": | ||
remove_dotgithub_folder() | ||
|
||
generate_gitignore() | ||
|
||
if ( | ||
"{{ cookiecutter.code_formatter_print_width }}" | ||
!= "{{ cookiecutter.__default_code_formatter_print_width }}" | ||
): | ||
run_pre_commit_subprocess() | ||
|
||
if yes("{{ cookiecutter.git_init | default('false') }}"): | ||
run_initial_git_commit_subprocess() | ||
|
||
print(SUCCESS + "The cookie is cut!" + TERMINATOR) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
assert "\\" not in "{{ cookiecutter.author_name }}", "Don't include backslashes in author name." | ||
|
||
code_formatter_print_width = "{{ cookiecutter.code_formatter_print_width }}" | ||
assert ( | ||
code_formatter_print_width.isdigit() and float(code_formatter_print_width).is_integer() | ||
), "Invalid value for code_formatter_print_width. Please provide an integer value." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import json | ||
import shutil | ||
|
||
COOKIEJSON_PATH = "cookiecutter.json" | ||
|
||
|
||
def remove_cookiecutterjson_key(key: str): | ||
with open(COOKIEJSON_PATH, "r") as file: | ||
cookiecutter_dict = json.load(file) | ||
|
||
if key in cookiecutter_dict: | ||
del cookiecutter_dict[key] | ||
|
||
with open(COOKIEJSON_PATH, "w") as file: | ||
json.dump(cookiecutter_dict, file, indent=2) | ||
|
||
|
||
def main(): | ||
if shutil.which("git") is None: | ||
remove_cookiecutterjson_key("git_init") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
from tests.common import generate_cookiecutter_template | ||
|
||
template_dir = Path(__file__).resolve().parent | ||
|
||
|
||
@pytest.mark.default | ||
def test_default(): | ||
git_init = {"git_init": "true"} | ||
lint_non_default_print_width = {"code_formatter_print_width": "30", "git_init": "true"} | ||
no_print_width_limit = {"code_formatter_print_width": "0"} | ||
relaxed_rulset = {"wordpress_coding_standards": "relaxed"} | ||
generate_cookiecutter_template(template_dir, git_init) | ||
generate_cookiecutter_template(template_dir, lint_non_default_print_width) | ||
generate_cookiecutter_template(template_dir, no_print_width_limit) | ||
generate_cookiecutter_template(template_dir, relaxed_rulset) |
29 changes: 29 additions & 0 deletions
29
templates-stack/wordpress/{{cookiecutter.repo_name}}/.env.local
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Get live data | ||
FTP_READ_USERNAME=fe15ee4 | ||
FTP_READ_PASSWORD=password | ||
FTP_HOST=subdomain.example.com | ||
PROD_WP_ROOT_DIR=example.com | ||
LOCAL_WP_ROOT_DIR=wordpress | ||
PROD_BACKUP_DIR=backup/example.com | ||
|
||
# Live website (WordPress) | ||
DOMAIN=example.com | ||
PROD_DB_NAME=fe45224d | ||
WP_DB_PREFIX=dk583 # randomly generated by WordPress | ||
PROD_WP_BASE_URL=https://www.example.com | ||
|
||
# Local website | ||
WP_PORT=8080 # adjust init.sql accordingly | ||
STAGING_WP_BASE_URL=http://localhost:$WP_PORT | ||
STAGING_DB_NAME=$PROD_DB_NAME | ||
STAGING_DB_USER=john | ||
STAGING_DB_PASSWORD="Neuter#Scoop5#Velcro" | ||
STAGING_DB_ROOT_PASSWORD=$STAGING_DB_PASSWORD | ||
|
||
WP_HOST_DB_NAME=wp_database | ||
WP_HOST_DB_PORT=3306 | ||
|
||
# Import and db setup | ||
WP_CONFIG_PATH="./wordpress/wp-config.php" | ||
PROD_DB_DUMP_PATH="./data/$PROD_DB_NAME.sql" | ||
PROD_DB_INIT_PATH="./local-init.sql" |
8 changes: 8 additions & 0 deletions
8
templates-stack/wordpress/{{cookiecutter.repo_name}}/.eslintrc.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
env: | ||
browser: true | ||
es2021: true | ||
extends: ['eslint:recommended', 'plugin:@wordpress/eslint-plugin/recommended'] | ||
parserOptions: | ||
ecmaVersion: latest | ||
sourceType: module | ||
rules: { 'prettier/prettier': 0, 'no-unused-vars': 'off' } |
23 changes: 23 additions & 0 deletions
23
templates-stack/wordpress/{{cookiecutter.repo_name}}/.github/workflows/pre-commit.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: pre-commit | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: [main] | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.11' | ||
- name: Install PHP, composer and dependencies | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install -y php-cli php-xml php-curl composer | ||
composer update | ||
- uses: actions/setup-node@v4 | ||
- run: npm install @wordpress/prettier-config @wordpress/eslint-plugin --save-dev | ||
- uses: pre-commit/[email protected] |
Oops, something went wrong.