Skip to content

Commit cb975d8

Browse files
authored
Merge pull request #36 from creyD/dev
New prettier-plugin feature
2 parents 34cc6fd + acf2e1f commit cb975d8

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ A GitHub action for styling files with [prettier](https://prettier.io).
2323
| 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) |
2424
| commit_message | :x: | `"Prettified Code!"` | Custom git commit message, will be ignored if used with `same_commit` |
2525
| file_pattern | :x: | `*` | Custom git add file pattern, can't be used with only_changed! |
26+
| prettier_plugins | :x: | ` ` | Install Prettier plugins, i.e. `@prettier/prettier-php @prettier/some-other-plugin` |
2627
| 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)|
2728

2829
> 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.

action.yml

+4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ inputs:
3535
description: Only prettify files changed in the last commit, can't be used with file_pattern!
3636
required: false
3737
default: false
38+
prettier_plugins:
39+
description: Install Prettier plugins, i.e. `@prettier/prettier-php @prettier/some-other-plugin`
40+
required: false
41+
default: ''
3842

3943
runs:
4044
using: 'docker'

entrypoint.sh

+13
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,19 @@ case $INPUT_PRETTIER_VERSION in
3636
;;
3737
esac
3838

39+
# Install plugins
40+
if [ -n "$INPUT_PRETTIER_PLUGINS" ]; then
41+
for plugin in $INPUT_PRETTIER_PLUGINS; do
42+
echo "Checking plugin: $plugin"
43+
# check regex against @prettier/xyz
44+
if ! echo "$plugin" | grep -Eq '(@prettier\/)+(plugin-[a-z\-]+)'; then
45+
echo "$plugin does not seem to be a valid @prettier/plugin-x plugin. Exiting."
46+
exit 1
47+
fi
48+
done
49+
npm install --silent --global $INPUT_PRETTIER_PLUGINS
50+
fi
51+
3952
echo "Prettifing files..."
4053
echo "Files:"
4154
prettier $INPUT_PRETTIER_OPTIONS || echo "Problem running prettier with $INPUT_PRETTIER_OPTIONS"

0 commit comments

Comments
 (0)