1 | "use strict";
|
2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4 | return new (P || (P = Promise))(function (resolve, reject) {
|
5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9 | });
|
10 | };
|
11 | var __generator = (this && this.__generator) || function (thisArg, body) {
|
12 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
13 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
14 | function verb(n) { return function (v) { return step([n, v]); }; }
|
15 | function step(op) {
|
16 | if (f) throw new TypeError("Generator is already executing.");
|
17 | while (_) try {
|
18 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
19 | if (y = 0, t) op = [op[0] & 2, t.value];
|
20 | switch (op[0]) {
|
21 | case 0: case 1: t = op; break;
|
22 | case 4: _.label++; return { value: op[1], done: false };
|
23 | case 5: _.label++; y = op[1]; op = [0]; continue;
|
24 | case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
25 | default:
|
26 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
27 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
28 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
29 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
30 | if (t[2]) _.ops.pop();
|
31 | _.trys.pop(); continue;
|
32 | }
|
33 | op = body.call(thisArg, _);
|
34 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
35 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
36 | }
|
37 | };
|
38 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
39 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
40 | };
|
41 | Object.defineProperty(exports, "__esModule", { value: true });
|
42 | var command_line_usage_1 = __importDefault(require("command-line-usage"));
|
43 | var child_process_1 = require("child_process");
|
44 | var npm_1 = require("../../shared/npm");
|
45 | var axios_1 = __importDefault(require("axios"));
|
46 | module.exports = function (ctx) {
|
47 | function showToolVersion() {
|
48 | return __awaiter(this, void 0, void 0, function () {
|
49 | var sections, _a, _b, _c, result;
|
50 | return __generator(this, function (_d) {
|
51 | switch (_d.label) {
|
52 | case 0:
|
53 | _a = [{
|
54 | header: 'Your environment information',
|
55 | content: 'Show something very important.'
|
56 | },
|
57 | {
|
58 | header: 'Tools Version',
|
59 | optionList: [
|
60 | {
|
61 | name: 'node ',
|
62 | typeLabel: '{underline Version:}',
|
63 | description: executeSync('node -v')
|
64 | },
|
65 | {
|
66 | name: 'npm ',
|
67 | typeLabel: '{underline Version:}',
|
68 | description: executeSync('npm -v')
|
69 | },
|
70 | {
|
71 | name: 'tnpm ',
|
72 | typeLabel: '{underline Version:}',
|
73 | description: executeSync('tnpm -v')
|
74 | },
|
75 | {
|
76 | name: 'fef ',
|
77 | typeLabel: '{underline Version:}',
|
78 | description: executeSync('fef -v')
|
79 | },
|
80 | {
|
81 | name: 'Python ',
|
82 | typeLabel: '{underline Version:}',
|
83 | description: executeSync('python -c "import platform; print(platform.python_version())"')
|
84 | }
|
85 | ]
|
86 | },
|
87 | {
|
88 | header: 'Proxy config info',
|
89 | optionList: [
|
90 | {
|
91 | name: 'http_proxy ',
|
92 | typeLabel: '{underline info:}',
|
93 | description: executeSync('echo $http_proxy')
|
94 | },
|
95 | {
|
96 | name: 'npm_config_proxy ',
|
97 | typeLabel: '{underline info:}',
|
98 | description: executeSync('npm config get proxy')
|
99 | },
|
100 | {
|
101 | name: 'npm_config_registry ',
|
102 | typeLabel: '{underline info:}',
|
103 | description: executeSync('npm config get registry')
|
104 | },
|
105 | {
|
106 | name: 'npm user_config path ',
|
107 | typeLabel: '{underline info:}',
|
108 | description: executeSync('npm config get userconfig')
|
109 | },
|
110 | {
|
111 | name: 'iOA pac ',
|
112 | typeLabel: '{underline info:}',
|
113 | description: '@TODO'
|
114 | }
|
115 | ]
|
116 | }];
|
117 | _b = {
|
118 | header: 'Network access info'
|
119 | };
|
120 | _c = {
|
121 | name: 'curl npm_config_registry ',
|
122 | typeLabel: '{underline info:}'
|
123 | };
|
124 | return [4 , accessTnpmRegistry()];
|
125 | case 1:
|
126 | sections = _a.concat([
|
127 | (_b.optionList = [
|
128 | (_c.description = _d.sent(),
|
129 | _c)
|
130 | ],
|
131 | _b)
|
132 | ]);
|
133 | result = command_line_usage_1.default(sections);
|
134 | return [2 , result];
|
135 | }
|
136 | });
|
137 | });
|
138 | }
|
139 | function executeSync(command) {
|
140 | var resultBuf;
|
141 | try {
|
142 | resultBuf = child_process_1.execSync(command, { windowsHide: true });
|
143 | }
|
144 | catch (e) {
|
145 | return e.message;
|
146 | }
|
147 | var result = resultBuf.toString("utf8").trim();
|
148 | return result;
|
149 | }
|
150 | ;
|
151 | function accessTnpmRegistry() {
|
152 | return __awaiter(this, void 0, void 0, function () {
|
153 | var tnpmRegistry, response, error_1;
|
154 | return __generator(this, function (_a) {
|
155 | switch (_a.label) {
|
156 | case 0: return [4 , npm_1.getRegistryUrl('tnpm')];
|
157 | case 1:
|
158 | tnpmRegistry = _a.sent();
|
159 | tnpmRegistry = tnpmRegistry.trim().split('\n');
|
160 | tnpmRegistry = tnpmRegistry[tnpmRegistry.length - 1];
|
161 | _a.label = 2;
|
162 | case 2:
|
163 | _a.trys.push([2, 4, , 5]);
|
164 | return [4 , axios_1.default.get(tnpmRegistry)];
|
165 | case 3:
|
166 | response = _a.sent();
|
167 | if (response.status === 200) {
|
168 | return [2 , 'access tnpm registry is ok!'];
|
169 | }
|
170 | else {
|
171 | return [2 , 'access tnpm registry has error, http code: ${response.statusCode}'];
|
172 | }
|
173 | return [3 , 5];
|
174 | case 4:
|
175 | error_1 = _a.sent();
|
176 | return [2 , 'access tnpm registry has error: ${error}'];
|
177 | case 5: return [2 ];
|
178 | }
|
179 | });
|
180 | });
|
181 | }
|
182 | ctx.commander.register('doctor', 'environment information', function () {
|
183 | showToolVersion().then(function (result) {
|
184 | console.log(result);
|
185 | }).catch(function (error) {
|
186 | console.log('error:', error);
|
187 | });
|
188 | });
|
189 | };
|
190 |
|
\ | No newline at end of file |