PACX ⁓ WebResource Management Commands - Push

Riccardo Gregori - Jul 25 - - Dev Community

In this post I subtly introduced a few PACX commands created to streamline WebResource development lifecycle.

In this other post we've seen how I like to setup my WebResource project, while here we've seen how to create JS WebResources starting from a template.

Now we'll take a look on how I like to push the stuff I make from local to Dataverse.

🫸🏻 pacx webresources push

My favourite XrmToolbox tool ever is WebResource Manager. It saved me a huge amount of time.

Ages ago, before it existed, uploading Web Resources to Dataverse was quite painful and error prone, you had to do it manually for each single file. Probability to miss something, or to upload the wrong file, was really high, and errors happened daily.

WebResource Manager streamlined this process. In 7 simple steps you can select the WebResources to upload, upload them to Dataverse, add them in a solution, and publish them. Assuming you are starting from scratch, the steps are:

  1. Open XrmToolbox, connect to your environment, and open WebResource Manager
  2. Add a new root that matches your publisher prefix.
  3. Right click on the root, and select "Update web resources in this folder with local files"
  4. Click "Yes" on the dialog that opens right away
  5. Select the folder that contains your WebResources (manually or via Folder Picker)
  6. Once loaded, in the "Pending updates" panel select "Update and Publish and Add to solution"
  7. Then click "Apply"

Add new root

Update web resources in this folder with local files

Click yes

Select the folder

Apply

Once done, when you update anything, you need to:

  1. Right click on the root, and select "Update web resources in this folder with local files"
  2. Once loaded, in the "Pending updates" panel select "Update and Publish"
  3. Then click "Apply"

If, by any chance, you close XrmToolbox, to update you have to run again 7 steps:

  1. Reopen XrmToolbox, connect to your environment, and open WebResource Manager
  2. Click on "CRM"
  3. Click on "Load WebResources from a specific solution"
  4. Right click on the root, and select "Update web resources in this folder with local files"
  5. Click "Yes" on the dialog that opens right away
  6. Select the folder that contains your WebResources (manually or via Folder Picker)
  7. Once loaded, in the "Pending updates" panel select "Update and Publish and Add to solution"
  8. Then click "Apply"

Load WebResources from a specific solution

Quite easy 😎, isn't it?

Sure, but I'm lazy 🥱.

Opening XrmToolbox (specially when you have a lot of tools) takes time, and I want to be fast when I'm working with code. My dev experience revolves around Visual Studio (Code, for WebResources) and pacx, so I tried to speed up that part too.. that's why I've created pacx webresources push 🫸🏻.

This command in its basic form can be run without arguments (and I like most the shorter alias).

pacx wr push
Enter fullscreen mode Exit fullscreen mode

When run in a folder that is below a WebResource project created via pacx wr init it:

  • takes all the files contained in the current folder and its subfolders
  • for each file
    • determines the WebResource name navigating backwards to the WebResources root folder (as described in this post)
  • then extracts all the WebResources with the given names from the Dataverse
  • compares them to the ones to update (from the first bullet point), in order to check if there is something to create or update
  • if it finds some WebResource to create or update
    • creates the WebResource, or updates the WebResource contents
    • if not present in the default solution for the current environment, adds the WebResource to that solution
    • then runs a Publish for all the created or updated WebResources.

In 🚀 just 1 single command 🚀.

Command execution

Of course you can play with the command arguments to customize the behavior of the command:

  • --solution (or -s) allows you to peek a different target solution where to save the files. The solution selection is important because the command will select only folders and files starting with publisher prefix + _.

E.g. If you have the following folder structure:

📂 WebResources
  📂 ava_
    📂 scripts
      📄 account.js
      📄 contact.js
  📂 test_
    📄 ava_common.js
  📄 ava_common.js
  📄 account.html
  📄 .wr.pacx
Enter fullscreen mode Exit fullscreen mode

And the selected solution publisher prefix is ava, the command will peek and update only these files:

📂 WebResources
  📂 ava_
    📂 scripts
      📄 account.js
      📄 contact.js
  📄 ava_common.js
Enter fullscreen mode Exit fullscreen mode
  • --path (or -p) allows to specify which folder(s) or file(s) to push. You can specify absolute or relative paths. You can use the $ wildcard to refer to the root of the current WebResource project (the 📂 WebResources in the previous example). You can also use the * wildcard to match for all the files with a given extension. E.g., in the following example:
📂 WebResources
  📂 ava_
    📂 images
      🖼️ account.svg
      🖼️ account.png
      🖼️ contact.svg
    📂 scripts
      📄 account.js
      📄 contact.js
  📂 test_
    📄 ava_common.js
  📄 ava_common.js
  📄 account.html
  📄 .wr.pacx
Enter fullscreen mode Exit fullscreen mode

If you are in the test_ folder and type:

C:\WebResources\test_> pacx wr push --path $\ava_\images
Enter fullscreen mode Exit fullscreen mode

It will push

📂 WebResources
  📂 ava_
    📂 images
      🖼️ account.svg
      🖼️ account.png
      🖼️ contact.svg
Enter fullscreen mode Exit fullscreen mode

While if you type

C:\WebResources\test_> pacx wr push --path $\ava_\images\*.svg
Enter fullscreen mode Exit fullscreen mode

It will push only the following files

📂 WebResources
  📂 ava_
    📂 images
      🖼️ account.svg
      🖼️ contact.svg
Enter fullscreen mode Exit fullscreen mode

You can also use the following additional command arguments:

  • --no-action (or -nop): if specified, the command will show what it would do, without performing any actual action on the dataverse. Useful as double check to avoid mistakes
  • --no-publish (or -np): if specified, it does everything described above but publish.
  • --verbose (or --v): if specified, prints in the console a more verbose log on the push operations.

Not bad, isn't it?! 😎 7 steps reduced to 1.

Conclusions

Let me know what do you think about the approach and tools I presented in this series of posts. Any comment, suggestion and/or feature request is appreciated!

And if you like you can drop a pull request to the official PACX Github Repo and add your own feature to the tool!

. . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player