summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Speicher <robert@gitlab.com>2018-01-03 19:52:26 +0000
committerRobert Speicher <robert@gitlab.com>2018-01-03 19:52:26 +0000
commitc8ddf067edf38f9f0e9c6c9bd226513db90f283a (patch)
tree711f526a7f6d7537df0ced89cdbe08c068db8ff4
parentea55445dad4e11a16ab6eec58c85198870bd1f40 (diff)
parent2abf63899d449c74090a4149f508a61e766d47ec (diff)
downloadgitlab-ce-c8ddf067edf38f9f0e9c6c9bd226513db90f283a.tar.gz
Merge branch 'pre-commit-prettier' into 'master'
Pre commit prettier See merge request gitlab-org/gitlab-ce!16061
-rw-r--r--package.json1
-rwxr-xr-xscripts/add-code-formatters18
-rw-r--r--scripts/pre-commit18
-rw-r--r--yarn.lock4
4 files changed, 41 insertions, 0 deletions
diff --git a/package.json b/package.json
index d80e25e1ac6..8c3932dccfd 100644
--- a/package.json
+++ b/package.json
@@ -61,6 +61,7 @@
"mousetrap": "^1.4.6",
"name-all-modules-plugin": "^1.0.1",
"pikaday": "^1.6.1",
+ "prettier": "^1.9.2",
"prismjs": "^1.6.0",
"raphael": "^2.2.7",
"raven-js": "^3.14.0",
diff --git a/scripts/add-code-formatters b/scripts/add-code-formatters
new file mode 100755
index 00000000000..56bb8754d80
--- /dev/null
+++ b/scripts/add-code-formatters
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+# Check if file exists with -f. Check if in in the gdk rook directory.
+if [ ! -f ../GDK_ROOT ]; then
+ echo "Please run script from gitlab (e.g. gitlab-development-kit/gitlab) root directory."
+ exit 1
+fi
+
+PRECOMMIT=$(git rev-parse --git-dir)/hooks/pre-commit
+
+# Check if symlink exists with -L. Check if script was already installed.
+if [ -L $PRECOMMIT ]; then
+ echo "Pre-commit script already installed."
+ exit 1
+fi
+
+ln -s ./pre-commit $PRECOMMIT
+echo "Pre-commit script installed successfully"
diff --git a/scripts/pre-commit b/scripts/pre-commit
new file mode 100644
index 00000000000..48935e90a87
--- /dev/null
+++ b/scripts/pre-commit
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+# Check if file exists with -f. Check if in in the gdk rook directory.
+if [ ! -f ../GDK_ROOT ]; then
+ echo "Please run pre-commit from gitlab (e.g. gitlab-development-kit/gitlab) root directory."
+ exit 1
+fi
+
+jsfiles=$(git diff --cached --name-only --diff-filter=ACM "*.js" | tr '\n' ' ')
+[ -z "$jsfiles" ] && exit 0
+
+# Prettify all staged .js files
+echo "$jsfiles" | xargs ./node_modules/.bin/prettier --write
+
+# Add back the modified/prettified files to staging
+echo "$jsfiles" | xargs git add
+
+exit 0
diff --git a/yarn.lock b/yarn.lock
index 358a1baec42..381b1a243f8 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -5150,6 +5150,10 @@ prettier@^1.7.0:
version "1.8.2"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.8.2.tgz#bff83e7fd573933c607875e5ba3abbdffb96aeb8"
+prettier@^1.9.2:
+ version "1.9.2"
+ resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.9.2.tgz#96bc2132f7a32338e6078aeb29727178c6335827"
+
prismjs@^1.6.0:
version "1.6.0"
resolved "https://registry.yarnpkg.com/prismjs/-/prismjs-1.6.0.tgz#118d95fb7a66dba2272e343b345f5236659db365"