gulp-execa
Version:
Gulp.js command execution for humans
59 lines (33 loc) • 930 B
JavaScript
import{Buffer}from"node:buffer";
import{execCommand,streamCommand}from"../exec.js";
import{isValidInput}from"../input.js";
export const setResult=({file,input,opts,resultOpt})=>{
initSave({file,resultOpt});
if(!isValidInput(input)){
return
}
if(resultOpt==="save"){
return saveResult({file,input,opts})
}
if(file.isStream()){
return streamResult({file,input,opts})
}
return bufferResult({file,input,opts})
};
const initSave=({file,file:{execa},resultOpt})=>{
if(resultOpt!=="save"||execa!==undefined){
return
}
file.execa=[]
};
const saveResult=async({file,file:{execa},input,opts})=>{
const execaResult=await execCommand(input,opts);
file.execa=[...execa,execaResult]
};
const streamResult=({file,input,opts})=>{
file.contents=streamCommand(input,opts)
};
const bufferResult=async({file,input,opts,opts:{from}})=>{
const{[from]:output}=await execCommand(input,opts);
file.contents=Buffer.from(output)
};