Completed
Push — master ( c17b81...3a1758 )
by Dimas
19:57 queued 11s
created

libs/index.ts   A

Complexity

Total Complexity 10
Complexity/F 0

Size

Lines of Code 124
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 10
eloc 97
mnd 10
bc 10
fnc 0
dl 0
loc 124
rs 10
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
1
/// <reference path="./src/compiler/globals.d.ts" />
2
3
/**
4
 * Package.json maintainer
5
 */
6
7
import * as fs from "fs";
8
import { serve } from "./src/UI/index";
9
import * as path from "path";
10
import * as Process from "process";
11
import filemanager from "./src/compiler/filemanager";
12
import {
13
  config_builder,
14
  fixDeps,
15
  writeFile,
16
  execute,
17
  writenow,
18
  asset,
19
} from "./src/compiler/func";
20
const args = Process.argv.slice(2);
21
22
var constructor = JSON.parse(
23
  fs.readFileSync(asset("./package.json")).toString()
24
);
25
var variant: "production" | "development" | "gui" | null = null;
26
var isWin = process.platform === "win32";
27
28
if (isWin) {
29
  execute("cls", function () {});
30
}
31
32
if (typeof args[0] != "undefined") {
33
  switch (args[0]) {
34
    case "gui":
35
      serve();
36
      variant = "gui";
37
      break;
38
39
    case "dev":
40
    case "development":
41
      variant = "development";
42
      config_builder();
43
      break;
44
45
    case "init":
46
      variant = null;
47
      constructor.scripts.preinstall = "npm install typescript gulp -g";
48
      constructor.scripts.postinstall =
49
        "node ./index.js dev && && tsc -p tsconfig.build.json &&tsc -p tsconfig.precompiler.json && tsc -p tsconfig.compiler.json";
50
      fs.writeFileSync(
51
        __dirname + "/package.json",
52
        JSON.stringify(constructor, null, 4)
53
      );
54
      if (fs.existsSync("./node_modules")) {
55
        filemanager.unlink("./node_modules");
56
      }
57
      execute("npm install --prefer-offline");
58
      break;
59
    case "test":
60
      //npm.install(["node", 'async', "typescript", "tslib", "ts-node"]);
61
      //module_exists("node");
62
      variant = null;
63
      break;
64
    case "fix":
65
      if (fs.existsSync("./package.json")) {
66
        constructor = Object.assign(
67
          {},
68
          constructor,
69
          JSON.parse(fs.readFileSync("./package.json").toString())
70
        );
71
        constructor = fixDeps(constructor);
72
        writenow(constructor);
73
      }
74
      filemanager.unlink("./tmp/storage/compiler");
75
      filemanager.unlink("./tmp/storage/compile");
76
77
      variant = null;
78
      break;
79
    case "rebuild":
80
      variant = null;
81
      execute("tsc -p tsconfig.build.json", function (success, message) {
82
        console.log(message);
83
      });
84
      execute("tsc -p tsconfig.precompiler.json", function (success, message) {
85
        console.log(message);
86
      });
87
      execute("tsc -p tsconfig.compiler.json", function (success, message) {
88
        console.log(message);
89
      });
90
      break;
91
  }
92
} else {
93
  serve();
94
  variant = "gui";
95
}
96
97
if (variant) {
98
  console.log("variant", variant);
99
100
  if (variant == "production") {
101
    constructor.scripts.preinstall = "";
102
    constructor.scripts.postinstall = "";
103
    constructor.scripts.test = "";
104
    delete constructor.files;
105
    delete constructor.bin;
106
  } else if (variant == "development") {
107
    constructor.scripts.preinstall = "";
108
    constructor.scripts.postinstall = "";
109
    constructor.scripts.test = "";
110
    constructor.bin = "./libs/bin";
111
    constructor.files = ["./libs/"];
112
    /*Object.assign(
113
      constructor.devDependencies,
114
      shared_packages().devDependencies
115
    );
116
    Object.assign(constructor.dependencies, shared_packages().dependencies);*/
117
    //console.log(constructor.dependencies);
118
  } else if (variant == "gui") {
119
  }
120
  if (["development", "fix"].includes(variant)) {
121
    writenow(constructor);
122
  }
123
}
124