44 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			44 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| /*
 | |
|  *               dotfiles - subprocessRunner.ts
 | |
|  *
 | |
|  *   Created by Janis Hutz 03/22/2025, Licensed under the GPL V3 License
 | |
|  *           https://janishutz.com, development@janishutz.com
 | |
|  *
 | |
|  *
 | |
|  */
 | |
| 
 | |
| import { subprocess, execAsync, Process } from "astal/process";
 | |
| 
 | |
| // TODO: Get cwd and the likes to then use that to run JavaScript files with node / python with python, etc
 | |
| 
 | |
| /**
 | |
|  * Run a subprocess. If you simply want to run a command that doesn't need continuous updates
 | |
|  * run executeCommand instead.
 | |
|  * @param cmd - The command to be run
 | |
|  * @param onOut - Calback function for stdout of the subprocess
 | |
|  * @param onErr - [TODO:description]
 | |
|  * @returns [TODO:return]
 | |
|  */
 | |
| const startSubProcess = (
 | |
|     cmd: string | string[],
 | |
|     onOut: (stdout: string) => void,
 | |
|     onErr: (stderr: string) => void | undefined,
 | |
| ): Process => {
 | |
|     return subprocess( cmd, onOut, onErr );
 | |
| };
 | |
| 
 | |
| /**
 | |
|  * Run a command. If you need continuous updates, run startSubProcess instead 
 | |
|  * @param cmd - The command to be run. Either a string or an array of strings
 | |
|  * @returns A Promise resolving to stdout of the command
 | |
|  */
 | |
| const executeCommand = (cmd: string | string[]): Promise<string> => {
 | |
|     return execAsync( cmd );
 | |
| };
 | |
| 
 | |
| 
 | |
| export default {
 | |
|     startSubProcess,
 | |
|     executeCommand
 | |
| }
 |