diff --git a/.github/rename_project.sh b/.github/rename_project.sh new file mode 100755 index 0000000..f989a1c --- /dev/null +++ b/.github/rename_project.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash +while getopts a:n:u:d: flag +do + case "${flag}" in + a) author=${OPTARG};; + n) display_name=${OPTARG};; + u) urlname=${OPTARG};; + d) description=${OPTARG};; + esac +done + +code_name="$(echo "$display_name" | sed -r 's/.*/\L&/;s/(^| )([a-z])/\U\2/g')" +mod_id="$(echo "${author}.${code_name}" | sed -r 's/.*/\L&/')" + +echo "Author: $author"; +echo "Display Name: $display_name"; +echo "Description: $description"; +echo "Code Name: $code_name"; +echo "Mod ID: $mod_id"; + +echo "Renaming project..." + +original_author="Author" +original_code_name="TestMod" +original_mod_id="author.testmod" +original_display_name="Test Mod" +original_description="Put a neat description here" + +for filename in $(git ls-files) +do + if [[ "$filename" != lib/* && "$filename" != .github/* ]] + then + sed -i "s/$original_author/$author/g" $filename + sed -i "s/$original_code_name/$code_name/g" $filename + sed -i "s/$original_mod_id/$mod_id/g" $filename + sed -i "s/$original_display_name/$display_name/g" $filename + sed -i "s/$original_description/$description/g" $filename + #sed -i "s/ / /g" $filename + echo "Renamed $filename" + fi +done + +mv src/TestMod.csproj "src/${code_name}.csproj" + +# This command runs only once on GHA! +rm -r .github/ diff --git a/.github/workflows/rename_project.yml b/.github/workflows/rename_project.yml new file mode 100755 index 0000000..62aae78 --- /dev/null +++ b/.github/workflows/rename_project.yml @@ -0,0 +1,53 @@ +name: Rename the project from template + +on: [push] + +permissions: write-all + +jobs: + rename-project: + if: ${{ !contains (github.repository, '/TemplateMod') }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + # by default, it uses a depth of 1 + # this fetches all history so that we can read each commit + fetch-depth: 0 + ref: ${{ github.head_ref }} + + - run: echo "REPOSITORY_NAME=$(echo '${{ github.repository }}' | awk -F '/' '{print $2}' | tr '-' ' ')" >> $GITHUB_ENV + shell: bash + + - run: echo "REPOSITORY_URLNAME=$(echo '${{ github.repository }}' | awk -F '/' '{print $2}')" >> $GITHUB_ENV + shell: bash + + - run: echo "REPOSITORY_OWNER=$(echo '${{ github.repository }}' | awk -F '/' '{print $1}')" >> $GITHUB_ENV + shell: bash + + - name: Get repository description and fork status + uses: actions/github-script@v6 + id: get_info + with: + script: | + const response = await github.rest.repos.get({ + owner: context.repo.owner, + repo: context.repo.repo, + }); + return {"description": response.data.description, "isFork": response.data.fork}; + result-encoding: json + + - run: echo "REPOSITORY_DESCRIPTION=$(echo "${{fromJson(steps.get_info.outputs.result).description}}")" >> $GITHUB_ENV + shell: bash + + - name: Rename the project + if: fromJson(steps.get_info.outputs.result).isFork != true + run: | + echo "Renaming the project with -a(author) ${{ env.REPOSITORY_OWNER }} -n(name) ${{ env.REPOSITORY_NAME }} -u(urlname) ${{ env.REPOSITORY_URLNAME }}" + .github/rename_project.sh -a ${{ env.REPOSITORY_OWNER }} -n "${{ env.REPOSITORY_NAME }}" -u ${{ env.REPOSITORY_URLNAME }} -d "${{ env.REPOSITORY_DESCRIPTION }}" + + - uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: "Applied template changes." + # commit_options: '--amend --no-edit' + push_options: --force diff --git a/README.md b/README.md index 8d6f4aa..ef7d344 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,8 @@ ## Usage Use this template on GitHub or just [download the code](https://github.com/alduris/TemplateMod/archive/refs/heads/master.zip), whichever is easiest. +If you chose the latter it's recommended you delete the hidden `.github` folder before uploading to github. + Rename `src/TestMod.csproj`, then edit `mod/modinfo.json` and `src/Plugin.cs` to customize your mod. See [the modding wiki](https://rainworldmodding.miraheze.org/wiki/Mod_Directories) for `modinfo.json` documentation. @@ -21,4 +23,4 @@ In a nutshell, this means: You do not have to license your code under CC0 though! (Though it would be cool if you did.) Feel free to license your code however you wish, or not at all. -**DISCLAIMER**: Any and all reference .dll files included (in the `lib` folder) are NOT covered under CC0! They are protected by copyright under their original owners. The actual code in the .dll files has been stripped so they serve no purpose other than for compiler reference (hopefully alleviating most legal issues this would otherwise cause), but this is expected to be upheld by you, the person using this template! Any reference .dlls you may add should be stripped before pushing to any public repository! And if it is possible to get code from Nuget instead, I recommend you do that instead of adding the dll here. \ No newline at end of file +**DISCLAIMER**: Any and all reference .dll files included (in the `lib` folder) are NOT covered under CC0! They are protected by copyright under their original owners. The actual code in the .dll files has been stripped so they serve no purpose other than for compiler reference (hopefully alleviating most legal issues this would otherwise cause), but this is expected to be upheld by you, the person using this template! Any reference .dlls you may add should be stripped before pushing to any public repository! And if it is possible to get code from Nuget instead, I recommend you do that instead of adding the dll here. diff --git a/mod/modinfo.json b/mod/modinfo.json index cef04f1..85aec3c 100644 --- a/mod/modinfo.json +++ b/mod/modinfo.json @@ -1,5 +1,5 @@ { - "id": "testmod", + "id": "author.testmod", "name": "Test Mod", "version": "0.1.0", "authors": "Author", diff --git a/src/Plugin.cs b/src/Plugin.cs index e8c8862..cc2f903 100644 --- a/src/Plugin.cs +++ b/src/Plugin.cs @@ -9,7 +9,7 @@ namespace TestMod; -[BepInPlugin("com.author.testmod", "Test Mod", "0.1.0")] +[BepInPlugin("author.testmod", "Test Mod", "0.1.0")] sealed class Plugin : BaseUnityPlugin { public static new ManualLogSource Logger;