bdy 1.18.15-stage → 1.18.17-dev
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/distTs/package.json +1 -1
- package/distTs/src/command/login.js +2 -0
- package/distTs/src/index.js +4 -0
- package/distTs/src/main.js +170 -0
- package/distTs/src/output.js +2 -1
- package/distTs/src/tunnel/cfg.js +1 -0
- package/package.json +1 -1
package/distTs/package.json
CHANGED
|
@@ -9,6 +9,7 @@ const node_http_1 = __importDefault(require("node:http"));
|
|
|
9
9
|
const texts_1 = require("../texts");
|
|
10
10
|
const utils_1 = require("../utils");
|
|
11
11
|
const input_1 = __importDefault(require("../input"));
|
|
12
|
+
const logger_1 = __importDefault(require("../logger"));
|
|
12
13
|
const OAUTH_CLIENT_APP_PORT = 7596;
|
|
13
14
|
const OAUTH_CLIENT_APP_HOST = 'localhost';
|
|
14
15
|
const OAUTH_CLIENT_APP_REDIRECT_URL = `http://localhost:${OAUTH_CLIENT_APP_PORT}`;
|
|
@@ -138,6 +139,7 @@ commandLogin.option('--api <url>', texts_1.OPTION_REST_API_ENDPOINT);
|
|
|
138
139
|
commandLogin.option('--region <region>', texts_1.OPTION_REST_API_REGION);
|
|
139
140
|
commandLogin.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
|
|
140
141
|
commandLogin.action(async (options) => {
|
|
142
|
+
logger_1.default.info(options);
|
|
141
143
|
output_1.default.handleSignals();
|
|
142
144
|
cfg_1.default.clearLogin();
|
|
143
145
|
let api = options.api || process.env.BUDDY_API_ENDPOINT;
|
package/distTs/src/index.js
CHANGED
|
@@ -27,6 +27,7 @@ const api_1 = __importDefault(require("./command/api"));
|
|
|
27
27
|
const autocomplete_1 = __importDefault(require("./autocomplete"));
|
|
28
28
|
const autocomplete_2 = __importDefault(require("./command/autocomplete"));
|
|
29
29
|
const domain_1 = __importDefault(require("./command/domain"));
|
|
30
|
+
const main_1 = __importDefault(require("./main"));
|
|
30
31
|
stream_1.default.setDefaultHighWaterMark(false, 67108864);
|
|
31
32
|
process.title = 'bdy';
|
|
32
33
|
process.on('uncaughtException', (err) => {
|
|
@@ -56,6 +57,9 @@ program.addCommand(workspace_1.default);
|
|
|
56
57
|
program.addCommand(project_1.default);
|
|
57
58
|
program.addCommand(api_1.default);
|
|
58
59
|
program.addCommand(autocomplete_2.default);
|
|
60
|
+
program.action(async () => {
|
|
61
|
+
await (0, main_1.default)(program);
|
|
62
|
+
});
|
|
59
63
|
if (autocomplete_1.default.init(program)) {
|
|
60
64
|
process.exit(0);
|
|
61
65
|
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const output_1 = __importDefault(require("./output"));
|
|
7
|
+
const selectCommand = async (parentCommand) => {
|
|
8
|
+
let items = [];
|
|
9
|
+
const map = {};
|
|
10
|
+
parentCommand.commands.forEach((c) => {
|
|
11
|
+
const name = c.name();
|
|
12
|
+
map[name] = c;
|
|
13
|
+
items.push({
|
|
14
|
+
name,
|
|
15
|
+
description: c.description(),
|
|
16
|
+
value: name,
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
items.push({
|
|
20
|
+
name: 'help',
|
|
21
|
+
description: 'Display help for current command',
|
|
22
|
+
value: 'help',
|
|
23
|
+
});
|
|
24
|
+
items = items.sort((a, b) => a.name.localeCompare(b.name));
|
|
25
|
+
const name = await output_1.default.inputMenuAdv('Command', items);
|
|
26
|
+
if (name === 'help') {
|
|
27
|
+
parentCommand.help();
|
|
28
|
+
output_1.default.exitNormal();
|
|
29
|
+
}
|
|
30
|
+
const cmd = map[name];
|
|
31
|
+
if (cmd.commands.length > 0) {
|
|
32
|
+
return await selectCommand(cmd);
|
|
33
|
+
}
|
|
34
|
+
return cmd;
|
|
35
|
+
};
|
|
36
|
+
const setOptionValue = async (opt) => {
|
|
37
|
+
if (opt.isBoolean()) {
|
|
38
|
+
const val = await output_1.default.inputMenu('Value', ['true', 'false']);
|
|
39
|
+
return val === 0;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
return await output_1.default.inputString('Value', opt.defaultValue);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const nameToCamelCase = (name) => {
|
|
46
|
+
const s = name.split('-');
|
|
47
|
+
if (s.length <= 1)
|
|
48
|
+
return name;
|
|
49
|
+
return s
|
|
50
|
+
.map((txt, i) => {
|
|
51
|
+
if (!txt || !txt.length || !i)
|
|
52
|
+
return txt;
|
|
53
|
+
return `${txt[0].toUpperCase()}${txt.substring(1)}`;
|
|
54
|
+
})
|
|
55
|
+
.join('');
|
|
56
|
+
};
|
|
57
|
+
const camelCaseToName = (cc) => {
|
|
58
|
+
return cc.replace(/[A-Z]/g, (char) => `-${char.toLowerCase()}`);
|
|
59
|
+
};
|
|
60
|
+
const selectOptions = async (cmd) => {
|
|
61
|
+
const options = {};
|
|
62
|
+
if (cmd.options.length > 0) {
|
|
63
|
+
const map = {};
|
|
64
|
+
let items = [];
|
|
65
|
+
cmd.options.forEach((opt) => {
|
|
66
|
+
const name = opt.name();
|
|
67
|
+
map[name] = opt;
|
|
68
|
+
items.push({
|
|
69
|
+
name,
|
|
70
|
+
description: opt.description,
|
|
71
|
+
value: name,
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
items = items.sort((a, b) => a.name.localeCompare(b.name));
|
|
75
|
+
items.unshift({
|
|
76
|
+
name: 'Go next',
|
|
77
|
+
value: '',
|
|
78
|
+
});
|
|
79
|
+
while (true) {
|
|
80
|
+
const name = await output_1.default.inputMenuAdv('Option', items);
|
|
81
|
+
if (map[name]) {
|
|
82
|
+
const opt = map[name];
|
|
83
|
+
const value = await setOptionValue(opt);
|
|
84
|
+
const cc = nameToCamelCase(name);
|
|
85
|
+
if (opt.variadic) {
|
|
86
|
+
if (!options[cc])
|
|
87
|
+
options[cc] = [];
|
|
88
|
+
const o = options[cc];
|
|
89
|
+
o.push(value);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
options[cc] = value;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return options;
|
|
101
|
+
};
|
|
102
|
+
const selectArguments = async (cmd) => {
|
|
103
|
+
const args = [];
|
|
104
|
+
if (cmd.registeredArguments.length > 0) {
|
|
105
|
+
for (let i = 0; i < cmd.registeredArguments.length; i += 1) {
|
|
106
|
+
const arg = cmd.registeredArguments[i];
|
|
107
|
+
let desc = arg.name();
|
|
108
|
+
if (arg.description)
|
|
109
|
+
desc += ` - ${arg.description}`;
|
|
110
|
+
desc += ':';
|
|
111
|
+
const value = await output_1.default.inputString(`${desc[0].toUpperCase()}${desc.substring(1)}`, arg.defaultValue, arg.required);
|
|
112
|
+
if (arg.variadic) {
|
|
113
|
+
args.push(value.split(' '));
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
args.push(value);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return args;
|
|
121
|
+
};
|
|
122
|
+
const outputFinalCommand = (cmd, options, args) => {
|
|
123
|
+
let txt = '';
|
|
124
|
+
let c = cmd;
|
|
125
|
+
while (c !== null) {
|
|
126
|
+
txt = c.name() + ' ' + txt;
|
|
127
|
+
c = c.parent;
|
|
128
|
+
}
|
|
129
|
+
txt = txt.trim();
|
|
130
|
+
Object.entries(options).forEach(([name, val]) => {
|
|
131
|
+
const n = camelCaseToName(name);
|
|
132
|
+
if (val === true) {
|
|
133
|
+
txt += ` --${n}`;
|
|
134
|
+
}
|
|
135
|
+
else if (val === false) {
|
|
136
|
+
txt += ` --${n}=false`;
|
|
137
|
+
}
|
|
138
|
+
else if (Array.isArray(val)) {
|
|
139
|
+
val.forEach((v) => {
|
|
140
|
+
txt += ` --${n}="${v}"`;
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
txt += ` --${n}="${val}"`;
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
args.forEach((arg) => {
|
|
148
|
+
if (Array.isArray(arg)) {
|
|
149
|
+
txt += ` ${arg.map(a => `"${a}"`).join(' ')}`;
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
txt += ` "${arg}"`;
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
output_1.default.cyan('❯ ', false);
|
|
156
|
+
output_1.default.normal(txt);
|
|
157
|
+
};
|
|
158
|
+
const main = async (program) => {
|
|
159
|
+
if (!output_1.default.isTTY()) {
|
|
160
|
+
program.help();
|
|
161
|
+
output_1.default.exitNormal();
|
|
162
|
+
}
|
|
163
|
+
const cmd = await selectCommand(program);
|
|
164
|
+
const options = await selectOptions(cmd);
|
|
165
|
+
const args = await selectArguments(cmd);
|
|
166
|
+
Object.entries(options).forEach(([k, v]) => cmd.setOptionValue(camelCaseToName(k), v));
|
|
167
|
+
outputFinalCommand(cmd, options, args);
|
|
168
|
+
await cmd._actionHandler([...args, options, cmd]);
|
|
169
|
+
};
|
|
170
|
+
exports.default = main;
|
package/distTs/src/output.js
CHANGED
|
@@ -259,10 +259,11 @@ class Output {
|
|
|
259
259
|
this.cyan(` No`);
|
|
260
260
|
return false;
|
|
261
261
|
}
|
|
262
|
-
static async inputString(message, def) {
|
|
262
|
+
static async inputString(message, def, required) {
|
|
263
263
|
if (this.isStdInTTY()) {
|
|
264
264
|
const prompts = require('@inquirer/prompts');
|
|
265
265
|
return await prompts.input({
|
|
266
|
+
required,
|
|
266
267
|
message,
|
|
267
268
|
default: def,
|
|
268
269
|
theme: this.getInquirerTheme(),
|
package/distTs/src/tunnel/cfg.js
CHANGED