@teambit/cli 0.0.1063 → 0.0.1065
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/artifacts/__bit_junit.xml +1 -1
- package/artifacts/preview/teambit_harmony_cli-preview.js +1 -1
- package/artifacts/schema.json +4365 -1557
- package/dist/cli-parser.d.ts +2 -2
- package/dist/cli-parser.js +16 -16
- package/dist/cli-parser.js.map +1 -1
- package/dist/cli.cmd.d.ts +1 -1
- package/dist/cli.cmd.js +8 -8
- package/dist/cli.cmd.js.map +1 -1
- package/dist/cli.main.runtime.d.ts +2 -2
- package/dist/cli.main.runtime.js +12 -12
- package/dist/cli.main.runtime.js.map +1 -1
- package/dist/command-groups.d.ts +19 -0
- package/dist/command-groups.js +21 -0
- package/dist/command-groups.js.map +1 -0
- package/dist/command-runner.d.ts +1 -1
- package/dist/command-runner.js +22 -24
- package/dist/command-runner.js.map +1 -1
- package/dist/command.d.ts +130 -0
- package/dist/command.js +3 -0
- package/dist/command.js.map +1 -0
- package/dist/completion.cmd.d.ts +1 -1
- package/dist/completion.cmd.js.map +1 -1
- package/dist/default-error-handler.d.ts +12 -0
- package/dist/default-error-handler.js +81 -0
- package/dist/default-error-handler.js.map +1 -0
- package/dist/generate-doc-md.d.ts +1 -1
- package/dist/generate-doc-md.js.map +1 -1
- package/dist/global-flags.d.ts +7 -0
- package/dist/global-flags.js +24 -0
- package/dist/global-flags.js.map +1 -0
- package/dist/handle-errors.js +10 -10
- package/dist/handle-errors.js.map +1 -1
- package/dist/help.cmd.d.ts +1 -1
- package/dist/help.cmd.js.map +1 -1
- package/dist/help.d.ts +1 -1
- package/dist/help.js.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -1
- package/dist/preview-1733830651067.js +7 -0
- package/dist/version.cmd.d.ts +1 -1
- package/dist/version.cmd.js.map +1 -1
- package/dist/yargs-adapter.d.ts +2 -2
- package/dist/yargs-adapter.js +4 -4
- package/dist/yargs-adapter.js.map +1 -1
- package/package.json +10 -6
- package/dist/preview-1733541556857.js +0 -7
package/dist/command-runner.js
CHANGED
|
@@ -5,16 +5,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.CommandRunner = void 0;
|
|
7
7
|
exports.parseCommandName = parseCommandName;
|
|
8
|
-
function
|
|
9
|
-
const data =
|
|
10
|
-
|
|
8
|
+
function _legacy() {
|
|
9
|
+
const data = require("@teambit/legacy.logger");
|
|
10
|
+
_legacy = function () {
|
|
11
11
|
return data;
|
|
12
12
|
};
|
|
13
13
|
return data;
|
|
14
14
|
}
|
|
15
|
-
function
|
|
15
|
+
function _legacy2() {
|
|
16
16
|
const data = require("@teambit/legacy.loader");
|
|
17
|
-
|
|
17
|
+
_legacy2 = function () {
|
|
18
18
|
return data;
|
|
19
19
|
};
|
|
20
20
|
return data;
|
|
@@ -26,23 +26,23 @@ function _handleErrors() {
|
|
|
26
26
|
};
|
|
27
27
|
return data;
|
|
28
28
|
}
|
|
29
|
-
function
|
|
30
|
-
const data = require("@teambit/legacy
|
|
31
|
-
|
|
29
|
+
function _legacy3() {
|
|
30
|
+
const data = require("@teambit/legacy.constants");
|
|
31
|
+
_legacy3 = function () {
|
|
32
32
|
return data;
|
|
33
33
|
};
|
|
34
34
|
return data;
|
|
35
35
|
}
|
|
36
36
|
function _globalFlags() {
|
|
37
|
-
const data = _interopRequireDefault(require("
|
|
37
|
+
const data = _interopRequireDefault(require("./global-flags"));
|
|
38
38
|
_globalFlags = function () {
|
|
39
39
|
return data;
|
|
40
40
|
};
|
|
41
41
|
return data;
|
|
42
42
|
}
|
|
43
|
-
function
|
|
43
|
+
function _legacy4() {
|
|
44
44
|
const data = require("@teambit/legacy.analytics");
|
|
45
|
-
|
|
45
|
+
_legacy4 = function () {
|
|
46
46
|
return data;
|
|
47
47
|
};
|
|
48
48
|
return data;
|
|
@@ -55,8 +55,6 @@ function _pMapSeries() {
|
|
|
55
55
|
return data;
|
|
56
56
|
}
|
|
57
57
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
58
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
59
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
60
58
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
61
59
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
62
60
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
@@ -94,12 +92,12 @@ class CommandRunner {
|
|
|
94
92
|
throw new Error(`command "${this.commandName}" doesn't implement "render" nor "report" nor "wait" methods`);
|
|
95
93
|
}
|
|
96
94
|
bootstrapCommand() {
|
|
97
|
-
|
|
98
|
-
|
|
95
|
+
_legacy4().Analytics.init(this.commandName, this.flags, this.args);
|
|
96
|
+
_legacy().logger.info(`[*] started a new command: "${this.commandName}" with the following data:`, {
|
|
99
97
|
args: this.args,
|
|
100
98
|
flags: this.flags
|
|
101
99
|
});
|
|
102
|
-
const token = this.flags[
|
|
100
|
+
const token = this.flags[_legacy3().TOKEN_FLAG_NAME];
|
|
103
101
|
if (token) {
|
|
104
102
|
_globalFlags().default.token = token.toString();
|
|
105
103
|
}
|
|
@@ -131,7 +129,7 @@ class CommandRunner {
|
|
|
131
129
|
async runReportHandler(shouldReturnResult = false) {
|
|
132
130
|
if (!this.command.report) throw new Error('runReportHandler expects command.report to be implemented');
|
|
133
131
|
const result = await this.command.report(this.args, this.flags);
|
|
134
|
-
|
|
132
|
+
_legacy2().loader.off();
|
|
135
133
|
const data = typeof result === 'string' ? result : result.data;
|
|
136
134
|
const exitCode = typeof result === 'string' ? 0 : result.code;
|
|
137
135
|
if (shouldReturnResult) return {
|
|
@@ -150,18 +148,18 @@ class CommandRunner {
|
|
|
150
148
|
* for internals commands, such as, _put, _fetch, the command.loader = false.
|
|
151
149
|
*/
|
|
152
150
|
determineConsoleWritingDuringCommand() {
|
|
153
|
-
if (this.command.loader && !this.flags.json && !this.flags['get-yargs-completions'] && !
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
151
|
+
if (this.command.loader && !this.flags.json && !this.flags['get-yargs-completions'] && !_legacy().shouldDisableLoader) {
|
|
152
|
+
_legacy2().loader.on();
|
|
153
|
+
_legacy2().loader.start(`running command "${this.commandName}"...`);
|
|
154
|
+
_legacy().logger.shouldWriteToConsole = true;
|
|
157
155
|
} else {
|
|
158
|
-
|
|
159
|
-
|
|
156
|
+
_legacy2().loader.off();
|
|
157
|
+
_legacy().logger.shouldWriteToConsole = false;
|
|
160
158
|
}
|
|
161
159
|
}
|
|
162
160
|
async writeAndExit(data, exitCode) {
|
|
163
161
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
164
|
-
return process.stdout.write(data, async () =>
|
|
162
|
+
return process.stdout.write(data, async () => _legacy().logger.exitAfterFlush(exitCode, this.commandName, data));
|
|
165
163
|
}
|
|
166
164
|
}
|
|
167
165
|
exports.CommandRunner = CommandRunner;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_logger","data","_interopRequireWildcard","require","_legacy","_handleErrors","_constants","_globalFlags","_interopRequireDefault","_legacy2","_pMapSeries","e","__esModule","default","_getRequireWildcardCache","WeakMap","r","t","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","_defineProperty","_toPropertyKey","value","enumerable","configurable","writable","_toPrimitive","Symbol","toPrimitive","TypeError","String","Number","CommandRunner","constructor","command","args","flags","onCommandStartSlot","commandName","parseCommandName","name","runCommand","shouldReturnResult","bootstrapCommand","invokeOnCommandStart","determineConsoleWritingDuringCommand","json","runJsonHandler","report","runReportHandler","wait","runWaitHandler","err","handleErrorAndExit","Error","Analytics","init","logger","info","token","TOKEN_FLAG_NAME","globalFlags","toString","funcs","values","pMapSeries","onCommandStart","undefined","result","code","exitCode","isJsonStream","Boolean","stream","end","jsonStr","JSON","stringify","writeAndExit","loader","off","shouldDisableLoader","on","start","shouldWriteToConsole","process","stdout","write","exitAfterFlush","exports","split"],"sources":["command-runner.ts"],"sourcesContent":["import logger, { shouldDisableLoader } from '@teambit/legacy/dist/logger/logger';\nimport { CLIArgs, Command, Flags } from '@teambit/legacy/dist/cli/command';\nimport { loader } from '@teambit/legacy.loader';\nimport { handleErrorAndExit } from './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.analytics';\nimport { OnCommandStartSlot } from './cli.main.runtime';\nimport pMapSeries from 'p-map-series';\n\ntype CommandResult = { data: any; exitCode: number };\n\nexport class CommandRunner {\n private commandName: string;\n constructor(\n private command: Command,\n private args: CLIArgs,\n private flags: Flags,\n private onCommandStartSlot: OnCommandStartSlot\n ) {\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(shouldReturnResult = false): Promise<void | CommandResult> {\n try {\n this.bootstrapCommand();\n await this.invokeOnCommandStart();\n this.determineConsoleWritingDuringCommand();\n if (this.flags.json) {\n return await this.runJsonHandler(shouldReturnResult);\n }\n if (this.command.report) {\n return await this.runReportHandler(shouldReturnResult);\n }\n if (this.command.wait) {\n return await this.runWaitHandler();\n }\n } catch (err: any) {\n if (shouldReturnResult) throw err;\n return handleErrorAndExit(err, this.commandName);\n }\n\n throw new Error(`command \"${this.commandName}\" doesn't implement \"render\" nor \"report\" nor \"wait\" 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 private async invokeOnCommandStart() {\n const funcs = this.onCommandStartSlot.values();\n await pMapSeries(funcs, (onCommandStart) => onCommandStart(this.commandName, this.args, this.flags));\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(shouldReturnResult = false): Promise<CommandResult | undefined> {\n if (!this.flags.json) return undefined;\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 if (shouldReturnResult) return { data, exitCode: code };\n const isJsonStream = Boolean(this.flags.stream);\n if (isJsonStream) data.end = true;\n const jsonStr = isJsonStream ? `${JSON.stringify(data)}\\n` : JSON.stringify(data, null, 2);\n await this.writeAndExit(jsonStr, code);\n }\n\n private async runReportHandler(shouldReturnResult = false): Promise<CommandResult | undefined> {\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 if (shouldReturnResult) return { data, exitCode };\n await this.writeAndExit(`${data}\\n`, exitCode);\n }\n\n private async runWaitHandler() {\n if (!this.command.wait) throw new Error('runReportHandler expects command.wait to be implemented');\n await this.command.wait(this.args, this.flags);\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'] && !shouldDisableLoader) {\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 }\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\nexport function parseCommandName(commandName: string): string {\n if (!commandName) return '';\n return commandName.split(' ')[0];\n}\n"],"mappings":";;;;;;;AAAA,SAAAA,QAAA;EAAA,MAAAC,IAAA,GAAAC,uBAAA,CAAAC,OAAA;EAAAH,OAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAG,QAAA;EAAA,MAAAH,IAAA,GAAAE,OAAA;EAAAC,OAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,cAAA;EAAA,MAAAJ,IAAA,GAAAE,OAAA;EAAAE,aAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAK,WAAA;EAAA,MAAAL,IAAA,GAAAE,OAAA;EAAAG,UAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAM,aAAA;EAAA,MAAAN,IAAA,GAAAO,sBAAA,CAAAL,OAAA;EAAAI,YAAA,YAAAA,CAAA;IAAA,OAAAN,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,S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MAAM,CAAC;MACxDmB,iBAAM,CAAC2B,oBAAoB,GAAG,IAAI;IACpC,CAAC,MAAM;MACLL,gBAAM,CAACC,GAAG,CAAC,CAAC;MACZvB,iBAAM,CAAC2B,oBAAoB,GAAG,KAAK;IACrC;EACF;EAEA,MAAcN,YAAYA,CAACxF,IAAY,EAAEgF,QAAgB,EAAE;IACzD;IACA,OAAOe,OAAO,CAACC,MAAM,CAACC,KAAK,CAACjG,IAAI,EAAE,YAAYmE,iBAAM,CAAC+B,cAAc,CAAClB,QAAQ,EAAE,IAAI,CAAChC,WAAW,EAAEhD,IAAI,CAAC,CAAC;EACxG;AACF;AAACmG,OAAA,CAAAzD,aAAA,GAAAA,aAAA;AAEM,SAASO,gBAAgBA,CAACD,WAAmB,EAAU;EAC5D,IAAI,CAACA,WAAW,EAAE,OAAO,EAAE;EAC3B,OAAOA,WAAW,CAACoD,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AAClC","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_legacy","data","require","_legacy2","_handleErrors","_legacy3","_globalFlags","_interopRequireDefault","_legacy4","_pMapSeries","e","__esModule","default","_defineProperty","r","t","_toPropertyKey","Object","defineProperty","value","enumerable","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","CommandRunner","constructor","command","args","flags","onCommandStartSlot","commandName","parseCommandName","name","runCommand","shouldReturnResult","bootstrapCommand","invokeOnCommandStart","determineConsoleWritingDuringCommand","json","runJsonHandler","report","runReportHandler","wait","runWaitHandler","err","handleErrorAndExit","Error","Analytics","init","logger","info","token","TOKEN_FLAG_NAME","globalFlags","toString","funcs","values","pMapSeries","onCommandStart","undefined","result","code","exitCode","isJsonStream","Boolean","stream","end","jsonStr","JSON","stringify","writeAndExit","loader","off","shouldDisableLoader","on","start","shouldWriteToConsole","process","stdout","write","exitAfterFlush","exports","split"],"sources":["command-runner.ts"],"sourcesContent":["import { logger, shouldDisableLoader } from '@teambit/legacy.logger';\nimport { CLIArgs, Command, Flags } from './command';\nimport { loader } from '@teambit/legacy.loader';\nimport { handleErrorAndExit } from './handle-errors';\nimport { TOKEN_FLAG_NAME } from '@teambit/legacy.constants';\nimport globalFlags from './global-flags';\nimport { Analytics } from '@teambit/legacy.analytics';\nimport { OnCommandStartSlot } from './cli.main.runtime';\nimport pMapSeries from 'p-map-series';\n\ntype CommandResult = { data: any; exitCode: number };\n\nexport class CommandRunner {\n private commandName: string;\n constructor(\n private command: Command,\n private args: CLIArgs,\n private flags: Flags,\n private onCommandStartSlot: OnCommandStartSlot\n ) {\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(shouldReturnResult = false): Promise<void | CommandResult> {\n try {\n this.bootstrapCommand();\n await this.invokeOnCommandStart();\n this.determineConsoleWritingDuringCommand();\n if (this.flags.json) {\n return await this.runJsonHandler(shouldReturnResult);\n }\n if (this.command.report) {\n return await this.runReportHandler(shouldReturnResult);\n }\n if (this.command.wait) {\n return await this.runWaitHandler();\n }\n } catch (err: any) {\n if (shouldReturnResult) throw err;\n return handleErrorAndExit(err, this.commandName);\n }\n\n throw new Error(`command \"${this.commandName}\" doesn't implement \"render\" nor \"report\" nor \"wait\" 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 private async invokeOnCommandStart() {\n const funcs = this.onCommandStartSlot.values();\n await pMapSeries(funcs, (onCommandStart) => onCommandStart(this.commandName, this.args, this.flags));\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(shouldReturnResult = false): Promise<CommandResult | undefined> {\n if (!this.flags.json) return undefined;\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 if (shouldReturnResult) return { data, exitCode: code };\n const isJsonStream = Boolean(this.flags.stream);\n if (isJsonStream) data.end = true;\n const jsonStr = isJsonStream ? `${JSON.stringify(data)}\\n` : JSON.stringify(data, null, 2);\n await this.writeAndExit(jsonStr, code);\n }\n\n private async runReportHandler(shouldReturnResult = false): Promise<CommandResult | undefined> {\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 if (shouldReturnResult) return { data, exitCode };\n await this.writeAndExit(`${data}\\n`, exitCode);\n }\n\n private async runWaitHandler() {\n if (!this.command.wait) throw new Error('runReportHandler expects command.wait to be implemented');\n await this.command.wait(this.args, this.flags);\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'] && !shouldDisableLoader) {\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 }\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\nexport function parseCommandName(commandName: string): string {\n if (!commandName) return '';\n return commandName.split(' ')[0];\n}\n"],"mappings":";;;;;;;AAAA,SAAAA,QAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,OAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAE,SAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,QAAA,YAAA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-0,0 +1,130 @@
|
|
|
1
|
+
import { Group } from './command-groups';
|
|
2
|
+
type CommandOption = [string, string, string];
|
|
3
|
+
export type CommandOptions = Array<CommandOption>;
|
|
4
|
+
export interface Command {
|
|
5
|
+
/**
|
|
6
|
+
* Name of command with arguments:
|
|
7
|
+
* <> for mandatory arguments.
|
|
8
|
+
* [] for optional arguments.
|
|
9
|
+
* e.g. 'add <path>'
|
|
10
|
+
*/
|
|
11
|
+
name: string;
|
|
12
|
+
/**
|
|
13
|
+
* command alias (for example: 't' for 'tag')
|
|
14
|
+
*/
|
|
15
|
+
alias?: string;
|
|
16
|
+
/**
|
|
17
|
+
* The description of the command. Being used in the commands summery (`bit --help`) and the help (e.g. `bit create --help`).
|
|
18
|
+
* should be short and precise. not more than one line. (use extendedDescription for more info).
|
|
19
|
+
*/
|
|
20
|
+
description?: string;
|
|
21
|
+
/**
|
|
22
|
+
* The extended description of the command. Will be seen in only in the command help, just after the description.
|
|
23
|
+
*/
|
|
24
|
+
extendedDescription?: string;
|
|
25
|
+
/**
|
|
26
|
+
* url to a doc page explaining the command. shown in the command help just after the extendedDescription.
|
|
27
|
+
* if a relative url is entered, the base url will be retrieved from `teambit.community/community` aspect.
|
|
28
|
+
*/
|
|
29
|
+
helpUrl?: string;
|
|
30
|
+
/**
|
|
31
|
+
* allow grouping of commands to hint summery renderer
|
|
32
|
+
* Places in default automatic help
|
|
33
|
+
*/
|
|
34
|
+
group?: Group | string;
|
|
35
|
+
/**
|
|
36
|
+
* should a command be exposed to the user (by bit help).
|
|
37
|
+
* e.g. experimental or plumbing commands should be hidden.
|
|
38
|
+
*/
|
|
39
|
+
private?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* should turn on Loader.
|
|
42
|
+
* the default is false for internal-commands and true for others.
|
|
43
|
+
* @see cliMain.setDefaults()
|
|
44
|
+
*/
|
|
45
|
+
loader?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Array of command options where each element is a tuple.
|
|
48
|
+
* ['flag alias', 'flag name', 'flag description']
|
|
49
|
+
* for example:
|
|
50
|
+
* ['j', 'json', 'output json format']
|
|
51
|
+
*/
|
|
52
|
+
options: CommandOptions;
|
|
53
|
+
/**
|
|
54
|
+
* arguments are defined in the "name" property, and that's where the source of truth is.
|
|
55
|
+
* this prop is optional and provides a way to describe the args. later, it'll support more fields, such as defaultValue.
|
|
56
|
+
* if this is set, it'll be shown in the command help under "Arguments" section.
|
|
57
|
+
*/
|
|
58
|
+
arguments?: CommandArg[];
|
|
59
|
+
/**
|
|
60
|
+
* sub commands for example:
|
|
61
|
+
* bit capsule list to list active capsules.
|
|
62
|
+
*/
|
|
63
|
+
commands?: Command[];
|
|
64
|
+
/**
|
|
65
|
+
* interact with a remote, e.g. "export" push to a remote
|
|
66
|
+
* for now, the only difference is that they get a "token" flag to authenticate anonymously.
|
|
67
|
+
*/
|
|
68
|
+
remoteOp?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* if true, it indicates that it doesn't need the workspace to work and can be executed outside a
|
|
71
|
+
* workspace
|
|
72
|
+
*/
|
|
73
|
+
skipWorkspace?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* optionally, give some examples how to use the command.
|
|
76
|
+
*/
|
|
77
|
+
examples?: Example[];
|
|
78
|
+
/**
|
|
79
|
+
* whether to load aspects set in workspace.jsonc before running the command.
|
|
80
|
+
* default is true.
|
|
81
|
+
*/
|
|
82
|
+
loadAspects?: boolean;
|
|
83
|
+
/**
|
|
84
|
+
* do not set this. it is being set once the command run.
|
|
85
|
+
* the values are those followed `--` in the command line. (e.g. `bit import -- --no-optional`)
|
|
86
|
+
*/
|
|
87
|
+
_packageManagerArgs?: string[];
|
|
88
|
+
/**
|
|
89
|
+
* Command handler which prints the return value to the console and exits.
|
|
90
|
+
* If the command has both, `render` and `report`, this one will be called when process.isTTY is false.
|
|
91
|
+
* @param args - arguments object as defined in name.
|
|
92
|
+
* @param flags - command flags as described in options.
|
|
93
|
+
* @return - Report object. The Report.data is printed to the stdout as is.
|
|
94
|
+
*/
|
|
95
|
+
report?(args: CLIArgs, flags: Flags): Promise<string | Report>;
|
|
96
|
+
/**
|
|
97
|
+
* Command handler which never exits the process
|
|
98
|
+
* @param args - arguments object as defined in name.
|
|
99
|
+
* @param flags - command flags as described in options.
|
|
100
|
+
*/
|
|
101
|
+
wait?(args: CLIArgs, flags: Flags): Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
* Optional handler to provide a raw result of the command.
|
|
104
|
+
* Will be go called if '-j'/'--json' option is provided by user.
|
|
105
|
+
* @param args - arguments object as defined in name.
|
|
106
|
+
* @param flags - command flags as described in options.
|
|
107
|
+
* @return a GenericObject to be rendered to string (by json.stringify) in the console.
|
|
108
|
+
*/
|
|
109
|
+
json?(args: CLIArgs, flags: Flags): Promise<GenericObject>;
|
|
110
|
+
}
|
|
111
|
+
export type Flags = {
|
|
112
|
+
[flagName: string]: string | boolean | undefined | any;
|
|
113
|
+
};
|
|
114
|
+
export type CLIArgs = Array<string[] | string>;
|
|
115
|
+
export type GenericObject = {
|
|
116
|
+
[k: string]: any;
|
|
117
|
+
};
|
|
118
|
+
export type Report = {
|
|
119
|
+
data: string;
|
|
120
|
+
code: number;
|
|
121
|
+
};
|
|
122
|
+
export type CommandArg = {
|
|
123
|
+
name: string;
|
|
124
|
+
description?: string;
|
|
125
|
+
};
|
|
126
|
+
export type Example = {
|
|
127
|
+
cmd: string;
|
|
128
|
+
description: string;
|
|
129
|
+
};
|
|
130
|
+
export {};
|
package/dist/command.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["command.ts"],"sourcesContent":["import { Group } from './command-groups';\n\ntype CommandOption = [string, string, string];\nexport type CommandOptions = Array<CommandOption>;\n\nexport interface Command {\n /**\n * Name of command with arguments:\n * <> for mandatory arguments.\n * [] for optional arguments.\n * e.g. 'add <path>'\n */\n name: string;\n\n /**\n * command alias (for example: 't' for 'tag')\n */\n alias?: string;\n\n /**\n * The description of the command. Being used in the commands summery (`bit --help`) and the help (e.g. `bit create --help`).\n * should be short and precise. not more than one line. (use extendedDescription for more info).\n */\n description?: string;\n\n /**\n * The extended description of the command. Will be seen in only in the command help, just after the description.\n */\n extendedDescription?: string;\n\n /**\n * url to a doc page explaining the command. shown in the command help just after the extendedDescription.\n * if a relative url is entered, the base url will be retrieved from `teambit.community/community` aspect.\n */\n helpUrl?: string;\n\n /**\n * allow grouping of commands to hint summery renderer\n * Places in default automatic help\n */\n group?: Group | string;\n\n /**\n * should a command be exposed to the user (by bit help).\n * e.g. experimental or plumbing commands should be hidden.\n */\n private?: boolean;\n\n /**\n * should turn on Loader.\n * the default is false for internal-commands and true for others.\n * @see cliMain.setDefaults()\n */\n loader?: boolean;\n\n /**\n * Array of command options where each element is a tuple.\n * ['flag alias', 'flag name', 'flag description']\n * for example:\n * ['j', 'json', 'output json format']\n */\n options: CommandOptions;\n\n /**\n * arguments are defined in the \"name\" property, and that's where the source of truth is.\n * this prop is optional and provides a way to describe the args. later, it'll support more fields, such as defaultValue.\n * if this is set, it'll be shown in the command help under \"Arguments\" section.\n */\n arguments?: CommandArg[];\n\n /**\n * sub commands for example:\n * bit capsule list to list active capsules.\n */\n commands?: Command[];\n\n /**\n * interact with a remote, e.g. \"export\" push to a remote\n * for now, the only difference is that they get a \"token\" flag to authenticate anonymously.\n */\n remoteOp?: boolean;\n\n /**\n * if true, it indicates that it doesn't need the workspace to work and can be executed outside a\n * workspace\n */\n skipWorkspace?: boolean;\n\n /**\n * optionally, give some examples how to use the command.\n */\n examples?: Example[];\n\n /**\n * whether to load aspects set in workspace.jsonc before running the command.\n * default is true.\n */\n loadAspects?: boolean;\n\n /**\n * do not set this. it is being set once the command run.\n * the values are those followed `--` in the command line. (e.g. `bit import -- --no-optional`)\n */\n _packageManagerArgs?: string[];\n\n /**\n * Command handler which prints the return value to the console and exits.\n * If the command has both, `render` and `report`, this one will be called when process.isTTY is false.\n * @param args - arguments object as defined in name.\n * @param flags - command flags as described in options.\n * @return - Report object. The Report.data is printed to the stdout as is.\n */\n report?(args: CLIArgs, flags: Flags): Promise<string | Report>;\n\n /**\n * Command handler which never exits the process\n * @param args - arguments object as defined in name.\n * @param flags - command flags as described in options.\n */\n wait?(args: CLIArgs, flags: Flags): Promise<void>;\n\n /**\n * Optional handler to provide a raw result of the command.\n * Will be go called if '-j'/'--json' option is provided by user.\n * @param args - arguments object as defined in name.\n * @param flags - command flags as described in options.\n * @return a GenericObject to be rendered to string (by json.stringify) in the console.\n */\n json?(args: CLIArgs, flags: Flags): Promise<GenericObject>;\n}\nexport type Flags = { [flagName: string]: string | boolean | undefined | any };\nexport type CLIArgs = Array<string[] | string>;\nexport type GenericObject = { [k: string]: any };\nexport type Report = { data: string; code: number };\nexport type CommandArg = { name: string; description?: string };\nexport type Example = { cmd: string; description: string };\n"],"mappings":"","ignoreList":[]}
|
package/dist/completion.cmd.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["CompletionCmd","constructor","_defineProperty","exports"],"sources":["completion.cmd.ts"],"sourcesContent":["import { Command } from '
|
|
1
|
+
{"version":3,"names":["CompletionCmd","constructor","_defineProperty","exports"],"sources":["completion.cmd.ts"],"sourcesContent":["import { Command } from './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;EAAAC,YAAA;IAAAC,eAAA,eACrC,YAAY;IAAAA,eAAA,sBACL,+DAA+D;IAAAA,eAAA,gBACrE,EAAE;IAAAA,eAAA,gBACF,SAAS;IAAAA,eAAA,kBACP,EAAE;EAAA;AACd;AAACC,OAAA,CAAAH,aAAA,GAAAA,aAAA","ignoreList":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* if err.userError is set, it inherits from AbstractError, which are user errors not Bit errors
|
|
3
|
+
* and should not be reported to Sentry.
|
|
4
|
+
* reason why we don't check (err instanceof AbstractError) is that it could be thrown from a fork,
|
|
5
|
+
* in which case, it loses its class and has only the fields.
|
|
6
|
+
*/
|
|
7
|
+
export declare function sendToAnalyticsAndSentry(err: Error): void;
|
|
8
|
+
declare const _default: (err: Error) => {
|
|
9
|
+
message: string;
|
|
10
|
+
error: Error;
|
|
11
|
+
};
|
|
12
|
+
export default _default;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
exports.sendToAnalyticsAndSentry = sendToAnalyticsAndSentry;
|
|
8
|
+
function _chalk() {
|
|
9
|
+
const data = _interopRequireDefault(require("chalk"));
|
|
10
|
+
_chalk = function () {
|
|
11
|
+
return data;
|
|
12
|
+
};
|
|
13
|
+
return data;
|
|
14
|
+
}
|
|
15
|
+
function _bitError() {
|
|
16
|
+
const data = require("@teambit/bit-error");
|
|
17
|
+
_bitError = function () {
|
|
18
|
+
return data;
|
|
19
|
+
};
|
|
20
|
+
return data;
|
|
21
|
+
}
|
|
22
|
+
function _legacy() {
|
|
23
|
+
const data = require("@teambit/legacy.analytics");
|
|
24
|
+
_legacy = function () {
|
|
25
|
+
return data;
|
|
26
|
+
};
|
|
27
|
+
return data;
|
|
28
|
+
}
|
|
29
|
+
function _legacyCli() {
|
|
30
|
+
const data = require("@teambit/legacy.cli.error");
|
|
31
|
+
_legacyCli = function () {
|
|
32
|
+
return data;
|
|
33
|
+
};
|
|
34
|
+
return data;
|
|
35
|
+
}
|
|
36
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
37
|
+
// all errors that the command does not handle comes to this switch statement
|
|
38
|
+
// if you handle the error, then return true
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* if err.userError is set, it inherits from AbstractError, which are user errors not Bit errors
|
|
42
|
+
* and should not be reported to Sentry.
|
|
43
|
+
* reason why we don't check (err instanceof AbstractError) is that it could be thrown from a fork,
|
|
44
|
+
* in which case, it loses its class and has only the fields.
|
|
45
|
+
*/
|
|
46
|
+
function sendToAnalyticsAndSentry(err) {
|
|
47
|
+
const possiblyHashedError = (0, _legacyCli().hashErrorIfNeeded)(err);
|
|
48
|
+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
|
|
49
|
+
const shouldNotReportToSentry = Boolean(err.isUserError || err.code === 'EACCES');
|
|
50
|
+
// only level FATAL are reported to Sentry.
|
|
51
|
+
const level = shouldNotReportToSentry ? _legacy().LEVEL.INFO : _legacy().LEVEL.FATAL;
|
|
52
|
+
_legacy().Analytics.setError(level, possiblyHashedError);
|
|
53
|
+
}
|
|
54
|
+
function handleNonBitCustomErrors(err) {
|
|
55
|
+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
|
|
56
|
+
if (err.code === 'EACCES' && err.path) {
|
|
57
|
+
// see #1774
|
|
58
|
+
return _chalk().default.red(
|
|
59
|
+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
|
|
60
|
+
`error: you do not have permissions to access '${err.path}', were you running bit, npm or git as root?`);
|
|
61
|
+
}
|
|
62
|
+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
|
|
63
|
+
return _chalk().default.red(err.message || err);
|
|
64
|
+
}
|
|
65
|
+
var _default = err => {
|
|
66
|
+
const getErrMsg = () => {
|
|
67
|
+
if (err instanceof _bitError().BitError) {
|
|
68
|
+
return err.report();
|
|
69
|
+
}
|
|
70
|
+
return handleNonBitCustomErrors(err);
|
|
71
|
+
};
|
|
72
|
+
sendToAnalyticsAndSentry(err);
|
|
73
|
+
const errorMessage = getErrMsg();
|
|
74
|
+
return {
|
|
75
|
+
message: _chalk().default.red(errorMessage),
|
|
76
|
+
error: err
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
exports.default = _default;
|
|
80
|
+
|
|
81
|
+
//# sourceMappingURL=default-error-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_chalk","data","_interopRequireDefault","require","_bitError","_legacy","_legacyCli","e","__esModule","default","sendToAnalyticsAndSentry","err","possiblyHashedError","hashErrorIfNeeded","shouldNotReportToSentry","Boolean","isUserError","code","level","LEVEL","INFO","FATAL","Analytics","setError","handleNonBitCustomErrors","path","chalk","red","message","_default","getErrMsg","BitError","report","errorMessage","error","exports"],"sources":["default-error-handler.ts"],"sourcesContent":["// all errors that the command does not handle comes to this switch statement\n// if you handle the error, then return true\nimport chalk from 'chalk';\nimport { BitError } from '@teambit/bit-error';\nimport { Analytics, LEVEL } from '@teambit/legacy.analytics';\nimport { hashErrorIfNeeded } from '@teambit/legacy.cli.error';\n\n/**\n * if err.userError is set, it inherits from AbstractError, which are user errors not Bit errors\n * and should not be reported to Sentry.\n * reason why we don't check (err instanceof AbstractError) is that it could be thrown from a fork,\n * in which case, it loses its class and has only the fields.\n */\nexport function sendToAnalyticsAndSentry(err: Error) {\n const possiblyHashedError = hashErrorIfNeeded(err);\n // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!\n const shouldNotReportToSentry = Boolean(err.isUserError || err.code === 'EACCES');\n // only level FATAL are reported to Sentry.\n const level = shouldNotReportToSentry ? LEVEL.INFO : LEVEL.FATAL;\n Analytics.setError(level, possiblyHashedError);\n}\n\nfunction handleNonBitCustomErrors(err: Error): string {\n // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!\n if (err.code === 'EACCES' && err.path) {\n // see #1774\n return chalk.red(\n // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!\n `error: you do not have permissions to access '${err.path}', were you running bit, npm or git as root?`\n );\n }\n // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!\n return chalk.red(err.message || err);\n}\n\nexport default (err: Error): { message: string; error: Error } => {\n const getErrMsg = (): string => {\n if (err instanceof BitError) {\n return err.report();\n }\n return handleNonBitCustomErrors(err);\n };\n sendToAnalyticsAndSentry(err);\n const errorMessage = getErrMsg();\n return { message: chalk.red(errorMessage), error: err };\n};\n"],"mappings":";;;;;;;AAEA,SAAAA,OAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,MAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,UAAA;EAAA,MAAAH,IAAA,GAAAE,OAAA;EAAAC,SAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,QAAA;EAAA,MAAAJ,IAAA,GAAAE,OAAA;EAAAE,OAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAK,WAAA;EAAA,MAAAL,IAAA,GAAAE,OAAA;EAAAG,UAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAA8D,SAAAC,uBAAAK,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAL9D;AACA;;AAMA;AACA;AACA;AACA;AACA;AACA;AACO,SAASG,wBAAwBA,CAACC,GAAU,EAAE;EACnD,MAAMC,mBAAmB,GAAG,IAAAC,8BAAiB,EAACF,GAAG,CAAC;EAClD;EACA,MAAMG,uBAAuB,GAAGC,OAAO,CAACJ,GAAG,CAACK,WAAW,IAAIL,GAAG,CAACM,IAAI,KAAK,QAAQ,CAAC;EACjF;EACA,MAAMC,KAAK,GAAGJ,uBAAuB,GAAGK,eAAK,CAACC,IAAI,GAAGD,eAAK,CAACE,KAAK;EAChEC,mBAAS,CAACC,QAAQ,CAACL,KAAK,EAAEN,mBAAmB,CAAC;AAChD;AAEA,SAASY,wBAAwBA,CAACb,GAAU,EAAU;EACpD;EACA,IAAIA,GAAG,CAACM,IAAI,KAAK,QAAQ,IAAIN,GAAG,CAACc,IAAI,EAAE;IACrC;IACA,OAAOC,gBAAK,CAACC,GAAG;IACd;IACA,iDAAiDhB,GAAG,CAACc,IAAI,8CAC3D,CAAC;EACH;EACA;EACA,OAAOC,gBAAK,CAACC,GAAG,CAAChB,GAAG,CAACiB,OAAO,IAAIjB,GAAG,CAAC;AACtC;AAAC,IAAAkB,QAAA,GAEelB,GAAU,IAAwC;EAChE,MAAMmB,SAAS,GAAGA,CAAA,KAAc;IAC9B,IAAInB,GAAG,YAAYoB,oBAAQ,EAAE;MAC3B,OAAOpB,GAAG,CAACqB,MAAM,CAAC,CAAC;IACrB;IACA,OAAOR,wBAAwB,CAACb,GAAG,CAAC;EACtC,CAAC;EACDD,wBAAwB,CAACC,GAAG,CAAC;EAC7B,MAAMsB,YAAY,GAAGH,SAAS,CAAC,CAAC;EAChC,OAAO;IAAEF,OAAO,EAAEF,gBAAK,CAACC,GAAG,CAACM,YAAY,CAAC;IAAEC,KAAK,EAAEvB;EAAI,CAAC;AACzD,CAAC;AAAAwB,OAAA,CAAA1B,OAAA,GAAAoB,QAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_lodash","data","require","_getCommandId","GenerateCommandsDoc","constructor","commands","options","generate","getAllPublicCommandsSorted","output","getFrontmatter","map","cmd","generateCommand","join","generateJson","commandsToObjects","command","cmdObject","oneCommandToObject","length","metadata","metadataStr","Object","keys","key","publicCommands","filter","private","sort","a","b","name","localeCompare","commandName","getCommandId","result","alias","formatDescription","generateSubCommands","generateArguments","arguments","generateOptions","subCommands","ret","forEach","subCommand","subcommandName","usage","args","arg","description","replaceAll","opt","flag","aliasFormatted","flagFormatted","formatStringToMD","str","split","extendedDescription","exports","pick"],"sources":["generate-doc-md.ts"],"sourcesContent":["import { CommandOptions, Command, CommandArg } from '@teambit/legacy/dist/cli/command';\nimport { pick } from 'lodash';\nimport { getCommandId } from './get-command-id';\n\nexport type GenerateOpts = {\n metadata?: Record<string, string>;\n};\n\ntype CommandObject = ReturnType<typeof oneCommandToObject> & { commands?: any };\n\nexport class GenerateCommandsDoc {\n constructor(\n private commands: Command[],\n private options: GenerateOpts\n ) {}\n\n generate(): string {\n const commands = this.getAllPublicCommandsSorted();\n let output = `${this.getFrontmatter()}\n# CLI Reference\n\nRun the following to list all available Bit commands (alternatively, use the \\`-h\\` alias, instead of \\`--help\\`):\n\n\\`\\`\\`sh\nbit --help\n\\`\\`\\`\n\nRun the following to get help on a specific command:\n\n\\`\\`\\`sh\nbit COMMAND --help\n\\`\\`\\`\n\nRun the following to get help on a specific sub-command:\n\n\\`\\`\\`sh\nbit COMMAND SUB_COMMAND --help\n\\`\\`\\`\n`;\n output += commands.map((cmd) => this.generateCommand(cmd)).join('\\n');\n\n return output;\n }\n\n generateJson() {\n return this.commandsToObjects();\n }\n\n private commandsToObjects(commands: Command[] = this.commands): CommandObject[] {\n return commands.map((command) => {\n const cmdObject: CommandObject = oneCommandToObject(command);\n if (command.commands?.length) {\n cmdObject.commands = this.commandsToObjects(command.commands);\n }\n return cmdObject;\n });\n }\n\n private getFrontmatter() {\n const metadata = this.options.metadata;\n if (!metadata) {\n return '';\n }\n const metadataStr = Object.keys(metadata)\n .map((key) => `${key}: ${metadata[key]}`)\n .join('\\n');\n\n return `---\n ${metadataStr}\n ---\n`;\n }\n\n private getAllPublicCommandsSorted() {\n const publicCommands = this.commands.filter((cmd) => !cmd.private);\n return publicCommands.sort((a, b) => a.name.localeCompare(b.name));\n }\n\n private generateCommand(cmd: Command) {\n const commandName = getCommandId(cmd.name);\n let result = `## ${commandName} \\n\\n`;\n if (cmd.alias && cmd.alias.length > 0) {\n result += `**Alias**: \\`${cmd.alias}\\` \\n`;\n }\n result += `**Description**: ${this.formatDescription(cmd)}`;\n result += `\\`bit ${cmd.name}\\` \\n\\n`;\n\n if (cmd.commands && cmd.commands.length > 0) {\n result += this.generateSubCommands(cmd.commands, cmd);\n }\n result += this.generateArguments(cmd.arguments);\n result += this.generateOptions(cmd.options);\n result += `--- \\n`;\n\n return result;\n }\n\n private generateSubCommands(subCommands: Command[], command: Command) {\n let ret = '';\n subCommands.forEach((subCommand) => {\n const commandName = getCommandId(command.name);\n const subcommandName = getCommandId(subCommand.name);\n const usage = `${commandName} ${subCommand.name}`;\n ret += `### ${commandName} ${subcommandName} \\n`;\n ret += `**Usage**: \\`${usage}\\` \\n\\n`;\n ret += `**Description**: ${this.formatDescription(subCommand)}`;\n\n ret += '\\n';\n ret += this.generateArguments(subCommand.arguments);\n ret += this.generateOptions(subCommand.options);\n });\n return ret;\n }\n\n private generateArguments(args?: CommandArg[]): string {\n if (!args || !args.length) return '';\n let output = `| **Arg** | **Description** | \\n`;\n output += `|---|:-----:|\\n`;\n args.forEach((arg) => {\n const { name, description } = arg;\n output += `|\\`${name}\\`|${(description || '').replaceAll('\\n', ' ')}|\\n`;\n });\n output += `\\n`;\n return output;\n }\n\n private generateOptions(options: CommandOptions): string {\n if (!options || options.length <= 0) return '';\n let output = `| **Option** | **Option alias** | **Description**| \\n`;\n output += `|---|:-----:|---|\\n`;\n options.forEach((opt) => {\n const [alias, flag, description] = opt;\n const aliasFormatted = alias ? `\\`-${alias}\\`` : ' ';\n const flagFormatted = `--${flag}`;\n output += `|\\`${flagFormatted}\\`|${aliasFormatted}|${description.replaceAll('\\n', ' ')}|\\n`;\n });\n output += `\\n`;\n return output;\n }\n\n private formatStringToMD(str: string): string {\n return str.split('\\n').join(' \\n');\n }\n\n private formatDescription(command: Command): string {\n const extendedDescription = command.extendedDescription\n ? ` \\n${this.formatStringToMD(command.extendedDescription)}`\n : '';\n const description = this.formatStringToMD(command.description as string);\n return `${description}${extendedDescription} \\n\\n`;\n }\n}\n\nfunction oneCommandToObject(command: Command) {\n return pick(command, [\n 'name',\n 'alias',\n 'options',\n 'description',\n 'extendedDescription',\n 'group',\n 'private',\n 'internal',\n 'remo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AAO,CAACkC,WAAqB,CAAC;IACxE,OAAO,GAAGA,WAAW,GAAGS,mBAAmB,QAAQ;EACrD;AACF;AAACC,OAAA,CAAA1D,mBAAA,GAAAA,mBAAA;AAED,SAASgB,kBAAkBA,CAACF,OAAgB,EAAE;EAC5C,OAAO,IAAA6C,cAAI,EAAC7C,OAAO,EAAE,CACnB,MAAM,EACN,OAAO,EACP,SAAS,EACT,aAAa,EACb,qBAAqB,EACrB,OAAO,EACP,SAAS,EACT,UAAU,EACV,UAAU,EACV,eAAe,EACf,WAAW,EACX,UAAU,CACX,CAAC;AACJ","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_lodash","data","require","_getCommandId","GenerateCommandsDoc","constructor","commands","options","generate","getAllPublicCommandsSorted","output","getFrontmatter","map","cmd","generateCommand","join","generateJson","commandsToObjects","command","cmdObject","oneCommandToObject","length","metadata","metadataStr","Object","keys","key","publicCommands","filter","private","sort","a","b","name","localeCompare","commandName","getCommandId","result","alias","formatDescription","generateSubCommands","generateArguments","arguments","generateOptions","subCommands","ret","forEach","subCommand","subcommandName","usage","args","arg","description","replaceAll","opt","flag","aliasFormatted","flagFormatted","formatStringToMD","str","split","extendedDescription","exports","pick"],"sources":["generate-doc-md.ts"],"sourcesContent":["import { CommandOptions, Command, CommandArg } from './command';\nimport { pick } from 'lodash';\nimport { getCommandId } from './get-command-id';\n\nexport type GenerateOpts = {\n metadata?: Record<string, string>;\n};\n\ntype CommandObject = ReturnType<typeof oneCommandToObject> & { commands?: any };\n\nexport class GenerateCommandsDoc {\n constructor(\n private commands: Command[],\n private options: GenerateOpts\n ) {}\n\n generate(): string {\n const commands = this.getAllPublicCommandsSorted();\n let output = `${this.getFrontmatter()}\n# CLI Reference\n\nRun the following to list all available Bit commands (alternatively, use the \\`-h\\` alias, instead of \\`--help\\`):\n\n\\`\\`\\`sh\nbit --help\n\\`\\`\\`\n\nRun the following to get help on a specific command:\n\n\\`\\`\\`sh\nbit COMMAND --help\n\\`\\`\\`\n\nRun the following to get help on a specific sub-command:\n\n\\`\\`\\`sh\nbit COMMAND SUB_COMMAND --help\n\\`\\`\\`\n`;\n output += commands.map((cmd) => this.generateCommand(cmd)).join('\\n');\n\n return output;\n }\n\n generateJson() {\n return this.commandsToObjects();\n }\n\n private commandsToObjects(commands: Command[] = this.commands): CommandObject[] {\n return commands.map((command) => {\n const cmdObject: CommandObject = oneCommandToObject(command);\n if (command.commands?.length) {\n cmdObject.commands = this.commandsToObjects(command.commands);\n }\n return cmdObject;\n });\n }\n\n private getFrontmatter() {\n const metadata = this.options.metadata;\n if (!metadata) {\n return '';\n }\n const metadataStr = Object.keys(metadata)\n .map((key) => `${key}: ${metadata[key]}`)\n .join('\\n');\n\n return `---\n ${metadataStr}\n ---\n`;\n }\n\n private getAllPublicCommandsSorted() {\n const publicCommands = this.commands.filter((cmd) => !cmd.private);\n return publicCommands.sort((a, b) => a.name.localeCompare(b.name));\n }\n\n private generateCommand(cmd: Command) {\n const commandName = getCommandId(cmd.name);\n let result = `## ${commandName} \\n\\n`;\n if (cmd.alias && cmd.alias.length > 0) {\n result += `**Alias**: \\`${cmd.alias}\\` \\n`;\n }\n result += `**Description**: ${this.formatDescription(cmd)}`;\n result += `\\`bit ${cmd.name}\\` \\n\\n`;\n\n if (cmd.commands && cmd.commands.length > 0) {\n result += this.generateSubCommands(cmd.commands, cmd);\n }\n result += this.generateArguments(cmd.arguments);\n result += this.generateOptions(cmd.options);\n result += `--- \\n`;\n\n return result;\n }\n\n private generateSubCommands(subCommands: Command[], command: Command) {\n let ret = '';\n subCommands.forEach((subCommand) => {\n const commandName = getCommandId(command.name);\n const subcommandName = getCommandId(subCommand.name);\n const usage = `${commandName} ${subCommand.name}`;\n ret += `### ${commandName} ${subcommandName} \\n`;\n ret += `**Usage**: \\`${usage}\\` \\n\\n`;\n ret += `**Description**: ${this.formatDescription(subCommand)}`;\n\n ret += '\\n';\n ret += this.generateArguments(subCommand.arguments);\n ret += this.generateOptions(subCommand.options);\n });\n return ret;\n }\n\n private generateArguments(args?: CommandArg[]): string {\n if (!args || !args.length) return '';\n let output = `| **Arg** | **Description** | \\n`;\n output += `|---|:-----:|\\n`;\n args.forEach((arg) => {\n const { name, description } = arg;\n output += `|\\`${name}\\`|${(description || '').replaceAll('\\n', ' ')}|\\n`;\n });\n output += `\\n`;\n return output;\n }\n\n private generateOptions(options: CommandOptions): string {\n if (!options || options.length <= 0) return '';\n let output = `| **Option** | **Option alias** | **Description**| \\n`;\n output += `|---|:-----:|---|\\n`;\n options.forEach((opt) => {\n const [alias, flag, description] = opt;\n const aliasFormatted = alias ? `\\`-${alias}\\`` : ' ';\n const flagFormatted = `--${flag}`;\n output += `|\\`${flagFormatted}\\`|${aliasFormatted}|${description.replaceAll('\\n', ' ')}|\\n`;\n });\n output += `\\n`;\n return output;\n }\n\n private formatStringToMD(str: string): string {\n return str.split('\\n').join(' \\n');\n }\n\n private formatDescription(command: Command): string {\n const extendedDescription = command.extendedDescription\n ? ` \\n${this.formatStringToMD(command.extendedDescription)}`\n : '';\n const description = this.formatStringToMD(command.description as string);\n return `${description}${extendedDescription} \\n\\n`;\n }\n}\n\nfunction oneCommandToObject(command: Command) {\n return pick(command, [\n 'name',\n 'alias',\n 'options',\n 'description',\n 'extendedDescription',\n 'group',\n 'private',\n 'internal',\n 'remoteOp',\n 'skipWorkspace',\n 'arguments',\n 'examples',\n ]);\n}\n"],"mappings":";;;;;;AACA,SAAAA,QAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,OAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAE,cAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,aAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAQO,MAAMG,mBAAmB,CAAC;EAC/BC,WAAWA,CACDC,QAAmB,EACnBC,OAAqB,EAC7B;IAAA,KAFQD,QAAmB,GAAnB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|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
8
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
9
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
10
|
+
class GlobalFlags {
|
|
11
|
+
constructor() {
|
|
12
|
+
_defineProperty(this, "_token", void 0);
|
|
13
|
+
}
|
|
14
|
+
get token() {
|
|
15
|
+
return this._token;
|
|
16
|
+
}
|
|
17
|
+
set token(token) {
|
|
18
|
+
this._token = token;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const globalFlags = new GlobalFlags();
|
|
22
|
+
var _default = exports.default = globalFlags;
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=global-flags.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["GlobalFlags","constructor","_defineProperty","token","_token","globalFlags","_default","exports","default"],"sources":["global-flags.ts"],"sourcesContent":["class GlobalFlags {\n private _token?: string;\n get token(): string | undefined {\n return this._token;\n }\n\n set token(token: string | undefined) {\n this._token = token;\n }\n}\n\nconst globalFlags = new GlobalFlags();\n\nexport default globalFlags;\n"],"mappings":";;;;;;;;;AAAA,MAAMA,WAAW,CAAC;EAAAC,YAAA;IAAAC,eAAA;EAAA;EAEhB,IAAIC,KAAKA,CAAA,EAAuB;IAC9B,OAAO,IAAI,CAACC,MAAM;EACpB;EAEA,IAAID,KAAKA,CAACA,KAAyB,EAAE;IACnC,IAAI,CAACC,MAAM,GAAGD,KAAK;EACrB;AACF;AAEA,MAAME,WAAW,GAAG,IAAIL,WAAW,CAAC,CAAC;AAAC,IAAAM,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEvBH,WAAW","ignoreList":[]}
|
package/dist/handle-errors.js
CHANGED
|
@@ -6,23 +6,23 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.handleErrorAndExit = handleErrorAndExit;
|
|
7
7
|
exports.handleUnhandledRejection = handleUnhandledRejection;
|
|
8
8
|
exports.setExitOnUnhandledRejection = setExitOnUnhandledRejection;
|
|
9
|
-
function
|
|
10
|
-
const data =
|
|
11
|
-
|
|
9
|
+
function _legacy() {
|
|
10
|
+
const data = require("@teambit/legacy.logger");
|
|
11
|
+
_legacy = function () {
|
|
12
12
|
return data;
|
|
13
13
|
};
|
|
14
14
|
return data;
|
|
15
15
|
}
|
|
16
16
|
function _defaultErrorHandler() {
|
|
17
|
-
const data = _interopRequireDefault(require("
|
|
17
|
+
const data = _interopRequireDefault(require("./default-error-handler"));
|
|
18
18
|
_defaultErrorHandler = function () {
|
|
19
19
|
return data;
|
|
20
20
|
};
|
|
21
21
|
return data;
|
|
22
22
|
}
|
|
23
|
-
function
|
|
23
|
+
function _legacy2() {
|
|
24
24
|
const data = require("@teambit/legacy.loader");
|
|
25
|
-
|
|
25
|
+
_legacy2 = function () {
|
|
26
26
|
return data;
|
|
27
27
|
};
|
|
28
28
|
return data;
|
|
@@ -40,8 +40,8 @@ function setExitOnUnhandledRejection(exit) {
|
|
|
40
40
|
}
|
|
41
41
|
async function handleErrorAndExit(err, commandName) {
|
|
42
42
|
try {
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
_legacy2().loader.off();
|
|
44
|
+
_legacy().logger.error(`got an error from command ${commandName}: ${err}`, err);
|
|
45
45
|
const {
|
|
46
46
|
message
|
|
47
47
|
} = (0, _defaultErrorHandler().default)(err);
|
|
@@ -58,7 +58,7 @@ async function handleUnhandledRejection(err) {
|
|
|
58
58
|
// eslint-disable-next-line no-console
|
|
59
59
|
console.error('** unhandled rejection found, please make sure the promise is resolved/rejected correctly! **', err);
|
|
60
60
|
if (!exitOnUnhandled) {
|
|
61
|
-
|
|
61
|
+
_legacy().logger.error(`ignoring unhandled rejection error:`, err);
|
|
62
62
|
return;
|
|
63
63
|
}
|
|
64
64
|
if (err instanceof Error) {
|
|
@@ -72,7 +72,7 @@ async function logErrAndExit(errMsg, commandName, errObj) {
|
|
|
72
72
|
console.error(errMsg); // eslint-disable-line
|
|
73
73
|
// for CI, print the entire error with the stacktrace
|
|
74
74
|
if (process.env.CI) console.error(errObj); // eslint-disable-line
|
|
75
|
-
await
|
|
75
|
+
await _legacy().logger.exitAfterFlush(1, commandName, errMsg.toString());
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
//# sourceMappingURL=handle-errors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["_legacy","data","require","_defaultErrorHandler","_interopRequireDefault","_legacy2","e","__esModule","default","exitOnUnhandled","setExitOnUnhandledRejection","exit","handleErrorAndExit","err","commandName","loader","off","logger","error","message","defaultHandleError","logErrAndExit","console","process","handleUnhandledRejection","Error","argv","errMsg","errObj","env","CI","exitAfterFlush","toString"],"sources":["handle-errors.ts"],"sourcesContent":["import { logger } from '@teambit/legacy.logger';\nimport defaultHandleError from './default-error-handler';\nimport { loader } from '@teambit/legacy.loader';\n\nlet exitOnUnhandled = true;\n\n// This provide a way to not exit when an unhandled rejection is found\n// This is main required when we load plugins which are esm modules and they require cjs modules\n// and there is as an error in the cjs module\n// in such case the regular catch will not catch the error and the process will exit\n// we don't want to exit in such case (of plugins load) so we provide a way to not exit\nexport function setExitOnUnhandledRejection(exit: boolean) {\n exitOnUnhandled = exit;\n}\n\nexport async function handleErrorAndExit(err: Error, commandName: string): Promise<void> {\n try {\n loader.off();\n logger.error(`got an error from command ${commandName}: ${err}`, err);\n const { message } = defaultHandleError(err);\n await logErrAndExit(message, commandName, err);\n } catch (e: any) {\n // eslint-disable-next-line no-console\n console.error('failed to log the error properly, failure error', e);\n // eslint-disable-next-line no-console\n console.error('failed to log the error properly, original error', err);\n process.exit(1);\n }\n}\n\nexport async function handleUnhandledRejection(err: Error | null | undefined | {}) {\n // eslint-disable-next-line no-console\n console.error('** unhandled rejection found, please make sure the promise is resolved/rejected correctly! **', err);\n if (!exitOnUnhandled) {\n logger.error(`ignoring unhandled rejection error:`, err);\n return;\n }\n if (err instanceof Error) {\n return handleErrorAndExit(err, process.argv[2]);\n }\n console.error(err); // eslint-disable-line\n return handleErrorAndExit(new Error(`unhandledRejections found. err ${err}`), process.argv[2]);\n}\n\nasync function logErrAndExit(errMsg: Error | string, commandName: string, errObj: Error) {\n if (!errMsg) throw new Error(`logErrAndExit expects to get either an Error or a string, got nothing`);\n console.error(errMsg); // eslint-disable-line\n // for CI, print the entire error with the stacktrace\n if (process.env.CI) console.error(errObj); // eslint-disable-line\n await logger.exitAfterFlush(1, commandName, errMsg.toString());\n}\n"],"mappings":";;;;;;;;AAAA,SAAAA,QAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,OAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAE,qBAAA;EAAA,MAAAF,IAAA,GAAAG,sBAAA,CAAAF,OAAA;EAAAC,oBAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,SAAA;EAAA,MAAAJ,IAAA,GAAAC,OAAA;EAAAG,QAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAAgD,SAAAG,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAEhD,IAAIG,eAAe,GAAG,IAAI;;AAE1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