Skip to content

Commit

Permalink
Merge pull request #36 from creyD/dev
Browse files Browse the repository at this point in the history
New prettier-plugin feature
  • Loading branch information
creyD committed Jan 10, 2021
2 parents 34cc6fd + acf2e1f commit cb975d8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ A GitHub action for styling files with [prettier](https://prettier.io).
| same_commit | :x: | `false` | Update the current commit instead of creating a new one, created by [Joren Broekema](https://github.com/jorenbroekema), this command works only with the checkout action set to fetch depth '0' (see example 2) |
| commit_message | :x: | `"Prettified Code!"` | Custom git commit message, will be ignored if used with `same_commit` |
| file_pattern | :x: | `*` | Custom git add file pattern, can't be used with only_changed! |
| prettier_plugins | :x: | ` ` | Install Prettier plugins, i.e. `@prettier/prettier-php @prettier/some-other-plugin` |
| only_changed | :x: | `false` | Only prettify changed files, can't be used with file_pattern! This command works only with the checkout action set to fetch depth '0' (see example 2)|

> Note: using the same_commit option may lead to problems if other actions are relying on the commit being the same before and after the prettier action has ran. Keep this in mind.
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ inputs:
description: Only prettify files changed in the last commit, can't be used with file_pattern!
required: false
default: false
prettier_plugins:
description: Install Prettier plugins, i.e. `@prettier/prettier-php @prettier/some-other-plugin`
required: false
default: ''

runs:
using: 'docker'
Expand Down
13 changes: 13 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ case $INPUT_PRETTIER_VERSION in
;;
esac

# Install plugins
if [ -n "$INPUT_PRETTIER_PLUGINS" ]; then
for plugin in $INPUT_PRETTIER_PLUGINS; do
echo "Checking plugin: $plugin"
# check regex against @prettier/xyz
if ! echo "$plugin" | grep -Eq '(@prettier\/)+(plugin-[a-z\-]+)'; then
echo "$plugin does not seem to be a valid @prettier/plugin-x plugin. Exiting."
exit 1
fi
done
npm install --silent --global $INPUT_PRETTIER_PLUGINS
fi

echo "Prettifing files..."
echo "Files:"
prettier $INPUT_PRETTIER_OPTIONS || echo "Problem running prettier with $INPUT_PRETTIER_OPTIONS"
Expand Down

0 comments on commit cb975d8

Please sign in to comment.