hotstaq 0.5.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (299) hide show
  1. package/.eslintignore +17 -0
  2. package/.eslintrc.js +11 -0
  3. package/.vscode/launch.json +199 -0
  4. package/.vscode/settings.json +2 -0
  5. package/.vscode/tasks.json +78 -0
  6. package/CONTRIBUTING.md +157 -0
  7. package/README.md +126 -0
  8. package/bin/hotstaq +3 -0
  9. package/bin/hotstaq.cmd +1 -0
  10. package/build/src/Hot.d.ts +167 -0
  11. package/build/src/Hot.d.ts.map +1 -0
  12. package/build/src/Hot.js +365 -0
  13. package/build/src/Hot.js.map +1 -0
  14. package/build/src/HotAPI.d.ts +130 -0
  15. package/build/src/HotAPI.d.ts.map +1 -0
  16. package/build/src/HotAPI.js +353 -0
  17. package/build/src/HotAPI.js.map +1 -0
  18. package/build/src/HotAgentAPI.d.ts +22 -0
  19. package/build/src/HotAgentAPI.d.ts.map +1 -0
  20. package/build/src/HotAgentAPI.js +85 -0
  21. package/build/src/HotAgentAPI.js.map +1 -0
  22. package/build/src/HotAgentRoute.d.ts +17 -0
  23. package/build/src/HotAgentRoute.d.ts.map +1 -0
  24. package/build/src/HotAgentRoute.js +109 -0
  25. package/build/src/HotAgentRoute.js.map +1 -0
  26. package/build/src/HotBuilder.d.ts +52 -0
  27. package/build/src/HotBuilder.d.ts.map +1 -0
  28. package/build/src/HotBuilder.js +239 -0
  29. package/build/src/HotBuilder.js.map +1 -0
  30. package/build/src/HotClient.d.ts +31 -0
  31. package/build/src/HotClient.d.ts.map +1 -0
  32. package/build/src/HotClient.js +19 -0
  33. package/build/src/HotClient.js.map +1 -0
  34. package/build/src/HotComponent.d.ts +118 -0
  35. package/build/src/HotComponent.d.ts.map +1 -0
  36. package/build/src/HotComponent.js +89 -0
  37. package/build/src/HotComponent.js.map +1 -0
  38. package/build/src/HotCreator.d.ts +92 -0
  39. package/build/src/HotCreator.d.ts.map +1 -0
  40. package/build/src/HotCreator.js +465 -0
  41. package/build/src/HotCreator.js.map +1 -0
  42. package/build/src/HotDB.d.ts +69 -0
  43. package/build/src/HotDB.d.ts.map +1 -0
  44. package/build/src/HotDB.js +29 -0
  45. package/build/src/HotDB.js.map +1 -0
  46. package/build/src/HotDBConnectionInterface.d.ts +40 -0
  47. package/build/src/HotDBConnectionInterface.d.ts.map +1 -0
  48. package/build/src/HotDBConnectionInterface.js +3 -0
  49. package/build/src/HotDBConnectionInterface.js.map +1 -0
  50. package/build/src/HotFile.d.ts +134 -0
  51. package/build/src/HotFile.d.ts.map +1 -0
  52. package/build/src/HotFile.js +454 -0
  53. package/build/src/HotFile.js.map +1 -0
  54. package/build/src/HotHTTPServer.d.ts +162 -0
  55. package/build/src/HotHTTPServer.d.ts.map +1 -0
  56. package/build/src/HotHTTPServer.js +863 -0
  57. package/build/src/HotHTTPServer.js.map +1 -0
  58. package/build/src/HotIO.d.ts +39 -0
  59. package/build/src/HotIO.d.ts.map +1 -0
  60. package/build/src/HotIO.js +195 -0
  61. package/build/src/HotIO.js.map +1 -0
  62. package/build/src/HotLog.d.ts +60 -0
  63. package/build/src/HotLog.d.ts.map +1 -0
  64. package/build/src/HotLog.js +126 -0
  65. package/build/src/HotLog.js.map +1 -0
  66. package/build/src/HotPage.d.ts +125 -0
  67. package/build/src/HotPage.d.ts.map +1 -0
  68. package/build/src/HotPage.js +178 -0
  69. package/build/src/HotPage.js.map +1 -0
  70. package/build/src/HotRoute.d.ts +82 -0
  71. package/build/src/HotRoute.d.ts.map +1 -0
  72. package/build/src/HotRoute.js +83 -0
  73. package/build/src/HotRoute.js.map +1 -0
  74. package/build/src/HotRouteMethod.d.ts +129 -0
  75. package/build/src/HotRouteMethod.d.ts.map +1 -0
  76. package/build/src/HotRouteMethod.js +84 -0
  77. package/build/src/HotRouteMethod.js.map +1 -0
  78. package/build/src/HotServer.d.ts +152 -0
  79. package/build/src/HotServer.d.ts.map +1 -0
  80. package/build/src/HotServer.js +109 -0
  81. package/build/src/HotServer.js.map +1 -0
  82. package/build/src/HotSetAsWeb.d.ts +2 -0
  83. package/build/src/HotSetAsWeb.d.ts.map +1 -0
  84. package/build/src/HotSetAsWeb.js +5 -0
  85. package/build/src/HotSetAsWeb.js.map +1 -0
  86. package/build/src/HotStaq.d.ts +601 -0
  87. package/build/src/HotStaq.d.ts.map +1 -0
  88. package/build/src/HotStaq.js +1258 -0
  89. package/build/src/HotStaq.js.map +1 -0
  90. package/build/src/HotStaqWeb.d.ts +18 -0
  91. package/build/src/HotStaqWeb.d.ts.map +1 -0
  92. package/build/src/HotStaqWeb.js +44 -0
  93. package/build/src/HotStaqWeb.js.map +1 -0
  94. package/build/src/HotTestDriver.d.ts +63 -0
  95. package/build/src/HotTestDriver.d.ts.map +1 -0
  96. package/build/src/HotTestDriver.js +187 -0
  97. package/build/src/HotTestDriver.js.map +1 -0
  98. package/build/src/HotTestElement.d.ts +71 -0
  99. package/build/src/HotTestElement.d.ts.map +1 -0
  100. package/build/src/HotTestElement.js +37 -0
  101. package/build/src/HotTestElement.js.map +1 -0
  102. package/build/src/HotTestMap.d.ts +83 -0
  103. package/build/src/HotTestMap.d.ts.map +1 -0
  104. package/build/src/HotTestMap.js +58 -0
  105. package/build/src/HotTestMap.js.map +1 -0
  106. package/build/src/HotTestSeleniumDriver.d.ts +82 -0
  107. package/build/src/HotTestSeleniumDriver.d.ts.map +1 -0
  108. package/build/src/HotTestSeleniumDriver.js +398 -0
  109. package/build/src/HotTestSeleniumDriver.js.map +1 -0
  110. package/build/src/HotTester.d.ts +188 -0
  111. package/build/src/HotTester.d.ts.map +1 -0
  112. package/build/src/HotTester.js +623 -0
  113. package/build/src/HotTester.js.map +1 -0
  114. package/build/src/HotTesterAPI.d.ts +15 -0
  115. package/build/src/HotTesterAPI.d.ts.map +1 -0
  116. package/build/src/HotTesterAPI.js +161 -0
  117. package/build/src/HotTesterAPI.js.map +1 -0
  118. package/build/src/HotTesterMocha.d.ts +50 -0
  119. package/build/src/HotTesterMocha.d.ts.map +1 -0
  120. package/build/src/HotTesterMocha.js +205 -0
  121. package/build/src/HotTesterMocha.js.map +1 -0
  122. package/build/src/HotTesterMochaSelenium.d.ts +70 -0
  123. package/build/src/HotTesterMochaSelenium.d.ts.map +1 -0
  124. package/build/src/HotTesterMochaSelenium.js +257 -0
  125. package/build/src/HotTesterMochaSelenium.js.map +1 -0
  126. package/build/src/HotTesterServer.d.ts +114 -0
  127. package/build/src/HotTesterServer.d.ts.map +1 -0
  128. package/build/src/HotTesterServer.js +575 -0
  129. package/build/src/HotTesterServer.js.map +1 -0
  130. package/build/src/api.d.ts +33 -0
  131. package/build/src/api.d.ts.map +1 -0
  132. package/build/src/api.js +78 -0
  133. package/build/src/api.js.map +1 -0
  134. package/build/src/cli.d.ts +2 -0
  135. package/build/src/cli.d.ts.map +1 -0
  136. package/build/src/cli.js +935 -0
  137. package/build/src/cli.js.map +1 -0
  138. package/build/src/schemas/HotDBInflux.d.ts +63 -0
  139. package/build/src/schemas/HotDBInflux.d.ts.map +1 -0
  140. package/build/src/schemas/HotDBInflux.js +239 -0
  141. package/build/src/schemas/HotDBInflux.js.map +1 -0
  142. package/build/src/schemas/HotDBMigration.d.ts +19 -0
  143. package/build/src/schemas/HotDBMigration.d.ts.map +1 -0
  144. package/build/src/schemas/HotDBMigration.js +15 -0
  145. package/build/src/schemas/HotDBMigration.js.map +1 -0
  146. package/build/src/schemas/HotDBMySQL.d.ts +65 -0
  147. package/build/src/schemas/HotDBMySQL.d.ts.map +1 -0
  148. package/build/src/schemas/HotDBMySQL.js +387 -0
  149. package/build/src/schemas/HotDBMySQL.js.map +1 -0
  150. package/build/src/schemas/HotDBSchema.d.ts +15 -0
  151. package/build/src/schemas/HotDBSchema.d.ts.map +1 -0
  152. package/build/src/schemas/HotDBSchema.js +19 -0
  153. package/build/src/schemas/HotDBSchema.js.map +1 -0
  154. package/build/src/schemas/influx/InfluxSchema.d.ts +14 -0
  155. package/build/src/schemas/influx/InfluxSchema.d.ts.map +1 -0
  156. package/build/src/schemas/influx/InfluxSchema.js +33 -0
  157. package/build/src/schemas/influx/InfluxSchema.js.map +1 -0
  158. package/build/src/schemas/mysql/MySQLSchema.d.ts +39 -0
  159. package/build/src/schemas/mysql/MySQLSchema.d.ts.map +1 -0
  160. package/build/src/schemas/mysql/MySQLSchema.js +151 -0
  161. package/build/src/schemas/mysql/MySQLSchema.js.map +1 -0
  162. package/build/src/schemas/mysql/MySQLSchemaField.d.ts +168 -0
  163. package/build/src/schemas/mysql/MySQLSchemaField.d.ts.map +1 -0
  164. package/build/src/schemas/mysql/MySQLSchemaField.js +260 -0
  165. package/build/src/schemas/mysql/MySQLSchemaField.js.map +1 -0
  166. package/build/src/schemas/mysql/MySQLSchemaTable.d.ts +49 -0
  167. package/build/src/schemas/mysql/MySQLSchemaTable.d.ts.map +1 -0
  168. package/build/src/schemas/mysql/MySQLSchemaTable.js +310 -0
  169. package/build/src/schemas/mysql/MySQLSchemaTable.js.map +1 -0
  170. package/build-web/HotStaq.js +2 -0
  171. package/build-web/HotStaq.min.js +125 -0
  172. package/builder/docker/Dockerfile.linux.gen +42 -0
  173. package/builder/docker/README.md +36 -0
  174. package/builder/docker/app/start.sh +8 -0
  175. package/builder/docker/dockerignore +3 -0
  176. package/builder/docker/scripts/build.bat +11 -0
  177. package/builder/docker/scripts/build.sh +11 -0
  178. package/builder/docker/scripts/start-app.bat +7 -0
  179. package/builder/docker/scripts/start-app.sh +7 -0
  180. package/builder/docker/scripts/stop-app.bat +5 -0
  181. package/builder/docker/scripts/stop-app.sh +5 -0
  182. package/builder/docker-compose/docker-compose.gen.yaml +41 -0
  183. package/builder/docker-compose/env-skeleton +4 -0
  184. package/creator/project/.vscode/launch.json +59 -0
  185. package/creator/project/README.md +20 -0
  186. package/creator/project/gitignore +118 -0
  187. package/creator/project/npmignore +118 -0
  188. package/creator/public/api-test.hott +28 -0
  189. package/creator/public/index.hott +12 -0
  190. package/creator/ts/src/AppAPI.ts +30 -0
  191. package/creator/ts/src/HelloWorld.ts +39 -0
  192. package/creator/ts/src/WebExport.ts +7 -0
  193. package/creator/ts/tsconfig-web.json +73 -0
  194. package/creator/ts/tsconfig.json +73 -0
  195. package/creator/ts/webpack-api.config.js +57 -0
  196. package/dbstart.sh +19 -0
  197. package/dbstop.sh +4 -0
  198. package/docs/.nojekyll +1 -0
  199. package/docs/README.md +128 -0
  200. package/docs/classes/Hot.md +477 -0
  201. package/docs/classes/HotAPI.md +369 -0
  202. package/docs/classes/HotClient.md +95 -0
  203. package/docs/classes/HotComponent.md +279 -0
  204. package/docs/classes/HotDB.md +247 -0
  205. package/docs/classes/HotDBInflux.md +404 -0
  206. package/docs/classes/HotDBMigration.md +80 -0
  207. package/docs/classes/HotDBMySQL.md +310 -0
  208. package/docs/classes/HotDBSchema.md +51 -0
  209. package/docs/classes/HotFile.md +353 -0
  210. package/docs/classes/HotHTTPServer.md +700 -0
  211. package/docs/classes/HotLog.md +162 -0
  212. package/docs/classes/HotPage.md +357 -0
  213. package/docs/classes/HotRoute.md +312 -0
  214. package/docs/classes/HotRouteMethod.md +271 -0
  215. package/docs/classes/HotServer.md +311 -0
  216. package/docs/classes/HotStaq.md +1153 -0
  217. package/docs/classes/HotTestDestination.md +58 -0
  218. package/docs/classes/HotTestDriver.md +332 -0
  219. package/docs/classes/HotTestElement.md +88 -0
  220. package/docs/classes/HotTestElementOptions.md +71 -0
  221. package/docs/classes/HotTestMap.md +92 -0
  222. package/docs/classes/HotTestSeleniumDriver.md +529 -0
  223. package/docs/classes/HotTester.md +653 -0
  224. package/docs/classes/HotTesterAPI.md +493 -0
  225. package/docs/classes/HotTesterMocha.md +843 -0
  226. package/docs/classes/HotTesterMochaSelenium.md +896 -0
  227. package/docs/classes/HotTesterServer.md +633 -0
  228. package/docs/classes/InfluxSchema.md +74 -0
  229. package/docs/classes/MySQLSchema.md +199 -0
  230. package/docs/classes/MySQLSchemaField.md +330 -0
  231. package/docs/classes/MySQLSchemaTable.md +176 -0
  232. package/docs/enums/ConnectionStatus.md +43 -0
  233. package/docs/enums/DeveloperMode.md +38 -0
  234. package/docs/enums/EventExecutionType.md +43 -0
  235. package/docs/enums/HTTPMethod.md +32 -0
  236. package/docs/enums/HotDBGenerationType.md +30 -0
  237. package/docs/enums/HotLogLevel.md +88 -0
  238. package/docs/interfaces/HotDBConnectionInterface.md +116 -0
  239. package/docs/interfaces/HotDestination.md +62 -0
  240. package/docs/interfaces/HotSite.md +187 -0
  241. package/docs/interfaces/HotSiteMapPath.md +37 -0
  242. package/docs/interfaces/HotSiteRoute.md +79 -0
  243. package/docs/interfaces/HotStartOptions.md +115 -0
  244. package/docs/interfaces/HotTestPage.md +44 -0
  245. package/docs/interfaces/HotTestStop.md +62 -0
  246. package/docs/interfaces/IHotComponent.md +135 -0
  247. package/docs/interfaces/IHotStaq.md +118 -0
  248. package/docs/interfaces/IHotTestElement.md +54 -0
  249. package/docs/interfaces/IHotTestElementOptions.md +43 -0
  250. package/docs/interfaces/MySQLResults.md +43 -0
  251. package/docs/interfaces/MySQLSchemaFieldResult.md +75 -0
  252. package/docs/modules.md +162 -0
  253. package/package.json +65 -0
  254. package/selenium-start.sh +7 -0
  255. package/selenium-stop.sh +3 -0
  256. package/src/Hot.ts +319 -0
  257. package/src/HotAPI.ts +378 -0
  258. package/src/HotAgentAPI.ts +43 -0
  259. package/src/HotAgentRoute.ts +44 -0
  260. package/src/HotBuilder.ts +221 -0
  261. package/src/HotClient.ts +40 -0
  262. package/src/HotComponent.ts +158 -0
  263. package/src/HotCreator.ts +482 -0
  264. package/src/HotDB.ts +79 -0
  265. package/src/HotDBConnectionInterface.ts +40 -0
  266. package/src/HotFile.ts +617 -0
  267. package/src/HotHTTPServer.ts +954 -0
  268. package/src/HotIO.ts +128 -0
  269. package/src/HotLog.ts +158 -0
  270. package/src/HotPage.ts +206 -0
  271. package/src/HotRoute.ts +137 -0
  272. package/src/HotRouteMethod.ts +216 -0
  273. package/src/HotServer.ts +211 -0
  274. package/src/HotSetAsWeb.ts +3 -0
  275. package/src/HotStaq.ts +1877 -0
  276. package/src/HotStaqWeb.ts +59 -0
  277. package/src/HotTestDriver.ts +172 -0
  278. package/src/HotTestElement.ts +97 -0
  279. package/src/HotTestMap.ts +130 -0
  280. package/src/HotTestSeleniumDriver.ts +374 -0
  281. package/src/HotTester.ts +697 -0
  282. package/src/HotTesterAPI.ts +126 -0
  283. package/src/HotTesterMocha.ts +133 -0
  284. package/src/HotTesterMochaSelenium.ts +189 -0
  285. package/src/HotTesterServer.ts +551 -0
  286. package/src/api.ts +102 -0
  287. package/src/cli.ts +1147 -0
  288. package/src/schemas/HotDBInflux.ts +211 -0
  289. package/src/schemas/HotDBMigration.ts +24 -0
  290. package/src/schemas/HotDBMySQL.ts +312 -0
  291. package/src/schemas/HotDBSchema.ts +21 -0
  292. package/src/schemas/influx/InfluxSchema.ts +19 -0
  293. package/src/schemas/mysql/MySQLSchema.ts +90 -0
  294. package/src/schemas/mysql/MySQLSchemaField.ts +408 -0
  295. package/src/schemas/mysql/MySQLSchemaTable.ts +353 -0
  296. package/tsconfig-web.json +74 -0
  297. package/tsconfig.json +73 -0
  298. package/webpack.config.js +51 -0
  299. package/webpack.config.tests.js +56 -0
package/src/HotFile.ts ADDED
@@ -0,0 +1,617 @@
1
+ import * as fs from "fs";
2
+
3
+ import fetch from "cross-fetch";
4
+
5
+ import { DeveloperMode, Hot } from "./Hot";
6
+ import { HotPage } from "./HotPage";
7
+ import { HotTestElement } from "./HotTestElement";
8
+
9
+ /**
10
+ * A file to process.
11
+ */
12
+ export interface IHotFile
13
+ {
14
+ /**
15
+ * The parent page.
16
+ */
17
+ page?: HotPage;
18
+ /**
19
+ * The name of the file.
20
+ */
21
+ name?: string;
22
+ /**
23
+ * The url to the file to get.
24
+ */
25
+ url?: string;
26
+ /**
27
+ * The path to the local file to get.
28
+ */
29
+ localFile?: string;
30
+ /**
31
+ * The content of the file to process.
32
+ */
33
+ content?: string;
34
+ /**
35
+ * Force all errors to be thrown.
36
+ */
37
+ throwAllErrors?: boolean;
38
+ }
39
+
40
+ /**
41
+ * A file to process.
42
+ */
43
+ export class HotFile implements IHotFile
44
+ {
45
+ /**
46
+ * The parent page.
47
+ */
48
+ page: HotPage;
49
+ /**
50
+ * The name of the file.
51
+ */
52
+ name: string;
53
+ /**
54
+ * The url to the file to get.
55
+ */
56
+ url: string;
57
+ /**
58
+ * The path to the local file to get.
59
+ */
60
+ localFile: string;
61
+ /**
62
+ * The content of the file to process.
63
+ */
64
+ content: string;
65
+ /**
66
+ * Force all errors to be thrown.
67
+ */
68
+ throwAllErrors: boolean;
69
+
70
+ constructor (copy: IHotFile = {})
71
+ {
72
+ this.page = copy.page || null;
73
+ this.name = copy.name || "";
74
+ this.url = copy.url || "";
75
+ this.localFile = copy.localFile || "";
76
+ this.content = copy.content || "";
77
+ this.throwAllErrors = copy.throwAllErrors || false;
78
+ }
79
+
80
+ /**
81
+ * Set the content of this file.
82
+ */
83
+ setContent (content: string): void
84
+ {
85
+ this.content = content;
86
+ }
87
+
88
+ /**
89
+ * Get the content of this file.
90
+ */
91
+ getContent (): string
92
+ {
93
+ return (this.content);
94
+ }
95
+
96
+ /**
97
+ * Make a HTTP get request.
98
+ */
99
+ static async httpGet (url: string): Promise<string>
100
+ {
101
+ try
102
+ {
103
+ let res: Response = await fetch (url);
104
+
105
+ if (res.ok === false)
106
+ throw new Error (`${res.status}: ${res.statusText}`);
107
+
108
+ let content: string = await res.text ();
109
+
110
+ return (content);
111
+ }
112
+ catch (ex)
113
+ {
114
+ return (JSON.stringify ({ "error": `${ex.message} - Could not fetch ${url}` }));
115
+ }
116
+ }
117
+
118
+ /**
119
+ * Load content from a url.
120
+ */
121
+ async loadUrl (): Promise<string>
122
+ {
123
+ this.content = await HotFile.httpGet (this.url);
124
+
125
+ return (this.content);
126
+ }
127
+
128
+ /**
129
+ * Load content from a local file.
130
+ */
131
+ async loadLocalFile (): Promise<string>
132
+ {
133
+ let promise: Promise<string> = new Promise (
134
+ (resolve: any, reject: any): void =>
135
+ {
136
+ fs.readFile (this.localFile, (err: NodeJS.ErrnoException, data: Buffer): void =>
137
+ {
138
+ if (err != null)
139
+ throw err;
140
+
141
+ let content: string = data.toString ();
142
+ this.content = content;
143
+
144
+ resolve (this.content);
145
+ });
146
+ });
147
+
148
+ return (promise);
149
+ }
150
+
151
+ /**
152
+ * Load the contents of the file.
153
+ */
154
+ async load (): Promise<string>
155
+ {
156
+ let content: string = "";
157
+
158
+ if (this.url !== "")
159
+ content = await this.loadUrl ();
160
+
161
+ if (this.localFile !== "")
162
+ content = await this.loadLocalFile ();
163
+
164
+ return (content);
165
+ }
166
+
167
+ /**
168
+ * Process string content. This will take in a regular expression and
169
+ * parse the content based on the regex. When the regex content is found
170
+ * contentProcessor will be executed with the regex content found. When
171
+ * the regex content is not found, offContentProcessor will be called with
172
+ * the content outside of the regex.
173
+ *
174
+ * @param content The content to parse.
175
+ * @param contentRegex The regex to use to parse the content.
176
+ * @param contentProcessor The content found inside the regex.
177
+ * @param offContentProcessor The content found outside of the regex.
178
+ * @param numRemoveFromBeginning The number of characters to remove from the
179
+ * beginning of the found content.
180
+ * @param numRemoveFromEnd The number of characters to remove from the end of
181
+ * the found content.
182
+ */
183
+ static processContent (content: string, contentRegex: RegExp,
184
+ contentProcessor: (regexFound: string) => string,
185
+ offContentProcessor: (offContent: string) => string,
186
+ numRemoveFromBeginning: number = 2,
187
+ numRemoveFromEnd: number = 2): string
188
+ {
189
+ let result: RegExpExecArray = contentRegex.exec (content);
190
+ let previousIndex: number = 0;
191
+ let output: string = "";
192
+
193
+ while (result != null)
194
+ {
195
+ let start: number = result.index - numRemoveFromBeginning;
196
+ let end: number = contentRegex.lastIndex + numRemoveFromEnd;
197
+
198
+ // Get the previous section.
199
+ let prevContent: string = content.substr (previousIndex, (start - previousIndex));
200
+ previousIndex = end;
201
+
202
+ output += offContentProcessor (prevContent);
203
+
204
+ // Process the content found from the regex
205
+ let contentFound: string = result[0];
206
+ output += contentProcessor (contentFound);
207
+
208
+ // Move on to the next section to parse.
209
+ result = contentRegex.exec (content);
210
+ }
211
+
212
+ // Append whatever else is after the last parsed section.
213
+ let lastContent: string = content.substr (previousIndex);
214
+
215
+ output += offContentProcessor (lastContent);
216
+
217
+ return (output);
218
+ }
219
+
220
+ /**
221
+ * Process any content that could have nested values. This will
222
+ * take in a regular expression and
223
+ * parse the content based on the regex. When the regex content is found
224
+ * contentProcessor will be executed with the regex content found. When
225
+ * the regex content is not found, offContentProcessor will be called with
226
+ * the content outside of the regex.
227
+ *
228
+ * @fixme Needs to be able to ignore any characters found inside comments
229
+ * or a string. For example, if the following is used ```${"Test }"}``` It
230
+ * will error out.
231
+ *
232
+ * @param content The content to parse.
233
+ * @param contentRegex The regex to use to parse the content.
234
+ * @param contentProcessor The content found inside the regex.
235
+ * @param offContentProcessor The content found outside of the regex.
236
+ * @param numRemoveFromBeginning The number of characters to remove from the
237
+ * beginning of the found content.
238
+ * @param numRemoveFromEnd The number of characters to remove from the end of
239
+ * the found content.
240
+ */
241
+ static processNestedContent (content: string, startChars: string, endChars: string,
242
+ triggerChar: string, contentProcessor: (regexFound: string) => string,
243
+ offContentProcessor: (offContent: string) => string,
244
+ numRemoveFromBeginning: number = 2,
245
+ numRemoveFromEnd: number = 1): string
246
+ {
247
+ let pos: number = content.indexOf (startChars);
248
+ let previousIndex: number = 0;
249
+ let startTriggerPos: number = content.indexOf (triggerChar, pos);
250
+ let output: string = "";
251
+
252
+ while (pos > -1)
253
+ {
254
+ let end: number = content.indexOf (endChars, pos);
255
+ let nestedCounter: number = 0;
256
+
257
+ if (triggerChar !== "")
258
+ {
259
+ // Reverse search the trigger characters and count the number of
260
+ // occurrences.
261
+ let rpos: number = content.lastIndexOf (triggerChar, end - numRemoveFromEnd);
262
+
263
+ while (rpos > -1)
264
+ {
265
+ if (rpos === startTriggerPos)
266
+ break;
267
+
268
+ rpos = content.lastIndexOf (triggerChar, rpos - numRemoveFromEnd);
269
+ nestedCounter++;
270
+ }
271
+ }
272
+
273
+ // If there's nested trigger characters, get the last occurrence of
274
+ // the end character.
275
+ if (nestedCounter > 0)
276
+ {
277
+ let epos: number = content.indexOf (endChars, end + numRemoveFromEnd);
278
+ let tempepos: number = epos;
279
+
280
+ while ((epos > -1) && (nestedCounter > 0))
281
+ {
282
+ if (tempepos < 0)
283
+ break;
284
+
285
+ // Make sure we aren't discovering endChars that we shouldn't be.
286
+ let posOutsideOfContent: number = content.lastIndexOf (startChars, tempepos - numRemoveFromEnd);
287
+
288
+ if (posOutsideOfContent > epos)
289
+ break;
290
+
291
+ epos = tempepos;
292
+
293
+ tempepos = content.indexOf (endChars, epos + numRemoveFromEnd);
294
+ nestedCounter--;
295
+ }
296
+
297
+ end = epos;
298
+ }
299
+
300
+ let offContentStr: string = content.substr (previousIndex, (pos - previousIndex));
301
+ output += offContentProcessor (offContentStr);
302
+
303
+ let foundContent: string = content.substr (
304
+ pos + numRemoveFromBeginning, (end - (pos + numRemoveFromBeginning)));
305
+ output += contentProcessor (foundContent);
306
+
307
+ // Get the next content
308
+ pos = content.indexOf (startChars, end + numRemoveFromEnd);
309
+ startTriggerPos = content.indexOf (triggerChar, pos);
310
+ previousIndex = end + numRemoveFromEnd;
311
+ }
312
+
313
+ // Append whatever else is after the last parsed section.
314
+ let lastContent: string = content.substr (previousIndex);
315
+
316
+ output += offContentProcessor (lastContent);
317
+
318
+ return (output);
319
+ }
320
+
321
+ /**
322
+ * Process the content in this file. This treats each file as one large JavaScript
323
+ * file. Any text outside of the <* *> areas will be treated as:
324
+ *
325
+ * Hot.echo ("text");
326
+ *
327
+ * @fixme The regex's in the offContent functions need to be fixed. There's several
328
+ * test cases where they will fail.
329
+ */
330
+ async process (args: any = null): Promise<string>
331
+ {
332
+ let output: string = "";
333
+ let thisContent: string = this.content;
334
+
335
+ Hot.Mode = this.page.processor.mode;
336
+ Hot.Arguments = args;
337
+ Hot.CurrentPage = this.page;
338
+ Hot.PublicSecrets = this.page.processor.publicSecrets;
339
+ Hot.API = this.page.getAPI ();
340
+ Hot.TesterAPI = this.page.getTesterAPI ();
341
+
342
+ // Assemble the JS to evaluate. This will take all content outside of
343
+ // <* and *> and wrap a Hot.echo around it. Any JS found inside of the
344
+ // <* and *> will be executed as is.
345
+ output = HotFile.processContent (thisContent,
346
+ new RegExp ("(?=\\<\\*)([\\s\\S]*?)(?=\\*\\>)", "g"),
347
+ (regexFound: string): string =>
348
+ {
349
+ // A little hack, since I suck at Regex :(
350
+ regexFound = regexFound.substr (2);
351
+
352
+ return (`${regexFound}`);
353
+ },
354
+ (offContent: string): string =>
355
+ {
356
+ if (offContent === "")
357
+ return ("");
358
+
359
+ let tempOutput: string = HotFile.processNestedContent (
360
+ offContent, "!{", "}", "{",
361
+ (regexFound2: string): string =>
362
+ {
363
+ let out: string = `*&&%*%@#@!${regexFound2}*&!#%@!@*!`;
364
+
365
+ return (out);
366
+ },
367
+ (offContent3: string): string =>
368
+ {
369
+ return (offContent3);
370
+ });
371
+ let tempOutput2: string = HotFile.processNestedContent (
372
+ tempOutput, "STR{", "}", "{",
373
+ (regexFound2: string): string =>
374
+ {
375
+ let out: string =
376
+ `*&&%*%@#@!echoOutput (JSON.stringify(${regexFound2}), ${this.throwAllErrors});*&!#%@!@*!`;
377
+
378
+ return (out);
379
+ },
380
+ (offContent3: string): string =>
381
+ {
382
+ return (offContent3);
383
+ }, 4, 1);
384
+ let tempOutput3: string = HotFile.processNestedContent (
385
+ tempOutput2, "${", "}", "{",
386
+ (regexFound2: string): string =>
387
+ {
388
+ let out: string = `*&&%*%@#@!try { Hot.echo (${regexFound2}); }catch (ex){Hot.echo ("");}*&!#%@!@*!`;
389
+
390
+ if (this.throwAllErrors === true)
391
+ out = `*&&%*%@#@!Hot.echo (${regexFound2});*&!#%@!@*!`;
392
+
393
+ return (out);
394
+ },
395
+ (offContent3: string): string =>
396
+ {
397
+ return (offContent3);
398
+ /*let escapedContent: string = JSON.stringify (offContent3);
399
+ let out: string = `echoOutput (${escapedContent}, ${this.throwAllErrors});\n`;
400
+
401
+ return (out);*/
402
+ });
403
+
404
+ let tempOutput4: string = "";
405
+
406
+ if (Hot.Mode === DeveloperMode.Production)
407
+ {
408
+ tempOutput4 = HotFile.processNestedContent (
409
+ tempOutput3, "?(", ")", "(",
410
+ (regexFound2: string): string =>
411
+ {
412
+ return ("");
413
+ },
414
+ (offContent3: string): string =>
415
+ {
416
+ return (offContent3);
417
+ /*let out: string = `echoOutput (${offContent3}, ${this.throwAllErrors});\n`;
418
+
419
+ return (out);*/
420
+ });
421
+ }
422
+
423
+ if (Hot.Mode === DeveloperMode.Development)
424
+ {
425
+ tempOutput4 = HotFile.processNestedContent (
426
+ tempOutput3, "?(", ")", "(",
427
+ (regexFound2: string): string =>
428
+ {
429
+ let foundStr: string = "";
430
+
431
+ try
432
+ {
433
+ // Check to see if it be parsed. If so, stringify it.
434
+ JSON.parse (regexFound2);
435
+ foundStr = JSON.stringify (regexFound2);
436
+ }
437
+ catch (ex)
438
+ {
439
+ // If valid JSON is not received, don't worry about it, pass it
440
+ // along to the function below for it to be parsed in the page.
441
+ // The exception should be thrown there instead.
442
+ foundStr = `${regexFound2}`;
443
+ }
444
+
445
+ /// @fixme Make this a callable function and pass foundStr, etc.
446
+ let out: string =
447
+ `*&&%*%@#@!{
448
+ const testElm = createTestElement (${foundStr});
449
+ Hot.echo (\`data-test-object-name = "\${testElm.name}" data-test-object-func = "\${testElm.func}" data-test-object-value = "\${testElm.value}"\`);
450
+ }*&!#%@!@*!\n`;
451
+
452
+ return (out);
453
+ },
454
+ (offContent3: string): string =>
455
+ {
456
+ return (offContent3);
457
+ /*let out: string = `echoOutput (${offContent3}, ${this.throwAllErrors});\n`;
458
+
459
+ return (out);*/
460
+ });
461
+ }
462
+
463
+ let tempOutput5: string = HotFile.processNestedContent (
464
+ tempOutput4, "*&&%*%@#@!", "*&!#%@!@*!", "*&&%*%@#@!",
465
+ (regexFound: string): string =>
466
+ {
467
+ return (regexFound);
468
+ },
469
+ (offContent: string): string =>
470
+ {
471
+ let escapedContent: string = JSON.stringify (offContent);
472
+ let out: string = `echoOutput (${escapedContent}, ${this.throwAllErrors});\n`;
473
+
474
+ return (out);
475
+ },
476
+ "*&&%*%@#@!".length, "*&!#%@!@*!".length);
477
+
478
+ /// @fixme Temporary hack. These delimiters should be removed from tempOutput when
479
+ /// executing processNestedContent.
480
+ tempOutput5 = tempOutput5.replace (/\*\&\&\%\*\%\@\#\@\!/g, "");
481
+ tempOutput5 = tempOutput5.replace (/\*\&\!\#\%\@\!\@\*\!/g, "");
482
+
483
+ return (tempOutput5);
484
+ }, 0);
485
+
486
+ // Execute the assembled JS file.
487
+ let returnedOutput: any = null;
488
+
489
+ try
490
+ {
491
+ let executionContent: string = `
492
+ var Hot = arguments[0];
493
+ var PassedHotFile = arguments[1];
494
+
495
+ `;
496
+
497
+ if (typeof (args) === "string")
498
+ throw new Error (`The passing arguments cannot be a string!`);
499
+
500
+ for (let key in args)
501
+ {
502
+ let newVar: string = "";
503
+ let newVarValue: any = args[key];
504
+ let newVarValueStr: string = JSON.stringify (newVarValue);
505
+
506
+ newVar = `var ${key} = ${newVarValueStr};\n`;
507
+
508
+ executionContent += newVar;
509
+ }
510
+
511
+ let contentName: string = this.name;
512
+
513
+ if (contentName === "")
514
+ contentName = this.localFile;
515
+
516
+ if (contentName === "")
517
+ contentName = this.url;
518
+
519
+ executionContent += `
520
+
521
+ function echoOutput (content, throwErrors)
522
+ {
523
+ if (throwErrors == null)
524
+ throwErrors = true;
525
+
526
+ if (throwErrors === true)
527
+ {
528
+ Hot.echo (content);
529
+
530
+ return;
531
+ }
532
+
533
+ try
534
+ {
535
+ Hot.echo (content);
536
+ }
537
+ catch (ex)
538
+ {
539
+ Hot.echo ("");
540
+ }
541
+ }
542
+
543
+ function createTestElement (foundStr)
544
+ {
545
+ let testElm = null;
546
+
547
+ try
548
+ {
549
+ let obj = foundStr;
550
+
551
+ if (typeof (foundStr) === "string")
552
+ obj = JSON.parse (foundStr);
553
+
554
+ if (typeof (obj) === "string")
555
+ testElm = new Hot.HotTestElement (obj);
556
+
557
+ if (obj instanceof Array)
558
+ testElm = new Hot.HotTestElement (obj[0], obj[1], obj[2]);
559
+
560
+ if (obj["name"] != null)
561
+ testElm = new Hot.HotTestElement (obj);
562
+
563
+ if (Hot.CurrentPage.testElements[testElm.name] != null)
564
+ throw new Error (\`Test element \${testElm.name} already exists!\`);
565
+
566
+ Hot.CurrentPage.addTestElement (testElm);
567
+ }
568
+ catch (ex)
569
+ {
570
+ throw new Error (
571
+ \`Error processing test element \${foundStr} in \${Hot.CurrentPage.name}. Error: \${ex.message}\`
572
+ );
573
+ }
574
+
575
+ return (testElm);
576
+ }
577
+
578
+ async function runContent (CurrentHotFile)
579
+ {\n`;
580
+ executionContent += output;
581
+ executionContent += `
582
+ }
583
+
584
+ return (runContent (PassedHotFile).then (() =>
585
+ {
586
+ return ({
587
+ hot: Hot,
588
+ output: Hot.Output,
589
+ data: JSON.stringify (Hot.Data)
590
+ });
591
+ }));`;
592
+
593
+ /// @fixme Prior to execution compile any TypeScript and make it ES5 compatible.
594
+ let func: Function = new Function (executionContent);
595
+ returnedOutput = await func.apply (this, [Hot, this]);
596
+ }
597
+ catch (ex)
598
+ {
599
+ if (ex instanceof SyntaxError)
600
+ {
601
+ /// @fixme Put what's in the content variable into a prev content variable?
602
+ /// Then once there's no longer any syntax errors being thrown, execute the
603
+ /// code? This would also require saving any HTML outside of the *> and <*
604
+ /// then echoing it out. The throw below would have to be removed as well.
605
+ throw ex;
606
+ }
607
+ else
608
+ throw ex;
609
+ }
610
+
611
+ Hot.Data = returnedOutput.hot.Data;
612
+ let finalOutput: string = returnedOutput.output;
613
+ Hot.Output = "";
614
+
615
+ return (finalOutput);
616
+ }
617
+ }