From bf0114dde522e50771629a0f3a104ab3025f012c Mon Sep 17 00:00:00 2001 From: Miroslav Shubernetskiy Date: Wed, 7 Sep 2022 01:08:23 -0400 Subject: [PATCH] switching to better sync script --- .pre-commit-config.yaml | 11 +++-------- .pre-commit-hooks.yaml | 30 ++++++++++++------------------ sync_versions.sh | 33 --------------------------------- 3 files changed, 15 insertions(+), 59 deletions(-) delete mode 100755 sync_versions.sh diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6dca9ff..0ab6253 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,10 +1,5 @@ --- - -- repo: local +- repo: https://github.com/miki725/pre-commit-sync + rev: 0.1.0.a1 hooks: - - id: sync_versions - name: sync versions of additional_dependencies in .pre-commit-hooks.yaml - language: script - entry: ./sync_versions.sh - pass_filenames: false - files: ^package.json$ + - id: pre-commit-sync diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index bf20b55..81c0188 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -22,21 +22,15 @@ - file files: \.(js|ts)$ additional_dependencies: - - '@typescript-eslint/eslint-plugin@5.20.0' # sync:package.json - - '@typescript-eslint/parser@5.20.0' # sync:package.json - - 'eslint@8.13.0' # sync:package.json - - 'eslint-config-prettier@8.5.0' # sync:package.json - - 'eslint-plugin-import@2.26.0' # sync:package.json - - 'eslint-plugin-es@4.1.0' # sync:package.json - - 'eslint-plugin-no-only-tests@2.6.0' # sync:package.json - - 'eslint-plugin-prettier@4.0.0' # sync:package.json - - 'eslint-plugin-simple-import-sort@7.0.0' # sync:package.json - - 'import-modules@3.1.0' # sync:package.json - - 'prettier@2.6.2' # sync:package.json - - 'typescript@4.6.3' # sync:package.json - -- id: sync_versions - name: sync versions of additional_dependencies in .pre-commit-hooks.yaml - language: script - entry: ./sync_versions.sh - files: ^package.json$ + - '@typescript-eslint/eslint-plugin@5.20.0' # sync:yarn.lock + - '@typescript-eslint/parser@5.20.0' # sync:yarn.lock + - 'eslint@8.13.0' # sync:yarn.lock + - 'eslint-config-prettier@8.5.0' # sync:yarn.lock + - 'eslint-plugin-import@2.26.0' # sync:yarn.lock + - 'eslint-plugin-es@4.1.0' # sync:yarn.lock + - 'eslint-plugin-no-only-tests@2.6.0' # sync:yarn.lock + - 'eslint-plugin-prettier@4.0.0' # sync:yarn.lock + - 'eslint-plugin-simple-import-sort@7.0.0' # sync:yarn.lock + - 'import-modules@3.1.0' # sync:yarn.lock + - 'prettier@2.6.2' # sync:yarn.lock + - 'typescript@4.6.3' # sync:yarn.lock diff --git a/sync_versions.sh b/sync_versions.sh deleted file mode 100755 index f6fc6ad..0000000 --- a/sync_versions.sh +++ /dev/null @@ -1,33 +0,0 @@ -#! /usr/bin/env sh - -HOOKS_FILE=${1:-./.pre-commit-hooks.yaml} -PACKAGE_FILE=./package.json - -# need to fully consume file to allow usage like: -# ./sync_versions.sh > ./.pre-commit-hooks.yaml -# otherwise ./.pre-commit-hooks.yaml is overwritten -# as empty file since ">" is piped before rading -# the file in the script -content=$(< $HOOKS_FILE) - -exec &> $HOOKS_FILE - -while IFS= read line; do - if [ -n "$line" ] && [ -z "${line##*sync:package.json*}" ]; then - IFS=' ' read package version < <( - echo $line \ - | awk '{ print $2 }' \ - | tr -d '"' \ - | tr -d "'" \ - | sed -r "s/(.)@/\1 /g" - ) - version_in_package=$( - cat $PACKAGE_FILE \ - | grep "\"$package\"" \ - | cut -d'"' -f 4 - ) - echo "$line" | sed "s/$(echo $version | sed 's/\^/\\^/g')/$version_in_package/g" - else - echo "$line" - fi -done < <(echo "$content" | sed 's/\\/\\\\/g')