2024-07-14 13:03:06 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import fs from "fs-extra";
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import path from "path";
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-01 00:05:24 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-03-09 08:29:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								const DEST_DIR = "./build";
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-01 00:05:24 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2024-07-27 16:42:47 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								const VERBOSE = process.env.VERBOSE;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-02-15 13:08:13 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								function log(...args: any[]) {
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (VERBOSE) {
							 | 
						
					
						
							
								
									
										
										
										
											2025-02-15 13:08:13 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        console.log(...args);
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2024-07-27 16:42:47 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-02-27 08:59:12 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								function copyNodeModuleFileOrFolder(source: string) {
							 | 
						
					
						
							
								
									
										
										
										
											2025-02-27 08:53:02 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    const destination = path.join(DEST_DIR, source);
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    log(`Copying ${source} to ${destination}`);
							 | 
						
					
						
							
								
									
										
										
										
											2025-02-27 08:59:12 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    fs.ensureDirSync(path.dirname(destination));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    fs.copySync(source, destination);
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-01 00:05:24 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-02-27 09:10:27 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								try {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-02-27 08:01:07 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    const assetsToCopy = new Set([
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "./images",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "./libraries",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "./translations",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "./db",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "./config-sample.ini",
							 | 
						
					
						
							
								
									
										
										
										
											2025-03-05 09:01:21 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        "./package-lock.json",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "./package.json",
							 | 
						
					
						
							
								
									
										
										
										
											2025-03-09 09:57:35 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        "./LICENSE",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "./README.md",
							 | 
						
					
						
							
								
									
										
											 
										 
										
											
												build(electron-forge): execute electron-forge commands in our "build" output context
since we build TS and webpack ourselves and are not using any electron-forge plugins (at least at the moment) -> we should use the "build" folder as build context for electron-forge:
in comparison to running electron-forge in the root folder of the project, this avoids electron-forge from packing the source code multiple times (e.g. once as uncompiled TS, then as compiled JS, and then (partially) a third time as webpack bundled JS files), same as some of the assets.
to achieve this, we run our usual TS/Webpack build process, but then install the npm dependencies *inside* the build folder (as otherwise electron-forge would choke on the missing node_modules it and abort building).
In theory we could avoid cd-ing into the build folder, by providing the "dir" as argument to electron-forge's CLI -- BUT that wouldn't play well with our CI, where we are passing --arch and --platform options to it, which need to come *before* the dir argument.
since we now cd into the "build" folder, we also need to adjust the path in package.json "main" again
											
										 
										
											2025-03-11 22:12:37 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        "./forge.config.cjs",
							 | 
						
					
						
							
								
									
										
										
										
											2025-03-12 09:24:10 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        "./bin/tpl/",
							 | 
						
					
						
							
								
									
										
										
										
											2025-03-12 09:36:06 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        "./bin/electron-forge/desktop.ejs",
							 | 
						
					
						
							
								
									
										
										
										
											2025-02-27 08:01:07 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        "./src/views/",
							 | 
						
					
						
							
								
									
										
										
										
											2025-02-15 00:25:23 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        "./src/etapi/etapi.openapi.yaml",
							 | 
						
					
						
							
								
									
										
										
										
											2025-02-26 21:24:00 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        "./src/routes/api/openapi.json",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "./src/public/icon.png",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "./src/public/manifest.webmanifest",
							 | 
						
					
						
							
								
									
										
										
										
											2025-02-27 08:01:07 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        "./src/public/robots.txt",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "./src/public/fonts",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "./src/public/stylesheets",
							 | 
						
					
						
							
								
									
										
										
										
											2025-03-19 19:23:43 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        "./src/public/translations",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "./packages/turndown-plugin-gfm/src"
							 | 
						
					
						
							
								
									
										
										
										
											2025-02-27 08:01:07 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ]);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    for (const asset of assetsToCopy) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        log(`Copying ${asset}`);
							 | 
						
					
						
							
								
									
										
										
										
											2025-02-27 08:59:12 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        fs.copySync(asset, path.join(DEST_DIR, asset));
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-01 00:05:24 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    /**
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								     * Directories to be copied relative to the project root into <resource_dir>/src/public/app-dist.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								     */
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    const publicDirsToCopy = ["./src/public/app/doc_notes"];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    const PUBLIC_DIR = path.join(DEST_DIR, "src", "public", "app-dist");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    for (const dir of publicDirsToCopy) {
							 | 
						
					
						
							
								
									
										
										
										
											2025-02-27 08:59:12 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        fs.copySync(dir, path.join(PUBLIC_DIR, path.basename(dir)));
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2024-11-02 16:11:59 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-02-27 09:02:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    const nodeModulesFile = new Set([
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        "node_modules/react/umd/react.production.min.js",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "node_modules/react/umd/react.development.js",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "node_modules/react-dom/umd/react-dom.production.min.js",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "node_modules/react-dom/umd/react-dom.development.js",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "node_modules/katex/dist/katex.min.js",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "node_modules/katex/dist/contrib/mhchem.min.js",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "node_modules/katex/dist/contrib/auto-render.min.js",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "node_modules/@highlightjs/cdn-assets/highlight.min.js",
							 | 
						
					
						
							
								
									
										
										
										
											2025-02-27 09:02:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ]);
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-01 00:05:24 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-02-27 09:02:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    const nodeModulesFolder = new Set([
							 | 
						
					
						
							
								
									
										
										
										
											2025-03-12 08:56:47 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        "node_modules/@excalidraw/excalidraw/dist/prod/fonts/",
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        "node_modules/katex/dist/",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "node_modules/dayjs/",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "node_modules/boxicons/css/",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "node_modules/boxicons/fonts/",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "node_modules/jquery/dist/",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "node_modules/jquery-hotkeys/",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "node_modules/split.js/dist/",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "node_modules/i18next/",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "node_modules/i18next-http-backend/",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "node_modules/vanilla-js-wheel-zoom/dist/",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "node_modules/mark.js/dist/",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "node_modules/normalize.css/",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "node_modules/jquery.fancytree/dist/",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "node_modules/autocomplete.js/dist/",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "node_modules/codemirror/lib/",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "node_modules/codemirror/addon/",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "node_modules/codemirror/mode/",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "node_modules/codemirror/keymap/",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "node_modules/@highlightjs/cdn-assets/languages",
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-22 23:08:25 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        "node_modules/@highlightjs/cdn-assets/styles",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "node_modules/leaflet/dist"
							 | 
						
					
						
							
								
									
										
										
										
											2025-02-27 09:02:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ]);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-01 00:05:24 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-02-27 09:02:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    for (const nodeModuleItem of [...nodeModulesFile, ...nodeModulesFolder]) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        copyNodeModuleFileOrFolder(nodeModuleItem);
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2025-02-27 09:10:27 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    console.log("Copying complete!")
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-01 00:05:24 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-02-27 09:10:27 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								} catch(err) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    console.error("Error during copy:", err)
							 | 
						
					
						
							
								
									
										
										
										
											2025-03-12 09:52:42 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    process.exit(1)
							 | 
						
					
						
							
								
									
										
										
										
											2025-03-11 23:03:13 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 |