hotstaq 0.5.3
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.
- package/.dockerignore +123 -0
- package/.eslintignore +17 -0
- package/.eslintrc.js +11 -0
- package/.vscode/launch.json +201 -0
- package/.vscode/settings.json +2 -0
- package/.vscode/tasks.json +88 -0
- package/CONTRIBUTING.md +157 -0
- package/LICENSE +21 -0
- package/README.md +128 -0
- package/bin/hotstaq +3 -0
- package/bin/hotstaq.cmd +1 -0
- package/build/src/Hot.d.ts +167 -0
- package/build/src/Hot.d.ts.map +1 -0
- package/build/src/Hot.js +365 -0
- package/build/src/Hot.js.map +1 -0
- package/build/src/HotAPI.d.ts +137 -0
- package/build/src/HotAPI.d.ts.map +1 -0
- package/build/src/HotAPI.js +353 -0
- package/build/src/HotAPI.js.map +1 -0
- package/build/src/HotAgentAPI.d.ts +22 -0
- package/build/src/HotAgentAPI.d.ts.map +1 -0
- package/build/src/HotAgentAPI.js +85 -0
- package/build/src/HotAgentAPI.js.map +1 -0
- package/build/src/HotAgentRoute.d.ts +17 -0
- package/build/src/HotAgentRoute.d.ts.map +1 -0
- package/build/src/HotAgentRoute.js +109 -0
- package/build/src/HotAgentRoute.js.map +1 -0
- package/build/src/HotBuilder.d.ts +52 -0
- package/build/src/HotBuilder.d.ts.map +1 -0
- package/build/src/HotBuilder.js +242 -0
- package/build/src/HotBuilder.js.map +1 -0
- package/build/src/HotClient.d.ts +31 -0
- package/build/src/HotClient.d.ts.map +1 -0
- package/build/src/HotClient.js +19 -0
- package/build/src/HotClient.js.map +1 -0
- package/build/src/HotComponent.d.ts +118 -0
- package/build/src/HotComponent.d.ts.map +1 -0
- package/build/src/HotComponent.js +89 -0
- package/build/src/HotComponent.js.map +1 -0
- package/build/src/HotCreator.d.ts +88 -0
- package/build/src/HotCreator.d.ts.map +1 -0
- package/build/src/HotCreator.js +445 -0
- package/build/src/HotCreator.js.map +1 -0
- package/build/src/HotDB.d.ts +69 -0
- package/build/src/HotDB.d.ts.map +1 -0
- package/build/src/HotDB.js +29 -0
- package/build/src/HotDB.js.map +1 -0
- package/build/src/HotDBConnectionInterface.d.ts +40 -0
- package/build/src/HotDBConnectionInterface.d.ts.map +1 -0
- package/build/src/HotDBConnectionInterface.js +3 -0
- package/build/src/HotDBConnectionInterface.js.map +1 -0
- package/build/src/HotFile.d.ts +134 -0
- package/build/src/HotFile.d.ts.map +1 -0
- package/build/src/HotFile.js +454 -0
- package/build/src/HotFile.js.map +1 -0
- package/build/src/HotGenerator.d.ts +80 -0
- package/build/src/HotGenerator.d.ts.map +1 -0
- package/build/src/HotGenerator.js +342 -0
- package/build/src/HotGenerator.js.map +1 -0
- package/build/src/HotHTTPServer.d.ts +162 -0
- package/build/src/HotHTTPServer.d.ts.map +1 -0
- package/build/src/HotHTTPServer.js +863 -0
- package/build/src/HotHTTPServer.js.map +1 -0
- package/build/src/HotIO.d.ts +47 -0
- package/build/src/HotIO.d.ts.map +1 -0
- package/build/src/HotIO.js +232 -0
- package/build/src/HotIO.js.map +1 -0
- package/build/src/HotLog.d.ts +60 -0
- package/build/src/HotLog.d.ts.map +1 -0
- package/build/src/HotLog.js +126 -0
- package/build/src/HotLog.js.map +1 -0
- package/build/src/HotPage.d.ts +125 -0
- package/build/src/HotPage.d.ts.map +1 -0
- package/build/src/HotPage.js +178 -0
- package/build/src/HotPage.js.map +1 -0
- package/build/src/HotRoute.d.ts +82 -0
- package/build/src/HotRoute.d.ts.map +1 -0
- package/build/src/HotRoute.js +83 -0
- package/build/src/HotRoute.js.map +1 -0
- package/build/src/HotRouteMethod.d.ts +129 -0
- package/build/src/HotRouteMethod.d.ts.map +1 -0
- package/build/src/HotRouteMethod.js +84 -0
- package/build/src/HotRouteMethod.js.map +1 -0
- package/build/src/HotServer.d.ts +152 -0
- package/build/src/HotServer.d.ts.map +1 -0
- package/build/src/HotServer.js +109 -0
- package/build/src/HotServer.js.map +1 -0
- package/build/src/HotSetAsWeb.d.ts +2 -0
- package/build/src/HotSetAsWeb.d.ts.map +1 -0
- package/build/src/HotSetAsWeb.js +5 -0
- package/build/src/HotSetAsWeb.js.map +1 -0
- package/build/src/HotStaq.d.ts +603 -0
- package/build/src/HotStaq.d.ts.map +1 -0
- package/build/src/HotStaq.js +1260 -0
- package/build/src/HotStaq.js.map +1 -0
- package/build/src/HotStaqWeb.d.ts +18 -0
- package/build/src/HotStaqWeb.d.ts.map +1 -0
- package/build/src/HotStaqWeb.js +44 -0
- package/build/src/HotStaqWeb.js.map +1 -0
- package/build/src/HotTestDriver.d.ts +63 -0
- package/build/src/HotTestDriver.d.ts.map +1 -0
- package/build/src/HotTestDriver.js +187 -0
- package/build/src/HotTestDriver.js.map +1 -0
- package/build/src/HotTestElement.d.ts +71 -0
- package/build/src/HotTestElement.d.ts.map +1 -0
- package/build/src/HotTestElement.js +37 -0
- package/build/src/HotTestElement.js.map +1 -0
- package/build/src/HotTestMap.d.ts +83 -0
- package/build/src/HotTestMap.d.ts.map +1 -0
- package/build/src/HotTestMap.js +58 -0
- package/build/src/HotTestMap.js.map +1 -0
- package/build/src/HotTestSeleniumDriver.d.ts +86 -0
- package/build/src/HotTestSeleniumDriver.d.ts.map +1 -0
- package/build/src/HotTestSeleniumDriver.js +400 -0
- package/build/src/HotTestSeleniumDriver.js.map +1 -0
- package/build/src/HotTester.d.ts +188 -0
- package/build/src/HotTester.d.ts.map +1 -0
- package/build/src/HotTester.js +622 -0
- package/build/src/HotTester.js.map +1 -0
- package/build/src/HotTesterAPI.d.ts +15 -0
- package/build/src/HotTesterAPI.d.ts.map +1 -0
- package/build/src/HotTesterAPI.js +161 -0
- package/build/src/HotTesterAPI.js.map +1 -0
- package/build/src/HotTesterMocha.d.ts +50 -0
- package/build/src/HotTesterMocha.d.ts.map +1 -0
- package/build/src/HotTesterMocha.js +205 -0
- package/build/src/HotTesterMocha.js.map +1 -0
- package/build/src/HotTesterMochaSelenium.d.ts +70 -0
- package/build/src/HotTesterMochaSelenium.d.ts.map +1 -0
- package/build/src/HotTesterMochaSelenium.js +257 -0
- package/build/src/HotTesterMochaSelenium.js.map +1 -0
- package/build/src/HotTesterServer.d.ts +114 -0
- package/build/src/HotTesterServer.d.ts.map +1 -0
- package/build/src/HotTesterServer.js +575 -0
- package/build/src/HotTesterServer.js.map +1 -0
- package/build/src/api copy.d.ts +2 -0
- package/build/src/api copy.d.ts.map +1 -0
- package/build/src/api copy.js +153 -0
- package/build/src/api copy.js.map +1 -0
- package/build/src/api-web.d.ts +2 -0
- package/build/src/api-web.d.ts.map +1 -0
- package/build/src/api-web.js +45 -0
- package/build/src/api-web.js.map +1 -0
- package/build/src/api.d.ts +33 -0
- package/build/src/api.d.ts.map +1 -0
- package/build/src/api.js +78 -0
- package/build/src/api.js.map +1 -0
- package/build/src/cli.d.ts +2 -0
- package/build/src/cli.d.ts.map +1 -0
- package/build/src/cli.js +1040 -0
- package/build/src/cli.js.map +1 -0
- package/build/src/schemas/HotDBInflux.d.ts +63 -0
- package/build/src/schemas/HotDBInflux.d.ts.map +1 -0
- package/build/src/schemas/HotDBInflux.js +239 -0
- package/build/src/schemas/HotDBInflux.js.map +1 -0
- package/build/src/schemas/HotDBMigration.d.ts +19 -0
- package/build/src/schemas/HotDBMigration.d.ts.map +1 -0
- package/build/src/schemas/HotDBMigration.js +15 -0
- package/build/src/schemas/HotDBMigration.js.map +1 -0
- package/build/src/schemas/HotDBMySQL.d.ts +65 -0
- package/build/src/schemas/HotDBMySQL.d.ts.map +1 -0
- package/build/src/schemas/HotDBMySQL.js +387 -0
- package/build/src/schemas/HotDBMySQL.js.map +1 -0
- package/build/src/schemas/HotDBSchema.d.ts +15 -0
- package/build/src/schemas/HotDBSchema.d.ts.map +1 -0
- package/build/src/schemas/HotDBSchema.js +19 -0
- package/build/src/schemas/HotDBSchema.js.map +1 -0
- package/build/src/schemas/influx/InfluxSchema.d.ts +14 -0
- package/build/src/schemas/influx/InfluxSchema.d.ts.map +1 -0
- package/build/src/schemas/influx/InfluxSchema.js +33 -0
- package/build/src/schemas/influx/InfluxSchema.js.map +1 -0
- package/build/src/schemas/mysql/MySQLSchema.d.ts +39 -0
- package/build/src/schemas/mysql/MySQLSchema.d.ts.map +1 -0
- package/build/src/schemas/mysql/MySQLSchema.js +151 -0
- package/build/src/schemas/mysql/MySQLSchema.js.map +1 -0
- package/build/src/schemas/mysql/MySQLSchemaField.d.ts +168 -0
- package/build/src/schemas/mysql/MySQLSchemaField.d.ts.map +1 -0
- package/build/src/schemas/mysql/MySQLSchemaField.js +260 -0
- package/build/src/schemas/mysql/MySQLSchemaField.js.map +1 -0
- package/build/src/schemas/mysql/MySQLSchemaTable.d.ts +49 -0
- package/build/src/schemas/mysql/MySQLSchemaTable.d.ts.map +1 -0
- package/build/src/schemas/mysql/MySQLSchemaTable.js +310 -0
- package/build/src/schemas/mysql/MySQLSchemaTable.js.map +1 -0
- package/build-web/HotStaq.js +2 -0
- package/build-web/HotStaq.min.js +119 -0
- package/build-web/HotStaqTests_HelloWorldAPI.js +133 -0
- package/builder/docker/Dockerfile.linux.gen +42 -0
- package/builder/docker/README.md +36 -0
- package/builder/docker/app/start.sh +8 -0
- package/builder/docker/dockerignore +3 -0
- package/builder/docker/scripts/build.bat +11 -0
- package/builder/docker/scripts/build.sh +11 -0
- package/builder/docker/scripts/start-app.bat +7 -0
- package/builder/docker/scripts/start-app.sh +7 -0
- package/builder/docker/scripts/stop-app.bat +5 -0
- package/builder/docker/scripts/stop-app.sh +5 -0
- package/builder/docker-compose/docker-compose.gen.yaml +41 -0
- package/builder/docker-compose/env-skeleton +4 -0
- package/creator/project/.vscode/launch.json +59 -0
- package/creator/project/README.md +20 -0
- package/creator/project/gitignore +118 -0
- package/creator/project/npmignore +118 -0
- package/creator/public/api-test.hott +28 -0
- package/creator/public/index.hott +12 -0
- package/creator/ts/src/AppAPI.ts +30 -0
- package/creator/ts/src/HelloWorld.ts +39 -0
- package/creator/ts/src/WebExport.ts +7 -0
- package/creator/ts/tsconfig-web.json +73 -0
- package/creator/ts/tsconfig.json +73 -0
- package/creator/ts/webpack-api.config.js +57 -0
- package/dbstart.sh +19 -0
- package/dbstop.sh +4 -0
- package/docs/.nojekyll +1 -0
- package/docs/README.md +130 -0
- package/docs/classes/Hot.md +477 -0
- package/docs/classes/HotAPI.md +369 -0
- package/docs/classes/HotClient.md +95 -0
- package/docs/classes/HotComponent.md +279 -0
- package/docs/classes/HotDB.md +247 -0
- package/docs/classes/HotDBInflux.md +404 -0
- package/docs/classes/HotDBMigration.md +80 -0
- package/docs/classes/HotDBMySQL.md +310 -0
- package/docs/classes/HotDBSchema.md +51 -0
- package/docs/classes/HotFile.md +353 -0
- package/docs/classes/HotHTTPServer.md +700 -0
- package/docs/classes/HotLog.md +162 -0
- package/docs/classes/HotPage.md +357 -0
- package/docs/classes/HotRoute.md +312 -0
- package/docs/classes/HotRouteMethod.md +271 -0
- package/docs/classes/HotServer.md +311 -0
- package/docs/classes/HotStaq.md +1155 -0
- package/docs/classes/HotTestDestination.md +58 -0
- package/docs/classes/HotTestDriver.md +332 -0
- package/docs/classes/HotTestElement.md +88 -0
- package/docs/classes/HotTestElementOptions.md +71 -0
- package/docs/classes/HotTestMap.md +92 -0
- package/docs/classes/HotTestSeleniumDriver.md +542 -0
- package/docs/classes/HotTester.md +653 -0
- package/docs/classes/HotTesterAPI.md +493 -0
- package/docs/classes/HotTesterMocha.md +843 -0
- package/docs/classes/HotTesterMochaSelenium.md +896 -0
- package/docs/classes/HotTesterServer.md +633 -0
- package/docs/classes/InfluxSchema.md +74 -0
- package/docs/classes/MySQLSchema.md +199 -0
- package/docs/classes/MySQLSchemaField.md +330 -0
- package/docs/classes/MySQLSchemaTable.md +176 -0
- package/docs/enums/ConnectionStatus.md +43 -0
- package/docs/enums/DeveloperMode.md +38 -0
- package/docs/enums/EventExecutionType.md +43 -0
- package/docs/enums/HTTPMethod.md +32 -0
- package/docs/enums/HotDBGenerationType.md +30 -0
- package/docs/enums/HotLogLevel.md +88 -0
- package/docs/interfaces/HotDBConnectionInterface.md +116 -0
- package/docs/interfaces/HotDestination.md +62 -0
- package/docs/interfaces/HotSite.md +187 -0
- package/docs/interfaces/HotSiteMapPath.md +37 -0
- package/docs/interfaces/HotSiteRoute.md +79 -0
- package/docs/interfaces/HotStartOptions.md +115 -0
- package/docs/interfaces/HotTestPage.md +44 -0
- package/docs/interfaces/HotTestStop.md +62 -0
- package/docs/interfaces/IHotComponent.md +135 -0
- package/docs/interfaces/IHotStaq.md +118 -0
- package/docs/interfaces/IHotTestElement.md +54 -0
- package/docs/interfaces/IHotTestElementOptions.md +43 -0
- package/docs/interfaces/MySQLResults.md +43 -0
- package/docs/interfaces/MySQLSchemaFieldResult.md +75 -0
- package/docs/modules.md +182 -0
- package/package.json +65 -0
- package/selenium-start.sh +7 -0
- package/selenium-stop.sh +3 -0
- package/src/Hot.ts +319 -0
- package/src/HotAPI.ts +386 -0
- package/src/HotAgentAPI.ts +43 -0
- package/src/HotAgentRoute.ts +44 -0
- package/src/HotBuilder.ts +221 -0
- package/src/HotClient.ts +40 -0
- package/src/HotComponent.ts +158 -0
- package/src/HotCreator.ts +470 -0
- package/src/HotDB.ts +79 -0
- package/src/HotDBConnectionInterface.ts +40 -0
- package/src/HotFile.ts +617 -0
- package/src/HotGenerator.ts +446 -0
- package/src/HotHTTPServer.ts +954 -0
- package/src/HotIO.ts +160 -0
- package/src/HotLog.ts +158 -0
- package/src/HotPage.ts +206 -0
- package/src/HotRoute.ts +137 -0
- package/src/HotRouteMethod.ts +216 -0
- package/src/HotServer.ts +211 -0
- package/src/HotSetAsWeb.ts +3 -0
- package/src/HotStaq.ts +1881 -0
- package/src/HotTestDriver.ts +171 -0
- package/src/HotTestElement.ts +97 -0
- package/src/HotTestMap.ts +130 -0
- package/src/HotTestSeleniumDriver.ts +381 -0
- package/src/HotTester.ts +696 -0
- package/src/HotTesterAPI.ts +126 -0
- package/src/HotTesterMocha.ts +133 -0
- package/src/HotTesterMochaSelenium.ts +189 -0
- package/src/HotTesterServer.ts +551 -0
- package/src/api-web.ts +48 -0
- package/src/api.ts +103 -0
- package/src/cli.ts +1225 -0
- package/src/schemas/HotDBInflux.ts +211 -0
- package/src/schemas/HotDBMigration.ts +24 -0
- package/src/schemas/HotDBMySQL.ts +312 -0
- package/src/schemas/HotDBSchema.ts +21 -0
- package/src/schemas/influx/InfluxSchema.ts +19 -0
- package/src/schemas/mysql/MySQLSchema.ts +90 -0
- package/src/schemas/mysql/MySQLSchemaField.ts +408 -0
- package/src/schemas/mysql/MySQLSchemaTable.ts +353 -0
- package/temp/HotStaqWeb.ts +59 -0
- package/tsconfig-generator.json +17 -0
- package/tsconfig-web.json +74 -0
- package/tsconfig.json +73 -0
- package/webpack.config.generator.js +41 -0
- package/webpack.config.js +53 -0
- package/webpack.config.tests.js +56 -0
|
@@ -0,0 +1,446 @@
|
|
|
1
|
+
import * as ppath from "path";
|
|
2
|
+
import { HotIO } from "./HotIO";
|
|
3
|
+
|
|
4
|
+
import { HotStaq, HotSite } from "./HotStaq";
|
|
5
|
+
import { HotLog } from "./HotLog";
|
|
6
|
+
import { HotHTTPServer } from "./HotHTTPServer";
|
|
7
|
+
import { APItoLoad, HotAPI } from "./HotAPI";
|
|
8
|
+
import { HotRoute } from "./HotRoute";
|
|
9
|
+
import { HotRouteMethod } from "./HotRouteMethod";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Generates stuff like API
|
|
13
|
+
*/
|
|
14
|
+
export class HotGenerator
|
|
15
|
+
{
|
|
16
|
+
/**
|
|
17
|
+
* The HotSites to build from.
|
|
18
|
+
*/
|
|
19
|
+
hotsites: HotSite[];
|
|
20
|
+
/**
|
|
21
|
+
* Generate the API for the client web browser.
|
|
22
|
+
*/
|
|
23
|
+
api: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* The type of code to generate. Can be:
|
|
26
|
+
* * typescript
|
|
27
|
+
* * javascript
|
|
28
|
+
*/
|
|
29
|
+
generateType: string;
|
|
30
|
+
/**
|
|
31
|
+
* Compile the typescript using Webpack.
|
|
32
|
+
*/
|
|
33
|
+
compileTS: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Specify a custom tsconfig path.
|
|
36
|
+
*/
|
|
37
|
+
tsconfigPath: string;
|
|
38
|
+
/**
|
|
39
|
+
* Specify a custom webpack config path.
|
|
40
|
+
*/
|
|
41
|
+
webpackConfigPath: string;
|
|
42
|
+
/**
|
|
43
|
+
* Optimize the compiled JavaScript.
|
|
44
|
+
*/
|
|
45
|
+
optimizeJS: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* The logger.
|
|
48
|
+
*/
|
|
49
|
+
logger: HotLog;
|
|
50
|
+
/**
|
|
51
|
+
* The output directory.
|
|
52
|
+
*/
|
|
53
|
+
outputDir: string;
|
|
54
|
+
|
|
55
|
+
constructor (logger: HotLog)
|
|
56
|
+
{
|
|
57
|
+
this.hotsites = [];
|
|
58
|
+
this.api = true;
|
|
59
|
+
this.generateType = "javascript";
|
|
60
|
+
this.compileTS = true;
|
|
61
|
+
this.tsconfigPath = ppath.normalize(`${__dirname}/../../tsconfig-generator.json`);
|
|
62
|
+
this.webpackConfigPath = ppath.normalize(`${__dirname}/../../webpack.config.generator.js`);
|
|
63
|
+
this.optimizeJS = false;
|
|
64
|
+
this.logger = logger;
|
|
65
|
+
this.outputDir = ppath.normalize (`${process.cwd ()}/build-web/`);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Get the base url from the HotSite.
|
|
70
|
+
*/
|
|
71
|
+
getBaseUrlFromHotSite (processor: HotStaq, apiServer: HotHTTPServer,
|
|
72
|
+
loadedAPI: APItoLoad, baseAPIUrl: string = ""): string
|
|
73
|
+
{
|
|
74
|
+
if (baseAPIUrl === "")
|
|
75
|
+
baseAPIUrl = `http://127.0.0.1:${apiServer.ports.http}`;
|
|
76
|
+
|
|
77
|
+
let foundAPIUrl: string = baseAPIUrl;
|
|
78
|
+
|
|
79
|
+
// Attempt to find the base url from the HotSite's API.
|
|
80
|
+
if (processor.hotSite != null)
|
|
81
|
+
{
|
|
82
|
+
if (processor.hotSite.apis != null)
|
|
83
|
+
{
|
|
84
|
+
for (let key in processor.hotSite.apis)
|
|
85
|
+
{
|
|
86
|
+
let tempAPI = processor.hotSite.apis[key];
|
|
87
|
+
|
|
88
|
+
if (tempAPI.apiName != null)
|
|
89
|
+
{
|
|
90
|
+
if (tempAPI.apiName === loadedAPI.exportedClassName)
|
|
91
|
+
{
|
|
92
|
+
if (tempAPI.url != null)
|
|
93
|
+
foundAPIUrl = tempAPI.url;
|
|
94
|
+
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return (foundAPIUrl);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Start the API server.
|
|
107
|
+
*/
|
|
108
|
+
protected async startAPIServer (processor: HotStaq, loadedAPI: APItoLoad): Promise<{ api: HotAPI; baseAPIUrl: string; }>
|
|
109
|
+
{
|
|
110
|
+
let server: HotHTTPServer = new HotHTTPServer (processor);
|
|
111
|
+
let baseAPIUrl: string = this.getBaseUrlFromHotSite (processor, server, loadedAPI);
|
|
112
|
+
|
|
113
|
+
process.chdir (process.cwd ());
|
|
114
|
+
let foundModulePath = require.resolve (loadedAPI.path, { paths: [process.cwd ()] });
|
|
115
|
+
let apiJS = require (foundModulePath);
|
|
116
|
+
let apiClass: any = apiJS[loadedAPI.exportedClassName];
|
|
117
|
+
let api: HotAPI = new apiClass (baseAPIUrl, server);
|
|
118
|
+
|
|
119
|
+
server.logger.verbose (`Loaded API class: ${loadedAPI.exportedClassName}`);
|
|
120
|
+
|
|
121
|
+
server.processor.api = api;
|
|
122
|
+
server.api = api;
|
|
123
|
+
|
|
124
|
+
// Add this since this is an API server only.
|
|
125
|
+
server.addRoute ("/", async (req: any, res: any) =>
|
|
126
|
+
{
|
|
127
|
+
res.json ({ "status": "ok" });
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
//server.serverType = "API Server";
|
|
131
|
+
//await server.listen ();
|
|
132
|
+
|
|
133
|
+
return ({ api: api, baseAPIUrl: baseAPIUrl });
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Generate the API.
|
|
138
|
+
*
|
|
139
|
+
* @fixme Needs tests!
|
|
140
|
+
*/
|
|
141
|
+
async generateAPI (processor: HotStaq, apis: { [name: string]: APItoLoad; }): Promise<void>
|
|
142
|
+
{
|
|
143
|
+
if (this.api === true)
|
|
144
|
+
{
|
|
145
|
+
let outputDir: string = ppath.normalize (`${this.outputDir}/`);
|
|
146
|
+
|
|
147
|
+
if (await HotIO.exists (outputDir) === false)
|
|
148
|
+
await HotIO.mkdir (outputDir);
|
|
149
|
+
|
|
150
|
+
for (let iIdx = 0; iIdx < this.hotsites.length; iIdx++)
|
|
151
|
+
{
|
|
152
|
+
const hotsite: HotSite = this.hotsites[iIdx];
|
|
153
|
+
|
|
154
|
+
if (hotsite.apis === null)
|
|
155
|
+
{
|
|
156
|
+
this.logger.info (`HotSite "${hotsite.name}" contains no APIs. Skipping...`);
|
|
157
|
+
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
let numAPIs: number = Object.keys (hotsite.apis).length;
|
|
162
|
+
|
|
163
|
+
if (numAPIs < 1)
|
|
164
|
+
{
|
|
165
|
+
this.logger.info (`HotSite "${hotsite.name}" contains no APIs. Skipping...`);
|
|
166
|
+
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
for (let key in hotsite.apis)
|
|
171
|
+
{
|
|
172
|
+
let loadedAPI = apis[key];
|
|
173
|
+
let libraryName: string = hotsite.apis[key].libraryName;
|
|
174
|
+
let apiName: string = hotsite.apis[key].apiName;
|
|
175
|
+
|
|
176
|
+
if (libraryName == null)
|
|
177
|
+
{
|
|
178
|
+
this.logger.info (`Web API "${key}" from HotSite "${hotsite.name}" does not have a libraryName!`);
|
|
179
|
+
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (apiName == null)
|
|
184
|
+
{
|
|
185
|
+
this.logger.info (`Web API "${key}" from HotSite "${hotsite.name}" does not have an apiName!`);
|
|
186
|
+
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
this.logger.info (`Generating Web API "${key}" from HotSite "${hotsite.name}"...`);
|
|
191
|
+
|
|
192
|
+
let serverResult = await this.startAPIServer (processor, loadedAPI);
|
|
193
|
+
let apiFileContent: string = "";
|
|
194
|
+
|
|
195
|
+
for (let key2 in serverResult.api.routes)
|
|
196
|
+
{
|
|
197
|
+
let route: HotRoute = serverResult.api.routes[key2];
|
|
198
|
+
let routeName: string = route.route;
|
|
199
|
+
|
|
200
|
+
apiFileContent += this.getContent (this.generateType, "header",
|
|
201
|
+
{ routeName: routeName, baseAPIUrl: serverResult.baseAPIUrl,
|
|
202
|
+
libraryName: libraryName, apiName: apiName });
|
|
203
|
+
|
|
204
|
+
for (let iJdx = 0; iJdx < route.methods.length; iJdx++)
|
|
205
|
+
{
|
|
206
|
+
let method: HotRouteMethod = route.methods[iJdx];
|
|
207
|
+
let methodName: string = method.name;
|
|
208
|
+
|
|
209
|
+
apiFileContent += this.getContent (this.generateType, "function",
|
|
210
|
+
{ methodName: methodName, routeVersion: route.version,
|
|
211
|
+
routeName: routeName, methodType: method.type.toUpperCase (),
|
|
212
|
+
libraryName: libraryName, apiName: apiName });
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
apiFileContent += this.getContent (this.generateType, "footer",
|
|
216
|
+
{ libraryName: libraryName, apiName: apiName, routeName: routeName });
|
|
217
|
+
|
|
218
|
+
const outputFile: string = ppath.normalize (`${outputDir}/${libraryName}_${apiName}`);
|
|
219
|
+
let outputFileExtension: string = ".ts";
|
|
220
|
+
|
|
221
|
+
if (this.generateType === "javascript")
|
|
222
|
+
{
|
|
223
|
+
this.compileTS = false;
|
|
224
|
+
outputFileExtension = ".js";
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
await HotIO.writeTextFile (`${outputFile}${outputFileExtension}`, apiFileContent);
|
|
228
|
+
|
|
229
|
+
if (this.compileTS === true)
|
|
230
|
+
{
|
|
231
|
+
this.logger.info (`Compiling TypeScript...`);
|
|
232
|
+
|
|
233
|
+
const timestamp: string = Date.now ().toString ();
|
|
234
|
+
let tsconfigObj: any = JSON.parse (await HotIO.readTextFile (this.tsconfigPath));
|
|
235
|
+
|
|
236
|
+
tsconfigObj.compilerOptions.outDir = outputDir;
|
|
237
|
+
tsconfigObj.files = [`${outputFile}${outputFileExtension}`];
|
|
238
|
+
|
|
239
|
+
const temptsconfig: string = ppath.normalize (`${outputDir}/tsconfig-generator-temp-${timestamp}.json`);
|
|
240
|
+
await HotIO.writeTextFile (temptsconfig, JSON.stringify (tsconfigObj, null, 4));
|
|
241
|
+
|
|
242
|
+
let content: string = await HotIO.readTextFile (this.webpackConfigPath);
|
|
243
|
+
const tempWebpackConfig: string = ppath.normalize (
|
|
244
|
+
`${outputDir}/webpack.config.generator-temp-${timestamp}.js`);
|
|
245
|
+
|
|
246
|
+
content = HotStaq.replaceKey (content, "WEBPACK_VERSION", "1.0.0");
|
|
247
|
+
content = HotStaq.replaceKey (content, "WEBPACK_ENTRY", `${outputFile}${outputFileExtension}`);
|
|
248
|
+
content = HotStaq.replaceKey (content, "WEBPACK_TSCONFIG", temptsconfig);
|
|
249
|
+
content = HotStaq.replaceKey (content, "WEBPACK_IGNORE_PLUGINS_REGEX", "null");
|
|
250
|
+
content = HotStaq.replaceKey (content, "WEBPACK_OUTPUT_FILE", `${libraryName}_${apiName}.js`);
|
|
251
|
+
content = HotStaq.replaceKey (content, "WEBPACK_OUTPUT_PATH", outputDir);
|
|
252
|
+
content = HotStaq.replaceKey (content, "WEBPACK_LIBRARY_NAME", `${libraryName}_${apiName}`);
|
|
253
|
+
|
|
254
|
+
await HotIO.writeTextFile (tempWebpackConfig, content);
|
|
255
|
+
|
|
256
|
+
try
|
|
257
|
+
{
|
|
258
|
+
// Build the TypeScript so it can run in a web browser.
|
|
259
|
+
await HotIO.exec (`cd ${outputDir} && webpack --mode=production -c ${tempWebpackConfig}`);
|
|
260
|
+
}
|
|
261
|
+
catch (ex)
|
|
262
|
+
{
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
await HotIO.rm (temptsconfig);
|
|
266
|
+
await HotIO.rm (tempWebpackConfig);
|
|
267
|
+
|
|
268
|
+
this.logger.info (`Finished compiling TypeScript...`);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
if (this.optimizeJS === true)
|
|
272
|
+
{
|
|
273
|
+
this.logger.info (`Optimizing JavaScript...`);
|
|
274
|
+
await HotIO.exec (`npx google-closure-compiler --js=${outputFile}.js --js_output_file=${outputFile}.min.js`);
|
|
275
|
+
this.logger.info (`Finished optimizing JavaScript...`);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
this.logger.info (`Finished generating Web API "${key}" from HotSite "${hotsite.name}"...`);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Get the content.
|
|
287
|
+
*/
|
|
288
|
+
getContent (type: string, contentPart: string, data: any): string
|
|
289
|
+
{
|
|
290
|
+
let content = "";
|
|
291
|
+
|
|
292
|
+
if (type === "javascript")
|
|
293
|
+
content = this.getJavaScriptContent (contentPart, data);
|
|
294
|
+
|
|
295
|
+
if (type === "typescript")
|
|
296
|
+
content = this.getTypeScriptContent (contentPart, data);
|
|
297
|
+
|
|
298
|
+
return (content);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Get the Typescript content.
|
|
303
|
+
*/
|
|
304
|
+
getTypeScriptContent (contentPart: string, data: any): string
|
|
305
|
+
{
|
|
306
|
+
let content = "";
|
|
307
|
+
|
|
308
|
+
if (contentPart === "header")
|
|
309
|
+
{
|
|
310
|
+
content = `
|
|
311
|
+
import { HotAPI } from "HotStaq";
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* The ${data.routeName} API route.
|
|
315
|
+
*/
|
|
316
|
+
export class ${data.routeName} extends HotAPI
|
|
317
|
+
{
|
|
318
|
+
/**
|
|
319
|
+
* The base url to make calls to.
|
|
320
|
+
*/
|
|
321
|
+
baseUrl: string;
|
|
322
|
+
|
|
323
|
+
constructor (baseUrl: string = "${data.baseAPIUrl}")
|
|
324
|
+
{
|
|
325
|
+
this.baseUrl = baseUrl;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
`;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
if (contentPart === "function")
|
|
332
|
+
{
|
|
333
|
+
content = `
|
|
334
|
+
/**
|
|
335
|
+
* The ${data.methodName} method.
|
|
336
|
+
*/
|
|
337
|
+
async ${data.methodName} (jsonObj: any): Promise<any>
|
|
338
|
+
{
|
|
339
|
+
const response = await fetch (\`\${this.baseUrl}/${data.routeVersion}/${data.route}/${data.methodName}\`, {
|
|
340
|
+
"method": "${data.methodType}",
|
|
341
|
+
"headers": {
|
|
342
|
+
"Accept": "application/json",
|
|
343
|
+
"Content-Type": "application/json"
|
|
344
|
+
},
|
|
345
|
+
body: JSON.stringify (jsonObj)
|
|
346
|
+
});
|
|
347
|
+
const result = response.json ();
|
|
348
|
+
|
|
349
|
+
return (result);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
`;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
if (contentPart === "footer")
|
|
356
|
+
{
|
|
357
|
+
content = `
|
|
358
|
+
}
|
|
359
|
+
`;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
return (content);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Get the JavaScript content.
|
|
367
|
+
*/
|
|
368
|
+
getJavaScriptContent (contentPart: string, data: any): string
|
|
369
|
+
{
|
|
370
|
+
let content = "";
|
|
371
|
+
|
|
372
|
+
if (contentPart === "header")
|
|
373
|
+
{
|
|
374
|
+
content =
|
|
375
|
+
`if (typeof (${data.libraryName}) === "undefined")
|
|
376
|
+
${data.libraryName} = {};
|
|
377
|
+
|
|
378
|
+
var HotAPIGlobal = HotAPI;
|
|
379
|
+
|
|
380
|
+
if (typeof (HotAPIGlobal) === "undefined")
|
|
381
|
+
HotAPIGlobal = window.HotAPI;
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* The ${data.routeName} API route.
|
|
385
|
+
*/
|
|
386
|
+
class ${data.routeName} extends HotAPIGlobal
|
|
387
|
+
{
|
|
388
|
+
constructor (baseUrl, connection, db)
|
|
389
|
+
{
|
|
390
|
+
if (baseUrl == null)
|
|
391
|
+
baseUrl = "${data.baseAPIUrl}";
|
|
392
|
+
|
|
393
|
+
super (baseUrl, connection, db);
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* The base url to make calls to.
|
|
397
|
+
*/
|
|
398
|
+
this.baseUrl = baseUrl;
|
|
399
|
+
}
|
|
400
|
+
`;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
if (contentPart === "function")
|
|
404
|
+
{
|
|
405
|
+
content = `
|
|
406
|
+
/**
|
|
407
|
+
* The ${data.methodName} method.
|
|
408
|
+
*/
|
|
409
|
+
${data.methodName} (jsonObj)
|
|
410
|
+
{
|
|
411
|
+
var promise = new Promise (function (resolve, reject)
|
|
412
|
+
{
|
|
413
|
+
fetch (\`\${this.baseUrl}/${data.routeVersion}/${data.routeName}/${data.methodName}\`, {
|
|
414
|
+
"method": "${data.methodType}",
|
|
415
|
+
"headers": {
|
|
416
|
+
"Accept": "application/json",
|
|
417
|
+
"Content-Type": "application/json"
|
|
418
|
+
},
|
|
419
|
+
body: JSON.stringify (jsonObj)
|
|
420
|
+
}).then (function (response)
|
|
421
|
+
{
|
|
422
|
+
var result = response.json ();
|
|
423
|
+
|
|
424
|
+
resolve (result);
|
|
425
|
+
});
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
return (promise);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
`;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
if (contentPart === "footer")
|
|
435
|
+
{
|
|
436
|
+
content =
|
|
437
|
+
`
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
${data.libraryName}.${data.apiName} = ${data.routeName};
|
|
441
|
+
`;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
return (content);
|
|
445
|
+
}
|
|
446
|
+
}
|