-
Notifications
You must be signed in to change notification settings - Fork 3
/
configure-vscode.sh
executable file
·101 lines (91 loc) · 2.81 KB
/
configure-vscode.sh
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/sh
# Configures the .vscode directory (which is .gitignored so that everyone can tailor it)
die() {
echo "$*" >&2
exit 1
}
# Run at the top level of the repository
cd "$(git rev-parse --show-toplevel)" ||
die "Could not cd to top-level directory"
mkdir -p .vscode ||
die "Could not create .vscode/"
# General settings
cat >.vscode/settings.json.new <<\EOF ||
{
// Automatically format with Prettier on save
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"typescript.preferences.importModuleSpecifierEnding": "js",
"typescript.tsdk": "node_modules/typescript/lib",
// ESLint config
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"eslint.rules.customizations": [
// Leave this to Prettier itself
{ "rule": "prettier/*", "severity": "off" },
// Error in CI but a common state while coding in IDE
{ "rule": "no-unused-vars", "severity": "warn" },
// Imports are auto-fixed on save
{ "rule": "import/newline-after-import", "severity": "off" },
{ "rule": "import/order", "severity": "off" },
],
"eslint.useESLintClass": true,
"eslint.packageManager": "yarn"
}
EOF
die "Could not write settings.json"
cat > .vscode/launch.json.new <<\EOF ||
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "pwa-node",
"request": "launch",
"name": "Debug AVA file",
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/ava",
"runtimeArgs": [
"${file}"
],
"outputCapture": "std",
"skipFiles": [
"<node_internals>/**"
],
},
{
"type": "pwa-node",
"request": "launch",
"name": "Debug AVA matches",
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/ava",
"runtimeArgs": [
"${file}",
"-m",
"${selectedText}"
],
"outputCapture": "std",
"skipFiles": [
"<node_internals>/**"
],
}
]
}
EOF
die "Could not write launch.json"
for file in .vscode/launch.json .vscode/settings.json; do
printf "\nComparing %s\n" $file
if test -f $file; then
if git diff --no-index --quiet --exit-code $file $file.new; then
echo "Your existing configuration matches the recommendations."
rm $file.new
else
printf "The file %s.new has these changes:\n\n" $file
git --no-pager diff --no-index $file $file.new
printf "\n\nTo overwrite yours:\n\n mv %s.new %s\n\n" $file $file
fi
else
mv $file.new $file
fi
done