Completed
Push — master ( 229673...de5280 )
by Dimas
08:59
created

libs/src/UI/components/npm.ts   A

Complexity

Total Complexity 12
Complexity/F 4

Size

Lines of Code 54
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 35
dl 0
loc 54
rs 10
c 0
b 0
f 0
wmc 12
mnd 9
bc 9
fnc 3
bpm 3
cpm 4
noi 0

3 Functions

Rating   Name   Duplication   Size   Complexity  
A npm.npm 0 2 1
B npm.run 0 25 8
A npm.install 0 14 3
1
import { execute } from "../../compiler/func";
2
export class npm {
3
  static args = [];
4
  /**
5
   * Install package
6
   * @param pkg
7
   */
8
  static install(pkg: string | any[]) {
9
    if (typeof pkg == "string") {
10
      this.args.push({ install: pkg });
11
    } else if (Array.isArray(pkg)) {
12
      pkg.forEach(function (item) {
13
        npm.args.push({ install: item });
14
      });
15
    }
16
    this.run();
17
    return this;
18
  }
19
20
  static timer_run: any = null;
21
  static run() {
22
    if (this.args && this.args.length) {
23
      if (this.timer_run) {
24
        clearTimeout(this.timer_run);
25
      }
26
      setTimeout(function () {
27
        npm.timer_run = setTimeout(function () {
28
          npm.run();
29
        }, 3000);
30
      }, 200);
31
      if (this.running) {
32
        return;
33
      }
34
      var args = this.args[0];
35
      if (typeof args == "object") {
36
        for (const key in args) {
37
          if (args.hasOwnProperty(key)) {
38
            if (typeof key == "string" && typeof args[key] == "string") {
39
              console.log("npm", args);
40
              npm.npm([key, args[key]]);
41
            }
42
          }
43
        }
44
      }
45
      this.args.shift();
46
    }
47
  }
48
49
  private static running = null;
50
  static npm(args: string[]) {
51
    execute(`npm ${args.join(" ")}`);
52
  }
53
}
54