|
2 | 2 | Private Components As New Dictionary(Of String, Component)
|
3 | 3 | Private WsRoot As String
|
4 | 4 | Private SquashWS As Boolean
|
| 5 | + Private FileReadCallback As Action(Of String) = Nothing |
5 | 6 |
|
6 |
| - Public Shared Function Compile(wsRootPath As String, vueFile As String, Optional squashWS As Boolean = True) As String |
| 7 | + Public Shared Function Compile(wsRootPath As String, sourceFile As String, Optional squashWS As Boolean = True, Optional rootFileContent As String = Nothing, Optional fileReadCallback As Action(Of String) = Nothing) As String |
7 | 8 | If wsRootPath.EndsWith("\") Then wsRootPath = wsRootPath.Substring(0, wsRootPath.Length - 1)
|
8 |
| - Dim inst = New VueFilesToJS With {.WsRoot = wsRootPath, .SquashWS = squashWS} |
9 |
| - Return inst.ProcRoot(vueFile, AddressOf My.Computer.FileSystem.ReadAllText) |
10 |
| - End Function |
11 |
| - |
12 |
| - Public Shared Function CompileText(txt As String, wsRootPath As String, vueFile As String, Optional squashWS As Boolean = True) As String |
13 |
| - If wsRootPath.EndsWith("\") Then wsRootPath = wsRootPath.Substring(0, wsRootPath.Length - 1) |
14 |
| - Dim inst = New VueFilesToJS With {.WsRoot = wsRootPath, .SquashWS = squashWS} |
15 |
| - Return inst.ProcRoot(vueFile, Function(fn) txt) |
| 9 | + Dim inst = New VueFilesToJS With {.WsRoot = wsRootPath, .SquashWS = squashWS, .FileReadCallback = fileReadCallback} |
| 10 | + Return inst.ProcRoot(sourceFile, rootFileContent) |
16 | 11 | End Function
|
17 | 12 |
|
18 | 13 | Private Sub New()
|
19 | 14 | REM private constructor so only Compile function can create instance
|
20 | 15 | End Sub
|
21 | 16 |
|
22 |
| - Private Function ProcRoot(vueFile As String, loadFile As Func(Of String, String)) As String |
23 |
| - Dim res = ParseVueFile(vueFile, Nothing, loadFile) |
| 17 | + Private Function ProcRoot(vueFile As String, FileContent As String) As String |
| 18 | + Dim res = ParseVueFile(vueFile, Nothing, FileContent) |
24 | 19 |
|
25 | 20 | Dim sb As New System.Text.StringBuilder
|
26 | 21 | sb.AppendLine("function() {")
|
|
38 | 33 | End Function
|
39 | 34 |
|
40 | 35 | 'wsroot = "c:\web-sites\tjek" (no ending \)
|
41 |
| - Private Function ParseVueFile(vueFile As String, fromComp As Component, loadFile As Func(Of String, String)) As ParseVueFileResult |
| 36 | + Private Function ParseVueFile(vueFile As String, fromComp As Component, Optional fileContent As String = Nothing) As ParseVueFileResult |
42 | 37 | Dim cp = ResolvePath(vueFile)
|
43 | 38 | Dim vfWin = WsRoot & cp.Replace("/", "\") & JustFN(vueFile)
|
44 |
| - Dim x = loadFile(vfWin).Trim |
| 39 | + Dim x As String |
| 40 | + If fileContent Is Nothing Then |
| 41 | + If FileReadCallback IsNot Nothing Then FileReadCallback(vfWin) |
| 42 | + x = My.Computer.FileSystem.ReadAllText(vfWin).Trim |
| 43 | + Else |
| 44 | + x = fileContent.Trim |
| 45 | + End If |
45 | 46 |
|
46 | 47 | If Not x.EndsWith("</script>") Then Throw New Exception(".vue file '" & vueFile & "' does not end with </script>")
|
47 | 48 | x = x.Substring(0, x.Length - 9).Trim
|
|
171 | 172 | c = New Component With {.Name = compName, .File = vueFile}
|
172 | 173 | If parentComp IsNot Nothing Then parentComp.SubComps.Add(c)
|
173 | 174 | Components.Add(compName, c)
|
174 |
| - c.pvfr = ParseVueFile(vueFile, c, AddressOf My.Computer.FileSystem.ReadAllText) |
| 175 | + c.pvfr = ParseVueFile(vueFile, c) |
175 | 176 | End Sub
|
176 | 177 |
|
177 | 178 | Private Class Component
|
|
0 commit comments