Yeoman SharePoint Generator执行后,如何让PowerShell无需交互自动继续?
Yeoman在完成SPFx项目创建后会停留在完成界面等待用户按键,以下几种方法可以实现无交互自动继续脚本执行:
方法1:启用Yeoman的CI模式(推荐)
Yeoman支持CI(持续集成)环境模式,当检测到CI环境变量为true时,会跳过所有交互式提示,包括最后的按键等待。在执行Yeoman命令前设置该环境变量即可:
$env:CI = "true" yo @microsoft/sharepoint --component-type "webpart" --component-name $componentName --solution-name $solutionName --framework "react" --skip-install
方法2:通过管道模拟用户回车
向Yeoman进程的标准输入传递一个空行,模拟用户按下回车键,触发进程结束:
Write-Output "" | yo @microsoft/sharepoint --component-type "webpart" --component-name $componentName --solution-name $solutionName --framework "react" --skip-install
方法3:用Start-Process重定向输入
使用PowerShell的Start-Process命令,将进程的标准输入重定向到空设备,让Yeoman无输入可等待,自动结束:
Start-Process -FilePath "yo" -ArgumentList "@microsoft/sharepoint --component-type `"webpart`" --component-name $componentName --solution-name $solutionName --framework `"react`" --skip-install" -NoNewWindow -Wait -RedirectStandardInput "NUL"
内容的提问来源于stack exchange,提问作者Grobanix
相关产品推荐
相关产品推荐

