LSG: Allow the style guide to build without npm present at runtime
authorMatthew Flaschen <mflaschen@wikimedia.org>
Tue, 5 Aug 2014 22:07:05 +0000 (18:07 -0400)
committerMattflaschen <mflaschen@wikimedia.org>
Wed, 6 Aug 2014 18:29:53 +0000 (18:29 +0000)
By only requiring the actual kss-node executable, this allows
running "npm install" at a separate time/machine from the actual
build.

For example, this is useful since the machines used to run Tool Labs
grid jobs do not have npm.

Change-Id: I561b365d4aaf44d921fb54a020e9ff6319318063

docs/kss/Makefile
docs/kss/scripts/kss-node-check.sh [new file with mode: 0755]
docs/kss/scripts/nodecheck.sh [deleted file]

index 7d2ee3b..ff735d5 100644 (file)
@@ -1,8 +1,6 @@
 MEDIAWIKI_LOAD_URL ?= http://localhost/w/load.php
 
-kss: nodecheck
-# FIXME: Use more up-to-date Ruby version
-
+kss: kssnodecheck
 # Generates CSS of mediawiki.ui and mediawiki.ui.button using ResourceLoader, then applies it to the
 # KSS style guide
        $(eval KSS_RL_TMP := $(shell mktemp /tmp/tmp.XXXXXXXXXX))
@@ -15,5 +13,5 @@ kssopen: kss
        @command -v xdg-open >/dev/null 2>&1 || { open ${PWD}/static/index.html; exit 0; }
        @xdg-open ${PWD}/static/index.html
 
-nodecheck:
-       @scripts/nodecheck.sh
+kssnodecheck:
+       @scripts/kss-node-check.sh
diff --git a/docs/kss/scripts/kss-node-check.sh b/docs/kss/scripts/kss-node-check.sh
new file mode 100755 (executable)
index 0000000..84ee1c4
--- /dev/null
@@ -0,0 +1,20 @@
+#!/usr/bin/env bash
+
+if command -v npm > /dev/null ; then
+  npm install
+else
+  # If npm isn't installed, but kss-node is, exit normally.
+  # This allows setting it up on one machine, and running it on
+  # another (e.g. Tools Labs execution nodes) that doesn't have npm
+  # installed.  However, "npm install" still needs to be run
+  # occasionally to keep kss updated.
+
+  KSS_NODE="${BASH_SOURCE%/*}/../node_modules/.bin/kss-node"
+  if ! [ -x "$KSS_NODE" ] ; then
+    echo "Neither kss-node nor npm are installed."
+    echo "To install npm, see http://nodejs.org/"
+    echo "When npm is installed, the Makefile can automatically"
+    echo "install kss-node."
+    exit 1
+  fi
+fi
diff --git a/docs/kss/scripts/nodecheck.sh b/docs/kss/scripts/nodecheck.sh
deleted file mode 100755 (executable)
index 3ee0f83..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/usr/bin/env bash
-if command -v npm > /dev/null ; then
-  npm install
-else
-  echo "You need to install Node.JS!"
-  echo "See http://nodejs.org/"
-  exit 1
-fi