Skip to content

Commit

Permalink
build.wsf redesigned
Browse files Browse the repository at this point in the history
  • Loading branch information
Praveen Nandagiri committed Jun 16, 2021
1 parent 7bc722a commit eb4a55c
Show file tree
Hide file tree
Showing 17 changed files with 1,415 additions and 97 deletions.
15 changes: 15 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
node_modules
.npmrc
*.pfx
build.log
build/build.log

bin/wsfParser.js
lib/trash
lib/pkg
test.cmd
test.wsf
*.test.wsf
lib/core/Signtool/self-sign-cert.ps1
lib/core/Signtool/sign-file.vbs
lib/CPOL/compare_line_by_line.cmd
34 changes: 6 additions & 28 deletions bin/build.wsf
Original file line number Diff line number Diff line change
@@ -1,39 +1,17 @@
<package id="vbspm">
<job id="vbspm-build">
<runtime>
<named name="file" helpstring="the file to sign" required="true" type="string"/>
<named name="file" helpstring="File to be executed" required="true" type="string"/>
</runtime>

<script language="VBScript" src="lib/core/globals.vbs" />
<script language="VBScript" src="lib/core/init.vbs" />
<script language="VBScript" src="lib/core/FSO/FSO.vbs" />
<script language="VBScript" >
<![CDATA[
Dim cFS
set cFS = new FSO
Function log(msg)
cFS.WriteLog currentPath & "\build.log", msg, false
End Function
log "Execution Started for file"
]]>
</script>

<script language="VBScript" src="lib/core/Wshell.vbs" />
<script language="VBScript" src="lib/core/Wshell/Wshell.vbs" />
<script language="VBScript" src="lib/core/VbsJson/VbsJson.vbs" />
<script language="VBScript" src="lib/core/JSONToXML/JSONToXML.vbs" />
<script language="VBScript" src="lib/core/Signtool/Signtool.vbs" />
<script language="VBScript" src="CPOL/vb_format_function.vbs" />

<script language="VBScript">
<![CDATA[
Dim file: file = WScript.Arguments.Named("file")
log "File: " & file
Dim script: script = cFS.ReadFile(file)
if script = "" Then
Wscript.Echo "Script file called is empty."
Wscript.Quit
End if
Execute script
]]>
</script>
<script language="VBScript" src="lib/CPOL/vb_format_function.vbs" />
<script language="VBScript" src="lib/core/globals.vbs" />
<script language="VBScript" src="lib/core/params.vbs" />
</job>
</package>
5 changes: 5 additions & 0 deletions bin/test-cls.vbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Class BUILDTEST
Public default Property Get Status
Status = "Successfully.."
End Property
End Class
4 changes: 3 additions & 1 deletion bin/test.vbs
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
Wscript.Echo "Build completed Successfully."
Include "bin\test-cls.vbs"
set test = new BUILDTEST
Wscript.Echo "Build completed " & test & "."
13 changes: 11 additions & 2 deletions lib/core/FSO/FSO.vbs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ Class FSO
End If
End Sub

Public Sub WriteLog(strFileName, strMessage, overwrite)
Public Sub WriteFile(strFileName, strMessage, overwrite)
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Dim mode
Dim oFile

mode = ForWriting
mode = ForWriting
If Not overwrite Then
mode = ForAppending
End If
Expand Down Expand Up @@ -79,4 +80,12 @@ Class FSO
objFSO.DeleteFile(file)
On Error Goto 0
End Sub

Public Function GetExtn(file)
GetExtn = ""
on Error Resume Next
GetExtn = objFSO.GetExtensionName(file)
On Error goto 0
End Function

End Class
2 changes: 1 addition & 1 deletion lib/core/Wshell/Wshell.vbs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Class WShell
End Property


Private dir
' Private dir
Private oThis

Private Sub Class_Initialize
Expand Down
46 changes: 28 additions & 18 deletions lib/core/globals.vbs
Original file line number Diff line number Diff line change
@@ -1,28 +1,38 @@
With CreateObject("WScript.Shell")
CurrentPath=.CurrentDirectory
Wscript.Echo "Base path: " & CurrentPath
End With
Dim baseDir
Dim cFS
set cFS = new FSO


public Sub Echo(msg)
Wscript.Echo msg
End Sub
Function log(msg)
cFS.WriteFile "build.log", msg, false
End Function
log "================================= Call ================================="

Sub Include(file)
Wscript.Echo "Include(" + file + ")"
log "Include(" + file + ")"

' Dim cFS: cFS = new FS
Dim content: content = cFS.ReadFile(file)
if content <> "" Then ExecuteGlobal content
if content <> "" Then
' Dim pkg
' pkg = Replace(file, "\node_modules\", "")
' pkg = Replace(pkg, "\index.vbs", "")
' cFS.WriteFile "build\imported\" & pkg & ".vbs", content, true
ExecuteGlobal content
End If
End Sub


Public Sub Import(pkg)
Wscript.Echo "Import(" + Pkg + ")"
Include CurrentPath & "\node_modules\" + pkg + "\index.vbs"
log "Import(" + Pkg + ")"
Include baseDir & "\node_modules\" + pkg + "\index.vbs"
End Sub


public Sub Echo(msg)
Wscript.Echo msg
End Sub


Public Function jobSrc(file)
jobSrc = "<script language=""VBScript"" src=""" + file + """/>"
End Function
With CreateObject("WScript.Shell")
baseDir=.CurrentDirectory
'Wscript.Echo "Base path: " & baseDir
End With
log "Base path: " & baseDir
cFS.setDir(baseDir)
1 change: 1 addition & 0 deletions lib/core/init.vbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Option Explicit
41 changes: 41 additions & 0 deletions lib/core/params.vbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
log "Execution Started for file"

Dim file
file = WScript.Arguments.Named("file")
If file = "" Then
log "Script file not provided as a named argument [/file:]"
if Wscript.Arguments.count > 0 then
file = Wscript.Arguments(0)
if file = "" Then
log "No file argument provided."
Wscript.Quit
End If
else
file = "index.vbs"
end if
End If
' TODO: Assess all possible combinations a user can send in command line
file = baseDir & "\" & file

if Lcase(cFS.GetExtn(file)) = "vbs" Then
log "File extension is: .vbs"
Else
log "File extension missing. Adding .vbs"
file = file + ".vbs"
end if

log "File: " & file


Dim script
script = cFS.ReadFile(file)
if script = "" Then
log "No file supplied or is empty."
Wscript.Quit
End if



'===========================
Execute script
'===========================
30 changes: 30 additions & 0 deletions lib/trash/ErrCodes1.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<HTML>
<HEAD><TITLE>VBScript Error Message Generator</TITLE>
<SCRIPT LANGUAGE="VBSCRIPT">
Sub GenerateErrorList()
On Error Resume Next
Dim lCtr

For lCtr = 1 To 50000
Err.Raise lCtr
If Err.Description <> "Unknown runtime error" Then
Document.Write "<TR><TD>" & Err.Number
Document.Write "<TD>" & Err.Description
End If
Err.Clear
Next
End Sub
</SCRIPT>
<HEAD>
<BODY>
<CENTER>
<H2>VBScript Error Codes</H2>
<TABLE>
<TR>
<TH>Error Code</TH><TH>Description</TH>
<SCRIPT LANGUAGE="VBSCRIPT">
GenerateErrorList()
</SCRIPT>
</CENTER>
</BODY>
</HTML>
132 changes: 132 additions & 0 deletions lib/trash/ErrorCodes.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
Error Code Description
5 Invalid procedure call or argument
6 Overflow
7 Out of memory
9 Subscript out of range
10 This array is fixed or temporarily locked
11 Division by zero
13 Type mismatch
14 Out of string space
17 Can't perform requested operation
28 Out of stack space
35 Sub or Function not defined
48 Error in loading DLL
51 Internal error
52 Bad file name or number
53 File not found
54 Bad file mode
55 File already open
57 Device I/O error
58 File already exists
61 Disk full
62 Input past end of file
67 Too many files
68 Device unavailable
70 Permission denied
71 Disk not ready
74 Can't rename with different drive
75 Path/File access error
76 Path not found
91 Object variable not set
92 For loop not initialized
94 Invalid use of Null
322 Can't create necessary temporary file
424 Object required
429 ActiveX component can't create object
430 Class doesn't support Automation
432 File name or class name not found during Automation operation
438 Object doesn't support this property or method
440 Automation error
445 Object doesn't support this action
446 Object doesn't support named arguments
447 Object doesn't support current locale setting
448 Named argument not found
449 Argument not optional
450 Wrong number of arguments or invalid property assignment
451 Object not a collection
453 Specified DLL function not found
455 Code resource lock error
457 This key is already associated with an element of this collection
458 Variable uses an Automation type not supported in VBScript
462 The remote server machine does not exist or is unavailable
481 Invalid picture
500 Variable is undefined
501 Illegal assignment
502 Object not safe for scripting
503 Object not safe for initializing
504 Object not safe for creating
505 Invalid or unqualified reference
506 Class not defined
507 An exception occurred
1001 Out of memory
1002 Syntax error
1003 Expected ':'
1005 Expected '('
1006 Expected ')'
1007 Expected ']'
1010 Expected identifier
1011 Expected '='
1012 Expected 'If'
1013 Expected 'To'
1014 Expected 'End'
1015 Expected 'Function'
1016 Expected 'Sub'
1017 Expected 'Then'
1018 Expected 'Wend'
1019 Expected 'Loop'
1020 Expected 'Next'
1021 Expected 'Case'
1022 Expected 'Select'
1023 Expected expression
1024 Expected statement
1025 Expected end of statement
1026 Expected integer constant
1027 Expected 'While' or 'Until'
1028 Expected 'While', 'Until' or end of statement
1029 Expected 'With'
1030 Identifier too long
1031 Invalid number
1032 Invalid character
1033 Unterminated string constant
1034 Unterminated comment
1037 Invalid use of 'Me' keyword
1038 'loop' without 'do'
1039 Invalid 'exit' statement
1040 Invalid 'for' loop control variable
1041 Name redefined
1042 Must be first statement on the line
1043 Cannot assign to non-ByVal argument
1044 Cannot use parentheses when calling a Sub
1045 Expected literal constant
1046 Expected 'In'
1047 Expected 'Class'
1048 Must be defined inside a Class
1049 Expected Let or Set or Get in property declaration
1050 Expected 'Property'
1051 Number of arguments must be consistent across properties specification
1052 Cannot have multiple default property/method in a Class
1053 Class initialize or terminate do not have arguments
1054 Property set or let must have at least one argument
1055 Unexpected 'Next'
1056 'Default' can be specified only on 'Property' or 'Function' or 'Sub'
1057 'Default' specification must also specify 'Public'
1058 'Default' specification can only be on Property Get
4096 Microsoft VBScript compilation error
4097 Microsoft VBScript runtime error
5016 Regular Expression object expected
5017 Syntax error in regular expression
5018 Unexpected quantifier
5019 Expected ']' in regular expression
5020 Expected ')' in regular expression
5021 Invalid range in character set
30000 EN
32766 True
32767 False
32768 OK
32769 Cancel
32770 Help
32811 Element not found
32812 The specified date is not available in the current locale's calendar
32813 This script contains malicious content and has been blocked by your antivirus software.
32814 This script is blocked by IT policy.

Loading

0 comments on commit eb4a55c

Please sign in to comment.