Browse Source

[mod] manage: add themes.live command (rebuild on modification)

To have a live build while editing the HTML client of a theme.  The first
argument of the command is the theme name:

    ./manage themes.live simple

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Markus Heiser 3 years ago
parent
commit
edfd069d16
1 changed files with 29 additions and 5 deletions
  1. 29 5
      manage

+ 29 - 5
manage

@@ -511,12 +511,15 @@ gecko.driver() {
     dump_return $?
     dump_return $?
 }
 }
 
 
-node.env() {
+nodejs.ensure() {
     if ! nvm.min_node "${NODE_MINIMUM_VERSION}"; then
     if ! nvm.min_node "${NODE_MINIMUM_VERSION}"; then
         info_msg "install Node.js by NVM"
         info_msg "install Node.js by NVM"
         nvm.nodejs
         nvm.nodejs
     fi
     fi
+}
 
 
+node.env() {
+    nodejs.ensure
     (   set -e
     (   set -e
 
 
         build_msg INSTALL "searx/static/themes/oscar/package.json"
         build_msg INSTALL "searx/static/themes/oscar/package.json"
@@ -698,6 +701,30 @@ themes.all() {
     dump_return $?
     dump_return $?
 }
 }
 
 
+themes.live() {
+    local LIVE_THEME="${LIVE_THEME:-${1}}"
+    case "${LIVE_THEME}" in
+        simple|oscar)
+            theme="searx/static/themes/${LIVE_THEME}"
+            ;;
+        '')
+            die_caller 42 "missing theme argument"
+            ;;
+        *)
+            die_caller 42 "unknown theme '${LIVE_THEME}' // [simple|oscar]'"
+            ;;
+    esac
+    build_msg GRUNT "theme: $1 (live build)"
+    nodejs.ensure
+    cd "${theme}"
+    {
+        npm install
+        npm run watch
+    } 2>&1 \
+        | prefix_stdout "${_Blue}THEME ${1} ${_creset}  " \
+        | grep -E --ignore-case --color 'error[s]?[:]? |warning[s]?[:]? |'
+}
+
 themes.oscar() {
 themes.oscar() {
     build_msg GRUNT "theme: oscar"
     build_msg GRUNT "theme: oscar"
     npm --prefix searx/static/themes/oscar run build
     npm --prefix searx/static/themes/oscar run build
@@ -715,10 +742,7 @@ themes.simple() {
 
 
 themes.simple.test() {
 themes.simple.test() {
     build_msg TEST "theme: simple"
     build_msg TEST "theme: simple"
-    if ! nvm.min_node "${NODE_MINIMUM_VERSION}"; then
-        info_msg "install Node.js by NVM"
-        nvm.nodejs
-    fi
+    nodejs.ensure
     npm --prefix searx/static/themes/simple install
     npm --prefix searx/static/themes/simple install
     npm --prefix searx/static/themes/simple run test
     npm --prefix searx/static/themes/simple run test
     dump_return $?
     dump_return $?