"The [drawio](https://github.com/jgraph/drawio) distribution, submoduled into `src/drawio` is very large. We need to distribute parts of it, so that they are available on end user's computers."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Finding the files"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from pathlib import Path\n",
"import re, json, IPython"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/markdown": [
"> ### Packaging 0 of 3399 files"
],
"text/plain": [
"<IPython.core.display.Markdown object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"ROOT = Path.cwd().parent\n",
"SRC = ROOT / \"src\"\n",
"DIO = SRC / \"drawio\"\n",
"DIO_APP = DIO / \"src\" / \"main\" / \"webapp\"\n",
"ALL_FILES = sorted(DIO_APP.rglob(\"*.*\"))\n",
"WANT_FILES = set()\n",
"\n",
"def show_files():\n",
" IPython.display.display(IPython.display.Markdown(f\"> ### Packaging {len(WANT_FILES)} of {len(ALL_FILES)} files\"))\n",
"WANT_FILES = {wanted for wanted in WANT_FILES if not wanted.name.endswith(\".json\")}\n",
"show_files()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Get the files into webpack\n",
"\n",
"When launched by JupyterLab, drawio is served in an `iframe`, and all of its assets need to be available locally:\n",
"\n",
"- exactly as they were originally named\n",
"- in a predictable location relative to the main `index.html`\n",
"\n",
"This presents some challenges and opportunities:\n",
"\n",
"- Unfortunately, this conflicts with the JupyterLab/WebPack _weltanschauung_ of putting everything into a single file and munging the name with hashes\n",
"- Fortunately, webpack's [`file-loader`](https://webpack.js.org/loaders/file-loader/) gives us a way to just copy a file to a predictable location\n",