garvinhicking / typo3-documentation-browsersync
Standalone project (NodeJS, browsersync) to render and hot-reload changes in ReST documentation to your browser window
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 1
Open Issues: 0
Language:JavaScript
Requires
- php: ^8.2
- t3docs/render-guides: dev-main
Requires (Dev)
- phpstan/phpstan: ^1.10
- symfony/console: ^6.4
- symplify/phpstan-rules: ^12.4
- dev-main
- 1.0.110
- 1.0.109
- 1.0.108
- 1.0.107
- 1.0.106
- 1.0.105
- 1.0.104
- 1.0.103
- 1.0.102
- 1.0.101
- 1.0.100
- 1.0.99
- 1.0.88
- 1.0.87
- 1.0.86
- 1.0.85
- 1.0.84
- 1.0.83
- 1.0.82
- 1.0.81
- 1.0.80
- 1.0.79
- 1.0.78
- 1.0.77
- 1.0.76
- 1.0.75
- 1.0.74
- 1.0.73
- 1.0.72
- 1.0.71
- 1.0.70
- 1.0.69
- 1.0.68
- 1.0.67
- 1.0.66
- 1.0.65
- 1.0.64
- 1.0.63
- 1.0.62
- 1.0.61
- 1.0.60
- 1.0.59
- 1.0.58
- 1.0.57
- 1.0.56
- 1.0.55
- 1.0.54
- 1.0.53
- 1.0.52
- 1.0.51
- 1.0.50
- 1.0.49
- 1.0.48
- 1.0.47
- 1.0.46
- 1.0.45
- 1.0.44
- 1.0.43
- 1.0.42
- 1.0.41
- 1.0.40
- 1.0.39
- 1.0.38
- 1.0.37
- 1.0.36
- 1.0.35
- 1.0.34
- 1.0.33
- 1.0.32
- 1.0.31
- 1.0.30
- 1.0.29
- 1.0.28
- 1.0.27
- 1.0.26
- 1.0.25
- 1.0.24
- 1.0.23
- 1.0.22
- 1.0.21
- 1.0.20
- 1.0.19
- 1.0.18
- 1.0.17
- 1.0.16
- 1.0.15
- 1.0.14
- 1.0.13
- 1.0.12
- 1.0.11
- 1.0.10
- 1.0.9
- 1.0.8
- 1.0.7
- 1.0.6
- 1.0.5
- 0.1.4
- 0.1.3
- 0.1.2
- 0.1.1
- 0.1.0
- dev-dependabot/npm_and_yarn/nanoid-3.3.8
- dev-dependabot/composer/league/commonmark-2.6.0
This package is auto-updated.
Last update: 2024-12-10 00:01:49 UTC
README
TL;DR:
docker run --rm -it --pull always \
-v "./Documentation:/project/Documentation" \
-v "./Documentation-GENERATED-temp:/project/Documentation-GENERATED-temp" \
-p 5173:5173 ghcr.io/garvinhicking/typo3-documentation-browsersync:latest
Introduction
Standalone project (NodeJS, browsersync) to render and hot-reload changes in TYPO3 ReST documentation to your browser window.
The files are rendered through the official https://github.com/TYPO3-documentation/render-guides project. Please see https://docs.typo3.org/m/typo3/docs-how-to-document/main/en-us/WritingDocForExtension/Index.html for more information on TYPO3 documentations.
This project exists to be build and used as a Docker container. It's not meant
to run natively, because it would require a lot of dependencies (PHP, composer, NodeJS,
nvm) and the underlying TYPO3-Documentation/render-guides
project is NOT SUPPORTED as a Composer package, making native
use impossible.
The Docker container provides a proxy server that returns (proxies) your rendered ReST documentation (as HTML) to a browser. Any change you make to the ReST-files will automatically trigger a reload of your browser window.
This allows you to have some kind of "WYSIWYG" display of your documentation, without the need to manually reload browser windows or render documentation time and again. It will all happen on demand.
ReST is very dependent on the used renderer and its capabilities, so you cannot really have a WYSIWYG editor for ReST files. A tool like this is, what comes closest to editing files and directly seeing the impact of it.
General Usage
This project depends on the ability to execute Docker Containers on your host.
You can also use Podman, if you prefer. Replace the docker
commands with
podman
in that case.
You can use the provided Docker container within any project directory:
docker run --rm -it --pull always \
-v "./Documentation:/project/Documentation" \
-v "./Documentation-GENERATED-temp:/project/Documentation-GENERATED-temp" \
-p 5173:5173 ghcr.io/garvinhicking/typo3-documentation-browsersync:latest
This starts a server to listen on localhost port 5173, so you can point your browser to a URL like this:
http://localhost:5173/Documentation-GENERATED-temp/Index.html
Output
The Docker container will show you the vite console of the running server,
you can interact with it. It will run until you enter q
("quit") or use Ctrl-C
to end the process.
Whenever you make changes to either the .rst
or .html
files, you will
see console output about what is performed.
Demo project
There's a simple demo project which showcases how to use it with a dummy Documentation directory
https://github.com/garvinhicking/demo-typo3-documentation-browsersync
Parameters of the "docker run" command explained
The docker command above starts the Docker container
ghcr.io/garvinhicking/typo3-documentation-browsersync:latest
with these
options:
--rm
: When Docker finishes, the container is stopped.-it
: Runs an interactive shell, so that you can enter commands to the vite proxy server--pull always
: Ensures that the referenced Docker image is always fetched in its current version.-v "./Documentation:/project/Documentation"
: Makes the directoryDocumentation
available ("mount") in the Docker container, so that.rst
files can be accessed and watched.-v "./Documentation-GENERATED-temp:/project/Documentation-GENERATED-temp"
: Makes the output directoryDocumentation-GENERATED-temp
available ("mount") in the Docker container, so that.html
files can be written and watched there.-p 5173:5173
: This makes the proxy HTTP server that runs on port 5173 inside the Docker container available to your host, so that you can use your host's browser to view the rendered HTML output. If you want to have multiple ports running, you can pick any other number than5173
as the FIRST part of this parameter, e.g.-p 8080:5173
.ghcr.io/garvinhicking/typo3-documentation-browsersync:latest
: This specifies the Docker container that is being run. The tag:latest
is used so that you run the latest release version of the project. You can also specifically use a version like:0.1
, which is not recommended though.
If you want to know what is contained inside the Docker container, please check out the Dockerfile used to build it:
https://github.com/garvinhicking/typo3-documentation-browsersync/blob/main/Dockerfile
Once the Docker is up and running, it will watch the Directory Documentation
for
any changes, trigger rendering and proxy the created HTML to your browser.
Changing default port and directories
You can provide these environment variables, if you want to run on non-default ports and different directories:
- LOCAL_RENDER_PORT=5173
- LOCAL_RENDER_INPUT=Documentation
- LOCAL_RENDER_OUTPUT=Documentation-GENERATED-temp
So a full docker run command utilizing this, and directly opening a browser window with the URL, would look like:
LOCAL_RENDER_PORT=5175 \
LOCAL_RENDER_INPUT=Documentation \
LOCAL_RENDER_OUTPUT=Documentation-GENERATED-temp; \
\
open "http://localhost:${LOCAL_RENDER_PORT}/Documentation-GENERATED-temp/Index.html" && \
docker run --rm -it --pull always \
-e LOCAL_RENDER_PORT=$LOCAL_RENDER_PORT \
-e LOCAL_RENDER_INPUT=$LOCAL_RENDER_INPUT \
-e LOCAL_RENDER_OUTPUT=$LOCAL_RENDER_OUTPUT \
-v "$(pwd)/${LOCAL_RENDER_INPUT}:/project/Documentation" \
-v "$(pwd)/${LOCAL_RENDER_OUTPUT}:/project/Documentation-GENERATED-temp" \
-p "${LOCAL_RENDER_PORT}:5173" \
ghcr.io/garvinhicking/typo3-documentation-browsersync:latest
See the file alias.sh
in this repository, you could place these
lines into an alias of your Shell, or place it in a
/usr/local/bin/render-wysiwyg.sh
file and call it.
The reason why the environment variables are called twice is because the docker run command already needs to access them, and then they also need to be propagated into the docker container as well.
HEADS UP: WRITE-actions to files on the HOST-side!
IMPORTANT: The rendering process will CHANGE AND OVERWRITE FILES in the
output-directory (Documentation-GENERATED-temp
). Be sure to only execute
the container if there are no files in there that may not be overwritten!
If the directory is empty, a first-time rendering will be started when the Docker container is started.
If the input directory is missing, the watch server will fail.
The input directory (Documentation
) is only used for reading.
Building a local container
Via GitHub Actions, this project creates a Docker Container on ghcr.io via a multi-stage build process.
The contained Dockerfile
performs this:
- Use the
TYPO3-Documentation/render-guides
base Docker container (:latest
) - Put a NodeJS alpine environment on top
- Configures PHP (so the render-guides base can be used natively)
- Setup NPM and vite
- Define the entrypoint
If you check out this project, you can build the Docker container yourself:
docker build . -t typo3-documentation-browsersync:local
## or: make docker-build
and then execute it via:
docker run --rm -it --pull always \
-v "./Documentation:/project/Documentation" \
-v "./Documentation-GENERATED-temp:/project/Documentation-GENERATED-temp" \
-p 5173:5173 typo3-documentation-browsersync:local
## or enter: make docker-enter
Notes
A first idea was to also provide a native way (without Docker) to
perform rendering and proxying locally. The depedency chain for this
was harsh, and the render-guides
project does not support being
used as a dependency.
So this is currently "beyond scope". The repository has a base
composer.json
file and abilities to run locally, but this is
just a stub.
The only vital things inside this project are:
package.json
,package-lock.json
: NPM dependenciesvite.config.js
: The actual "code"Dockerfile
: The instructions to build the Docker Container.dockerignore
: Excluded files for Docker Container.nvmrc
: NVM version config.github/workflows
: GitHub workflow definition to automatically provide Docker Containers to the world
Alternatives (PHPStorm)
PHPStorm actually offers a cool way to create a local proxy server on its
own; when you pick a rendered HTML file and right-click Open in > Browser > Default
it will open a browser window on your host and show the contents
of the HTML file, and also have hot-reload capability. So when you change
anything in the HTML file, the PHPStorm proxy server will directly reload
your output, too. It will however NOT render the ReST files automatically,
when such a file is edited.
If your OS supports inotifywait
(on Linux), you could use this:
inotifywait -e close_write,moved_to,create -m . |
while read -r directory events filename; do
docker run --rm --pull always -v $(pwd):/project -it ghcr.io/typo3-documentation/render-guides:latest --config=Documentation
done
to automatically "watch" for any change on ReST files inside the
Documentation
folder, then re-render the HTML, which would then
automatically reload your browser window.
Sadly, inotifywait
is not available on macOS
and the alternative to
build a custom PHP pecl inotify
package-enabled tool was beyond my
personal scope, as well as using alternate tools like fswatch
.
I wanted to have an easy way for anyone to preview changes, so I wanted to not require PHPStorm or a specific inotify-enabled OS.
Instead, the NodeJS
ecosystem provides a browsersync
package that does
all of the needed watching and proxying. I coupled this with vite
, because
alternatives like gulp
or grunt
are outdated and report many security
issues on their dependencies.