diff --git a/package.json b/package.json index 26e04244..6fcf357d 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,9 @@ "playground": "npx http-server playground", "prepare": "husky install", "prerelease": "scripts/prerelease", - "prettier": "prettier --plugin . --parser=liquid-html", + "prettier": "scripts/prettier", + "prettier2": "cross-env PRETTIER_MAJOR=2 scripts/prettier", + "prettier3": "cross-env PRETTIER_MAJOR=3 scripts/prettier", "test": "node_modules/.bin/mocha '{src,test}/**/*.spec.ts'", "test:3": "cross-env PRETTIER_MAJOR=3 yarn test", "test:idempotence": "cross-env TEST_IDEMPOTENCE=true node_modules/.bin/mocha 'test/**/*.spec.ts'", diff --git a/scripts/prettier b/scripts/prettier new file mode 100755 index 00000000..de34bfa4 --- /dev/null +++ b/scripts/prettier @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +cleanup() { + rm node_modules/prettier +} + +run() { + echo "$@" + $@ +} + +if [[ $PRETTIER_MAJOR = 3 ]]; then + prettier='./prettier3' + cmd="./node_modules/prettier3/bin/prettier.cjs --plugin ./dist/index.js --parser=liquid-html --ignore-path=.prettierignore" +else + prettier='./prettier2' + cmd="./node_modules/prettier2/bin-prettier.js --plugin . --parser=liquid-html" +fi + +# format with prettier2 +ln -s $prettier node_modules/prettier + +# cleanup when done +trap cleanup EXIT + +# run command for version +run $cmd "$@"