Skip to content

Instantly share code, notes, and snippets.

@imtrinity94
Last active December 14, 2021 07:32
Show Gist options
  • Save imtrinity94/ac93e6cbece3568efbb7e555ffedb20e to your computer and use it in GitHub Desktop.
Save imtrinity94/ac93e6cbece3568efbb7e555ffedb20e to your computer and use it in GitHub Desktop.
update
<#
Author: Mayank Goyal
Version: 1.0.0
Description:
- Doesn't work for Workflows and Resource Elements
- Get all content from exported vRO package Elements folder from .package file
- Run through each folder and read categories (Modules)
- Create a new file *.js from Actions
#>
#Changing Default UTF-16 LE Encoding to UTF-8 for JSDoc compatibility
$PSDefaultParameterValues['*:Encoding'] = 'utf8'
## Inputs:
#Element Folder Path after package unziped
$ElementsFolder = $(Write-Host "Where is your unzipped vRO Package stored? (provide full path - e.g.: C:\vRA4U\com.vro.some.module\elements)-- " -NoNewLine -ForegroundColor yellow; Read-Host)
# Path to save all new Modules and Actions
$savePath = $(Write-Host "Where would you like to save all Modules and Actions? (provide full path) -- " -NoNewLine -ForegroundColor yellow; Read-Host)
#Ask if Script is being executed on a Mac (for forwards slash vs backslash in folders)
$defaultOSType = 'windows'
if (!($osType = $(Write-Host "What is your OS Version? [windows|mac] - default: windows -- " -NoNewLine -ForegroundColor yellow; Read-Host))){$osType = $defaultOSType}
$osType = $osType.ToLower()
#Set Slash / BackSlash
$slash = "\"
if ($osType -eq 'mac'){$slash = "/"}
# Enter the folder path
cd $ElementsFolder
$dir = dir $ElementsFolder | ?{$_.PSISContainer}
foreach ($d in $dir){
# Enter subfolder path
cd $d
## Do Tasks copying from Element folder and formatting to javascript with Parameters commented/scripts to .js
#Get the categories file to determine vRO Module
Select-Xml -Path .\categories -XPath 'categories'
[xml]$xmlElm = Get-Content -Path .\categories
#this getthe action name
$catNameFolder = $xmlElm.categories.category.name.'#cdata-section'
$catNameFolder = $catNameFolder.ToLower()
write-host "Module name: " $catNameFolder
[xml]$xmlElm = Get-Content -Path .\info
$elementType = $xmlElm.properties.entry.'#text'
#Get the Actions
if ($elementType -contains "ScriptModule") {
## if module contains space or more than 1 categorie = It's a workflow Folder or Configuration Element type
#Create module folder
if ($osType -eq 'mac'){
mkdir -p $savePath$slash'Actions'$slash$catNameFolder
} else {
mkdir $savePath$slash'Actions'$slash$catNameFolder
}
#Get the data file to determine vRO Action
Select-Xml -Path .\data -XPath 'dunes-script-module/script'
[xml]$xmlElm = Get-Content -Path .\data
#this get the action name
$actionName = $xmlElm.'dunes-script-module'.name
$actionName = $actionName+".js"
# This returns all parameters
$actionParams = $xmlElm.'dunes-script-module'.param
#This return all script part
$actionScript = $xmlElm.'dunes-script-module'.script.'#cdata-section'
# creating file javascript
New-Item -Name $actionName -ItemType File
# adding Metadata in JSDoc Style
echo "/**" >> $actionName
echo " * @author Mayank Goyal [mayankgoyalmax@gmail.com]" >> $actionName
$function = " * @function "+ $xmlElm.'dunes-script-module'.name
echo $function >> $actionName
$actionVersion = " * @version "+ $xmlElm.'dunes-script-module'.version
echo $actionVersion >> $actionName
if ($xmlElm.'dunes-script-module'.description.'#cdata-section') {
$description = " * @description" + $xmlElm.'dunes-script-module'.description.'#cdata-section'
}
echo $decription >> $actionName
$paramtypes = $xmlElm.'dunes-script-module'.param.t
$paramNames = $xmlElm.'dunes-script-module'.param.n
$paramDescription = $xmlElm.'dunes-script-module'.param.'#cdata-section'
For ($i=0; $i -lt $paramNames.length; $i++) {
$params = " * @param {" + $paramTypes[$i] + '} ' + $paramNames[$i] + ' ' + $paramDescription[$i]
echo $params >> $actionName
}
if ($xmlElm.'dunes-script-module'.'result-type'){
$return = " * @returns " + $xmlElm.'dunes-script-module'.'result-type'
}
echo $return >> $actionName
echo " */" >> $actionName
# adding script content
echo $actionScript >> $actionName
# Copy to final upload location
mv $actionName $savePath$slash'Actions'$slash$catNameFolder$slash$actionName
}else{
write-host "Skipping Workflows, Configuration Elements & Resource Elements"
}
#Go back root level
cd ..
}
@imtrinity94
Copy link
Author

imtrinity94 commented Dec 9, 2021

Heavily influenced by script made by Jose Cavalheri & Michael Van de gaer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment