How I use Batch Files to Package my Datatable Component for Release

Narender Singh (ForcePanda) recently wrote a blog post on how he uses SFDX Packaging Commands in VSCode to release component packages. Like Narender, I found it difficult to remember and reuse all of the CLI commands needed to create packaged versions of my components.

When I release a new update for my Datatable component, I need to generate a new unmanaged package with a link so users can install and upgrade the component. To create the new package I first need to create a new version by executing a command line command that looks something like this:

sfdx force:package:version:create -v lexhost -w 10 -x -c -n 3.2.1.0 -d force-app\

Then, to make the new package available, I issue another command similar to this:

sfdx force:package:version:promote -v lexhost --package "datatable@3.2.1-0"

To save all of this typing and to make sure I’m issuing the correct syntax for the commands each time, I created a series of Batch Command files and included them in a packaging directory in my Datatable source code project.

To create a new version, I use my CreateNewVersion.bat command file. This file takes an optional input where I can specify the new version number like this:

>CreateNewVersion 3.2.2

To execute the second command, I would need execute another command file by entering:

>Promote 3.2.2

To avoid any typos with mismatched version numbers, I created another command file to ask for and store the version number that is then used by the other commands if no version number is provided on the command line.

Here are each of the Batch Command Files I created and use to publish updates for Datatable.

SetVersion.bat
--------------
@echo off
if "%1" neq "" goto skipprompt
set /p version="Set Version Number: "
goto exit
:skipprompt
set version=%1
:exit
ShowVersion
@echo on

ShowVersion.bat
---------------
@echo off
echo Version: %version%
@echo on

CreateNewVersion.bat
--------------------
@echo off
if "%1" neq "" set version=%1
@echo on
sfdx force:package:version:create -v lexhost -w 10 -x -c -n %version%.0 -d force-app\

Promote.bat
-----------
@echo off
if "%1" neq "" set version=%1
@echo on
sfdx force:package:version:promote -v lexhost --package "datatable@%version%-0"

Details.bat
-----------
@echo off
if "%1" neq "" set version=%1
@echo on
sfdx force:package:version:report -v lexhost --package "datatable@%version%-0"

Here’s an example of them in actual use when I released a recent Datatable update: (My entries shown in bold)

D:\esmit\Documents\VSCode\LightningFlowComponents\flow_screen_components\datatable>packaging\setversion
Set Version Number: 3.4.5
Version: 3.4.5


D:\esmit\Documents\VSCode\LightningFlowComponents\flow_screen_components\datatable>packaging\createnewversion 

D:\esmit\Documents\VSCode\LightningFlowComponents\flow_screen_components\datatable>sfdx force:package:version:create -v lexhost -w 10 -x -c -n 3.4.5.0 -d force-app\
Request in progress. Sleeping 30 seconds. Will wait a total of 600 more seconds before timing out. Current Status='Queued'
Request in progress. Sleeping 30 seconds. Will wait a total of 570 more seconds before timing out. Current Status='Verifying dependencies'
Request in progress. Sleeping 30 seconds. Will wait a total of 540 more seconds before timing out. Current Status='Verifying dependencies'
Request in progress. Sleeping 30 seconds. Will wait a total of 510 more seconds before timing out. Current Status='Verifying dependencies'
Request in progress. Sleeping 30 seconds. Will wait a total of 480 more seconds before timing out. Current Status='Verifying dependencies'
Request in progress. Sleeping 30 seconds. Will wait a total of 450 more seconds before timing out. Current Status='Verifying dependencies'
Request in progress. Sleeping 30 seconds. Will wait a total of 420 more seconds before timing out. Current Status='Verifying dependencies'
Request in progress. Sleeping 30 seconds. Will wait a total of 390 more seconds before timing out. Current Status='Verifying dependencies'
Request in progress. Sleeping 30 seconds. Will wait a total of 360 more seconds before timing out. Current Status='Verifying metadata'
Request in progress. Sleeping 30 seconds. Will wait a total of 330 more seconds before timing out. Current Status='Verifying metadata'
Request in progress. Sleeping 30 seconds. Will wait a total of 300 more seconds before timing out. Current Status='Verifying metadata'
Request in progress. Sleeping 30 seconds. Will wait a total of 270 more seconds before timing out. Current Status='Verifying metadata'
Request in progress. Sleeping 30 seconds. Will wait a total of 240 more seconds before timing out. Current Status='Verifying metadata'
Request in progress. Sleeping 30 seconds. Will wait a total of 210 more seconds before timing out. Current Status='Finalizing package version'
Request in progress. Sleeping 30 seconds. Will wait a total of 180 more seconds before timing out. Current Status='Finalizing package version'
sfdx-project.json has been updated.
Successfully created the package version [08c5G000000kAvYQAU]. Subscriber Package Version Id: 04t5G000003rUrOQAU
Package Installation URL: https://login.salesforce.com/packaging/installPackage.apexp?p0=04t5G000003rUrOQAU
As an alternative, you can use the "sfdx force:package:install" command.

D:\esmit\Documents\VSCode\LightningFlowComponents\flow_screen_components\datatable>packaging\Promote

D:\esmit\Documents\VSCode\LightningFlowComponents\flow_screen_components\datatable>sfdx force:package:version:promote -v lexhost --package "datatable@3.4.5-0"
Are you sure you want to release package version datatable@3.4.5-0? You can't undo this action. Release package (y/n)?: y
Successfully promoted the package version, ID: 04t5G000003rUrOQAU, to released. Starting in Winter ‘21, only unlocked package versions that have met the minimum 75% code coverage requirement can be promoted. Code coverage minimums aren’t enforced on org-dependent unlocked packages.

D:\esmit\Documents\VSCode\LightningFlowComponents\flow_screen_components\datatable>packaging\Details

D:\esmit\Documents\VSCode\LightningFlowComponents\flow_screen_components\datatable>sfdx force:package:version:report -v lexhost --package "datatable@3.4.5-0"
=== Package Version
Name                            Value
──────────────────────────────  ─────────────────────────────────────────────
Name                            Datatable v3
Subscriber Package Version Id   04t5G000003rUrOQAU
Package Id                      0Ho5G000000XZNaSAO
Version                         3.4.5.0
Description                     Datatable Flow Screen Component by Eric Smith
Branch
Tag
Released                        true
Validation Skipped              false
Ancestor                        N/A
Ancestor Version                N/A
Code Coverage                   92%
Code Coverage Met               true
Org-Dependent Unlocked Package  No
Release Version                 54.0
Build Duration in Seconds       426
Managed Metadata Removed        N/A
Created By                      0055G00000607zRQAQ

One thought on “How I use Batch Files to Package my Datatable Component for Release

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s