@webtypen/webframez-core 0.0.18 → 0.0.20
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/lib/Commands/BuildFinishCommand.d.ts +6 -0
- package/lib/Commands/BuildFinishCommand.js +50 -0
- package/lib/Commands/ConsoleCommand.d.ts +5 -0
- package/lib/Commands/ConsoleCommand.js +18 -0
- package/lib/ConsoleApplication.d.ts +6 -0
- package/lib/ConsoleApplication.js +46 -0
- package/lib/Router/Router.js +22 -4
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/package.json +2 -1
- package/src/Commands/BuildFinishCommand.ts +38 -0
- package/src/Commands/ConsoleCommand.ts +6 -0
- package/src/ConsoleApplication.ts +38 -0
- package/src/Router/Router.ts +47 -25
- package/src/index.ts +1 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.BuildFinishCommand = void 0;
|
|
16
|
+
const child_process_1 = require("child_process");
|
|
17
|
+
const fs_1 = __importDefault(require("fs"));
|
|
18
|
+
const ConsoleCommand_1 = require("./ConsoleCommand");
|
|
19
|
+
class BuildFinishCommand extends ConsoleCommand_1.ConsoleCommand {
|
|
20
|
+
handle() {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
const buildDir = process.cwd() + "/build";
|
|
23
|
+
const nodeModulesDir = process.cwd() + "/node_modules";
|
|
24
|
+
if (!fs_1.default.existsSync(buildDir)) {
|
|
25
|
+
throw new Error("Missing build folder `" + buildDir + "` ...");
|
|
26
|
+
}
|
|
27
|
+
if (!fs_1.default.existsSync(nodeModulesDir)) {
|
|
28
|
+
throw new Error("Missing node_modules folder `" + nodeModulesDir + "` ...");
|
|
29
|
+
}
|
|
30
|
+
// Prepare node_modules/
|
|
31
|
+
if (fs_1.default.existsSync(buildDir + "/node_modules")) {
|
|
32
|
+
(0, child_process_1.execSync)("rm -rf " + buildDir + "/node_modules");
|
|
33
|
+
}
|
|
34
|
+
(0, child_process_1.execSync)("cp -r " + nodeModulesDir + " " + buildDir + "/node_modules");
|
|
35
|
+
// Prepare files
|
|
36
|
+
const copyFiles = [".env", "package.json", "package-lock.json", "README.md", ".gitignore"];
|
|
37
|
+
for (let file of copyFiles) {
|
|
38
|
+
if (fs_1.default.existsSync(buildDir + "/" + file)) {
|
|
39
|
+
(0, child_process_1.execSync)("rm " + buildDir + "/" + file);
|
|
40
|
+
}
|
|
41
|
+
if (fs_1.default.existsSync(buildDir + "/" + file)) {
|
|
42
|
+
(0, child_process_1.execSync)("cp " + process.cwd() + "/" + file + " " + buildDir + "/" + file);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.BuildFinishCommand = BuildFinishCommand;
|
|
49
|
+
BuildFinishCommand.signature = "build";
|
|
50
|
+
BuildFinishCommand.description = "Creates a new production-build";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ConsoleCommand = void 0;
|
|
13
|
+
class ConsoleCommand {
|
|
14
|
+
handle() {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () { });
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.ConsoleCommand = ConsoleCommand;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ConsoleApplication = void 0;
|
|
13
|
+
const { Command } = require("commander");
|
|
14
|
+
const Config_1 = require("./Config");
|
|
15
|
+
const BuildFinishCommand_1 = require("./Commands/BuildFinishCommand");
|
|
16
|
+
class ConsoleApplication {
|
|
17
|
+
/**
|
|
18
|
+
* Init the routes and start the http-server
|
|
19
|
+
*/
|
|
20
|
+
boot(options) {
|
|
21
|
+
if (options && options.config) {
|
|
22
|
+
for (let key in options.config) {
|
|
23
|
+
Config_1.Config.register(key, options.config[key]);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const program = new Command();
|
|
27
|
+
program.name("webframez console").description("CLI to some JavaScript string utilities").version("0.0.1");
|
|
28
|
+
const systemCommands = [BuildFinishCommand_1.BuildFinishCommand];
|
|
29
|
+
for (let command of systemCommands) {
|
|
30
|
+
if (!command.signature) {
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
const consoleCommand = new Command(command.signature);
|
|
34
|
+
if (command.description && command.description.trim() !== "") {
|
|
35
|
+
consoleCommand.description(command.description);
|
|
36
|
+
}
|
|
37
|
+
consoleCommand.action(() => __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
const service = yield new command();
|
|
39
|
+
return yield service.handle();
|
|
40
|
+
}));
|
|
41
|
+
program.addCommand(consoleCommand);
|
|
42
|
+
}
|
|
43
|
+
program.parse();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.ConsoleApplication = ConsoleApplication;
|
package/lib/Router/Router.js
CHANGED
|
@@ -13,6 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.Router = void 0;
|
|
16
|
+
const fs_1 = __importDefault(require("fs"));
|
|
16
17
|
const qs_1 = __importDefault(require("qs"));
|
|
17
18
|
const Response_1 = require("./Response");
|
|
18
19
|
const Config_1 = require("../Config");
|
|
@@ -270,7 +271,7 @@ class RouterFacade {
|
|
|
270
271
|
}
|
|
271
272
|
// Set Controller method as route-component
|
|
272
273
|
const controllerInstance = new controller();
|
|
273
|
-
route.component = controllerInstance[split[1]];
|
|
274
|
+
route.component = controllerInstance[split[1]].bind(controllerInstance);
|
|
274
275
|
}
|
|
275
276
|
if (route && route.component !== undefined) {
|
|
276
277
|
try {
|
|
@@ -291,7 +292,8 @@ class RouterFacade {
|
|
|
291
292
|
});
|
|
292
293
|
}
|
|
293
294
|
requestConsoleLog(req, httpCode) {
|
|
294
|
-
if (Config_1.Config.get("application.router.requests.logConsole") !== true
|
|
295
|
+
if (Config_1.Config.get("application.router.requests.logConsole") !== true &&
|
|
296
|
+
!Config_1.Config.get("application.router.requests.logFile")) {
|
|
295
297
|
return;
|
|
296
298
|
}
|
|
297
299
|
const date = new Date();
|
|
@@ -305,7 +307,7 @@ class RouterFacade {
|
|
|
305
307
|
: req.socket && req.socket.remoteAddress
|
|
306
308
|
? req.socket.remoteAddress
|
|
307
309
|
: null;
|
|
308
|
-
|
|
310
|
+
const logString = '{ date: "' +
|
|
309
311
|
date.getFullYear() +
|
|
310
312
|
"-" +
|
|
311
313
|
(month < 10 ? "0" + month : month) +
|
|
@@ -325,7 +327,23 @@ class RouterFacade {
|
|
|
325
327
|
ip +
|
|
326
328
|
'", httpcode: ' +
|
|
327
329
|
httpCode.toString() +
|
|
328
|
-
" }"
|
|
330
|
+
" }";
|
|
331
|
+
if (Config_1.Config.get("application.router.requests.logConsole")) {
|
|
332
|
+
console.log(logString);
|
|
333
|
+
}
|
|
334
|
+
if (Config_1.Config.get("application.router.requests.logFile")) {
|
|
335
|
+
try {
|
|
336
|
+
const filepath = Config_1.Config.get("application.router.requests.logFile");
|
|
337
|
+
if (filepath && filepath.trim() !== "") {
|
|
338
|
+
fs_1.default.appendFileSync(filepath.trim().substring(0, 1) === "/"
|
|
339
|
+
? filepath
|
|
340
|
+
: process.cwd() + "/" + filepath, logString + "\n");
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
catch (e) {
|
|
344
|
+
console.error(e);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
329
347
|
}
|
|
330
348
|
}
|
|
331
349
|
exports.Router = new RouterFacade();
|
package/lib/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export * from "./BaseKernelWeb";
|
|
|
3
3
|
export * from "./BaseKernelConsole";
|
|
4
4
|
export * from "./Controller/Controller";
|
|
5
5
|
export * from "./Database/Model";
|
|
6
|
+
export * from "./ConsoleApplication";
|
|
6
7
|
export * from "./WebApplication";
|
|
7
8
|
export * from "./Router/Route";
|
|
8
9
|
export * from "./Router/Request";
|
package/lib/index.js
CHANGED
|
@@ -19,6 +19,7 @@ __exportStar(require("./BaseKernelWeb"), exports);
|
|
|
19
19
|
__exportStar(require("./BaseKernelConsole"), exports);
|
|
20
20
|
__exportStar(require("./Controller/Controller"), exports);
|
|
21
21
|
__exportStar(require("./Database/Model"), exports);
|
|
22
|
+
__exportStar(require("./ConsoleApplication"), exports);
|
|
22
23
|
__exportStar(require("./WebApplication"), exports);
|
|
23
24
|
__exportStar(require("./Router/Route"), exports);
|
|
24
25
|
__exportStar(require("./Router/Request"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webtypen/webframez-core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.20",
|
|
4
4
|
"description": "The core package of the typescript based webframez (web-framework) by webtypen.de",
|
|
5
5
|
"homepage": "https://webtypen.de/",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"dotenv": "^8.2.0",
|
|
33
33
|
"lodash": "^4.17.20",
|
|
34
|
+
"commander": "^9.4.1",
|
|
34
35
|
"qs": "^6.11.0"
|
|
35
36
|
}
|
|
36
37
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { exec, execSync } from "child_process";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import { ConsoleCommand } from "./ConsoleCommand";
|
|
4
|
+
|
|
5
|
+
export class BuildFinishCommand extends ConsoleCommand {
|
|
6
|
+
static signature = "build";
|
|
7
|
+
static description = "Creates a new production-build";
|
|
8
|
+
|
|
9
|
+
async handle() {
|
|
10
|
+
const buildDir = process.cwd() + "/build";
|
|
11
|
+
const nodeModulesDir = process.cwd() + "/node_modules";
|
|
12
|
+
if (!fs.existsSync(buildDir)) {
|
|
13
|
+
throw new Error("Missing build folder `" + buildDir + "` ...");
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (!fs.existsSync(nodeModulesDir)) {
|
|
17
|
+
throw new Error("Missing node_modules folder `" + nodeModulesDir + "` ...");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Prepare node_modules/
|
|
21
|
+
if (fs.existsSync(buildDir + "/node_modules")) {
|
|
22
|
+
execSync("rm -rf " + buildDir + "/node_modules");
|
|
23
|
+
}
|
|
24
|
+
execSync("cp -r " + nodeModulesDir + " " + buildDir + "/node_modules");
|
|
25
|
+
|
|
26
|
+
// Prepare files
|
|
27
|
+
const copyFiles = [".env", "package.json", "package-lock.json", "README.md", ".gitignore"];
|
|
28
|
+
for (let file of copyFiles) {
|
|
29
|
+
if (fs.existsSync(buildDir + "/" + file)) {
|
|
30
|
+
execSync("rm " + buildDir + "/" + file);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (fs.existsSync(buildDir + "/" + file)) {
|
|
34
|
+
execSync("cp " + process.cwd() + "/" + file + " " + buildDir + "/" + file);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const { Command } = require("commander");
|
|
2
|
+
import { Config } from "./Config";
|
|
3
|
+
import { BuildFinishCommand } from "./Commands/BuildFinishCommand";
|
|
4
|
+
|
|
5
|
+
export class ConsoleApplication {
|
|
6
|
+
/**
|
|
7
|
+
* Init the routes and start the http-server
|
|
8
|
+
*/
|
|
9
|
+
boot(options?: any) {
|
|
10
|
+
if (options && options.config) {
|
|
11
|
+
for (let key in options.config) {
|
|
12
|
+
Config.register(key, options.config[key]);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const program = new Command();
|
|
17
|
+
program.name("webframez console").description("CLI to some JavaScript string utilities").version("0.0.1");
|
|
18
|
+
|
|
19
|
+
const systemCommands = [BuildFinishCommand];
|
|
20
|
+
for (let command of systemCommands) {
|
|
21
|
+
if (!command.signature) {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const consoleCommand = new Command(command.signature);
|
|
26
|
+
if (command.description && command.description.trim() !== "") {
|
|
27
|
+
consoleCommand.description(command.description);
|
|
28
|
+
}
|
|
29
|
+
consoleCommand.action(async () => {
|
|
30
|
+
const service = await new command();
|
|
31
|
+
return await service.handle();
|
|
32
|
+
});
|
|
33
|
+
program.addCommand(consoleCommand);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
program.parse();
|
|
37
|
+
}
|
|
38
|
+
}
|
package/src/Router/Router.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import fs from "fs";
|
|
1
2
|
import qs from "qs";
|
|
2
3
|
import { IncomingMessage, ServerResponse } from "http";
|
|
3
4
|
import { Response } from "./Response";
|
|
@@ -328,7 +329,7 @@ class RouterFacade {
|
|
|
328
329
|
|
|
329
330
|
// Set Controller method as route-component
|
|
330
331
|
const controllerInstance = new controller();
|
|
331
|
-
route.component = controllerInstance[split[1]];
|
|
332
|
+
route.component = controllerInstance[split[1]].bind(controllerInstance);
|
|
332
333
|
}
|
|
333
334
|
|
|
334
335
|
if (route && route.component !== undefined) {
|
|
@@ -348,7 +349,10 @@ class RouterFacade {
|
|
|
348
349
|
}
|
|
349
350
|
|
|
350
351
|
requestConsoleLog(req: IncomingMessage, httpCode: number) {
|
|
351
|
-
if (
|
|
352
|
+
if (
|
|
353
|
+
Config.get("application.router.requests.logConsole") !== true &&
|
|
354
|
+
!Config.get("application.router.requests.logFile")
|
|
355
|
+
) {
|
|
352
356
|
return;
|
|
353
357
|
}
|
|
354
358
|
|
|
@@ -363,30 +367,48 @@ class RouterFacade {
|
|
|
363
367
|
: req.socket && req.socket.remoteAddress
|
|
364
368
|
? req.socket.remoteAddress
|
|
365
369
|
: null;
|
|
366
|
-
|
|
367
|
-
console.log(
|
|
370
|
+
const logString =
|
|
368
371
|
'{ date: "' +
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
372
|
+
date.getFullYear() +
|
|
373
|
+
"-" +
|
|
374
|
+
(month < 10 ? "0" + month : month) +
|
|
375
|
+
"-" +
|
|
376
|
+
date.getDate() +
|
|
377
|
+
" " +
|
|
378
|
+
(date.getHours() + 1) +
|
|
379
|
+
":" +
|
|
380
|
+
date.getMinutes() +
|
|
381
|
+
":" +
|
|
382
|
+
date.getSeconds() +
|
|
383
|
+
'", method: "' +
|
|
384
|
+
req.method +
|
|
385
|
+
'", url: "' +
|
|
386
|
+
req.url +
|
|
387
|
+
'", ip: "' +
|
|
388
|
+
ip +
|
|
389
|
+
'", httpcode: ' +
|
|
390
|
+
httpCode.toString() +
|
|
391
|
+
" }";
|
|
392
|
+
|
|
393
|
+
if (Config.get("application.router.requests.logConsole")) {
|
|
394
|
+
console.log(logString);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
if (Config.get("application.router.requests.logFile")) {
|
|
398
|
+
try {
|
|
399
|
+
const filepath = Config.get("application.router.requests.logFile");
|
|
400
|
+
if (filepath && filepath.trim() !== "") {
|
|
401
|
+
fs.appendFileSync(
|
|
402
|
+
filepath.trim().substring(0, 1) === "/"
|
|
403
|
+
? filepath
|
|
404
|
+
: process.cwd() + "/" + filepath,
|
|
405
|
+
logString + "\n"
|
|
406
|
+
);
|
|
407
|
+
}
|
|
408
|
+
} catch (e) {
|
|
409
|
+
console.error(e);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
390
412
|
}
|
|
391
413
|
}
|
|
392
414
|
|
package/src/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ export * from "./BaseKernelWeb";
|
|
|
3
3
|
export * from "./BaseKernelConsole";
|
|
4
4
|
export * from "./Controller/Controller";
|
|
5
5
|
export * from "./Database/Model";
|
|
6
|
+
export * from "./ConsoleApplication";
|
|
6
7
|
export * from "./WebApplication";
|
|
7
8
|
export * from "./Router/Route";
|
|
8
9
|
export * from "./Router/Request";
|