@webtypen/webframez-core 0.1.4 → 0.1.6

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.
@@ -1,5 +1,19 @@
1
+ /// <reference types="node" />
2
+ import readline from "readline";
3
+ import { ConsoleProgressBar } from "./ConsoleProgressBar";
1
4
  export declare class ConsoleCommand {
2
5
  static signature: string;
3
6
  static description?: string;
7
+ rl: readline.Interface | null;
8
+ currentProgress: ConsoleProgressBar | null;
9
+ constructor();
4
10
  handle(): Promise<void>;
11
+ handleSystem(): Promise<void>;
12
+ finallySystem(): Promise<void>;
13
+ write(message: string): this;
14
+ writeln(message: string): this;
15
+ ask(question: string): Promise<unknown>;
16
+ progress(count: number): this;
17
+ progressIncrement(): this;
18
+ progressFinish(): this;
5
19
  }
@@ -8,11 +8,82 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
11
14
  Object.defineProperty(exports, "__esModule", { value: true });
12
15
  exports.ConsoleCommand = void 0;
16
+ const os_1 = __importDefault(require("os"));
17
+ const readline_1 = __importDefault(require("readline"));
18
+ const ConsoleProgressBar_1 = require("./ConsoleProgressBar");
13
19
  class ConsoleCommand {
20
+ constructor() {
21
+ this.currentProgress = null;
22
+ this.rl = readline_1.default.createInterface({
23
+ input: process.stdin,
24
+ output: process.stdout,
25
+ });
26
+ }
14
27
  handle() {
15
28
  return __awaiter(this, void 0, void 0, function* () { });
16
29
  }
30
+ handleSystem() {
31
+ return __awaiter(this, void 0, void 0, function* () {
32
+ try {
33
+ yield this.handle();
34
+ }
35
+ catch (e) {
36
+ console.error(e);
37
+ }
38
+ finally {
39
+ yield this.finallySystem();
40
+ }
41
+ });
42
+ }
43
+ finallySystem() {
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ if (this.rl) {
46
+ this.rl.close();
47
+ }
48
+ });
49
+ }
50
+ write(message) {
51
+ process.stdout.write(message);
52
+ return this;
53
+ }
54
+ writeln(message) {
55
+ process.stdout.write(message + os_1.default.EOL);
56
+ return this;
57
+ }
58
+ ask(question) {
59
+ return __awaiter(this, void 0, void 0, function* () {
60
+ const result = yield new Promise((resolve) => {
61
+ if (this.rl) {
62
+ this.rl.question(question, (answer) => {
63
+ resolve(answer);
64
+ });
65
+ }
66
+ resolve(null);
67
+ });
68
+ return result;
69
+ });
70
+ }
71
+ progress(count) {
72
+ this.currentProgress = new ConsoleProgressBar_1.ConsoleProgressBar(count);
73
+ this.currentProgress.render();
74
+ return this;
75
+ }
76
+ progressIncrement() {
77
+ if (this.currentProgress) {
78
+ this.currentProgress.increment();
79
+ }
80
+ return this;
81
+ }
82
+ progressFinish() {
83
+ if (this.currentProgress) {
84
+ this.currentProgress.finish();
85
+ }
86
+ return this;
87
+ }
17
88
  }
18
89
  exports.ConsoleCommand = ConsoleCommand;
@@ -0,0 +1,10 @@
1
+ export declare class ConsoleProgressBar {
2
+ total: number;
3
+ current: number;
4
+ barLength: number;
5
+ constructor(total: number);
6
+ update(current: number): void;
7
+ finish(): void;
8
+ render(): void;
9
+ increment(): void;
10
+ }
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ConsoleProgressBar = void 0;
7
+ const os_1 = __importDefault(require("os"));
8
+ class ConsoleProgressBar {
9
+ constructor(total) {
10
+ this.total = 0;
11
+ this.current = 0;
12
+ this.barLength = 40;
13
+ this.total = total;
14
+ this.current = 0;
15
+ this.barLength = 40; // Länge der Fortschrittsanzeige in Zeichen
16
+ }
17
+ update(current) {
18
+ this.current = current;
19
+ this.render();
20
+ }
21
+ finish() {
22
+ const progressText = "█".repeat(this.barLength);
23
+ process.stdout.clearLine(0);
24
+ process.stdout.cursorTo(0);
25
+ process.stdout.write(`Progress: [${progressText}] | 100%` + os_1.default.EOL);
26
+ }
27
+ render() {
28
+ const percentage = this.current / this.total;
29
+ const progress = Math.round(this.barLength * percentage);
30
+ const emptyProgress = this.barLength - progress;
31
+ const progressText = "█".repeat(progress);
32
+ const emptyProgressText = "░".repeat(emptyProgress);
33
+ const percentageText = (percentage * 100).toFixed(2);
34
+ process.stdout.clearLine(0);
35
+ process.stdout.cursorTo(0);
36
+ process.stdout.write(`Progress: [${progressText}${emptyProgressText}] | ${percentageText}%`);
37
+ }
38
+ increment() {
39
+ this.current += 1;
40
+ if (this.current > this.total) {
41
+ this.current = this.total;
42
+ }
43
+ this.render();
44
+ }
45
+ }
46
+ exports.ConsoleProgressBar = ConsoleProgressBar;
@@ -36,7 +36,7 @@ class ConsoleApplication {
36
36
  }
37
37
  consoleCommand.action(() => __awaiter(this, void 0, void 0, function* () {
38
38
  const service = yield new command();
39
- return yield service.handle();
39
+ return yield service.handleSystem();
40
40
  }));
41
41
  program.addCommand(consoleCommand);
42
42
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webtypen/webframez-core",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
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",
@@ -1,6 +1,78 @@
1
+ import os from "os";
2
+ import readline from "readline";
3
+ import { ConsoleProgressBar } from "./ConsoleProgressBar";
4
+
1
5
  export class ConsoleCommand {
2
6
  static signature: string;
3
7
  static description?: string;
4
8
 
9
+ rl: readline.Interface | null;
10
+ currentProgress: ConsoleProgressBar | null = null;
11
+
12
+ constructor() {
13
+ this.rl = readline.createInterface({
14
+ input: process.stdin,
15
+ output: process.stdout,
16
+ });
17
+ }
18
+
5
19
  async handle() {}
20
+
21
+ async handleSystem() {
22
+ try {
23
+ await this.handle();
24
+ } catch (e) {
25
+ console.error(e);
26
+ } finally {
27
+ await this.finallySystem();
28
+ }
29
+ }
30
+
31
+ async finallySystem() {
32
+ if (this.rl) {
33
+ this.rl.close();
34
+ }
35
+ }
36
+
37
+ write(message: string) {
38
+ process.stdout.write(message);
39
+ return this;
40
+ }
41
+
42
+ writeln(message: string) {
43
+ process.stdout.write(message + os.EOL);
44
+ return this;
45
+ }
46
+
47
+ async ask(question: string) {
48
+ const result = await new Promise((resolve) => {
49
+ if (this.rl) {
50
+ this.rl.question(question, (answer) => {
51
+ resolve(answer);
52
+ });
53
+ }
54
+ resolve(null);
55
+ });
56
+ return result;
57
+ }
58
+
59
+ progress(count: number) {
60
+ this.currentProgress = new ConsoleProgressBar(count);
61
+ this.currentProgress.render();
62
+ return this;
63
+ }
64
+
65
+ progressIncrement() {
66
+ if (this.currentProgress) {
67
+ this.currentProgress.increment();
68
+ }
69
+ return this;
70
+ }
71
+
72
+ progressFinish() {
73
+ if (this.currentProgress) {
74
+ this.currentProgress.finish();
75
+ }
76
+ return this;
77
+ }
6
78
  }
@@ -0,0 +1,47 @@
1
+ import os from "os";
2
+
3
+ export class ConsoleProgressBar {
4
+ total: number = 0;
5
+ current: number = 0;
6
+ barLength: number = 40;
7
+
8
+ constructor(total: number) {
9
+ this.total = total;
10
+ this.current = 0;
11
+ this.barLength = 40; // Länge der Fortschrittsanzeige in Zeichen
12
+ }
13
+
14
+ update(current: number) {
15
+ this.current = current;
16
+ this.render();
17
+ }
18
+
19
+ finish() {
20
+ const progressText = "█".repeat(this.barLength);
21
+ process.stdout.clearLine(0);
22
+ process.stdout.cursorTo(0);
23
+ process.stdout.write(`Progress: [${progressText}] | 100%` + os.EOL);
24
+ }
25
+
26
+ render() {
27
+ const percentage = this.current / this.total;
28
+ const progress = Math.round(this.barLength * percentage);
29
+ const emptyProgress = this.barLength - progress;
30
+
31
+ const progressText = "█".repeat(progress);
32
+ const emptyProgressText = "░".repeat(emptyProgress);
33
+ const percentageText = (percentage * 100).toFixed(2);
34
+
35
+ process.stdout.clearLine(0);
36
+ process.stdout.cursorTo(0);
37
+ process.stdout.write(`Progress: [${progressText}${emptyProgressText}] | ${percentageText}%`);
38
+ }
39
+
40
+ increment() {
41
+ this.current += 1;
42
+ if (this.current > this.total) {
43
+ this.current = this.total;
44
+ }
45
+ this.render();
46
+ }
47
+ }
@@ -28,7 +28,7 @@ export class ConsoleApplication {
28
28
  }
29
29
  consoleCommand.action(async () => {
30
30
  const service = await new command();
31
- return await service.handle();
31
+ return await service.handleSystem();
32
32
  });
33
33
  program.addCommand(consoleCommand);
34
34
  }