mirror of
				https://github.com/Instadapp/dsa-connectors.git
				synced 2024-07-29 22:37:00 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			34 lines
		
	
	
		
			681 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			34 lines
		
	
	
		
			681 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import { execFile, spawn } from "child_process";
 | |
| 
 | |
| interface ICommand {
 | |
|   readonly cmd: string;
 | |
|   readonly args: string[];
 | |
|   readonly env: {
 | |
|     [param: string]: string;
 | |
|   };
 | |
| }
 | |
| 
 | |
| export async function execScript(input: ICommand): Promise<number> {
 | |
|   return new Promise((resolve, reject) => {
 | |
|     let cmdEnv = Object.create(process.env);
 | |
|     for (let param in input.env) {
 | |
|       cmdEnv[param] = input.env[param];
 | |
|     }
 | |
| 
 | |
|     const proc = spawn(input.cmd, [...input.args], {
 | |
|       env: cmdEnv,
 | |
|       shell: true,
 | |
|       stdio: "inherit",
 | |
|     });
 | |
| 
 | |
|     proc.on("exit", (code) => {
 | |
|       if (code !== 0) {
 | |
|         reject(code);
 | |
|         return;
 | |
|       }
 | |
| 
 | |
|       resolve(code);
 | |
|     });
 | |
|   });
 | |
| }
 | 
