From 678ca02935d41185b24d2504721052d8e943a311 Mon Sep 17 00:00:00 2001 From: Wessel Tip Date: Sun, 2 Mar 2025 13:35:48 +0100 Subject: [PATCH] feat: Modernize boilerplate --- .eslintignore | 2 - .eslintrc | 66 ----------------- .github/CODEOWNERS | 2 +- .github/CONTRIBUTING.md | 27 +------ .github/FUNDING.yml | 3 +- .github/ISSUE_TEMPLATE/bug_report.yml | 10 +-- .github/ISSUE_TEMPLATE/config.yml | 7 +- .github/ISSUE_TEMPLATE/feature_request.yml | 6 +- .github/PULL_REQUEST_TEMPLATE.md | 2 - .github/auto_assign.yml | 5 +- LICENSE | 2 +- README.md | 30 +------- init_repo.py | 86 ++++++++++++++++++++++ 13 files changed, 98 insertions(+), 150 deletions(-) delete mode 100644 .eslintignore delete mode 100644 .eslintrc create mode 100644 init_repo.py diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index 04c01ba..0000000 --- a/.eslintignore +++ /dev/null @@ -1,2 +0,0 @@ -node_modules/ -dist/ \ No newline at end of file diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index 4db8d1e..0000000 --- a/.eslintrc +++ /dev/null @@ -1,66 +0,0 @@ -{ - "env": { - "es6": true, - "amd": true, - "jest": true, - "node": true, - "mongo": true, - "jquery": true, - "browser": true, - "commonjs": true - }, - "parserOptions": { - "ecmaVersion": 9, - "sourceType": "module", - "ecmaFeatures": { - "jsx": true, - "forOf": true, - "spread": true, - "modules": true, - "classes": true, - "generators": true, - "restParams": true, - "regexUFlag": true, - "regexYFlag": true, - "globalReturn": true, - "destructuring": true, - "impliedStrict": true, - "blockBindings": true, - "defaultParams": true, - "octalLiterals": true, - "arrowFunctions": true, - "binaryLiterals": true, - "templateStrings": true, - "superInFunctions": true, - "unicodeCodePointEscapes": true, - "experimentalObjectRestSpread": true, - "objectLiteralShorthandMethods": true, - "objectLiteralComputedProperties": true, - "objectLiteralDuplicateProperties": true, - "objectLiteralShorthandProperties": true - } - }, - "plugins": [], - "rules": { - "semi": "warn", - "indent": [ "off", "error" ], - "strict": "off", - "eqeqeq": "error", - "no-var": "warn", - "no-undef": "warn", - "valid-jsdoc": "warn", - "comma-dangle": "warn", - "no-dupe-args": "warn", - "no-dupe-keys": "warn", - "require-await": "warn", - "spaced-comment": "error", - "space-in-parens": "error", - "no-global-assign": "warn", - "no-duplicate-imports": "error", - "no-dupe-class-members": "error" - }, - "globals": { - "_config": false, - "console": false - } -} diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 471b894..bee82d5 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1 +1 @@ -* @Wessel +* @{{project.master}} diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 8aeddf1..0706835 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -1,38 +1,13 @@ # Contributing - - If you wish to contribute to {{project.name}}, feel free to fork the repository and submit a pull request. {{project.linter}} is enforced to correct most typo's you make and keep the code style the same throughout the whole project, so it would be much appreciated if you installed {{project.linter}} to your editor of choice - ## Prerequisites The following prerequisites must be met before installing {{project.name}}: {{setup.prerequisites}} - ## Setup To get ready to work on the codebase, please do the following: @@ -46,4 +21,4 @@ When creating any new functions, please also create unit tests for them in the ` Use the library associated with the project when creating such tests. When modifying existing functions, make sure to test them before making a pull request, this will prevent -anything from breaking on the production environment. \ No newline at end of file +anything from breaking on the production environment. diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index a0960cb..b3be161 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,2 +1 @@ -github: wessel -ko_fi: wessel \ No newline at end of file +{{project.funding}} diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 75d986b..01b6643 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -1,18 +1,12 @@ -# Adapted from https://github.com/discordjs/discord.js/blob/main/.github/ISSUE_TEMPLATE/bug_report.yml name: Bug report description: Report incorrect or unexpected behavior of a package labels: [bug, need repro] body: - # - type: markdown - # attributes: - # value: | - # Use Discord for questions: https://discord.gg/djs - type: dropdown id: package attributes: label: Which part is this bug report for? - options: - - {{tree.parts}} + options: {{tree.parts}} validations: required: true - type: textarea @@ -75,4 +69,4 @@ body: label: I have tested this issue on a development release placeholder: d23280c (commit hash) description: | - The issue might already be fixed in a development release or main. This is not required, but helps us greatly. \ No newline at end of file + The issue might already be fixed in a development release or main. This is not required, but helps us greatly. diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index 678c4a1..a5f5423 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -1,7 +1,2 @@ blank_issues_enabled: false -# Example entry: -# name: -# url: -# about: -contact_links: - - {{project.contact}} \ No newline at end of file +{{project.contact}} diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml index 2c78a12..14a0911 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.yml +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -1,4 +1,3 @@ -# Adapted from https://github.com/discordjs/discord.js/blob/main/.github/ISSUE_TEMPLATE/feature_request.yml name: Feature request description: Request a new feature labels: [feature request] @@ -11,8 +10,7 @@ body: id: package attributes: label: Which part is this feature request for? - options: - - {{tree.parts}} + options: {{tree.parts}} validations: required: false - type: textarea @@ -39,4 +37,4 @@ body: id: additional-context attributes: label: Other context - description: Any other context, screenshots, or file uploads that help us understand your feature request. \ No newline at end of file + description: Any other context, screenshots, or file uploads that help us understand your feature request. diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index e73bb19..f35130a 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -3,8 +3,6 @@ name: Pull Request about: Propose changes to {{project.name}} title: "[PR] Your changes" labels: pullrequest -assignees: Wessel - --- **Please describe the changes this PR makes and why it should be merged:** diff --git a/.github/auto_assign.yml b/.github/auto_assign.yml index d262d75..3c8d1f2 100644 --- a/.github/auto_assign.yml +++ b/.github/auto_assign.yml @@ -1,5 +1,4 @@ addReviewers: true -reviewers: - - {{project.reviewers}} +reviewers: {{project.reviewers}} numberOfReviewers: 0 -runOnDraft: true \ No newline at end of file +runOnDraft: true diff --git a/LICENSE b/LICENSE index 05a71ff..b4bba09 100644 --- a/LICENSE +++ b/LICENSE @@ -1,7 +1,7 @@ The MIT License (MIT) -Copyright (c) 2023 Wessel T (https://wessel.gg/) +Copyright (c) {{project.license}} Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 71e71d4..020ea8d 100644 --- a/README.md +++ b/README.md @@ -1,40 +1,12 @@ - > {{project.name}} -[![MIT License](https://img.shields.io/badge/license-MIT-007EC7.svg?style=flat-square)](/LICENSE) {{info.badges}} +[![MIT License](https://img.shields.io/badge/license-MIT-007EC7.svg?style=flat-square)](/LICENSE) {{info.desc}}

- ## Table of contents -{{info.toc}} - diff --git a/init_repo.py b/init_repo.py new file mode 100644 index 0000000..5527d89 --- /dev/null +++ b/init_repo.py @@ -0,0 +1,86 @@ +import os +import yaml +import re +import datetime + +file_types = ['LICENSE', 'CODEOWNERS', '.md', '.yml'] +script_name = os.path.basename(__file__) + +def replace_placeholders(file_path, replacements): + with open(file_path, 'r', encoding='utf-8') as file: + content = file.read() + + for placeholder, replacement in replacements.items(): + content = re.sub(re.escape(placeholder), replacement, content) + + with open(file_path, 'w', encoding='utf-8') as file: + file.write(content) + +def initialize_repository(directory, replacements): + for root, _, files in os.walk(directory): + for file in files: + if file == script_name: + continue + if any(file.endswith(file_type) for file_type in file_types): + file_path = os.path.join(root, file) + replace_placeholders(file_path, replacements) + +def parse_input(prompt): + return [item.strip() for item in input(prompt).split(',')] + +def parse_contact(prompt): + contacts = [] + while True: + print(prompt) + name = input(f"\tName\t\t").strip() + if not name: + break + url = input(f"\tURL\t\t").strip() + about = input(f"\tAbout\t\t").strip() + contacts.append({'name': name, 'url': url, 'about': about}) + return {'contact_links': contacts} + +def parse_funding(prompt): + funding = {} + while True: + print(prompt) + key = input(f"\tKey\t\t").strip() + if not key: + break + value = input(f"\tValue\t\t").strip() + funding[key] = value + + return funding + +def main(): + current_year = str(datetime.datetime.now().year) + + replacements = { + "{{project.name}}": input("Project name\t\t"), + "{{info.desc}}": input("Project Description\t"), + "{{project.master}}": input("Master of the repo\t"), + "{{project.license}}": f"{current_year} " + input('License holder\t\t'), + + "{{tree.parts}}": yaml.dump(parse_input("Parts of the repo\t"), default_flow_style=True), + "{{project.lang}}": input("Language used\t\t"), + "{{project.linter}}": input("Linter used\t\t"), + + "{{setup.prerequisites}}": input("Prerequisites\t\t"), + "{{setup.install}}": input("Install command\t\t"), + "{{setup.test}}": input("Test command\t\t"), + + "{{project.logo}}": input("Project logo URL\t"), + "{{project.funding}}": yaml.dump(parse_funding("Funding methods\t\t"), default_flow_style=True), + "{{project.contact}}": yaml.dump(parse_contact("Contact information\t"), default_flow_style=False), + "{{project.reviewers}}": yaml.dump(parse_input("Auto-assign users (x,y)\t"), default_flow_style=True) + } + + directory = input("Initialize directory\t") or '.' + initialize_repository(directory, replacements) + + delete = input("Delete this script? (Y/n)\t") or "y" + if delete.lower() == "y": + os.remove(__file__) + +if __name__ == "__main__": + main()