-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
run-on-save
executable file
·43 lines (40 loc) · 1.08 KB
/
run-on-save
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#! /bin/bash
# PURPOSE
# =======
#
# This script is to be run when editor finishes editing a file.
#
# INSTALLATION
# ============
#
# Visual Studio Code
# ------------------
#
# 1. Install "Run On Save" extension
# - Marketplace ID: pucelle.run-on-save
# - GitHub Repo: https://github.com/pucelle/vscode-run-on-save
#
# 2. Add the following section to your `settings.json`:
# "runOnSave.commands": [
# {
# "match": ".*",
# "command": "sh -c 'if [ -x ./run-on-save ]; then FILE=${file} ./run-on-save; fi'",
# "runIn": "backend",
# }
# ]
set -o errexit -o pipefail -o nounset
# TASK: Use sane-fmt to format TypeScript/JavaScript file
# <https://github.com/sane-fmt/sane-fmt>
for ext in js ts jsx tsx; do
if [[ "$FILE" == *.$ext && "$FILE" != *node_modules* ]]; then
if which sane-fmt &>/dev/null; then
echo "Run sane-fmt on $FILE"
sane-fmt --color=never --write "$FILE"
else
echo 'Fail to detect sane-fmt in PATH'
echo 'See <https://github.com/sane-fmt/sane-fmt> for installation instruction'
exit 1
fi
break
fi
done