@kawalir/extension-node 0.2.0 → 0.4.0

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/CHANGELOG.md CHANGED
@@ -1 +1 @@
1
- Global Node modules
1
+ Declare dependency types
@@ -0,0 +1,6 @@
1
+ export class ArgumentsFunctions {
2
+ public static all: string[];
3
+ static {
4
+ this.all = process.argv.slice(2);
5
+ }
6
+ }
@@ -0,0 +1 @@
1
+ export * from "./ArgumentsFunctions";
@@ -0,0 +1,18 @@
1
+ import { ChildProcess } from "@kawalir/extension-node/External";
2
+
3
+ export class CommandFunctions {
4
+ public static pwsh = (request: {
5
+ command: string;
6
+ folderPath: string;
7
+ }): void => {
8
+ const result = ChildProcess.spawnSync(request.command, {
9
+ cwd: request.folderPath,
10
+ shell: "pwsh",
11
+ stdio: "inherit",
12
+ });
13
+ if (result.status === 0) {
14
+ return;
15
+ }
16
+ process.exit(result.status);
17
+ };
18
+ }
@@ -0,0 +1 @@
1
+ export * from "./CommandFunctions";
@@ -0,0 +1,23 @@
1
+ type Action = () => void;
2
+
3
+ class EnsuredAction {
4
+ public hasBeenCalled: boolean = false;
5
+ constructor(public action: Action) {}
6
+ public ensure = () => {
7
+ if (this.hasBeenCalled) {
8
+ return;
9
+ }
10
+ this.action();
11
+ this.hasBeenCalled = true;
12
+ };
13
+ }
14
+
15
+ export class LifeFunctions {
16
+ public static doBeforeEnd = (action: () => void) => {
17
+ const ea = new EnsuredAction(() => action());
18
+ process.on("SIGINT", () => ea.ensure());
19
+ process.on("SIGTERM", () => ea.ensure());
20
+ process.on("SIGHUP", () => ea.ensure());
21
+ process.on("exit", () => ea.ensure());
22
+ };
23
+ }
@@ -0,0 +1 @@
1
+ export * from "./LifeFunctions";
@@ -0,0 +1,9 @@
1
+ import { ArgumentsFunctions } from "./Arguments";
2
+ import { CommandFunctions } from "./Command";
3
+ import { LifeFunctions } from "./Life";
4
+
5
+ export class ProcessFunctions {
6
+ public static arguments = ArgumentsFunctions;
7
+ public static command = CommandFunctions;
8
+ public static life = LifeFunctions;
9
+ }
@@ -0,0 +1 @@
1
+ export * from "./ProcessFunctions";
@@ -1 +1,2 @@
1
1
  export * from "./File";
2
+ export * from "./Process";
package/External/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * as ReadLine from "readline/promises";
2
+ export * as ChildProcess from "child_process";
2
3
  export * as FileSystem from "fs";
3
4
 
4
5
  import * as Path from "path";
@@ -1,6 +1,10 @@
1
1
  import * as CORE from "@kawalir/extension-node/Core";
2
2
 
3
3
  declare global {
4
+ //? Static
5
+ var Process: typeof CORE.ProcessFunctions;
6
+
7
+ //? Proper classses
4
8
  interface TextFile extends CORE.TextFile {}
5
9
  var TextFile: typeof CORE.TextFile;
6
10
 
@@ -1,5 +1,9 @@
1
1
  import * as CORE from "@kawalir/extension-node/Core";
2
2
 
3
+ //? Static
4
+ globalThis.Process = CORE.ProcessFunctions;
5
+
6
+ //? Proper classses
3
7
  globalThis.TextFile = CORE.TextFile;
4
8
  globalThis.JsonFile = CORE.JsonFile;
5
9
  globalThis.Folder = CORE.Folder;
@@ -0,0 +1,7 @@
1
+ declare global {
2
+ interface Console {
3
+ ReadLine(prompt?: string): Promise<string>;
4
+ }
5
+ }
6
+
7
+ export {};
@@ -0,0 +1,8 @@
1
+ import { ReadLine } from "@kawalir/extension-node/External";
2
+
3
+ console.ReadLine = async (prompt?: string) => {
4
+ const int = ReadLine.createInterface(process.stdin, process.stdout);
5
+ const answer = await int.question(prompt ?? "");
6
+ int.close();
7
+ return answer;
8
+ };
@@ -0,0 +1 @@
1
+ import "./Console";
package/index.d.ts CHANGED
@@ -1,3 +1,6 @@
1
+ /// <reference path="../extension/index.d.ts" />
2
+
1
3
  //? [Global]
2
4
  /// <reference path="Global/Classes/GlobalClasses.d.ts" />
3
- /// <reference path="Global/Modules/GlobalModules.d.ts" />
5
+ /// <reference path="Global/Modules/GlobalModules.d.ts" />
6
+ /// <reference path="Global/Methods/Console/Console.d.ts" />
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "Node",
8
8
  "Node Extension"
9
9
  ],
10
- "version": "0.2.0",
10
+ "version": "0.4.0",
11
11
  "author": "Denis Mijatovic",
12
12
  "license": "MIT",
13
13
  "type": "commonjs",