This is the script (including AI instructions I was using to test the conversions)
for the as EA.Element this was
'<ai>translate statements such as "dim myElement as EA.Element" as "var myElement as EA.Element". The "as EA.xxx" should always stay, and the variables should be declared in a separate line if there is a "as EA.xxx" statement present</ai>'
The weird thing with those AI things is that is feels like it is non deterministic. Sometimes the result is different if you run the same input a second time.
'<ai>technology stack: Enterprise Architect</ai>'
'<ai>"msgbox" should be translated to Session.Prompt(text, prompt) the possible values for prompt are: promptOK, promptYESNO, promptYESNOCANCEL,promptOKCANCEL and there are no other parameters allowed</ai>
'<ai>if now() is used in a string, translate it to new Date().toLocaleString()</ai>
'[path=\Projects\Project H\Temp]
'[group=Temp]
option explicit
'<ai>Keep all !INC statements unchanged except for "EAConstants-VBScript" which should be translated to "EAConstants-JavaScript"</ai>
!INC Local Scripts.EAConstants-VBScript
'
' Script Name: SampleScriptForTestingConversion
' Author: Geert Bellekens
' Purpose: Contains a rich set of constructs so that we can test the translation
' Date: 2025-01-22
'
const outPutName = "Cleanup Reporting Model"
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
sub Main()
'create output tab
Repository.CreateOutputTab outPutName
Repository.ClearOutput outPutName
Repository.EnsureOutputVisible outPutName
'<ai>translate statements such as "dim myElement as EA.Element" as "var myElement as EA.Element". The "as EA.xxx" should always stay, and the variables should be declared in a separate line if there is a "as EA.xxx" statement present</ai>'
dim selectedPackage as EA.Package
set selectedPackage = Repository.GetTreeSelectedPackage
if not selectedPackage is nothing then
'report progress
Repository.WriteOutput outPutName, now() & " Starting " & outPutName & " for package '" & selectedPackage.Name & "'" , 0
'do the actual work
doTheActualWork selectedPackage
'report progress
Repository.WriteOutput outPutName, now() & " Finished " & outPutName & " for package '" & selectedPackage.Name & "'" , 0
else
Msgbox "Select a package in the project browser before running this script",vbOKOnly+vbExclamation,"No Package Selected!"
end if
end sub
function doTheActualWork(package)
'write to a file
writeToFile "c:\temp\testFile.txt", "Test contents"
'read a file
dim readText
readText = readFile("c:\temp\testFile.txt")
Repository.WriteOutput outPutName, now() & " Read the following '" & readText & "'" , 0
'create a dictionary
'create an arraylist
dim arrayList
'<ai>translate CreateObject("System.Collections.ArrayList") as New Array(), for other CreateObject(name) statements use new COMObject(name)</ai>'
set arrayList = CreateObject("System.Collections.ArrayList")
arrayList.Add "value1"
'parse an xml file
'create an excel file
end function
function readFile(path)
Dim fso
dim fsoFile
dim ts
dim contents
Set fso = CreateObject("Scripting.FileSystemObject")
if fso.FileExists(path) then
set fsoFile = fso.GetFile(path)
set ts = fsoFile.OpenAsTextStream(ForReading, TristateUseDefault)
If Not ts.AtEndOfStream Then
contents = ts.ReadAll
else
contents = ""
end if
end if
'return contents
readFile = contents
end function
function writeToFile(path, contents)
Dim fso, MyFile
Set fso = CreateObject("Scripting.FileSystemObject")
'then create file
Set MyFile = fso.CreateTextFile(path, True, False) 'second true for unicode
MyFile.Write(contents)
MyFile.Close
end function
main
Geert