@teambit/cli 0.0.590 → 0.0.592
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/dist/cli-parser.js +21 -106
- package/dist/cli-parser.js.map +1 -1
- package/dist/cli.aspect.js +0 -6
- package/dist/cli.aspect.js.map +1 -1
- package/dist/cli.cmd.js +3 -44
- package/dist/cli.cmd.js.map +1 -1
- package/dist/cli.composition.js +0 -6
- package/dist/cli.composition.js.map +1 -1
- package/dist/cli.main.runtime.js +11 -79
- package/dist/cli.main.runtime.js.map +1 -1
- package/dist/command-runner.js +6 -73
- package/dist/command-runner.js.map +1 -1
- package/dist/completion.cmd.js +0 -7
- package/dist/completion.cmd.js.map +1 -1
- package/dist/exceptions/already-exists.js +0 -6
- package/dist/exceptions/already-exists.js.map +1 -1
- package/dist/exceptions/command-not-found.js +0 -16
- package/dist/exceptions/command-not-found.js.map +1 -1
- package/dist/exceptions/index.js +0 -3
- package/dist/exceptions/index.js.map +1 -1
- package/dist/generate-doc-md.js +0 -33
- package/dist/generate-doc-md.js.map +1 -1
- package/dist/get-command-id.js +0 -3
- package/dist/get-command-id.js.map +1 -1
- package/dist/help.cmd.js +1 -12
- package/dist/help.cmd.js.map +1 -1
- package/dist/help.js +0 -23
- package/dist/help.js.map +1 -1
- package/dist/index.js +0 -11
- package/dist/index.js.map +1 -1
- package/dist/legacy-command-adapter.js +0 -14
- package/dist/legacy-command-adapter.js.map +1 -1
- package/dist/yargs-adapter.js +6 -41
- package/dist/yargs-adapter.js.map +1 -1
- package/package-tar/teambit-cli-0.0.592.tgz +0 -0
- package/package.json +5 -5
- package/{preview-1666312873430.js → preview-1666669368175.js} +2 -2
- package/package-tar/teambit-cli-0.0.590.tgz +0 -0
package/dist/command-runner.js
CHANGED
|
@@ -1,116 +1,82 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
require("core-js/modules/es.promise.js");
|
|
6
|
-
|
|
7
5
|
require("core-js/modules/es.regexp.flags.js");
|
|
8
|
-
|
|
9
6
|
Object.defineProperty(exports, "__esModule", {
|
|
10
7
|
value: true
|
|
11
8
|
});
|
|
12
9
|
exports.CommandRunner = void 0;
|
|
13
|
-
|
|
14
10
|
function _defineProperty2() {
|
|
15
11
|
const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
16
|
-
|
|
17
12
|
_defineProperty2 = function () {
|
|
18
13
|
return data;
|
|
19
14
|
};
|
|
20
|
-
|
|
21
15
|
return data;
|
|
22
16
|
}
|
|
23
|
-
|
|
24
17
|
function _ink() {
|
|
25
18
|
const data = require("ink");
|
|
26
|
-
|
|
27
19
|
_ink = function () {
|
|
28
20
|
return data;
|
|
29
21
|
};
|
|
30
|
-
|
|
31
22
|
return data;
|
|
32
23
|
}
|
|
33
|
-
|
|
34
24
|
function _consumer() {
|
|
35
25
|
const data = require("@teambit/legacy/dist/api/consumer");
|
|
36
|
-
|
|
37
26
|
_consumer = function () {
|
|
38
27
|
return data;
|
|
39
28
|
};
|
|
40
|
-
|
|
41
29
|
return data;
|
|
42
30
|
}
|
|
43
|
-
|
|
44
31
|
function _logger() {
|
|
45
32
|
const data = _interopRequireDefault(require("@teambit/legacy/dist/logger/logger"));
|
|
46
|
-
|
|
47
33
|
_logger = function () {
|
|
48
34
|
return data;
|
|
49
35
|
};
|
|
50
|
-
|
|
51
36
|
return data;
|
|
52
37
|
}
|
|
53
|
-
|
|
54
38
|
function _commandRegistry() {
|
|
55
39
|
const data = require("@teambit/legacy/dist/cli/command-registry");
|
|
56
|
-
|
|
57
40
|
_commandRegistry = function () {
|
|
58
41
|
return data;
|
|
59
42
|
};
|
|
60
|
-
|
|
61
43
|
return data;
|
|
62
44
|
}
|
|
63
|
-
|
|
64
45
|
function _loader() {
|
|
65
46
|
const data = _interopRequireDefault(require("@teambit/legacy/dist/cli/loader"));
|
|
66
|
-
|
|
67
47
|
_loader = function () {
|
|
68
48
|
return data;
|
|
69
49
|
};
|
|
70
|
-
|
|
71
50
|
return data;
|
|
72
51
|
}
|
|
73
|
-
|
|
74
52
|
function _handleErrors() {
|
|
75
53
|
const data = require("@teambit/legacy/dist/cli/handle-errors");
|
|
76
|
-
|
|
77
54
|
_handleErrors = function () {
|
|
78
55
|
return data;
|
|
79
56
|
};
|
|
80
|
-
|
|
81
57
|
return data;
|
|
82
58
|
}
|
|
83
|
-
|
|
84
59
|
function _constants() {
|
|
85
60
|
const data = require("@teambit/legacy/dist/constants");
|
|
86
|
-
|
|
87
61
|
_constants = function () {
|
|
88
62
|
return data;
|
|
89
63
|
};
|
|
90
|
-
|
|
91
64
|
return data;
|
|
92
65
|
}
|
|
93
|
-
|
|
94
66
|
function _globalFlags() {
|
|
95
67
|
const data = _interopRequireDefault(require("@teambit/legacy/dist/cli/global-flags"));
|
|
96
|
-
|
|
97
68
|
_globalFlags = function () {
|
|
98
69
|
return data;
|
|
99
70
|
};
|
|
100
|
-
|
|
101
71
|
return data;
|
|
102
72
|
}
|
|
103
|
-
|
|
104
73
|
function _analytics() {
|
|
105
74
|
const data = require("@teambit/legacy/dist/analytics/analytics");
|
|
106
|
-
|
|
107
75
|
_analytics = function () {
|
|
108
76
|
return data;
|
|
109
77
|
};
|
|
110
|
-
|
|
111
78
|
return data;
|
|
112
79
|
}
|
|
113
|
-
|
|
114
80
|
class CommandRunner {
|
|
115
81
|
constructor(command, args, flags) {
|
|
116
82
|
this.command = command;
|
|
@@ -119,70 +85,57 @@ class CommandRunner {
|
|
|
119
85
|
(0, _defineProperty2().default)(this, "commandName", void 0);
|
|
120
86
|
this.commandName = (0, _commandRegistry().parseCommandName)(this.command.name);
|
|
121
87
|
}
|
|
88
|
+
|
|
122
89
|
/**
|
|
123
90
|
* run command using one of the handler, "json"/"report"/"render". once done, exit the process.
|
|
124
91
|
*/
|
|
125
|
-
|
|
126
|
-
|
|
127
92
|
async runCommand() {
|
|
128
93
|
try {
|
|
129
94
|
this.bootstrapCommand();
|
|
130
95
|
await this.runMigrateIfNeeded();
|
|
131
96
|
this.determineConsoleWritingDuringCommand();
|
|
132
|
-
|
|
133
97
|
if (this.flags.json) {
|
|
134
98
|
return await this.runJsonHandler();
|
|
135
99
|
}
|
|
136
|
-
|
|
137
100
|
if (this.shouldRunRender()) {
|
|
138
101
|
return await this.runRenderHandler();
|
|
139
102
|
}
|
|
140
|
-
|
|
141
103
|
if (this.command.report) {
|
|
142
104
|
return await this.runReportHandler();
|
|
143
105
|
}
|
|
144
106
|
} catch (err) {
|
|
145
107
|
return (0, _handleErrors().handleErrorAndExit)(err, this.commandName, this.command.internal);
|
|
146
108
|
}
|
|
147
|
-
|
|
148
109
|
throw new Error(`command "${this.commandName}" doesn't implement "render" nor "report" methods`);
|
|
149
110
|
}
|
|
150
|
-
|
|
151
111
|
bootstrapCommand() {
|
|
152
112
|
_analytics().Analytics.init(this.commandName, this.flags, this.args);
|
|
153
|
-
|
|
154
113
|
_logger().default.info(`[*] started a new command: "${this.commandName}" with the following data:`, {
|
|
155
114
|
args: this.args,
|
|
156
115
|
flags: this.flags
|
|
157
116
|
});
|
|
158
|
-
|
|
159
117
|
const token = this.flags[_constants().TOKEN_FLAG_NAME];
|
|
160
|
-
|
|
161
118
|
if (token) {
|
|
162
119
|
_globalFlags().default.token = token.toString();
|
|
163
120
|
}
|
|
164
121
|
}
|
|
122
|
+
|
|
165
123
|
/**
|
|
166
124
|
* when both "render" and "report" were implemented, check whether it's a terminal.
|
|
167
125
|
* if it's a terminal, use "render", if not, use "report" because "report" is just a string
|
|
168
126
|
*/
|
|
169
|
-
|
|
170
|
-
|
|
171
127
|
shouldRunRender() {
|
|
172
128
|
const isTerminal = process.stdout.isTTY;
|
|
173
|
-
|
|
174
129
|
if (this.command.report && !isTerminal) {
|
|
175
130
|
return false;
|
|
176
131
|
}
|
|
177
|
-
|
|
178
132
|
return Boolean(this.command.render);
|
|
179
133
|
}
|
|
134
|
+
|
|
180
135
|
/**
|
|
181
136
|
* this works for both, Harmony commands and Legacy commands (the legacy-command-adapter
|
|
182
137
|
* implements json() method)
|
|
183
138
|
*/
|
|
184
|
-
|
|
185
|
-
|
|
186
139
|
async runJsonHandler() {
|
|
187
140
|
if (!this.flags.json) return null;
|
|
188
141
|
if (!this.command.json) throw new Error(`command "${this.commandName}" doesn't implement "json" method`);
|
|
@@ -191,13 +144,10 @@ class CommandRunner {
|
|
|
191
144
|
const data = result.data || result;
|
|
192
145
|
return this.writeAndExit(JSON.stringify(data, null, 2), code);
|
|
193
146
|
}
|
|
194
|
-
|
|
195
147
|
async runRenderHandler() {
|
|
196
148
|
if (!this.command.render) throw new Error('runRenderHandler expects command.render to be implemented');
|
|
197
149
|
const result = await this.command.render(this.args, this.flags);
|
|
198
|
-
|
|
199
150
|
_loader().default.off();
|
|
200
|
-
|
|
201
151
|
const {
|
|
202
152
|
data,
|
|
203
153
|
code
|
|
@@ -208,72 +158,55 @@ class CommandRunner {
|
|
|
208
158
|
await waitUntilExit();
|
|
209
159
|
return _logger().default.exitAfterFlush(code, this.commandName);
|
|
210
160
|
}
|
|
211
|
-
|
|
212
161
|
async runReportHandler() {
|
|
213
162
|
if (!this.command.report) throw new Error('runReportHandler expects command.report to be implemented');
|
|
214
163
|
const result = await this.command.report(this.args, this.flags);
|
|
215
|
-
|
|
216
164
|
_loader().default.off();
|
|
217
|
-
|
|
218
165
|
const data = typeof result === 'string' ? result : result.data;
|
|
219
166
|
const exitCode = typeof result === 'string' ? 0 : result.code;
|
|
220
167
|
return this.writeAndExit(`${data}\n`, exitCode);
|
|
221
168
|
}
|
|
169
|
+
|
|
222
170
|
/**
|
|
223
171
|
* the loader and logger.console write output to the console during the command execution.
|
|
224
172
|
* for internals commands, such as, _put, _fetch, the command.loader = false.
|
|
225
173
|
*/
|
|
226
|
-
|
|
227
|
-
|
|
228
174
|
determineConsoleWritingDuringCommand() {
|
|
229
175
|
if (this.command.loader && !this.flags.json && !this.flags['get-yargs-completions']) {
|
|
230
176
|
_loader().default.on();
|
|
231
|
-
|
|
232
177
|
_loader().default.start(`running command "${this.commandName}"...`);
|
|
233
|
-
|
|
234
178
|
_logger().default.shouldWriteToConsole = true;
|
|
235
179
|
} else {
|
|
236
180
|
_loader().default.off();
|
|
237
|
-
|
|
238
181
|
_logger().default.shouldWriteToConsole = false;
|
|
239
182
|
}
|
|
240
|
-
|
|
241
183
|
if (this.flags.log) {
|
|
242
184
|
// probably not necessary anymore. it is handled in src/logger - determineWritingLogToScreen()
|
|
243
185
|
const logValue = typeof this.flags.log === 'string' ? this.flags.log : undefined;
|
|
244
|
-
|
|
245
186
|
_logger().default.switchToConsoleLogger(logValue);
|
|
246
187
|
}
|
|
247
188
|
}
|
|
248
|
-
|
|
249
189
|
async writeAndExit(data, exitCode) {
|
|
250
190
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
251
191
|
return process.stdout.write(data, async () => _logger().default.exitAfterFlush(exitCode, this.commandName, data));
|
|
252
192
|
}
|
|
253
|
-
|
|
254
193
|
async runMigrateIfNeeded() {
|
|
255
194
|
// @ts-ignore LegacyCommandAdapter has .migration
|
|
256
195
|
if (this.command.migration) {
|
|
257
|
-
_logger().default.debug('Checking if a migration is needed');
|
|
258
|
-
|
|
259
|
-
|
|
196
|
+
_logger().default.debug('Checking if a migration is needed');
|
|
197
|
+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
|
|
260
198
|
return (0, _consumer().migrate)(null, false);
|
|
261
199
|
}
|
|
262
|
-
|
|
263
200
|
return null;
|
|
264
201
|
}
|
|
265
|
-
|
|
266
202
|
}
|
|
267
|
-
|
|
268
203
|
exports.CommandRunner = CommandRunner;
|
|
269
|
-
|
|
270
204
|
function toRenderResult(obj) {
|
|
271
205
|
return isRenderResult(obj) ? obj : {
|
|
272
206
|
data: obj,
|
|
273
207
|
code: 0
|
|
274
208
|
};
|
|
275
209
|
}
|
|
276
|
-
|
|
277
210
|
function isRenderResult(obj) {
|
|
278
211
|
// eslint-disable-next-line no-prototype-builtins
|
|
279
212
|
return typeof obj === 'object' && typeof obj.code === 'number' && obj.hasOwnProperty('data');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["CommandRunner","constructor","command","args","flags","commandName","parseCommandName","name","runCommand","bootstrapCommand","runMigrateIfNeeded","determineConsoleWritingDuringCommand","json","runJsonHandler","shouldRunRender","runRenderHandler","report","runReportHandler","err","handleErrorAndExit","internal","Error","Analytics","init","logger","info","token","TOKEN_FLAG_NAME","globalFlags","toString","isTerminal","process","stdout","isTTY","Boolean","render","result","code","data","writeAndExit","JSON","stringify","loader","off","toRenderResult","waitUntilExit","exitAfterFlush","exitCode","on","start","shouldWriteToConsole","log","logValue","undefined","switchToConsoleLogger","write","migration","debug","migrate","obj","isRenderResult","hasOwnProperty"],"sources":["command-runner.ts"],"sourcesContent":["import { render } from 'ink';\nimport { migrate } from '@teambit/legacy/dist/api/consumer';\nimport logger, { LoggerLevel } from '@teambit/legacy/dist/logger/logger';\nimport { CLIArgs, Command, Flags, RenderResult } from '@teambit/legacy/dist/cli/command';\nimport { parseCommandName } from '@teambit/legacy/dist/cli/command-registry';\nimport loader from '@teambit/legacy/dist/cli/loader';\nimport { handleErrorAndExit } from '@teambit/legacy/dist/cli/handle-errors';\nimport { TOKEN_FLAG_NAME } from '@teambit/legacy/dist/constants';\nimport globalFlags from '@teambit/legacy/dist/cli/global-flags';\nimport { Analytics } from '@teambit/legacy/dist/analytics/analytics';\n\nexport class CommandRunner {\n private commandName: string;\n constructor(private command: Command, private args: CLIArgs, private flags: Flags) {\n this.commandName = parseCommandName(this.command.name);\n }\n\n /**\n * run command using one of the handler, \"json\"/\"report\"/\"render\". once done, exit the process.\n */\n async runCommand() {\n try {\n this.bootstrapCommand();\n await this.runMigrateIfNeeded();\n this.determineConsoleWritingDuringCommand();\n if (this.flags.json) {\n return await this.runJsonHandler();\n }\n if (this.shouldRunRender()) {\n return await this.runRenderHandler();\n }\n if (this.command.report) {\n return await this.runReportHandler();\n }\n } catch (err: any) {\n return handleErrorAndExit(err, this.commandName, this.command.internal);\n }\n\n throw new Error(`command \"${this.commandName}\" doesn't implement \"render\" nor \"report\" methods`);\n }\n\n private bootstrapCommand() {\n Analytics.init(this.commandName, this.flags, this.args);\n logger.info(`[*] started a new command: \"${this.commandName}\" with the following data:`, {\n args: this.args,\n flags: this.flags,\n });\n const token = this.flags[TOKEN_FLAG_NAME];\n if (token) {\n globalFlags.token = token.toString();\n }\n }\n\n /**\n * when both \"render\" and \"report\" were implemented, check whether it's a terminal.\n * if it's a terminal, use \"render\", if not, use \"report\" because \"report\" is just a string\n */\n private shouldRunRender() {\n const isTerminal = process.stdout.isTTY;\n if (this.command.report && !isTerminal) {\n return false;\n }\n return Boolean(this.command.render);\n }\n\n /**\n * this works for both, Harmony commands and Legacy commands (the legacy-command-adapter\n * implements json() method)\n */\n private async runJsonHandler() {\n if (!this.flags.json) return null;\n if (!this.command.json) throw new Error(`command \"${this.commandName}\" doesn't implement \"json\" method`);\n const result = await this.command.json(this.args, this.flags);\n const code = result.code || 0;\n const data = result.data || result;\n return this.writeAndExit(JSON.stringify(data, null, 2), code);\n }\n\n private async runRenderHandler() {\n if (!this.command.render) throw new Error('runRenderHandler expects command.render to be implemented');\n const result = await this.command.render(this.args, this.flags);\n loader.off();\n\n const { data, code } = toRenderResult(result);\n\n const { waitUntilExit } = render(data);\n await waitUntilExit();\n return logger.exitAfterFlush(code, this.commandName);\n }\n\n private async runReportHandler() {\n if (!this.command.report) throw new Error('runReportHandler expects command.report to be implemented');\n const result = await this.command.report(this.args, this.flags);\n loader.off();\n const data = typeof result === 'string' ? result : result.data;\n const exitCode = typeof result === 'string' ? 0 : result.code;\n return this.writeAndExit(`${data}\\n`, exitCode);\n }\n\n /**\n * the loader and logger.console write output to the console during the command execution.\n * for internals commands, such as, _put, _fetch, the command.loader = false.\n */\n private determineConsoleWritingDuringCommand() {\n if (this.command.loader && !this.flags.json && !this.flags['get-yargs-completions']) {\n loader.on();\n loader.start(`running command \"${this.commandName}\"...`);\n logger.shouldWriteToConsole = true;\n } else {\n loader.off();\n logger.shouldWriteToConsole = false;\n }\n if (this.flags.log) {\n // probably not necessary anymore. it is handled in src/logger - determineWritingLogToScreen()\n const logValue = typeof this.flags.log === 'string' ? this.flags.log : undefined;\n logger.switchToConsoleLogger(logValue as LoggerLevel);\n }\n }\n\n private async writeAndExit(data: string, exitCode: number) {\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n return process.stdout.write(data, async () => logger.exitAfterFlush(exitCode, this.commandName, data));\n }\n\n private async runMigrateIfNeeded(): Promise<any> {\n // @ts-ignore LegacyCommandAdapter has .migration\n if (this.command.migration) {\n logger.debug('Checking if a migration is needed');\n // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!\n return migrate(null, false);\n }\n return null;\n }\n}\n\nfunction toRenderResult(obj: RenderResult | React.ReactElement) {\n return isRenderResult(obj) ? obj : { data: obj, code: 0 };\n}\n\nfunction isRenderResult(obj: RenderResult | any): obj is RenderResult {\n // eslint-disable-next-line no-prototype-builtins\n return typeof obj === 'object' && typeof obj.code === 'number' && obj.hasOwnProperty('data');\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEO,MAAMA,aAAN,CAAoB;EAEzBC,WAAW,CA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qC,KAAK/C,KAAL,CAAW+C,GAAhD,GAAsDE,SAAvE;;MACA7B,iBAAA,CAAO8B,qBAAP,CAA6BF,QAA7B;IACD;EACF;;EAEyB,MAAZb,YAAY,CAACD,IAAD,EAAeS,QAAf,EAAiC;IACzD;IACA,OAAOhB,OAAO,CAACC,MAAR,CAAeuB,KAAf,CAAqBjB,IAArB,EAA2B,YAAYd,iBAAA,CAAOsB,cAAP,CAAsBC,QAAtB,EAAgC,KAAK1C,WAArC,EAAkDiC,IAAlD,CAAvC,CAAP;EACD;;EAE+B,MAAlB5B,kBAAkB,GAAiB;IAC/C;IACA,IAAI,KAAKR,OAAL,CAAasD,SAAjB,EAA4B;MAC1BhC,iBAAA,CAAOiC,KAAP,CAAa,mCAAb,EAD0B,CAE1B;;;MACA,OAAO,IAAAC,mBAAA,EAAQ,IAAR,EAAc,KAAd,CAAP;IACD;;IACD,OAAO,IAAP;EACD;;AAzHwB;;;;AA4H3B,SAASd,cAAT,CAAwBe,GAAxB,EAAgE;EAC9D,OAAOC,cAAc,CAACD,GAAD,CAAd,GAAsBA,GAAtB,GAA4B;IAAErB,IAAI,EAAEqB,GAAR;IAAatB,IAAI,EAAE;EAAnB,CAAnC;AACD;;AAED,SAASuB,cAAT,CAAwBD,GAAxB,EAAsE;EACpE;EACA,OAAO,OAAOA,GAAP,KAAe,QAAf,IAA2B,OAAOA,GAAG,CAACtB,IAAX,KAAoB,QAA/C,IAA2DsB,GAAG,CAACE,cAAJ,CAAmB,MAAnB,CAAlE;AACD"}
|
|
1
|
+
{"version":3,"names":["CommandRunner","constructor","command","args","flags","commandName","parseCommandName","name","runCommand","bootstrapCommand","runMigrateIfNeeded","determineConsoleWritingDuringCommand","json","runJsonHandler","shouldRunRender","runRenderHandler","report","runReportHandler","err","handleErrorAndExit","internal","Error","Analytics","init","logger","info","token","TOKEN_FLAG_NAME","globalFlags","toString","isTerminal","process","stdout","isTTY","Boolean","render","result","code","data","writeAndExit","JSON","stringify","loader","off","toRenderResult","waitUntilExit","exitAfterFlush","exitCode","on","start","shouldWriteToConsole","log","logValue","undefined","switchToConsoleLogger","write","migration","debug","migrate","obj","isRenderResult","hasOwnProperty"],"sources":["command-runner.ts"],"sourcesContent":["import { render } from 'ink';\nimport { migrate } from '@teambit/legacy/dist/api/consumer';\nimport logger, { LoggerLevel } from '@teambit/legacy/dist/logger/logger';\nimport { CLIArgs, Command, Flags, RenderResult } from '@teambit/legacy/dist/cli/command';\nimport { parseCommandName } from '@teambit/legacy/dist/cli/command-registry';\nimport loader from '@teambit/legacy/dist/cli/loader';\nimport { handleErrorAndExit } from '@teambit/legacy/dist/cli/handle-errors';\nimport { TOKEN_FLAG_NAME } from '@teambit/legacy/dist/constants';\nimport globalFlags from '@teambit/legacy/dist/cli/global-flags';\nimport { Analytics } from '@teambit/legacy/dist/analytics/analytics';\n\nexport class CommandRunner {\n private commandName: string;\n constructor(private command: Command, private args: CLIArgs, private flags: Flags) {\n this.commandName = parseCommandName(this.command.name);\n }\n\n /**\n * run command using one of the handler, \"json\"/\"report\"/\"render\". once done, exit the process.\n */\n async runCommand() {\n try {\n this.bootstrapCommand();\n await this.runMigrateIfNeeded();\n this.determineConsoleWritingDuringCommand();\n if (this.flags.json) {\n return await this.runJsonHandler();\n }\n if (this.shouldRunRender()) {\n return await this.runRenderHandler();\n }\n if (this.command.report) {\n return await this.runReportHandler();\n }\n } catch (err: any) {\n return handleErrorAndExit(err, this.commandName, this.command.internal);\n }\n\n throw new Error(`command \"${this.commandName}\" doesn't implement \"render\" nor \"report\" methods`);\n }\n\n private bootstrapCommand() {\n Analytics.init(this.commandName, this.flags, this.args);\n logger.info(`[*] started a new command: \"${this.commandName}\" with the following data:`, {\n args: this.args,\n flags: this.flags,\n });\n const token = this.flags[TOKEN_FLAG_NAME];\n if (token) {\n globalFlags.token = token.toString();\n }\n }\n\n /**\n * when both \"render\" and \"report\" were implemented, check whether it's a terminal.\n * if it's a terminal, use \"render\", if not, use \"report\" because \"report\" is just a string\n */\n private shouldRunRender() {\n const isTerminal = process.stdout.isTTY;\n if (this.command.report && !isTerminal) {\n return false;\n }\n return Boolean(this.command.render);\n }\n\n /**\n * this works for both, Harmony commands and Legacy commands (the legacy-command-adapter\n * implements json() method)\n */\n private async runJsonHandler() {\n if (!this.flags.json) return null;\n if (!this.command.json) throw new Error(`command \"${this.commandName}\" doesn't implement \"json\" method`);\n const result = await this.command.json(this.args, this.flags);\n const code = result.code || 0;\n const data = result.data || result;\n return this.writeAndExit(JSON.stringify(data, null, 2), code);\n }\n\n private async runRenderHandler() {\n if (!this.command.render) throw new Error('runRenderHandler expects command.render to be implemented');\n const result = await this.command.render(this.args, this.flags);\n loader.off();\n\n const { data, code } = toRenderResult(result);\n\n const { waitUntilExit } = render(data);\n await waitUntilExit();\n return logger.exitAfterFlush(code, this.commandName);\n }\n\n private async runReportHandler() {\n if (!this.command.report) throw new Error('runReportHandler expects command.report to be implemented');\n const result = await this.command.report(this.args, this.flags);\n loader.off();\n const data = typeof result === 'string' ? result : result.data;\n const exitCode = typeof result === 'string' ? 0 : result.code;\n return this.writeAndExit(`${data}\\n`, exitCode);\n }\n\n /**\n * the loader and logger.console write output to the console during the command execution.\n * for internals commands, such as, _put, _fetch, the command.loader = false.\n */\n private determineConsoleWritingDuringCommand() {\n if (this.command.loader && !this.flags.json && !this.flags['get-yargs-completions']) {\n loader.on();\n loader.start(`running command \"${this.commandName}\"...`);\n logger.shouldWriteToConsole = true;\n } else {\n loader.off();\n logger.shouldWriteToConsole = false;\n }\n if (this.flags.log) {\n // probably not necessary anymore. it is handled in src/logger - determineWritingLogToScreen()\n const logValue = typeof this.flags.log === 'string' ? this.flags.log : undefined;\n logger.switchToConsoleLogger(logValue as LoggerLevel);\n }\n }\n\n private async writeAndExit(data: string, exitCode: number) {\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n return process.stdout.write(data, async () => logger.exitAfterFlush(exitCode, this.commandName, data));\n }\n\n private async runMigrateIfNeeded(): Promise<any> {\n // @ts-ignore LegacyCommandAdapter has .migration\n if (this.command.migration) {\n logger.debug('Checking if a migration is needed');\n // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!\n return migrate(null, false);\n }\n return null;\n }\n}\n\nfunction toRenderResult(obj: RenderResult | React.ReactElement) {\n return isRenderResult(obj) ? obj : { data: obj, code: 0 };\n}\n\nfunction isRenderResult(obj: RenderResult | any): obj is RenderResult {\n // eslint-disable-next-line no-prototype-builtins\n return typeof obj === 'object' && typeof obj.code === 'number' && obj.hasOwnProperty('data');\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEO,MAAMA,aAAa,CAAC;EAEzBC,WAAW,CAASC,OAAgB,EAAUC,IAAa,EAAUC,KAAY,EAAE;IAAA,KAA/DF,OAAgB,GAAhBA,OAAgB;IAAA,KAAUC,IAAa,GAAbA,IAAa;IAAA,KAAUC,KAAY,GAAZA,KAAY;IAAA;IAC/E,IAAI,CAACC,WAAW,GAAG,IAAAC,mCAAgB,EAAC,IAAI,CAACJ,OAAO,CAACK,IAAI,CAAC;EACxD;;EAEA;AACF;AACA;EACE,MAAMC,UAAU,GAAG;IACjB,IAAI;MACF,IAAI,CAACC,gBAAgB,EAAE;MACvB,MAAM,IAAI,CAACC,kBAAkB,EAAE;MAC/B,IAAI,CAACC,oCAAoC,EAAE;MAC3C,IAAI,IAAI,CAACP,KAAK,CAACQ,IAAI,EAAE;Q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WAAW,EAAEiC,IAAI,CAAC,CAAC;EACxG;EAEA,MAAc5B,kBAAkB,GAAiB;IAC/C;IACA,IAAI,IAAI,CAACR,OAAO,CAACsD,SAAS,EAAE;MAC1BhC,iBAAM,CAACiC,KAAK,CAAC,mCAAmC,CAAC;MACjD;MACA,OAAO,IAAAC,mBAAO,EAAC,IAAI,EAAE,KAAK,CAAC;IAC7B;IACA,OAAO,IAAI;EACb;AACF;AAAC;AAED,SAASd,cAAc,CAACe,GAAsC,EAAE;EAC9D,OAAOC,cAAc,CAACD,GAAG,CAAC,GAAGA,GAAG,GAAG;IAAErB,IAAI,EAAEqB,GAAG;IAAEtB,IAAI,EAAE;EAAE,CAAC;AAC3D;AAEA,SAASuB,cAAc,CAACD,GAAuB,EAAuB;EACpE;EACA,OAAO,OAAOA,GAAG,KAAK,QAAQ,IAAI,OAAOA,GAAG,CAACtB,IAAI,KAAK,QAAQ,IAAIsB,GAAG,CAACE,cAAc,CAAC,MAAM,CAAC;AAC9F"}
|
package/dist/completion.cmd.js
CHANGED
|
@@ -1,22 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.CompletionCmd = void 0;
|
|
9
|
-
|
|
10
8
|
function _defineProperty2() {
|
|
11
9
|
const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
12
|
-
|
|
13
10
|
_defineProperty2 = function () {
|
|
14
11
|
return data;
|
|
15
12
|
};
|
|
16
|
-
|
|
17
13
|
return data;
|
|
18
14
|
}
|
|
19
|
-
|
|
20
15
|
class CompletionCmd {
|
|
21
16
|
constructor() {
|
|
22
17
|
(0, _defineProperty2().default)(this, "name", 'completion');
|
|
@@ -25,9 +20,7 @@ class CompletionCmd {
|
|
|
25
20
|
(0, _defineProperty2().default)(this, "group", 'general');
|
|
26
21
|
(0, _defineProperty2().default)(this, "options", []);
|
|
27
22
|
}
|
|
28
|
-
|
|
29
23
|
}
|
|
30
|
-
|
|
31
24
|
exports.CompletionCmd = CompletionCmd;
|
|
32
25
|
|
|
33
26
|
//# sourceMappingURL=completion.cmd.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["CompletionCmd"],"sources":["completion.cmd.ts"],"sourcesContent":["import { Command } from '@teambit/legacy/dist/cli/command';\n\nexport class CompletionCmd implements Command {\n name = 'completion';\n description = 'enable bash/zsh-completion shortcuts for commands and options';\n alias = '';\n group = 'general';\n options = [];\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["CompletionCmd"],"sources":["completion.cmd.ts"],"sourcesContent":["import { Command } from '@teambit/legacy/dist/cli/command';\n\nexport class CompletionCmd implements Command {\n name = 'completion';\n description = 'enable bash/zsh-completion shortcuts for commands and options';\n alias = '';\n group = 'general';\n options = [];\n}\n"],"mappings":";;;;;;;;;;;;;;AAEO,MAAMA,aAAa,CAAoB;EAAA;IAAA,8CACrC,YAAY;IAAA,qDACL,+DAA+D;IAAA,+CACrE,EAAE;IAAA,+CACF,SAAS;IAAA,iDACP,EAAE;EAAA;AACd;AAAC"}
|
|
@@ -4,24 +4,18 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.AlreadyExistsError = void 0;
|
|
7
|
-
|
|
8
7
|
function _bitError() {
|
|
9
8
|
const data = require("@teambit/bit-error");
|
|
10
|
-
|
|
11
9
|
_bitError = function () {
|
|
12
10
|
return data;
|
|
13
11
|
};
|
|
14
|
-
|
|
15
12
|
return data;
|
|
16
13
|
}
|
|
17
|
-
|
|
18
14
|
class AlreadyExistsError extends _bitError().BitError {
|
|
19
15
|
constructor(type, name) {
|
|
20
16
|
super(`${type} ${name} already exists.`);
|
|
21
17
|
}
|
|
22
|
-
|
|
23
18
|
}
|
|
24
|
-
|
|
25
19
|
exports.AlreadyExistsError = AlreadyExistsError;
|
|
26
20
|
|
|
27
21
|
//# sourceMappingURL=already-exists.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["AlreadyExistsError","BitError","constructor","type","name"],"sources":["already-exists.ts"],"sourcesContent":["import { BitError } from '@teambit/bit-error';\n\nexport class AlreadyExistsError extends BitError {\n constructor(type: string, name: string) {\n super(`${type} ${name} already exists.`);\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["AlreadyExistsError","BitError","constructor","type","name"],"sources":["already-exists.ts"],"sourcesContent":["import { BitError } from '@teambit/bit-error';\n\nexport class AlreadyExistsError extends BitError {\n constructor(type: string, name: string) {\n super(`${type} ${name} already exists.`);\n }\n}\n"],"mappings":";;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEO,MAAMA,kBAAkB,SAASC,oBAAQ,CAAC;EAC/CC,WAAW,CAACC,IAAY,EAAEC,IAAY,EAAE;IACtC,KAAK,CAAE,GAAED,IAAK,IAAGC,IAAK,kBAAiB,CAAC;EAC1C;AACF;AAAC"}
|
|
@@ -1,42 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.CommandNotFound = void 0;
|
|
9
|
-
|
|
10
8
|
function _defineProperty2() {
|
|
11
9
|
const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
12
|
-
|
|
13
10
|
_defineProperty2 = function () {
|
|
14
11
|
return data;
|
|
15
12
|
};
|
|
16
|
-
|
|
17
13
|
return data;
|
|
18
14
|
}
|
|
19
|
-
|
|
20
15
|
function _bitError() {
|
|
21
16
|
const data = require("@teambit/bit-error");
|
|
22
|
-
|
|
23
17
|
_bitError = function () {
|
|
24
18
|
return data;
|
|
25
19
|
};
|
|
26
|
-
|
|
27
20
|
return data;
|
|
28
21
|
}
|
|
29
|
-
|
|
30
22
|
function _chalk() {
|
|
31
23
|
const data = _interopRequireDefault(require("chalk"));
|
|
32
|
-
|
|
33
24
|
_chalk = function () {
|
|
34
25
|
return data;
|
|
35
26
|
};
|
|
36
|
-
|
|
37
27
|
return data;
|
|
38
28
|
}
|
|
39
|
-
|
|
40
29
|
class CommandNotFound extends _bitError().BitError {
|
|
41
30
|
constructor(commandName, suggestion) {
|
|
42
31
|
super(`command ${commandName} was not found`);
|
|
@@ -45,20 +34,15 @@ class CommandNotFound extends _bitError().BitError {
|
|
|
45
34
|
this.commandName = commandName;
|
|
46
35
|
this.suggestion = suggestion;
|
|
47
36
|
}
|
|
48
|
-
|
|
49
37
|
report() {
|
|
50
38
|
let output = _chalk().default.yellow(`warning: '${_chalk().default.bold(this.commandName)}' is not a valid command.
|
|
51
39
|
see 'bit help' for additional information`);
|
|
52
|
-
|
|
53
40
|
if (this.suggestion) {
|
|
54
41
|
output += `\nDid you mean ${_chalk().default.bold(this.suggestion)}?`;
|
|
55
42
|
}
|
|
56
|
-
|
|
57
43
|
return output;
|
|
58
44
|
}
|
|
59
|
-
|
|
60
45
|
}
|
|
61
|
-
|
|
62
46
|
exports.CommandNotFound = CommandNotFound;
|
|
63
47
|
|
|
64
48
|
//# sourceMappingURL=command-not-found.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["CommandNotFound","BitError","constructor","commandName","suggestion","report","output","chalk","yellow","bold"],"sources":["command-not-found.ts"],"sourcesContent":["import { BitError } from '@teambit/bit-error';\nimport chalk from 'chalk';\n\nexport class CommandNotFound extends BitError {\n commandName: string;\n suggestion?: string;\n constructor(commandName: string, suggestion?: string) {\n super(`command ${commandName} was not found`);\n this.commandName = commandName;\n this.suggestion = suggestion;\n }\n report() {\n let output = chalk.yellow(\n `warning: '${chalk.bold(this.commandName)}' is not a valid command.\nsee 'bit help' for additional information`\n );\n if (this.suggestion) {\n output += `\\nDid you mean ${chalk.bold(this.suggestion)}?`;\n }\n return output;\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["CommandNotFound","BitError","constructor","commandName","suggestion","report","output","chalk","yellow","bold"],"sources":["command-not-found.ts"],"sourcesContent":["import { BitError } from '@teambit/bit-error';\nimport chalk from 'chalk';\n\nexport class CommandNotFound extends BitError {\n commandName: string;\n suggestion?: string;\n constructor(commandName: string, suggestion?: string) {\n super(`command ${commandName} was not found`);\n this.commandName = commandName;\n this.suggestion = suggestion;\n }\n report() {\n let output = chalk.yellow(\n `warning: '${chalk.bold(this.commandName)}' is not a valid command.\nsee 'bit help' for additional information`\n );\n if (this.suggestion) {\n output += `\\nDid you mean ${chalk.bold(this.suggestion)}?`;\n }\n return output;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEO,MAAMA,eAAe,SAASC,oBAAQ,CAAC;EAG5CC,WAAW,CAACC,WAAmB,EAAEC,UAAmB,EAAE;IACpD,KAAK,CAAE,WAAUD,WAAY,gBAAe,CAAC;IAAC;IAAA;IAC9C,IAAI,CAACA,WAAW,GAAGA,WAAW;IAC9B,IAAI,CAACC,UAAU,GAAGA,UAAU;EAC9B;EACAC,MAAM,GAAG;IACP,IAAIC,MAAM,GAAGC,gBAAK,CAACC,MAAM,CACtB,aAAYD,gBAAK,CAACE,IAAI,CAAC,IAAI,CAACN,WAAW,CAAE;AAChD,0CAA0C,CACrC;IACD,IAAI,IAAI,CAACC,UAAU,EAAE;MACnBE,MAAM,IAAK,kBAAiBC,gBAAK,CAACE,IAAI,CAAC,IAAI,CAACL,UAAU,CAAE,GAAE;IAC5D;IACA,OAAOE,MAAM;EACf;AACF;AAAC"}
|
package/dist/exceptions/index.js
CHANGED
|
@@ -9,14 +9,11 @@ Object.defineProperty(exports, "AlreadyExistsError", {
|
|
|
9
9
|
return _alreadyExists().AlreadyExistsError;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
-
|
|
13
12
|
function _alreadyExists() {
|
|
14
13
|
const data = require("./already-exists");
|
|
15
|
-
|
|
16
14
|
_alreadyExists = function () {
|
|
17
15
|
return data;
|
|
18
16
|
};
|
|
19
|
-
|
|
20
17
|
return data;
|
|
21
18
|
}
|
|
22
19
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { AlreadyExistsError } from './already-exists';\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { AlreadyExistsError } from './already-exists';\n"],"mappings":";;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA"}
|
package/dist/generate-doc-md.js
CHANGED
|
@@ -1,44 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
require("core-js/modules/es.symbol.description.js");
|
|
4
|
-
|
|
5
4
|
require("core-js/modules/es.array.iterator.js");
|
|
6
|
-
|
|
7
5
|
require("core-js/modules/es.array.sort.js");
|
|
8
|
-
|
|
9
6
|
require("core-js/modules/es.regexp.exec.js");
|
|
10
|
-
|
|
11
7
|
Object.defineProperty(exports, "__esModule", {
|
|
12
8
|
value: true
|
|
13
9
|
});
|
|
14
10
|
exports.GenerateCommandsDoc = void 0;
|
|
15
|
-
|
|
16
11
|
function _lodash() {
|
|
17
12
|
const data = require("lodash");
|
|
18
|
-
|
|
19
13
|
_lodash = function () {
|
|
20
14
|
return data;
|
|
21
15
|
};
|
|
22
|
-
|
|
23
16
|
return data;
|
|
24
17
|
}
|
|
25
|
-
|
|
26
18
|
function _getCommandId() {
|
|
27
19
|
const data = require("./get-command-id");
|
|
28
|
-
|
|
29
20
|
_getCommandId = function () {
|
|
30
21
|
return data;
|
|
31
22
|
};
|
|
32
|
-
|
|
33
23
|
return data;
|
|
34
24
|
}
|
|
35
|
-
|
|
36
25
|
class GenerateCommandsDoc {
|
|
37
26
|
constructor(commands, options) {
|
|
38
27
|
this.commands = commands;
|
|
39
28
|
this.options = options;
|
|
40
29
|
}
|
|
41
|
-
|
|
42
30
|
generate() {
|
|
43
31
|
const commands = this.getAllPublicCommandsSorted();
|
|
44
32
|
let output = `${this.getFrontmatter()}
|
|
@@ -49,65 +37,50 @@ Commands that are marked as workspace only must be executed inside a workspace.
|
|
|
49
37
|
output += commands.map(cmd => this.generateCommand(cmd)).join('\n');
|
|
50
38
|
return output;
|
|
51
39
|
}
|
|
52
|
-
|
|
53
40
|
generateJson() {
|
|
54
41
|
return this.commandsToObjects();
|
|
55
42
|
}
|
|
56
|
-
|
|
57
43
|
commandsToObjects(commands = this.commands) {
|
|
58
44
|
return commands.map(command => {
|
|
59
45
|
var _command$commands;
|
|
60
|
-
|
|
61
46
|
const cmdObject = oneCommandToObject(command);
|
|
62
|
-
|
|
63
47
|
if ((_command$commands = command.commands) !== null && _command$commands !== void 0 && _command$commands.length) {
|
|
64
48
|
cmdObject.commands = this.commandsToObjects(command.commands);
|
|
65
49
|
}
|
|
66
|
-
|
|
67
50
|
return cmdObject;
|
|
68
51
|
});
|
|
69
52
|
}
|
|
70
|
-
|
|
71
53
|
getFrontmatter() {
|
|
72
54
|
const metadata = this.options.metadata;
|
|
73
|
-
|
|
74
55
|
if (!metadata) {
|
|
75
56
|
return '';
|
|
76
57
|
}
|
|
77
|
-
|
|
78
58
|
const metadataStr = Object.keys(metadata).map(key => `${key}: ${metadata[key]}`).join('\n');
|
|
79
59
|
return `---
|
|
80
60
|
${metadataStr}
|
|
81
61
|
---
|
|
82
62
|
`;
|
|
83
63
|
}
|
|
84
|
-
|
|
85
64
|
getAllPublicCommandsSorted() {
|
|
86
65
|
const publicCommands = this.commands.filter(cmd => !cmd.private);
|
|
87
66
|
return publicCommands.sort((a, b) => a.name.localeCompare(b.name));
|
|
88
67
|
}
|
|
89
|
-
|
|
90
68
|
generateCommand(cmd) {
|
|
91
69
|
const commandName = (0, _getCommandId().getCommandId)(cmd.name);
|
|
92
70
|
let result = `## ${commandName} \n\n`;
|
|
93
|
-
|
|
94
71
|
if (cmd.alias && cmd.alias.length > 0) {
|
|
95
72
|
result += `**Alias**: \`${cmd.alias}\` \n`;
|
|
96
73
|
}
|
|
97
|
-
|
|
98
74
|
result += `**Workspace only**: ${cmd.skipWorkspace ? 'no' : 'yes'} \n`;
|
|
99
75
|
result += `**Description**: ${this.formatDescription(cmd)}`;
|
|
100
76
|
result += `\`bit ${cmd.name}\` \n\n`;
|
|
101
|
-
|
|
102
77
|
if (cmd.commands && cmd.commands.length > 0) {
|
|
103
78
|
result += this.generateSubCommands(cmd.commands, cmd);
|
|
104
79
|
}
|
|
105
|
-
|
|
106
80
|
result += this.generateOptions(cmd.options);
|
|
107
81
|
result += `--- \n`;
|
|
108
82
|
return result;
|
|
109
83
|
}
|
|
110
|
-
|
|
111
84
|
generateSubCommands(subCommands, command) {
|
|
112
85
|
let ret = '';
|
|
113
86
|
subCommands.forEach(subCommand => {
|
|
@@ -122,7 +95,6 @@ Commands that are marked as workspace only must be executed inside a workspace.
|
|
|
122
95
|
});
|
|
123
96
|
return ret;
|
|
124
97
|
}
|
|
125
|
-
|
|
126
98
|
generateOptions(options) {
|
|
127
99
|
if (!options || options.length <= 0) return '';
|
|
128
100
|
let output = `| **Option** | **Option alias** | **Description**| \n`;
|
|
@@ -136,21 +108,16 @@ Commands that are marked as workspace only must be executed inside a workspace.
|
|
|
136
108
|
output += `\n`;
|
|
137
109
|
return output;
|
|
138
110
|
}
|
|
139
|
-
|
|
140
111
|
formatStringToMD(str) {
|
|
141
112
|
return str.split('\n').join(' \n');
|
|
142
113
|
}
|
|
143
|
-
|
|
144
114
|
formatDescription(command) {
|
|
145
115
|
const extendedDescription = command.extendedDescription ? ` \n${this.formatStringToMD(command.extendedDescription)}` : '';
|
|
146
116
|
const description = this.formatStringToMD(command.description);
|
|
147
117
|
return `${description}${extendedDescription} \n\n`;
|
|
148
118
|
}
|
|
149
|
-
|
|
150
119
|
}
|
|
151
|
-
|
|
152
120
|
exports.GenerateCommandsDoc = GenerateCommandsDoc;
|
|
153
|
-
|
|
154
121
|
function oneCommandToObject(command) {
|
|
155
122
|
return (0, _lodash().pick)(command, ['name', 'alias', 'options', 'description', 'extendedDescription', 'group', 'private', 'internal', 'remoteOp', 'skipWorkspace', 'arguments', 'examples']);
|
|
156
123
|
}
|