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
package/src/HotAPI.ts
ADDED
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
import fetch from "cross-fetch";
|
|
2
|
+
|
|
3
|
+
import { HotServer } from "./HotServer";
|
|
4
|
+
import { HotRoute } from "./HotRoute";
|
|
5
|
+
import { HotClient } from "./HotClient";
|
|
6
|
+
import { HotRouteMethod, ServerAuthorizationFunction } from "./HotRouteMethod";
|
|
7
|
+
import { HotDB } from "./HotDB";
|
|
8
|
+
|
|
9
|
+
import { HotDBSchema } from "./schemas/HotDBSchema";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The API to load.
|
|
13
|
+
*/
|
|
14
|
+
export type APItoLoad = {
|
|
15
|
+
exportedClassName: string;
|
|
16
|
+
path: string;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The type of object to use during event executions.
|
|
21
|
+
*/
|
|
22
|
+
export enum EventExecutionType
|
|
23
|
+
{
|
|
24
|
+
HotRoute,
|
|
25
|
+
HotMethod,
|
|
26
|
+
HotAPI
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The API to use.
|
|
31
|
+
*/
|
|
32
|
+
export abstract class HotAPI
|
|
33
|
+
{
|
|
34
|
+
/**
|
|
35
|
+
* The server connection.
|
|
36
|
+
*/
|
|
37
|
+
connection: HotServer | HotClient;
|
|
38
|
+
/**
|
|
39
|
+
* The base url for the server.
|
|
40
|
+
*/
|
|
41
|
+
baseUrl: string;
|
|
42
|
+
/**
|
|
43
|
+
* If set, this will create the route variables and functions for
|
|
44
|
+
* easy client/server calling.
|
|
45
|
+
*/
|
|
46
|
+
createFunctions: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* The database connection.
|
|
49
|
+
*/
|
|
50
|
+
executeEventsUsing: EventExecutionType;
|
|
51
|
+
/**
|
|
52
|
+
* The database connection.
|
|
53
|
+
*/
|
|
54
|
+
db: HotDB;
|
|
55
|
+
/**
|
|
56
|
+
* The authorization credentials to use throughout the application.
|
|
57
|
+
*/
|
|
58
|
+
authCredentials: any;
|
|
59
|
+
/**
|
|
60
|
+
* The function used for user authentication.
|
|
61
|
+
*/
|
|
62
|
+
userAuth: ServerAuthorizationFunction;
|
|
63
|
+
/**
|
|
64
|
+
* The database connection.
|
|
65
|
+
*/
|
|
66
|
+
routes: { [name: string]: HotRoute };
|
|
67
|
+
/**
|
|
68
|
+
* Executed when the API is about to start registering routes. If
|
|
69
|
+
* this function returns false, the server will not start.
|
|
70
|
+
*/
|
|
71
|
+
onPreRegister: () => Promise<boolean>;
|
|
72
|
+
/**
|
|
73
|
+
* Executed when the API has finished registering routes. If
|
|
74
|
+
* this function returns false, the server will not start.
|
|
75
|
+
*/
|
|
76
|
+
onPostRegister: () => Promise<boolean>;
|
|
77
|
+
|
|
78
|
+
constructor (baseUrl: string, connection: HotServer | HotClient = null, db: HotDB = null)
|
|
79
|
+
{
|
|
80
|
+
this.connection = connection;
|
|
81
|
+
this.baseUrl = baseUrl;
|
|
82
|
+
this.createFunctions = true;
|
|
83
|
+
this.executeEventsUsing = EventExecutionType.HotRoute;
|
|
84
|
+
this.db = db;
|
|
85
|
+
this.authCredentials = null;
|
|
86
|
+
this.userAuth = null;
|
|
87
|
+
this.routes = {};
|
|
88
|
+
this.onPreRegister = null;
|
|
89
|
+
this.onPostRegister = null;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Set the database schema for use.
|
|
94
|
+
*/
|
|
95
|
+
setDBSchema (schema: HotDBSchema): void
|
|
96
|
+
{
|
|
97
|
+
if (this.connection.api == null)
|
|
98
|
+
throw new Error (`No API has been set!`);
|
|
99
|
+
|
|
100
|
+
if (this.connection.api.db == null)
|
|
101
|
+
throw new Error (`No database has been set for API base url ${this.connection.api.baseUrl}`);
|
|
102
|
+
|
|
103
|
+
this.connection.api.db.schema = schema;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Get the database being used.
|
|
108
|
+
*/
|
|
109
|
+
getDB (): HotDB
|
|
110
|
+
{
|
|
111
|
+
if (this.connection.api.db == null)
|
|
112
|
+
throw new Error (`No database has been set for API base url ${this.connection.api.baseUrl}`);
|
|
113
|
+
|
|
114
|
+
return (this.connection.api.db);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Get the database schema being used.
|
|
119
|
+
*/
|
|
120
|
+
getDBSchema (): HotDBSchema
|
|
121
|
+
{
|
|
122
|
+
if (this.connection.api.db == null)
|
|
123
|
+
throw new Error (`No database has been set for API base url ${this.connection.api.baseUrl}`);
|
|
124
|
+
|
|
125
|
+
return (this.connection.api.db.schema);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Add a route. If this.createFunctions is set to true, this will take the incoming
|
|
130
|
+
* route and create an object in this HotAPI object using the name of the route. If there's
|
|
131
|
+
* any HotRouteMethods inside of the incoming HotRoute, it will create the methods
|
|
132
|
+
* and attach them to the newly created HotRoute object.
|
|
133
|
+
*
|
|
134
|
+
* Example:
|
|
135
|
+
* ```
|
|
136
|
+
* export class Users extends HotRoute
|
|
137
|
+
* {
|
|
138
|
+
* constructor (api: FreeLightAPI)
|
|
139
|
+
* {
|
|
140
|
+
* super (api.connection, "user");
|
|
141
|
+
*
|
|
142
|
+
* this.addMethod ("create", this._create, HTTPMethod.POST);
|
|
143
|
+
* }
|
|
144
|
+
*
|
|
145
|
+
* protected async _create (req: any, res: any, authorizedValue: any, jsonObj: any, queryObj: any): Promise<any>
|
|
146
|
+
* {
|
|
147
|
+
* return (true);
|
|
148
|
+
* }
|
|
149
|
+
* }
|
|
150
|
+
* ```
|
|
151
|
+
*
|
|
152
|
+
* This in turn could be used like so:
|
|
153
|
+
* ```
|
|
154
|
+
* Hot.API.user.create ({});
|
|
155
|
+
* ```
|
|
156
|
+
*
|
|
157
|
+
* Additionally it would create the endpoint: ```http://127.0.0.1:8080/v1/user/create```
|
|
158
|
+
*
|
|
159
|
+
* @param route The route to add. Can be either a full HotRoute object, or just
|
|
160
|
+
* the route's name. If a HotRoute object is supplied, the rest of the parameters
|
|
161
|
+
* will be ignored.
|
|
162
|
+
* @param routeMethod The route's method to add. If the route parameter is a string,
|
|
163
|
+
* it will be interpreted as the route's name, and this will be the method added to
|
|
164
|
+
* the new route.
|
|
165
|
+
* @param executeFunction The function to execute when routeMethod is called by the API.
|
|
166
|
+
*/
|
|
167
|
+
addRoute (
|
|
168
|
+
route: HotRoute | string,
|
|
169
|
+
routeMethod: HotRouteMethod | string = null,
|
|
170
|
+
executeFunction: (req: any, res: any, authorizedValue: any, jsonObj: any, queryObj: any) => Promise<any> = null
|
|
171
|
+
): void
|
|
172
|
+
{
|
|
173
|
+
let routeName: string = "";
|
|
174
|
+
|
|
175
|
+
if (route instanceof HotRoute)
|
|
176
|
+
{
|
|
177
|
+
routeName = route.route;
|
|
178
|
+
this.routes[route.route] = route;
|
|
179
|
+
}
|
|
180
|
+
else
|
|
181
|
+
{
|
|
182
|
+
routeName = route;
|
|
183
|
+
|
|
184
|
+
if (this.routes[routeName] == null)
|
|
185
|
+
this.routes[routeName] = new HotRoute (this.connection, routeName);
|
|
186
|
+
|
|
187
|
+
if (routeMethod instanceof HotRouteMethod)
|
|
188
|
+
this.routes[routeName].addMethod (routeMethod);
|
|
189
|
+
else
|
|
190
|
+
{
|
|
191
|
+
this.routes[routeName].addMethod (new HotRouteMethod (
|
|
192
|
+
this.routes[routeName], routeMethod, executeFunction));
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
this.routes[routeName].connection = this.connection;
|
|
197
|
+
|
|
198
|
+
// Create the route functions for the server/client.
|
|
199
|
+
if (this.createFunctions === true)
|
|
200
|
+
{
|
|
201
|
+
// @ts-ignore
|
|
202
|
+
let newRoute: { [name: string]: Function } = this[routeName];
|
|
203
|
+
|
|
204
|
+
if (newRoute == null)
|
|
205
|
+
newRoute = {};
|
|
206
|
+
|
|
207
|
+
for (let iIdx = 0; iIdx < this.routes[routeName].methods.length; iIdx++)
|
|
208
|
+
{
|
|
209
|
+
let currentRoute: HotRoute = this.routes[routeName];
|
|
210
|
+
let newRouteMethod: HotRouteMethod = this.routes[routeName].methods[iIdx];
|
|
211
|
+
|
|
212
|
+
/*
|
|
213
|
+
/// @fixme Is this really necessary? A HTTP call is much more preferable,
|
|
214
|
+
/// especially for accruate testing.
|
|
215
|
+
if (this.connection instanceof HotServer)
|
|
216
|
+
{
|
|
217
|
+
if (newRouteMethod.onServerExecute != null)
|
|
218
|
+
newRoute[newRouteMethod.name] = newRouteMethod.onServerExecute;
|
|
219
|
+
}
|
|
220
|
+
else*/
|
|
221
|
+
{
|
|
222
|
+
/*
|
|
223
|
+
/// @fixme Is onClientExecute necessary? I'm thinking the dev can just simply create
|
|
224
|
+
/// their own function to call.
|
|
225
|
+
if (newRouteMethod.onClientExecute != null)
|
|
226
|
+
newRoute[newRouteMethod.name] = newRouteMethod.onClientExecute;
|
|
227
|
+
else
|
|
228
|
+
{*/
|
|
229
|
+
newRoute[newRouteMethod.name] = (data: any): any =>
|
|
230
|
+
{
|
|
231
|
+
let httpMethod: string = newRouteMethod.type;
|
|
232
|
+
// Construct the url here. Base + route + route method
|
|
233
|
+
let routeStr: string = "";
|
|
234
|
+
|
|
235
|
+
if (currentRoute.version !== "")
|
|
236
|
+
routeStr += `/${currentRoute.version}`;
|
|
237
|
+
|
|
238
|
+
if (currentRoute.route !== "")
|
|
239
|
+
routeStr += `/${currentRoute.route}`;
|
|
240
|
+
|
|
241
|
+
if (newRouteMethod.name !== "")
|
|
242
|
+
routeStr += `/${newRouteMethod.name}`;
|
|
243
|
+
|
|
244
|
+
let authCredentials: any = null;
|
|
245
|
+
|
|
246
|
+
// Getting the authorization credentials from the API is the lowest
|
|
247
|
+
// priority for getting credentials. The priorities are in this order:
|
|
248
|
+
// 1. HotRouteMethod
|
|
249
|
+
// 2. HotRoute
|
|
250
|
+
// 3. HotAPI
|
|
251
|
+
if (this.authCredentials != null)
|
|
252
|
+
authCredentials = this.authCredentials;
|
|
253
|
+
|
|
254
|
+
// Find the authorization credentials. Prioritize them when they're
|
|
255
|
+
// in the method. Only add the ones from the route if the ones from
|
|
256
|
+
// the method are missing.
|
|
257
|
+
if (newRouteMethod.authCredentials != null)
|
|
258
|
+
authCredentials = newRouteMethod.authCredentials;
|
|
259
|
+
else
|
|
260
|
+
{
|
|
261
|
+
if (newRouteMethod.parentRoute.authCredentials != null)
|
|
262
|
+
authCredentials = newRouteMethod.parentRoute.authCredentials;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (authCredentials == null)
|
|
266
|
+
{
|
|
267
|
+
// @ts-ignore
|
|
268
|
+
if (typeof (Hot) !== "undefined")
|
|
269
|
+
{
|
|
270
|
+
// @ts-ignore
|
|
271
|
+
if (Hot != null)
|
|
272
|
+
{
|
|
273
|
+
// @ts-ignore
|
|
274
|
+
if (Hot.API != null)
|
|
275
|
+
{
|
|
276
|
+
// @ts-ignore
|
|
277
|
+
if (Hot.API[currentRoute.route] != null)
|
|
278
|
+
{
|
|
279
|
+
// @ts-ignore
|
|
280
|
+
if (Hot.API[currentRoute.route].authCredentials != null)
|
|
281
|
+
{
|
|
282
|
+
// @ts-ignore
|
|
283
|
+
authCredentials = Hot.API[currentRoute.route].authCredentials;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
if (authCredentials != null)
|
|
292
|
+
{
|
|
293
|
+
// Add the authorization credentials to the data being sent.
|
|
294
|
+
for (let key in authCredentials)
|
|
295
|
+
{
|
|
296
|
+
let authCredential: any = authCredentials[key];
|
|
297
|
+
|
|
298
|
+
// Do not overwrite any existing keys in the data about
|
|
299
|
+
// to be sent.
|
|
300
|
+
if (data[key] == null)
|
|
301
|
+
data[key] = authCredential;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
let args: any[] = [routeStr, data, httpMethod];
|
|
306
|
+
|
|
307
|
+
return (this.makeCall.apply (this, args));
|
|
308
|
+
};
|
|
309
|
+
//}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// @ts-ignore
|
|
314
|
+
this[routeName] = newRoute;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Register a route with the server.
|
|
320
|
+
*/
|
|
321
|
+
async registerRoute (route: HotRoute): Promise<void>
|
|
322
|
+
{
|
|
323
|
+
if (this.connection instanceof HotServer)
|
|
324
|
+
await this.connection.registerRoute (route);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Register all routes with the server.
|
|
329
|
+
*/
|
|
330
|
+
async registerRoutes (): Promise<void>
|
|
331
|
+
{
|
|
332
|
+
for (let key in this.routes)
|
|
333
|
+
{
|
|
334
|
+
let route: HotRoute = this.routes[key];
|
|
335
|
+
|
|
336
|
+
await this.registerRoute (route);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Make a call to the API.
|
|
342
|
+
*/
|
|
343
|
+
async makeCall (route: string, data: any, httpMethod: string = "POST"): Promise<any>
|
|
344
|
+
{
|
|
345
|
+
let url: string = this.baseUrl;
|
|
346
|
+
|
|
347
|
+
if (url[(url.length - 1)] === "/")
|
|
348
|
+
url = url.substr (0, (url.length - 1));
|
|
349
|
+
|
|
350
|
+
if (route[0] !== "/")
|
|
351
|
+
url += "/";
|
|
352
|
+
|
|
353
|
+
url += route;
|
|
354
|
+
|
|
355
|
+
httpMethod = httpMethod.toUpperCase ();
|
|
356
|
+
|
|
357
|
+
let fetchObj: any = {
|
|
358
|
+
method: httpMethod,
|
|
359
|
+
headers: {
|
|
360
|
+
"Accept": "application/json",
|
|
361
|
+
"Content-Type": "application/json"
|
|
362
|
+
}
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
if ((httpMethod !== "GET") &&
|
|
366
|
+
(httpMethod !== "HEAD"))
|
|
367
|
+
{
|
|
368
|
+
fetchObj["body"] = JSON.stringify (data);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
let res: any = null;
|
|
372
|
+
|
|
373
|
+
try
|
|
374
|
+
{
|
|
375
|
+
res = await fetch (url, fetchObj);
|
|
376
|
+
}
|
|
377
|
+
catch (ex)
|
|
378
|
+
{
|
|
379
|
+
throw ex;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
let jsonObj: any = await res.json ();
|
|
383
|
+
|
|
384
|
+
return (jsonObj);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { HotAPI, HotServer, HotClient } from "./api";
|
|
2
|
+
import { HotAgentRoute } from "./HotAgentRoute";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The App's API and routes.
|
|
6
|
+
*/
|
|
7
|
+
export class HotAgentAPI extends HotAPI
|
|
8
|
+
{
|
|
9
|
+
/**
|
|
10
|
+
* The key to use.
|
|
11
|
+
*/
|
|
12
|
+
key: string;
|
|
13
|
+
/**
|
|
14
|
+
* The secret key to use.
|
|
15
|
+
*/
|
|
16
|
+
secret: string;
|
|
17
|
+
/**
|
|
18
|
+
* The commands to execute.
|
|
19
|
+
*/
|
|
20
|
+
commands: { [name: string]: string };
|
|
21
|
+
|
|
22
|
+
constructor (baseUrl: string, connection: HotServer | HotClient = null, db: any = null)
|
|
23
|
+
{
|
|
24
|
+
super(baseUrl, connection, db);
|
|
25
|
+
|
|
26
|
+
this.key = "";
|
|
27
|
+
this.secret = "";
|
|
28
|
+
this.commands = {};
|
|
29
|
+
|
|
30
|
+
this.userAuth = async (req: any, res: any, jsonObj: any, queryObj: any): Promise<any> =>
|
|
31
|
+
{
|
|
32
|
+
const apiKey: string = jsonObj["key"];
|
|
33
|
+
const apiSecret: string = jsonObj["secret"];
|
|
34
|
+
|
|
35
|
+
if ((apiKey !== this.key) && (apiSecret !== this.secret))
|
|
36
|
+
throw new Error ("Incorrect API key or secret!");
|
|
37
|
+
|
|
38
|
+
return (true);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
this.addRoute (new HotAgentRoute (this));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { HotRoute, HTTPMethod, HotRouteMethod, HotStaq } from "./api";
|
|
2
|
+
import { HotAgentAPI } from "./HotAgentAPI";
|
|
3
|
+
|
|
4
|
+
import * as fs from "fs";
|
|
5
|
+
import * as vm from "vm";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Hello world route.
|
|
9
|
+
*/
|
|
10
|
+
export class HotAgentRoute extends HotRoute
|
|
11
|
+
{
|
|
12
|
+
/**
|
|
13
|
+
* Helper to the parent API.
|
|
14
|
+
*/
|
|
15
|
+
thisApi: HotAgentAPI;
|
|
16
|
+
|
|
17
|
+
constructor (api: HotAgentAPI)
|
|
18
|
+
{
|
|
19
|
+
super (api.connection, "agent");
|
|
20
|
+
|
|
21
|
+
this.thisApi = api;
|
|
22
|
+
|
|
23
|
+
this.addMethod (new HotRouteMethod (this, "execute", this.execute,
|
|
24
|
+
HTTPMethod.POST, api.userAuth));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Execute a file.
|
|
29
|
+
*/
|
|
30
|
+
protected async execute (req: any, res: any, authorizedValue: any, jsonObj: any, queryObj: any): Promise<any>
|
|
31
|
+
{
|
|
32
|
+
const cmd: string = HotStaq.getParam ("cmd", jsonObj);
|
|
33
|
+
const data: any = HotStaq.getParamDefault ("data", jsonObj, undefined);
|
|
34
|
+
let foundCmd: string = this.thisApi.commands[cmd];
|
|
35
|
+
|
|
36
|
+
if (foundCmd == null)
|
|
37
|
+
throw new Error (`Command ${cmd} not found!`);
|
|
38
|
+
|
|
39
|
+
const cmdData: string = fs.readFileSync (foundCmd).toString ();
|
|
40
|
+
vm.runInNewContext (cmdData, data);
|
|
41
|
+
|
|
42
|
+
return (true);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import * as ppath from "path";
|
|
2
|
+
import { HotIO } from "./HotIO";
|
|
3
|
+
|
|
4
|
+
import { HotStaq, HotSite } from "./HotStaq";
|
|
5
|
+
import { HotLog } from "./HotLog";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Builds stuff for the CLI like docker images and Kubernetes clusters.
|
|
9
|
+
*/
|
|
10
|
+
export class HotBuilder
|
|
11
|
+
{
|
|
12
|
+
/**
|
|
13
|
+
* The HotSites to build from.
|
|
14
|
+
*/
|
|
15
|
+
hotsites: HotSite[];
|
|
16
|
+
/**
|
|
17
|
+
* Will build the web api.
|
|
18
|
+
* @default true
|
|
19
|
+
*/
|
|
20
|
+
api: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Will build the Dockerfiles.
|
|
23
|
+
*/
|
|
24
|
+
dockerFiles: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Will harden the Dockerfiles security when possible.
|
|
27
|
+
*/
|
|
28
|
+
dockerHardenSecurity: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Will append the docker documentation to the existing README.md.
|
|
31
|
+
*/
|
|
32
|
+
appendReadMe: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Will build the Docker compose file.
|
|
35
|
+
*/
|
|
36
|
+
dockerCompose: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Will build the Kubernetes cluster.
|
|
39
|
+
*/
|
|
40
|
+
kubernetes: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* The logger.
|
|
43
|
+
*/
|
|
44
|
+
logger: HotLog;
|
|
45
|
+
/**
|
|
46
|
+
* The output directory.
|
|
47
|
+
*/
|
|
48
|
+
outputDir: string;
|
|
49
|
+
|
|
50
|
+
constructor (logger: HotLog)
|
|
51
|
+
{
|
|
52
|
+
this.api = true;
|
|
53
|
+
this.dockerFiles = true;
|
|
54
|
+
this.dockerHardenSecurity = true;
|
|
55
|
+
this.appendReadMe = true;
|
|
56
|
+
this.dockerCompose = false;
|
|
57
|
+
this.kubernetes = false;
|
|
58
|
+
this.hotsites = [];
|
|
59
|
+
this.logger = logger;
|
|
60
|
+
this.outputDir = ppath.normalize (`${process.cwd ()}/`);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Build everything and output to outputDir.
|
|
65
|
+
*
|
|
66
|
+
* @fixme Needs tests!
|
|
67
|
+
*/
|
|
68
|
+
async build (): Promise<void>
|
|
69
|
+
{
|
|
70
|
+
if (this.api === true)
|
|
71
|
+
{
|
|
72
|
+
this.logger.info ("Building web API...");
|
|
73
|
+
|
|
74
|
+
/// @todo Finish this...
|
|
75
|
+
|
|
76
|
+
this.logger.info ("Finished building web API...");
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (this.dockerFiles === true)
|
|
80
|
+
{
|
|
81
|
+
this.logger.info ("Building docker files...");
|
|
82
|
+
|
|
83
|
+
const dockerDir: string = ppath.normalize (`${__dirname}/../../builder/docker`);
|
|
84
|
+
const dockerFileContent: string = await HotIO.readTextFile (
|
|
85
|
+
ppath.normalize (`${dockerDir}/Dockerfile.linux.gen`));
|
|
86
|
+
const startFileContent: string = await HotIO.readTextFile (
|
|
87
|
+
ppath.normalize (`${dockerDir}/app/start.sh`));
|
|
88
|
+
|
|
89
|
+
for (let iIdx = 0; iIdx < this.hotsites.length; iIdx++)
|
|
90
|
+
{
|
|
91
|
+
const hotsite: HotSite = this.hotsites[iIdx];
|
|
92
|
+
|
|
93
|
+
this.logger.info (`Building Dockerfile "${hotsite.name}"...`);
|
|
94
|
+
|
|
95
|
+
if (hotsite.name == null)
|
|
96
|
+
throw new Error (`HotSite ${hotsite.hotsitePath} is missing a name!`);
|
|
97
|
+
|
|
98
|
+
HotStaq.checkHotSiteName (hotsite.name, true);
|
|
99
|
+
|
|
100
|
+
const hotsiteName: string = hotsite.name;
|
|
101
|
+
let outputDir: string = ppath.normalize (`${this.outputDir}/`);
|
|
102
|
+
let newDockerfileContent: string = dockerFileContent;
|
|
103
|
+
let newStartFileContent: string = startFileContent;
|
|
104
|
+
let dockerfilePortsStr: string = "";
|
|
105
|
+
let dockercomposeAppPortsStr: string = "";
|
|
106
|
+
let dockercomposeAppAPIPortsStr: string = "";
|
|
107
|
+
let httpPort: number = HotStaq.getValueFromHotSiteObj (hotsite, ["server", "ports", "http"]);
|
|
108
|
+
let httpsPort: number = HotStaq.getValueFromHotSiteObj (hotsite, ["server", "ports", "https"]);
|
|
109
|
+
let hotsitePath: string = `/app/${hotsiteName}/HotSite.json`;
|
|
110
|
+
let hardenSecurity: string =
|
|
111
|
+
`
|
|
112
|
+
RUN npm -g uninstall npm && \
|
|
113
|
+
apk --purge del apk-tools
|
|
114
|
+
`;
|
|
115
|
+
/**
|
|
116
|
+
* Replace any keywords in a string.
|
|
117
|
+
*/
|
|
118
|
+
let replaceKeywords = (str: string): string =>
|
|
119
|
+
{
|
|
120
|
+
str = str.replace (/\$\{HOTSITE_NAME\}/g, hotsiteName);
|
|
121
|
+
str = str.replace (/\$\{DOCKERFILE_PORTS\}/g, dockerfilePortsStr);
|
|
122
|
+
str = str.replace (/\$\{DOCKER_COMPOSE_APP_PORTS\}/g, dockercomposeAppPortsStr);
|
|
123
|
+
str = str.replace (/\$\{DOCKER_COMPOSE_APP_API_PORTS\}/g, dockercomposeAppAPIPortsStr);
|
|
124
|
+
str = str.replace (/\$\{HARDEN\_SECURITY\}/g, hardenSecurity);
|
|
125
|
+
str = str.replace (/\$\{HOTSITE_PATH\}/g, hotsitePath);
|
|
126
|
+
|
|
127
|
+
return (str);
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* Replace any keywords in a file.
|
|
131
|
+
*/
|
|
132
|
+
let replaceKeywordsInFile = async (filepath: string): Promise<string> =>
|
|
133
|
+
{
|
|
134
|
+
let fileContent: string = await HotIO.readTextFile (ppath.normalize (filepath));
|
|
135
|
+
fileContent = replaceKeywords (fileContent);
|
|
136
|
+
|
|
137
|
+
return (fileContent);
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
if (this.dockerHardenSecurity === false)
|
|
141
|
+
hardenSecurity = "";
|
|
142
|
+
|
|
143
|
+
await HotIO.mkdir (`${outputDir}/docker/${hotsiteName}/app/`);
|
|
144
|
+
|
|
145
|
+
if (httpPort != null)
|
|
146
|
+
{
|
|
147
|
+
dockerfilePortsStr += `ARG HTTP_PORT=${httpPort}
|
|
148
|
+
ENV HTTP_PORT \${HTTP_PORT}
|
|
149
|
+
EXPOSE \${HTTP_PORT}`;
|
|
150
|
+
dockercomposeAppPortsStr += `
|
|
151
|
+
ports:
|
|
152
|
+
- "${httpPort}:${httpPort}"`;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (httpsPort != null)
|
|
156
|
+
{
|
|
157
|
+
dockerfilePortsStr += `ARG HTTPS_PORT=${httpsPort}
|
|
158
|
+
ENV HTTPS_PORT \${HTTPS_PORT}
|
|
159
|
+
EXPOSE \${HTTPS_PORT}`;
|
|
160
|
+
dockercomposeAppPortsStr += `
|
|
161
|
+
- "${httpsPort}:${httpsPort}"`;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (dockerfilePortsStr === "")
|
|
165
|
+
{
|
|
166
|
+
dockerfilePortsStr += `ARG HTTP_PORT=80
|
|
167
|
+
ENV HTTP_PORT \${HTTP_PORT}
|
|
168
|
+
EXPOSE \${HTTP_PORT}`;
|
|
169
|
+
dockercomposeAppPortsStr += `
|
|
170
|
+
ports:
|
|
171
|
+
- "80:80"`;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
newDockerfileContent = replaceKeywords (newDockerfileContent);
|
|
175
|
+
newStartFileContent = replaceKeywords (newStartFileContent);
|
|
176
|
+
|
|
177
|
+
await HotIO.writeTextFile (`${outputDir}/docker/${hotsiteName}/Dockerfile`, newDockerfileContent);
|
|
178
|
+
await HotIO.copyFiles (`${dockerDir}/scripts/`, `${outputDir}/`);
|
|
179
|
+
await HotIO.writeTextFile (`${outputDir}/docker/${hotsiteName}/app/start.sh`, newStartFileContent);
|
|
180
|
+
await HotIO.writeTextFile (`${outputDir}/start-app.sh`,
|
|
181
|
+
await HotIO.readTextFile (ppath.normalize (`${outputDir}/start-app.sh`)));
|
|
182
|
+
await HotIO.copyFile (`${dockerDir}/dockerignore`, `${outputDir}/.dockerignore`);
|
|
183
|
+
|
|
184
|
+
if (await HotIO.exists (`${outputDir}/README.md`) === true)
|
|
185
|
+
{
|
|
186
|
+
const prevREADME: string = await HotIO.readTextFile (`${outputDir}/README.md`);
|
|
187
|
+
const dockerREADME: string = await HotIO.readTextFile (`${dockerDir}/README.md`);
|
|
188
|
+
|
|
189
|
+
// Only append the docker readme if it's not already there...
|
|
190
|
+
if (prevREADME.indexOf ("Docker Getting Started") < 0)
|
|
191
|
+
await HotIO.writeTextFile (`${outputDir}/README.md`, `${prevREADME}\n${dockerREADME}`);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
this.logger.info (`Finished building Dockerfile "${hotsite.name}"...`);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
this.logger.info ("Finished building docker files...");
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (this.dockerCompose === true)
|
|
201
|
+
{
|
|
202
|
+
this.logger.info ("Building Docker Compose files...");
|
|
203
|
+
|
|
204
|
+
const dockerDir: string = ppath.normalize (`${__dirname}/../../builder/docker-compose`);
|
|
205
|
+
const dockerFileContent: string = await HotIO.readTextFile (
|
|
206
|
+
ppath.normalize (`${dockerDir}/docker-compose.gen.yaml`));
|
|
207
|
+
const startFileContent: string = await HotIO.readTextFile (
|
|
208
|
+
ppath.normalize (`${dockerDir}/app/start.sh`));
|
|
209
|
+
|
|
210
|
+
for (let iIdx = 0; iIdx < this.hotsites.length; iIdx++)
|
|
211
|
+
{
|
|
212
|
+
const hotsite: HotSite = this.hotsites[iIdx];
|
|
213
|
+
|
|
214
|
+
this.logger.info ("Building Docker Compose files...");
|
|
215
|
+
this.logger.info (`Finished building Docker Compose "${hotsite.name}"...`);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
this.logger.info ("Finished building Docker Compose files...");
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|