From c1ac4698f9fbac82315d0647b453ae37bbd1018a Mon Sep 17 00:00:00 2001 From: shortcuts Date: Mon, 2 Jan 2023 23:08:16 +0100 Subject: [PATCH 1/6] feat: add setup script --- .chglog/config.yml | 2 +- .github/CODEOWNERS | 2 +- .github/ISSUE_TEMPLATE/Bug_report.md | 2 +- .github/workflows/main.yml | 2 +- Makefile | 19 ++++++++--- README.md | 37 +++++++++++++++----- README_TEMPLATE.md | 2 +- scripts/release.sh | 4 +-- scripts/setup.sh | 50 ++++++++++++++++++++++++++++ 9 files changed, 101 insertions(+), 19 deletions(-) create mode 100755 scripts/setup.sh diff --git a/.chglog/config.yml b/.chglog/config.yml index 4d9c36f..8d8297e 100644 --- a/.chglog/config.yml +++ b/.chglog/config.yml @@ -2,7 +2,7 @@ style: github template: template.md info: title: CHANGELOG - repository_url: https://github.com/YOUR_GITHUB_NAME/YOUR_REPOSITORY_NAME + repository_url: https://github.com/YOUR_GITHUB_USERNAME/YOUR_REPOSITORY_NAME options: commits: filters: diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 1b8d87a..54eef35 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1 +1 @@ -* @YOUR_GITHUB_NAME +* @YOUR_GITHUB_USERNAME diff --git a/.github/ISSUE_TEMPLATE/Bug_report.md b/.github/ISSUE_TEMPLATE/Bug_report.md index da570fc..67a40e7 100644 --- a/.github/ISSUE_TEMPLATE/Bug_report.md +++ b/.github/ISSUE_TEMPLATE/Bug_report.md @@ -20,5 +20,5 @@ about: It helps making the plugin more stable. ## Environment - Neovim version: [e.g. 0.5.x / 0.6.x / 0.7.x / 0.8.x / Nightly] -- your-plugin-name.nvim version: [e.g. latest / 0.1.2 / dev] +- your-plugin-name version: [e.g. latest / 0.1.2 / dev] - Plugin clash: [e.g. Telescope float window / lsp diagnostic] diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 74e04df..ea7143d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -29,7 +29,7 @@ jobs: timeout-minutes: 2 strategy: matrix: - neovim_version: ['v0.7.2', 'v0.8.1', 'nightly'] + neovim_version: ['v0.6.1', 'v0.7.2', 'v0.8.2'] steps: - uses: actions/checkout@v3 diff --git a/Makefile b/Makefile index c731ff3..f00f26c 100644 --- a/Makefile +++ b/Makefile @@ -3,29 +3,40 @@ all: +# runs all the test files. test: nvim --version | head -n 1 && echo '' nvim --headless --noplugin -u ./scripts/minimal_init.lua \ -c "lua require('mini.test').setup()" \ -c "lua MiniTest.run({ execute = { reporter = MiniTest.gen_reporter.stdout({ group_depth = 1 }) } })" +# installs `mini.nvim`, used for both the tests and documentation. deps: @mkdir -p deps git clone --depth 1 https://github.com/echasnovski/mini.nvim deps/mini.nvim -test-ci: deps - nvim --headless --noplugin -u ./scripts/minimal_init.lua \ - -c "lua require('mini.test').setup()" \ - -c "lua MiniTest.run()" +# installs deps before running tests, useful for the CI. +test-ci: deps test +# generates the documentation. documentation: nvim --headless --noplugin -u ./scripts/minimal_init.lua -c "lua require('mini.doc').generate()" -c "qa!" +# installs deps before running the documentation generation, useful for the CI. +documentation-ci: deps documentation + +# performs a lint check and fixes issue if possible, following the config in `stylua.toml`. lint: stylua . +# runs the release script, go to file to see more details. release: ./scripts/release.sh +# generates a changelog, used by the `release` script. changelog: git-chglog -o CHANGELOG.md -no-case + +# setup +setup: + ./scripts/setup.sh diff --git a/README.md b/README.md index 6e0967b..3099cf4 100644 --- a/README.md +++ b/README.md @@ -30,29 +30,52 @@ - [Install Stylua linter](https://github.com/JohnnyMorganz/StyLua#installation) - [Install git-chglog generator](https://github.com/git-chglog/git-chglog) -## ☄ Usage +## ☄ Getting started The following checklist is all your need to do to start writing your first plugin. -### 1 - Clone the repository where you'd like your plugin to live +### 1 - Clone the template repository + +#### via HTTPs ```sh -# via HTTPs git clone https://github.com/shortcuts/neovim-plugin-boilerplate.git ~/my-awesome-plugin.nvim +``` -# via SSH +#### via SSH + +```sh git clone git@github.com:shortcuts/neovim-plugin-boilerplate.git ~/my-awesome-plugin.nvim +``` +### via GH +```sh +gh repo my-awesome-plugin -p shortcuts/neovim-plugin-boilerplate --public ``` ### 2 - Replace placeholder names with your plugin name +#### Automatically + +The [setup script](https://github.com/shortcuts/neovim-plugin-boilerplate/blob/main/scripts/setup.sh) will rename files and placeholder names for you. Once done, you can remove anything `setup` related if you want to. + +```sh +# tries to get your repository name +make setup + +# use the given repository name +REPOSITORY=my-awesome-plugin make setup +``` + +#### Manually + > **Note**: > The placeholder names are purposely written with different casing. Make sure to keep it. #### File names ```sh +rm -rf doc mv plugin/your-plugin-name.lua plugin/my-awesome-plugin.lua mv lua/your-plugin-name lua/my-awesome-plugin mv README_TEMPLATE.md README.md @@ -61,8 +84,6 @@ mv README_TEMPLATE.md README.md #### Search and replace placeholder occurrences: -> Below actions are Neovim commands - ```vim :vimgrep /YourPluginName/ **/* :cfdo %s/YourPluginName/MyAwesomePlugin/g | update @@ -70,8 +91,8 @@ mv README_TEMPLATE.md README.md :vimgrep /your-plugin-name/ **/* .github/** :cfdo %s/your-plugin-name/my-awesome-plugin/g | update -:vimgrep /YOUR_GITHUB_NAME/ .chglog/** .github/** **/*.md -:cfdo %s/YOUR_GITHUB_NAME/shortcuts/g | update +:vimgrep /YOUR_GITHUB_USERNAME/ .chglog/** .github/** **/*.md +:cfdo %s/YOUR_GITHUB_USERNAME/shortcuts/g | update :vimgrep /YOUR_REPOSITORY_NAME/ .chglog/** **/*.md :cfdo %s/YOUR_REPOSITORY_NAME/my-awesome-plugin.nvim/g | update diff --git a/README_TEMPLATE.md b/README_TEMPLATE.md index d52df98..e54c4ef 100644 --- a/README_TEMPLATE.md +++ b/README_TEMPLATE.md @@ -125,7 +125,7 @@ PRs and issues are always welcome. Make sure to provide as much context as possi ## 🗞 Wiki -You can find guides and showcase of the plugin on [the Wiki](https://github.com/YOUR_GITHUB_NAME/YOUR_REPOSITORY_NAME/wiki) +You can find guides and showcase of the plugin on [the Wiki](https://github.com/YOUR_GITHUB_USERNAME/YOUR_REPOSITORY_NAME/wiki) ## 🎭 Motivations diff --git a/scripts/release.sh b/scripts/release.sh index 452463d..4a45ec2 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -1,8 +1,8 @@ #!/bin/bash if [[ -z "$NEXT_TAG" ]]; then - echo "usage: NEXT_TAG=0.2.2 make release" - exit 1 + echo "usage: NEXT_TAG=0.2.2 make release" + exit 1 fi echo "Generating changelog for version $NEXT_TAG" diff --git a/scripts/setup.sh b/scripts/setup.sh new file mode 100755 index 0000000..fb09ac6 --- /dev/null +++ b/scripts/setup.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +echo -e "\033[0;37m[INFO] - usage: USERNAME=my-github-username PLUGIN_NAME=my-awesome-plugin REPOSITORY_NAME=my-awesome-plugin.nvim make setup\n\033[0m" + +if [[ -z "$USERNAME" ]]; then + echo -e "\t> No USERNAME provided, what's your GitHub/GitLab username?" + read USERNAME +fi + +if [[ -z "$REPOSITORY_NAME" ]]; then + REPOSITORY_NAME=$(basename -s .git `git config --get remote.origin.url`) + + while true; do + read -rp $'\t> No REPOSITORY_NAME provided, is \033[1;32m'"$REPOSITORY_NAME"$'\033[0m good? [Y/n]\n' yn + case $yn in + [Yy]* ) break;; + [Nn]* ) exit 1;; + * ) break;; + esac + done +fi + +if [[ -z "$PLUGIN_NAME" ]]; then + while true; do + read -rp $'\t> No PLUGIN_NAME provided, defaulting to \033[1;32m'"$REPOSITORY_NAME"$'\033[0m, continue? [Y/n]\n' yn + case $yn in + [Yy]* ) break;; + [Nn]* ) exit 1;; + * ) break;; + esac + done + + PLUGIN_NAME=$REPOSITORY_NAME +fi + +echo -e "Username: \033[1;32m$USERNAME\033[0m\nRepository: \033[1;32m$REPOSITORY_NAME\033[0m\nPlugin: \033[1;32m$PLUGIN_NAME\033[0m\n\n\tRenaming placeholder files..." + +rm -rf doc +mv plugin/your-plugin-name.lua plugin/$PLUGIN_NAME.lua +mv lua/your-plugin-name lua/$PLUGIN_NAME +mv README_TEMPLATE.md README.md + +echo -e "\tReplacing placeholder names..." + +PASCAL_CASE_PLUGIN_NAME=$(echo "$PLUGIN_NAME" | perl -pe 's/(^|-)./uc($&)/ge;s/-//g') + +grep -rl "YourPluginName" .github/ plugin/ tests/ lua/ | xargs sed -i "" -e "s/YourPluginName/$PASCAL_CASE_PLUGIN_NAME/g" +grep -rl "your-plugin-name" README.md .github/ plugin/ tests/ lua/ | xargs sed -i "" -e "s/your-plugin-name/$PLUGIN_NAME/g" +grep -rl "YOUR_GITHUB_USERNAME" README.md .github/ .chflog/ | xargs sed -i "" -e "s/YOUR_GITHUB_USERNAME/$USERNAME/g" +grep -rl "YOUR_REPOSITORY_NAME" README.md .github/ .chglog/ | xargs sed -i "" -e "s/YOUR_REPOSITORY_NAME/$REPOSITORY_NAME/g" From ed5fd711ae9aee901f85a5763ec31fc38b6eff26 Mon Sep 17 00:00:00 2001 From: shortcuts Date: Mon, 2 Jan 2023 23:10:45 +0100 Subject: [PATCH 2/6] typos --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3099cf4..67920ce 100644 --- a/README.md +++ b/README.md @@ -60,11 +60,11 @@ gh repo my-awesome-plugin -p shortcuts/neovim-plugin-boilerplate --public The [setup script](https://github.com/shortcuts/neovim-plugin-boilerplate/blob/main/scripts/setup.sh) will rename files and placeholder names for you. Once done, you can remove anything `setup` related if you want to. ```sh -# tries to get your repository name +# interactively make setup -# use the given repository name -REPOSITORY=my-awesome-plugin make setup +# automated +USERNAME=my-github-username PLUGIN_NAME=my-awesome-plugin REPOSITORY_NAME=my-awesome-plugin.nvim make setup ``` #### Manually From 1f6955a6c51c64027fa5545d27f507df5c635dbb Mon Sep 17 00:00:00 2001 From: shortcuts Date: Mon, 2 Jan 2023 23:17:38 +0100 Subject: [PATCH 3/6] fix: make script more interactive --- scripts/setup.sh | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/scripts/setup.sh b/scripts/setup.sh index fb09ac6..159aaa5 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -1,6 +1,8 @@ #!/bin/bash -echo -e "\033[0;37m[INFO] - usage: USERNAME=my-github-username PLUGIN_NAME=my-awesome-plugin REPOSITORY_NAME=my-awesome-plugin.nvim make setup\n\033[0m" +USAGE="\033[0;37m[INFO] - usage: USERNAME=my-github-username PLUGIN_NAME=my-awesome-plugin REPOSITORY_NAME=my-awesome-plugin.nvim make setup\n\033[0m" + +echo -e $USAGE if [[ -z "$USERNAME" ]]; then echo -e "\t> No USERNAME provided, what's your GitHub/GitLab username?" @@ -10,25 +12,31 @@ fi if [[ -z "$REPOSITORY_NAME" ]]; then REPOSITORY_NAME=$(basename -s .git `git config --get remote.origin.url`) - while true; do read -rp $'\t> No REPOSITORY_NAME provided, is \033[1;32m'"$REPOSITORY_NAME"$'\033[0m good? [Y/n]\n' yn case $yn in [Yy]* ) break;; - [Nn]* ) exit 1;; - * ) break;; + [Nn]* ) + echo -e "\t> Enter your repository name" + read REPOSITORY_NAME + ;; + * ) + echo -e $USAGE + exit 1;; esac - done fi if [[ -z "$PLUGIN_NAME" ]]; then - while true; do read -rp $'\t> No PLUGIN_NAME provided, defaulting to \033[1;32m'"$REPOSITORY_NAME"$'\033[0m, continue? [Y/n]\n' yn case $yn in [Yy]* ) break;; - [Nn]* ) exit 1;; - * ) break;; + [Nn]* ) + echo -e "\t> Enter your plugin name" + read PLUGIN_NAME + ;; + * ) + echo -e $USAGE + exit 1;; esac - done PLUGIN_NAME=$REPOSITORY_NAME fi @@ -46,5 +54,5 @@ PASCAL_CASE_PLUGIN_NAME=$(echo "$PLUGIN_NAME" | perl -pe 's/(^|-)./uc($&)/ge;s/- grep -rl "YourPluginName" .github/ plugin/ tests/ lua/ | xargs sed -i "" -e "s/YourPluginName/$PASCAL_CASE_PLUGIN_NAME/g" grep -rl "your-plugin-name" README.md .github/ plugin/ tests/ lua/ | xargs sed -i "" -e "s/your-plugin-name/$PLUGIN_NAME/g" -grep -rl "YOUR_GITHUB_USERNAME" README.md .github/ .chflog/ | xargs sed -i "" -e "s/YOUR_GITHUB_USERNAME/$USERNAME/g" +grep -rl "YOUR_GITHUB_USERNAME" README.md .github/ .chglog/ | xargs sed -i "" -e "s/YOUR_GITHUB_USERNAME/$USERNAME/g" grep -rl "YOUR_REPOSITORY_NAME" README.md .github/ .chglog/ | xargs sed -i "" -e "s/YOUR_REPOSITORY_NAME/$REPOSITORY_NAME/g" From 4eaa3e563ebe4284206ad09958dea9712d362c78 Mon Sep 17 00:00:00 2001 From: shortcuts Date: Mon, 2 Jan 2023 23:20:09 +0100 Subject: [PATCH 4/6] fix: useless break --- scripts/setup.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/setup.sh b/scripts/setup.sh index 159aaa5..a9d523c 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -14,7 +14,7 @@ if [[ -z "$REPOSITORY_NAME" ]]; then read -rp $'\t> No REPOSITORY_NAME provided, is \033[1;32m'"$REPOSITORY_NAME"$'\033[0m good? [Y/n]\n' yn case $yn in - [Yy]* ) break;; + [Yy]* );; [Nn]* ) echo -e "\t> Enter your repository name" read REPOSITORY_NAME @@ -28,7 +28,7 @@ fi if [[ -z "$PLUGIN_NAME" ]]; then read -rp $'\t> No PLUGIN_NAME provided, defaulting to \033[1;32m'"$REPOSITORY_NAME"$'\033[0m, continue? [Y/n]\n' yn case $yn in - [Yy]* ) break;; + [Yy]* ) ;; [Nn]* ) echo -e "\t> Enter your plugin name" read PLUGIN_NAME From ccf2d7206213ffa0ed1ac0cf6c235f4d668a6ee3 Mon Sep 17 00:00:00 2001 From: shortcuts Date: Mon, 2 Jan 2023 23:23:33 +0100 Subject: [PATCH 5/6] fix: yes case for plugin name --- scripts/setup.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/setup.sh b/scripts/setup.sh index a9d523c..3ab5191 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -28,7 +28,9 @@ fi if [[ -z "$PLUGIN_NAME" ]]; then read -rp $'\t> No PLUGIN_NAME provided, defaulting to \033[1;32m'"$REPOSITORY_NAME"$'\033[0m, continue? [Y/n]\n' yn case $yn in - [Yy]* ) ;; + [Yy]* ) + PLUGIN_NAME=$REPOSITORY_NAME + ;; [Nn]* ) echo -e "\t> Enter your plugin name" read PLUGIN_NAME @@ -37,8 +39,6 @@ if [[ -z "$PLUGIN_NAME" ]]; then echo -e $USAGE exit 1;; esac - - PLUGIN_NAME=$REPOSITORY_NAME fi echo -e "Username: \033[1;32m$USERNAME\033[0m\nRepository: \033[1;32m$REPOSITORY_NAME\033[0m\nPlugin: \033[1;32m$PLUGIN_NAME\033[0m\n\n\tRenaming placeholder files..." From 70cc6640d639f9dca39475d96638d2b0012781df Mon Sep 17 00:00:00 2001 From: shortcuts Date: Mon, 2 Jan 2023 23:27:26 +0100 Subject: [PATCH 6/6] fix: remove nightly --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ea7143d..008d5bc 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -29,7 +29,7 @@ jobs: timeout-minutes: 2 strategy: matrix: - neovim_version: ['v0.6.1', 'v0.7.2', 'v0.8.2'] + neovim_version: ['v0.7.2', 'v0.8.2'] steps: - uses: actions/checkout@v3