Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add setup script #1

Merged
merged 6 commits into from
Jan 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .chglog/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @YOUR_GITHUB_NAME
* @YOUR_GITHUB_USERNAME
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/Bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
timeout-minutes: 2
strategy:
matrix:
neovim_version: ['v0.7.2', 'v0.8.1', 'nightly']
neovim_version: ['v0.7.2', 'v0.8.2']

steps:
- uses: actions/checkout@v3
Expand Down
19 changes: 15 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
37 changes: 29 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
# interactively
make setup

# automated
USERNAME=my-github-username PLUGIN_NAME=my-awesome-plugin REPOSITORY_NAME=my-awesome-plugin.nvim 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
Expand All @@ -61,17 +84,15 @@ 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

: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
Expand Down
2 changes: 1 addition & 1 deletion README_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions scripts/release.sh
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
58 changes: 58 additions & 0 deletions scripts/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash

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?"
read USERNAME
fi

if [[ -z "$REPOSITORY_NAME" ]]; then
REPOSITORY_NAME=$(basename -s .git `git config --get remote.origin.url`)

read -rp $'\t> No REPOSITORY_NAME provided, is \033[1;32m'"$REPOSITORY_NAME"$'\033[0m good? [Y/n]\n' yn
case $yn in
[Yy]* );;
[Nn]* )
echo -e "\t> Enter your repository name"
read REPOSITORY_NAME
;;
* )
echo -e $USAGE
exit 1;;
esac
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]* )
PLUGIN_NAME=$REPOSITORY_NAME
;;
[Nn]* )
echo -e "\t> Enter your plugin name"
read PLUGIN_NAME
;;
* )
echo -e $USAGE
exit 1;;
esac
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/ .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"