Merge pull request #664 from return42/themes.live

[mod] manage: add themes.live command (rebuild on modification)
This commit is contained in:
Markus Heiser 2022-01-04 19:44:51 +01:00 committed by GitHub
commit 00d3a7477c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 58 additions and 18 deletions

View file

@ -25,11 +25,7 @@ help:
PHONY += run PHONY += run
run: install run: install
$(Q) ( \ $(Q)./manage webapp.run
sleep 2 ; \
xdg-open http://127.0.0.1:8888/ ; \
) &
SEARXNG_DEBUG=1 ./manage pyenv.cmd python -m searx.webapp
PHONY += install uninstall PHONY += install uninstall
install uninstall: install uninstall:

View file

@ -13,7 +13,7 @@ Makefile
To install system requirements follow :ref:`buildhosts`. To install system requirements follow :ref:`buildhosts`.
All relevant build tasks are implemented in :origin:`manage.sh` and for CI or All relevant build tasks are implemented in :origin:`manage` and for CI or
IDE integration a small ``Makefile`` wrapper is available. If you are not IDE integration a small ``Makefile`` wrapper is available. If you are not
familiar with Makefiles, we recommend to read gnu-make_ introduction. familiar with Makefiles, we recommend to read gnu-make_ introduction.
@ -173,14 +173,19 @@ Install latest Node.js_ LTS locally (uses nvm_)::
To get up a running a developer instance simply call ``make run``. This enables To get up a running a developer instance simply call ``make run``. This enables
*debug* option in :origin:`searx/settings.yml`, starts a ``./searx/webapp.py`` *debug* option in :origin:`searx/settings.yml`, starts a ``./searx/webapp.py``
instance, disables *debug* option again and opens the URL in your favorite WEB instance and opens the URL in your favorite WEB browser (:man:`xdg-open`)::
browser (:man:`xdg-open`)::
$ make run $ make run
PYENV OK
SEARXNG_DEBUG=1 ./manage.sh pyenv.cmd python ./searx/webapp.py Changes to theme's HTML templates (jinja2) are instant. Changes to the CSS & JS
... sources of the theme need to be rebuild. You can do that by running::
INFO:werkzeug: * Running on http://127.0.0.1:8888/ (Press CTRL+C to quit)
$ make themes.all
Alternatively to ``themes.all`` you can run *live builds* of the theme you are
modify::
$ LIVE_THEME=simple make run
.. _make clean: .. _make clean:

View file

@ -40,10 +40,15 @@ JavaScript:
Alternatively you can also compile selective the theme you have modified, Alternatively you can also compile selective the theme you have modified,
e.g. the *simple* theme. e.g. the *simple* theme.
.. code:: sh .. code:: sh
make themes.simple make themes.simple
.. tip::
To get live builds while modifying CSS & JS use: ``LIVE_THEME=simple make run``
If you finished your *tests* you can start to commit your changes. To separate If you finished your *tests* you can start to commit your changes. To separate
the modified source code from the build products first run: the modified source code from the build products first run:

46
manage
View file

@ -120,6 +120,17 @@ fi
# needed by sphinx-docs # needed by sphinx-docs
export DOCS_BUILD export DOCS_BUILD
webapp.run() {
SEARXNG_DEBUG=1 pyenv.cmd python -m searx.webapp &
sleep 3
if [ "${LIVE_THEME}" ]; then
themes.live "${LIVE_THEME}" &
fi
xdg-open http://127.0.0.1:8888/
wait -n
kill 0
}
buildenv() { buildenv() {
# settings file from repository's working tree are used by default # settings file from repository's working tree are used by default
@ -514,12 +525,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"
@ -701,6 +715,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
@ -708,7 +746,6 @@ themes.oscar() {
} }
themes.simple() { themes.simple() {
local static="searx/static/themes/simple"
( set -e ( set -e
build_msg GRUNT "theme: simple" build_msg GRUNT "theme: simple"
npm --prefix searx/static/themes/simple run build npm --prefix searx/static/themes/simple run build
@ -718,10 +755,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 nodejs.ensure
info_msg "install Node.js by NVM"
nvm.nodejs
fi
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 $?