1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var tslib_1 = require("tslib");
|
4 | var path = require("path");
|
5 | var fs = require("fs");
|
6 | var cli_highlight_1 = require("cli-highlight");
|
7 | var fs_1 = require("fs");
|
8 | exports.ReadStream = fs_1.ReadStream;
|
9 | var events_1 = require("events");
|
10 | exports.EventEmitter = events_1.EventEmitter;
|
11 | var stream_1 = require("stream");
|
12 | exports.Readable = stream_1.Readable;
|
13 | exports.Writable = stream_1.Writable;
|
14 | var chalk = require("chalk");
|
15 |
|
16 |
|
17 |
|
18 | var PlatformTools = (function () {
|
19 | function PlatformTools() {
|
20 | }
|
21 | |
22 |
|
23 |
|
24 | PlatformTools.getGlobalVariable = function () {
|
25 | return global;
|
26 | };
|
27 | |
28 |
|
29 |
|
30 |
|
31 | PlatformTools.load = function (name) {
|
32 |
|
33 |
|
34 |
|
35 | try {
|
36 |
|
37 | switch (name) {
|
38 | |
39 |
|
40 |
|
41 | case "mongodb":
|
42 | return require("mongodb");
|
43 | |
44 |
|
45 |
|
46 | case "mysql":
|
47 | return require("mysql");
|
48 | case "mysql2":
|
49 | return require("mysql2");
|
50 | |
51 |
|
52 |
|
53 | case "oracledb":
|
54 | return require("oracledb");
|
55 | |
56 |
|
57 |
|
58 | case "pg":
|
59 | return require("pg");
|
60 | case "pg-native":
|
61 | return require("pg-native");
|
62 | case "pg-query-stream":
|
63 | return require("pg-query-stream");
|
64 | |
65 |
|
66 |
|
67 | case "redis":
|
68 | return require("redis");
|
69 | |
70 |
|
71 |
|
72 | case "ioredis":
|
73 | case "ioredis/cluster":
|
74 | return require("ioredis");
|
75 | |
76 |
|
77 |
|
78 | case "sqlite3":
|
79 | return require("sqlite3");
|
80 | |
81 |
|
82 |
|
83 | case "sql.js":
|
84 | return require("sql.js");
|
85 | |
86 |
|
87 |
|
88 | case "mssql":
|
89 | return require("mssql");
|
90 | |
91 |
|
92 |
|
93 | case "mkdirp":
|
94 | return require("mkdirp");
|
95 | case "path":
|
96 | return require("path");
|
97 | case "debug":
|
98 | return require("debug");
|
99 | case "app-root-path":
|
100 | return require("app-root-path");
|
101 | case "glob":
|
102 | return require("glob");
|
103 | |
104 |
|
105 |
|
106 | default:
|
107 | return require(name);
|
108 | }
|
109 | }
|
110 | catch (err) {
|
111 | if (!path.isAbsolute(name) && name.substr(0, 2) !== "./" && name.substr(0, 3) !== "../") {
|
112 | return require(path.resolve(process.cwd() + "/node_modules/" + name));
|
113 | }
|
114 | throw err;
|
115 | }
|
116 | };
|
117 | |
118 |
|
119 |
|
120 | PlatformTools.pathNormalize = function (pathStr) {
|
121 | return path.normalize(pathStr);
|
122 | };
|
123 | |
124 |
|
125 |
|
126 | PlatformTools.pathExtname = function (pathStr) {
|
127 | return path.extname(pathStr);
|
128 | };
|
129 | |
130 |
|
131 |
|
132 | PlatformTools.pathResolve = function (pathStr) {
|
133 | return path.resolve(pathStr);
|
134 | };
|
135 | |
136 |
|
137 |
|
138 | PlatformTools.fileExist = function (pathStr) {
|
139 | return fs.existsSync(pathStr);
|
140 | };
|
141 | PlatformTools.readFileSync = function (filename) {
|
142 | return fs.readFileSync(filename);
|
143 | };
|
144 | PlatformTools.appendFileSync = function (filename, data) {
|
145 | fs.appendFileSync(filename, data);
|
146 | };
|
147 | PlatformTools.writeFile = function (path, data) {
|
148 | return tslib_1.__awaiter(this, void 0, void 0, function () {
|
149 | return tslib_1.__generator(this, function (_a) {
|
150 | return [2 , new Promise(function (ok, fail) {
|
151 | fs.writeFile(path, data, function (err) {
|
152 | if (err)
|
153 | fail(err);
|
154 | ok();
|
155 | });
|
156 | })];
|
157 | });
|
158 | });
|
159 | };
|
160 | |
161 |
|
162 |
|
163 | PlatformTools.getEnvVariable = function (name) {
|
164 | return process.env[name];
|
165 | };
|
166 | |
167 |
|
168 |
|
169 | PlatformTools.highlightSql = function (sql) {
|
170 | var theme = {
|
171 | "keyword": chalk.blueBright,
|
172 | "literal": chalk.blueBright,
|
173 | "string": chalk.white,
|
174 | "type": chalk.magentaBright,
|
175 | "built_in": chalk.magentaBright,
|
176 | "comment": chalk.gray,
|
177 | };
|
178 | return cli_highlight_1.highlight(sql, { theme: theme, language: "sql" });
|
179 | };
|
180 | |
181 |
|
182 |
|
183 | PlatformTools.highlightJson = function (json) {
|
184 | return cli_highlight_1.highlight(json, { language: "json" });
|
185 | };
|
186 | |
187 |
|
188 |
|
189 | PlatformTools.logInfo = function (prefix, info) {
|
190 | console.log(chalk.gray.underline(prefix), info);
|
191 | };
|
192 | PlatformTools.logError = function (prefix, error) {
|
193 | console.log(chalk.underline.red(prefix), error);
|
194 | };
|
195 | PlatformTools.logWarn = function (prefix, warning) {
|
196 | console.log(chalk.underline.yellow(prefix), warning);
|
197 | };
|
198 | PlatformTools.log = function (message) {
|
199 | console.log(chalk.underline(message));
|
200 | };
|
201 | PlatformTools.warn = function (message) {
|
202 | return chalk.yellow(message);
|
203 | };
|
204 | |
205 |
|
206 |
|
207 | PlatformTools.type = "node";
|
208 | return PlatformTools;
|
209 | }());
|
210 | exports.PlatformTools = PlatformTools;
|
211 |
|
212 |
|