Ok, it is time. Time to understand scripting.
I have been using Scratch Org for a while now and it is tedious to set them up. But I’ve been scared of scripting.
because most devs are mac users
because most devs think you just know about bash and how to use bash
because admitting you don’t know about scripting is like admitting you don’t know how to breathe to some devs
because powershell seems like it’s own coding language
Now, at least I have touched unix in a previous life and know about some unix commands and have used vi back in the dim dark distant past, so at least I would know how to quit vim these days, or at least know that there is a trick to quitting it and why that trick exists.
End Result:
I want to have a few aliases to shortcut DX commands
I want to have a script that I can create a scratch org with
That’s about it.
Getting Started
Well, you need to start at the begining… and gee is that hard. First of all just how many versions of Powershell are there? And does it need to be stand-alone or can it run in VS Code?
So keeping thing simple I started using the Integrated Powershell Terminal in VS Code - I don’t want a separate terminal.
When googling, you are not writing Powershell Scripts in VS Code, so it’s quite confusing.
The Integrated terminal in VS Code defaults to Powershell in Windows 10. See integrated terminal docs.
Use the Command Terminal: Select Default Shell to set Powershell as the default shell.
When you open Terminal PS then the folder name should be shown as the prompt
PS C:\Users\JodieM>
Set the Profile
I started with Peter Chittum’s Apply the Salesforce CLI to Everyday Problems. Thankfully Peter is talking about Powershell and Bash these days. I went to the Github repo and all of a sudden was stuck. What is the ISE? Wh do I need to know about that? What is a profile?
So I think what he’s doing is trying to get you to have a default set of commands that open up each time you open VS Code. This is stored in a profile it seems. I could not work out Peter’s instructions though.
I found a simple set of instructions that were basically the same as Peter’s instructions… the trick is to start in VS Code and don’t leave VS Code. And don’t install the Powershell VS Code Extension.
Test-Path $profile
This returns false
New-Item -path $profile -type file –force
this returns the folder where the profile is stored. I opened the folder in my file explorer then opened the profile file in vscode.
You may also need to do the following, but I’m not sure because it was all very confusing. Try it without using this command and report back.
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
I did not do the currentuserallhosts thing that Peter recommended because I only need to use it in VSCode.
Paste the contents of Peter Chittum’s sample profile into that file https://github.com/pchittum/everyday-sfcli/blob/master/utils/powershell-profile/Set-RecommendedProfileItems.ps1 and save.
Reload VS Code
Open the terminal and type
dxlist
A list of your scratch orgs appear! Magic!
We now have aliases!
dxlist --all
still works too!
0 Comments