@teambit/cli 0.0.838 → 0.0.840

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.
Files changed (44) hide show
  1. package/cli-parser.ts +296 -0
  2. package/cli.aspect.ts +11 -0
  3. package/cli.cmd.ts +110 -0
  4. package/cli.main.runtime.ts +193 -0
  5. package/command-runner.ts +143 -0
  6. package/completion.cmd.ts +9 -0
  7. package/dist/cli-parser.js +7 -10
  8. package/dist/cli-parser.js.map +1 -1
  9. package/dist/cli.cmd.js +3 -3
  10. package/dist/cli.cmd.js.map +1 -1
  11. package/dist/cli.composition.d.ts +2 -2
  12. package/dist/cli.main.runtime.d.ts +6 -6
  13. package/dist/cli.main.runtime.js +2 -2
  14. package/dist/cli.main.runtime.js.map +1 -1
  15. package/dist/command-runner.d.ts +1 -1
  16. package/dist/command-runner.js +2 -2
  17. package/dist/command-runner.js.map +1 -1
  18. package/dist/completion.cmd.d.ts +1 -1
  19. package/dist/completion.cmd.js +2 -2
  20. package/dist/exceptions/command-not-found.js +2 -2
  21. package/dist/exceptions/command-not-found.js.map +1 -1
  22. package/dist/generate-doc-md.d.ts +2 -2
  23. package/dist/generate-doc-md.js +1 -2
  24. package/dist/generate-doc-md.js.map +1 -1
  25. package/dist/help.cmd.js +2 -2
  26. package/dist/help.cmd.js.map +1 -1
  27. package/dist/legacy-command-adapter.js +2 -2
  28. package/dist/{preview-1703387662836.js → preview-1703647408454.js} +2 -2
  29. package/dist/version.cmd.js +2 -2
  30. package/dist/version.cmd.js.map +1 -1
  31. package/dist/yargs-adapter.d.ts +2 -2
  32. package/dist/yargs-adapter.js +4 -5
  33. package/dist/yargs-adapter.js.map +1 -1
  34. package/generate-doc-md.ts +167 -0
  35. package/get-command-id.ts +3 -0
  36. package/help.cmd.ts +18 -0
  37. package/help.ts +80 -0
  38. package/index.ts +8 -0
  39. package/legacy-command-adapter.ts +68 -0
  40. package/package.json +12 -19
  41. package/tsconfig.json +16 -21
  42. package/types/asset.d.ts +15 -3
  43. package/version.cmd.ts +21 -0
  44. package/yargs-adapter.ts +109 -0
package/help.ts ADDED
@@ -0,0 +1,80 @@
1
+ import chalk from 'chalk';
2
+ import rightpad from 'pad-right';
3
+ import { capitalize } from 'lodash';
4
+ import { GroupsType } from '@teambit/legacy/dist/cli/command-groups';
5
+ import { CommandList } from './cli.main.runtime';
6
+ import { getCommandId } from './get-command-id';
7
+
8
+ const SPACE = ' ';
9
+ const TITLE_LEFT_SPACES_NUMBER = 2;
10
+ const COMMAND_LEFT_SPACES_NUMBER = 4;
11
+ const NAME_WITH_SPACES_LENGTH = 15;
12
+
13
+ type HelpProps = {
14
+ [groupName: string]: GroupContent;
15
+ };
16
+
17
+ type GroupContent = {
18
+ commands: { [cmdName: string]: string };
19
+ description: string;
20
+ };
21
+
22
+ export function formatHelp(commands: CommandList, groups: GroupsType, showPrivateCommands = false) {
23
+ const helpProps = groupCommands(commands, groups, showPrivateCommands);
24
+ const commandsStr = formatCommandsHelp(helpProps);
25
+
26
+ return `${getHeader()}
27
+
28
+ ${commandsStr}
29
+
30
+ ${getFooter()}`;
31
+ }
32
+
33
+ function groupCommands(commands: CommandList, groups: GroupsType, showPrivateCommands = false): HelpProps {
34
+ const help: HelpProps = commands
35
+ .filter((command) => (showPrivateCommands ? true : !command.private && command.description))
36
+ .reduce(function (partialHelp, command) {
37
+ const groupName = command.group as string; // at this stage, it must be set
38
+ partialHelp[groupName] = partialHelp[groupName] || {
39
+ commands: {},
40
+ description: groups[groupName] || capitalize(command.group),
41
+ };
42
+ const cmdId = getCommandId(command.name);
43
+ partialHelp[groupName].commands[cmdId] = command.description;
44
+ return partialHelp;
45
+ }, {});
46
+ return help;
47
+ }
48
+
49
+ function formatCommandsHelp(helpProps: HelpProps): string {
50
+ return Object.keys(helpProps)
51
+ .map((groupName) => commandsSectionTemplate(helpProps[groupName]))
52
+ .join('\n\n');
53
+ }
54
+
55
+ function commandsSectionTemplate(section: GroupContent): string {
56
+ const titleSpace = SPACE.repeat(TITLE_LEFT_SPACES_NUMBER);
57
+ const title = `${titleSpace}${chalk.underline.bold.blue(section.description)}`;
58
+ const commands = Object.keys(section.commands)
59
+ .map((cmdName) => commandTemplate(cmdName, section.commands[cmdName]))
60
+ .join('\n');
61
+ const res = `${title}\n${commands}`;
62
+ return res;
63
+ }
64
+
65
+ function commandTemplate(name: string, description: string): string {
66
+ const nameSpace = SPACE.repeat(COMMAND_LEFT_SPACES_NUMBER);
67
+ const nameWithRightSpace = rightpad(name, NAME_WITH_SPACES_LENGTH, SPACE);
68
+ const res = `${nameSpace}${chalk.green(nameWithRightSpace)}${description}`;
69
+ return res;
70
+ }
71
+
72
+ function getHeader(): string {
73
+ return `${chalk.bold('usage: bit [--version] [--help] <command> [<args>]')}
74
+
75
+ ${chalk.yellow(`bit documentation: https://bit.dev/`)}`;
76
+ }
77
+
78
+ function getFooter(): string {
79
+ return `${chalk.yellow("please use 'bit <command> --help' for more information and guides on specific commands.")}`;
80
+ }
package/index.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { CLIAspect, MainRuntime } from './cli.aspect';
2
+
3
+ export type { CLIMain, CommandList, CommandsSlot } from './cli.main.runtime';
4
+ export type { Command, CLIArgs, Flags, GenericObject } from '@teambit/legacy/dist/cli/command';
5
+ export type { CommandOptions } from '@teambit/legacy/dist/cli/legacy-command';
6
+ export * from './exceptions';
7
+
8
+ export { CLIAspect as default, MainRuntime, CLIAspect };
@@ -0,0 +1,68 @@
1
+ import { LegacyCommand } from '@teambit/legacy/dist/cli/legacy-command';
2
+ import { Command, CommandOptions, GenericObject } from '.';
3
+ import { CLIMain } from './cli.main.runtime';
4
+
5
+ export class LegacyCommandAdapter implements Command {
6
+ alias: string;
7
+ name: string;
8
+ description: string;
9
+ options: CommandOptions;
10
+ extendedDescription?: string;
11
+ group?: string;
12
+ loader?: boolean;
13
+ commands: Command[];
14
+ private?: boolean;
15
+ migration?: boolean;
16
+ internal?: boolean;
17
+ skipWorkspace?: boolean;
18
+ helpUrl?: string;
19
+ _packageManagerArgs?: string[];
20
+ constructor(private cmd: LegacyCommand, cliExtension: CLIMain) {
21
+ this.name = cmd.name;
22
+ this.description = cmd.description;
23
+ this.helpUrl = cmd.helpUrl;
24
+ this.options = cmd.opts || [];
25
+ this.alias = cmd.alias;
26
+ this.extendedDescription = cmd.extendedDescription;
27
+ this.skipWorkspace = cmd.skipWorkspace;
28
+ this.group = cmd.group;
29
+ this.loader = cmd.loader;
30
+ this.private = cmd.private;
31
+ this.migration = cmd.migration;
32
+ this.internal = cmd.internal;
33
+ this.commands = (cmd.commands || []).map((sub) => new LegacyCommandAdapter(sub, cliExtension));
34
+ }
35
+
36
+ private async action(params: any, options: { [key: string]: any }): Promise<ActionResult> {
37
+ const res = await this.cmd.action(params, options, this._packageManagerArgs);
38
+ let data = res;
39
+ let code = 0;
40
+ if (res && res.__code !== undefined) {
41
+ data = res.data;
42
+ code = res.__code;
43
+ }
44
+ const report = this.cmd.report(data, params, options);
45
+ return {
46
+ code,
47
+ report,
48
+ };
49
+ }
50
+
51
+ async report(params: any, options: { [key: string]: any }): Promise<{ data: string; code: number }> {
52
+ const actionResult = await this.action(params, options);
53
+ return { data: actionResult.report, code: actionResult.code };
54
+ }
55
+
56
+ async json(params: any, options: { [key: string]: any }): Promise<GenericObject> {
57
+ const actionResult = await this.action(params, options);
58
+ return {
59
+ data: JSON.parse(actionResult.report),
60
+ code: actionResult.code,
61
+ };
62
+ }
63
+ }
64
+
65
+ type ActionResult = {
66
+ code: number;
67
+ report: string;
68
+ };
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/cli",
3
- "version": "0.0.838",
3
+ "version": "0.0.840",
4
4
  "homepage": "https://bit.cloud/teambit/harmony/cli",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.harmony",
8
8
  "name": "cli",
9
- "version": "0.0.838"
9
+ "version": "0.0.840"
10
10
  },
11
11
  "dependencies": {
12
12
  "chalk": "2.4.2",
@@ -16,27 +16,23 @@
16
16
  "p-map-series": "2.1.0",
17
17
  "ink": "3.2.0",
18
18
  "pad-right": "0.2.2",
19
- "core-js": "^3.0.0",
20
- "@babel/runtime": "7.20.0",
21
19
  "@teambit/harmony": "0.4.6",
22
20
  "@teambit/bit-error": "0.0.404",
23
- "@teambit/logger": "0.0.931"
21
+ "@teambit/logger": "0.0.933"
24
22
  },
25
23
  "devDependencies": {
26
24
  "@types/didyoumean": "1.2.0",
27
25
  "@types/lodash": "4.14.165",
28
26
  "@types/yargs": "17.0.0",
29
- "@types/react": "^17.0.8",
30
27
  "@types/mocha": "9.1.0",
31
- "@types/node": "12.20.4",
32
- "@types/react-dom": "^17.0.5",
33
- "@types/jest": "^26.0.0",
34
- "@types/testing-library__jest-dom": "5.9.5"
28
+ "@types/jest": "^29.2.2",
29
+ "@types/testing-library__jest-dom": "^5.9.5",
30
+ "@teambit/harmony.envs.core-aspect-env": "0.0.13"
35
31
  },
36
32
  "peerDependencies": {
37
- "@teambit/legacy": "1.0.623",
38
- "react": "^16.8.0 || ^17.0.0",
39
- "react-dom": "^16.8.0 || ^17.0.0"
33
+ "react": "^17.0.0 || ^18.0.0",
34
+ "@types/react": "^18.2.12",
35
+ "@teambit/legacy": "1.0.624"
40
36
  },
41
37
  "license": "Apache-2.0",
42
38
  "optionalDependencies": {},
@@ -50,7 +46,7 @@
50
46
  },
51
47
  "private": false,
52
48
  "engines": {
53
- "node": ">=12.22.0"
49
+ "node": ">=16.0.0"
54
50
  },
55
51
  "repository": {
56
52
  "type": "git",
@@ -59,12 +55,9 @@
59
55
  "keywords": [
60
56
  "bit",
61
57
  "bit-aspect",
58
+ "bit-core-aspect",
62
59
  "components",
63
60
  "collaboration",
64
- "web",
65
- "react",
66
- "react-components",
67
- "angular",
68
- "angular-components"
61
+ "web"
69
62
  ]
70
63
  }
package/tsconfig.json CHANGED
@@ -1,38 +1,33 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "lib": [
4
- "es2019",
5
- "DOM",
6
- "ES6",
7
- "DOM.Iterable",
8
- "ScriptHost"
4
+ "esnext",
5
+ "dom",
6
+ "dom.Iterable"
9
7
  ],
10
- "target": "es2015",
11
- "module": "CommonJS",
12
- "jsx": "react",
13
- "allowJs": true,
14
- "composite": true,
8
+ "target": "es2020",
9
+ "module": "es2020",
10
+ "jsx": "react-jsx",
15
11
  "declaration": true,
16
12
  "sourceMap": true,
17
- "skipLibCheck": true,
18
13
  "experimentalDecorators": true,
19
- "outDir": "dist",
14
+ "skipLibCheck": true,
20
15
  "moduleResolution": "node",
21
16
  "esModuleInterop": true,
22
- "rootDir": ".",
23
17
  "resolveJsonModule": true,
24
- "emitDeclarationOnly": true,
25
- "emitDecoratorMetadata": true,
26
- "allowSyntheticDefaultImports": true,
27
- "strictPropertyInitialization": false,
28
- "strict": true,
29
- "noImplicitAny": false,
30
- "preserveConstEnums": true
18
+ "allowJs": true,
19
+ "outDir": "dist",
20
+ "emitDeclarationOnly": true
31
21
  },
32
22
  "exclude": [
23
+ "artifacts",
24
+ "public",
33
25
  "dist",
26
+ "node_modules",
27
+ "package.json",
34
28
  "esm.mjs",
35
- "package.json"
29
+ "**/*.cjs",
30
+ "./dist"
36
31
  ],
37
32
  "include": [
38
33
  "**/*",
package/types/asset.d.ts CHANGED
@@ -5,12 +5,12 @@ declare module '*.png' {
5
5
  declare module '*.svg' {
6
6
  import type { FunctionComponent, SVGProps } from 'react';
7
7
 
8
- export const ReactComponent: FunctionComponent<SVGProps<SVGSVGElement> & { title?: string }>;
8
+ export const ReactComponent: FunctionComponent<
9
+ SVGProps<SVGSVGElement> & { title?: string }
10
+ >;
9
11
  const src: string;
10
12
  export default src;
11
13
  }
12
-
13
- // @TODO Gilad
14
14
  declare module '*.jpg' {
15
15
  const value: any;
16
16
  export = value;
@@ -27,3 +27,15 @@ declare module '*.bmp' {
27
27
  const value: any;
28
28
  export = value;
29
29
  }
30
+ declare module '*.otf' {
31
+ const value: any;
32
+ export = value;
33
+ }
34
+ declare module '*.woff' {
35
+ const value: any;
36
+ export = value;
37
+ }
38
+ declare module '*.woff2' {
39
+ const value: any;
40
+ export = value;
41
+ }
package/version.cmd.ts ADDED
@@ -0,0 +1,21 @@
1
+ import { Command, CommandOptions } from '@teambit/cli';
2
+ import { getHarmonyVersion } from '@teambit/legacy/dist/bootstrap';
3
+
4
+ export class VersionCmd implements Command {
5
+ name = 'version';
6
+ description = 'shows bit version';
7
+ alias = '';
8
+ loader = false;
9
+ group = 'general';
10
+ options = [['j', 'json', 'return the version in json format']] as CommandOptions;
11
+
12
+ async report() {
13
+ const results = await this.json();
14
+ return results.bit;
15
+ }
16
+
17
+ async json() {
18
+ const bit = getHarmonyVersion(true);
19
+ return { bit };
20
+ }
21
+ }
@@ -0,0 +1,109 @@
1
+ import { Command } from '@teambit/legacy/dist/cli/command';
2
+ import { Arguments, CommandModule, Argv, Options } from 'yargs';
3
+ import { TOKEN_FLAG } from '@teambit/legacy/dist/constants';
4
+ import { camelCase } from 'lodash';
5
+ import { CommandRunner } from './command-runner';
6
+
7
+ export const GLOBAL_GROUP = 'Global';
8
+ export const STANDARD_GROUP = 'Options';
9
+
10
+ export class YargsAdapter implements CommandModule {
11
+ command: string;
12
+ describe?: string;
13
+ aliases?: string;
14
+ constructor(private commanderCommand: Command) {
15
+ this.command = commanderCommand.name;
16
+ this.describe = commanderCommand.description;
17
+ this.aliases = commanderCommand.alias;
18
+ }
19
+
20
+ builder(yargs: Argv) {
21
+ const options = YargsAdapter.optionsToBuilder(this.commanderCommand);
22
+ yargs.option(options);
23
+ this.commanderCommand.arguments?.forEach((arg) => {
24
+ yargs.positional(arg.name, { description: arg.description });
25
+ });
26
+ this.commanderCommand.examples?.forEach((example) => {
27
+ yargs.example(example.cmd, example.description);
28
+ });
29
+
30
+ return yargs;
31
+ }
32
+
33
+ handler(argv: Arguments) {
34
+ const enteredArgs = getArgsFromCommandName(this.commanderCommand.name);
35
+ const argsValues = enteredArgs.map((a) => argv[a]) as any[];
36
+ // a workaround to get a flag syntax such as "--all [version]" work with yargs.
37
+ const flags = Object.keys(argv).reduce((acc, current) => {
38
+ if (current === '_' || current === '$0' || current === '--') return acc;
39
+ // const flagName = current.split(' ')[0];
40
+ const val = typeof argv[current] === 'string' && !argv[current] ? true : argv[current];
41
+ acc[current] = val;
42
+ return acc;
43
+ }, {});
44
+ this.commanderCommand._packageManagerArgs = (argv['--'] || []) as string[];
45
+
46
+ const commandRunner = new CommandRunner(this.commanderCommand, argsValues, flags);
47
+ return commandRunner.runCommand();
48
+ }
49
+
50
+ get positional() {
51
+ return this.commanderCommand.arguments;
52
+ }
53
+
54
+ static optionsToBuilder(command: Command): { [key: string]: Options } {
55
+ const option = command.options.reduce((acc, [alias, opt, desc]) => {
56
+ const optName = opt.split(' ')[0];
57
+ acc[optName] = {
58
+ alias,
59
+ describe: desc,
60
+ group: STANDARD_GROUP,
61
+ type: opt.includes(' ') ? 'string' : 'boolean',
62
+ requiresArg: opt.includes('<'),
63
+ } as Options;
64
+ return acc;
65
+ }, {});
66
+ const globalOptions = YargsAdapter.getGlobalOptions(command);
67
+
68
+ return { ...option, ...globalOptions };
69
+ }
70
+
71
+ static getGlobalOptions(command: Command): Record<string, any> {
72
+ const globalOptions: Record<string, any> = {};
73
+ if (command.remoteOp) {
74
+ globalOptions[TOKEN_FLAG] = {
75
+ describe: 'authentication token',
76
+ group: GLOBAL_GROUP,
77
+ };
78
+ }
79
+ if (!command.internal) {
80
+ globalOptions.log = {
81
+ describe:
82
+ 'print log messages to the screen, options are: [trace, debug, info, warn, error, fatal], the default is info',
83
+ group: GLOBAL_GROUP,
84
+ };
85
+ globalOptions['safe-mode'] = {
86
+ describe:
87
+ 'bootstrap the bare-minimum with only the CLI aspect. useful mainly for low-level commands when bit refuses to load',
88
+ group: GLOBAL_GROUP,
89
+ };
90
+ }
91
+ return globalOptions;
92
+ }
93
+ }
94
+
95
+ function getArgsFromCommandName(commandName: string) {
96
+ const commandSplit = commandName.split(' ');
97
+ commandSplit.shift(); // remove the first element, it's the command-name
98
+
99
+ return commandSplit.map((existArg) => {
100
+ const trimmed = existArg.trim();
101
+ if ((!trimmed.startsWith('<') && !trimmed.startsWith('[')) || (!trimmed.endsWith('>') && !trimmed.endsWith(']'))) {
102
+ throw new Error(`expect arg "${trimmed}" of "${commandName}" to be wrapped with "[]" or "<>"`);
103
+ }
104
+ // remove the opening and closing brackets
105
+ const withoutBrackets = trimmed.slice(1, -1);
106
+
107
+ return camelCase(withoutBrackets);
108
+ });
109
+ }