| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							|  |  |  | const DEST_DIR = "./dist"; | 
					
						
							|  |  |  | const DEST_DIR_SRC = path.join(DEST_DIR, "src"); | 
					
						
							|  |  |  | const DEST_DIR_NODE_MODULES = path.join(DEST_DIR, "node_modules"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-01 00:05:24 +02:00
										 |  |  | async function copyNodeModuleFileOrFolder(source: string) { | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |     const adjustedSource = source.substring(13); | 
					
						
							|  |  |  |     const destination = path.join(DEST_DIR_NODE_MODULES, adjustedSource); | 
					
						
							| 
									
										
										
										
											2024-05-01 00:05:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |     log(`Copying ${source} to ${destination}`); | 
					
						
							|  |  |  |     await fs.ensureDir(path.dirname(destination)); | 
					
						
							|  |  |  |     await fs.copy(source, destination); | 
					
						
							| 
									
										
										
										
											2024-05-01 00:05:24 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const copy = async () => { | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |     for (const srcFile of fs.readdirSync("build")) { | 
					
						
							|  |  |  |         const destFile = path.join(DEST_DIR, path.basename(srcFile)); | 
					
						
							|  |  |  |         log(`Copying source ${srcFile} -> ${destFile}.`); | 
					
						
							|  |  |  |         fs.copySync(path.join("build", srcFile), destFile, { recursive: true }); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2024-07-14 13:03:06 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-15 00:25:23 +02:00
										 |  |  |     const filesToCopy = [ | 
					
						
							|  |  |  |         "config-sample.ini", | 
					
						
							|  |  |  |         "./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", | 
					
						
							|  |  |  |         "./src/public/robots.txt" | 
					
						
							| 
									
										
										
										
											2025-02-15 00:25:23 +02:00
										 |  |  |     ]; | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |     for (const file of filesToCopy) { | 
					
						
							|  |  |  |         log(`Copying ${file}`); | 
					
						
							|  |  |  |         await fs.copy(file, path.join(DEST_DIR, file)); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2024-05-01 00:05:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-26 21:24:00 +01:00
										 |  |  |     const dirsToCopy = [ | 
					
						
							|  |  |  |         "images", | 
					
						
							|  |  |  |         "libraries", | 
					
						
							|  |  |  |         "translations", | 
					
						
							|  |  |  |         "db", | 
					
						
							|  |  |  |         "src/public/fonts", | 
					
						
							|  |  |  |         "src/public/stylesheets", | 
					
						
							|  |  |  |         "src/public/translations" | 
					
						
							|  |  |  |     ]; | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |     for (const dir of dirsToCopy) { | 
					
						
							|  |  |  |         log(`Copying ${dir}`); | 
					
						
							|  |  |  |         await fs.copy(dir, path.join(DEST_DIR, dir)); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2024-05-01 00:05:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-24 20:27:06 +01:00
										 |  |  |     const srcDirsToCopy = ["./src/public", "./src/views"]; | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |     for (const dir of srcDirsToCopy) { | 
					
						
							|  |  |  |         log(`Copying ${dir}`); | 
					
						
							|  |  |  |         await fs.copy(dir, path.join(DEST_DIR_SRC, path.basename(dir))); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											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) { | 
					
						
							|  |  |  |         await fs.copy(dir, path.join(PUBLIC_DIR, path.basename(dir))); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2024-11-02 16:11:59 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |     const nodeModulesFile = [ | 
					
						
							|  |  |  |         "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", | 
					
						
							|  |  |  |         "node_modules/@mind-elixir/node-menu/dist/node-menu.umd.cjs" | 
					
						
							|  |  |  |     ]; | 
					
						
							| 
									
										
										
										
											2024-05-01 00:05:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |     for (const file of nodeModulesFile) { | 
					
						
							|  |  |  |         await copyNodeModuleFileOrFolder(file); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2024-05-01 00:05:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |     const nodeModulesFolder = [ | 
					
						
							| 
									
										
										
										
											2025-01-18 11:19:35 +02:00
										 |  |  |         "node_modules/@excalidraw/excalidraw/dist/", | 
					
						
							| 
									
										
										
										
											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/mermaid/dist/", | 
					
						
							|  |  |  |         "node_modules/jquery/dist/", | 
					
						
							|  |  |  |         "node_modules/jquery-hotkeys/", | 
					
						
							|  |  |  |         "node_modules/split.js/dist/", | 
					
						
							|  |  |  |         "node_modules/panzoom/dist/", | 
					
						
							|  |  |  |         "node_modules/i18next/", | 
					
						
							|  |  |  |         "node_modules/i18next-http-backend/", | 
					
						
							|  |  |  |         "node_modules/jsplumb/dist/", | 
					
						
							|  |  |  |         "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/mind-elixir/dist/", | 
					
						
							|  |  |  |         "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-01-09 18:07:02 +02:00
										 |  |  |     ]; | 
					
						
							| 
									
										
										
										
											2024-05-01 00:05:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |     for (const folder of nodeModulesFolder) { | 
					
						
							|  |  |  |         await copyNodeModuleFileOrFolder(folder); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2024-05-01 00:05:24 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | copy() | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |     .then(() => console.log("Copying complete!")) | 
					
						
							|  |  |  |     .catch((err) => console.error("Error during copy:", err)); |