Hello Everyone, In the last post we have discussed how we can quickly setup the SalesforceDX (SFDX). We also used the basic commands to move code using SFDX, create scratch org and use the scratch org for development. Now we will check if we are an ISV partner then how we can use the SFDX and how we can Convert the Package Code in SFDX and then use it with scratch org to continue with development and can effectively use the SFDX.
First we need to authenticate our Dev Hub org. Then we will create a new project to store our project metadata.
Dev Hub is the org where Salesforce stores all related scratch org information. We need to enable Dev Hub in our production or developer org. We run the below code to create package.
sfdx force:project:create -n MyPkgProject
cd MyPkgProject
Now we need to authentic our package org to take a backup of code. It will run Web Auth Flow and will open a window. Once successfully done the auth we can close the window.
sfdx force:auth:web:login -a MyPkg
Now we will make a directory to store the metadata and fetch the data from source. To do that we will run below command.
sfdx force:mdapi:retrieve -s -r ./dummy -u MyPkg -p TestData

This will gives us a zip file. Which we need to unzip. Next we will convert this metadata into SFDX format. Below command convert that into SSFDX format.
sfdx force:mdapi:convert -r ./dummy
Next we will create a new scratch org to move our metadata there. For that we will take help of project-scratch-def file.
sfdx force:org:create -s -f config/project-scratch-def.json -a pkgscratchorg
And when our scratch org is created we are ready to push our code into new scratch org.

sfdx force:source:push
Once we push the code we will get the success message. We will now open the org and can continue with our development.
sfdx force:org:open
So using few lines of script code we can easily convert the Package Code in SFDX format and can use all the benefit of Salesforce DX (SFDX).
Did you have anything to add, Let me know in the comments section. Happy programming 🙂