Powershell Automation of Environment Setup and Scafolding.
Thank you for reporting an issue or suggesting an enhancement. We appreciate your feedback - to help the team to understand your needs, please complete the below template to ensure we have the necessary details to assist you.
Category
- [x] Question
- [ ] Typo
- [ ] Bug
- [ ] Enhancement / Suggestion
- [ ] Additional article idea
I'm trying to build a powershell script to automate all the steps on https://dev.office.com/sharepoint/docs/spfx/set-up-your-development-environment and then run the yo scafolding from https://dev.office.com/sharepoint/docs/spfx/web-parts/get-started/build-a-hello-world-web-part I've created the PowerShell Script and It appears to work perfectly until it runs the "yo @microsoft/sharepoint" command. It then seems to hang forever. I've tested the command from a command prompt and Yeoman builds the project perfectly, so I know everything except the way I'm launching yeoman worked.
Here's the powershell script. Can you provide any guidance? I'd like to use the script to lead a usergroup orientation on the framework.
...write-host "Installing Windows Build Tools" npm install -g --production windows-build-tools write-host "Installing Yeoman and Gulp" npm install -g yo gulp write-host "Installing generator-sharepoint" npm install -g @microsoft/generator-sharepoint $ProjectRootDir = Read-Host 'Enter the Root Directory path to install project folder' If(!(test-path $ProjectRootDir)) { New-Item -ItemType Directory -Force -Path $ProjectRootDir } cd $ProjectRootDir $ProjectName = Read-Host 'Enter a name for your project' If(!(test-path $ProjectName)) { New-Item -ItemType Directory -Force -Path $ProjectName } cd $ProjectName write-host "Running Yeoman generator" & cmd /c 'yo 2>&1' @microsoft/sharepoint ...
Are you sure its hanging or its just not showing the npm progress in the PowerShell?
I personally don't use PowerShell so not sure where the problem is. Have you tried a .bat file instead to see if that works?
It is hung when I run Yeoman in PowerShell or the Command Prompt (with elevated privileges) I'm pretty sure it's a PowerShell removing issue when it attempts to load @Microsoft/sharepoint. I think this one needs a PowerShell Ninja.
@DanKline The reason yo appears to hung is because it's waiting for you to type in the parameters required to build the project scafolding. since yo uses the command line it does not read the commands from a file, you have to type them.... ':(
As @dcu-sharepoint noted, Yeoman generator takes the parameters from the prompt. We will leave the issue open as we consider adding a feature in the Yeoman generator in order to accept parameters.
@DanKline See this issue: Extension type parameter is not passed to extension generator in @microsoft/[email protected] #623
You should be able to adapt the code to your needs.
@mpasarin one possible solution would be to modify the yo command to accept the parameters being passed in a command file.
We accept command-line parameters for the generator. Some general documentation is here. If this doesn't solve your issue, can you please open another issue.
Issues that have been closed & had no follow-up activity for at least 7 days are automatically locked. Please refer to our wiki for more details, including how to remediate this action if you feel this was done prematurely or in error: Issue List: Our approach to locked issues