@teambit/cli 0.0.839 → 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.
- package/cli-parser.ts +296 -0
- package/cli.aspect.ts +11 -0
- package/cli.cmd.ts +110 -0
- package/cli.main.runtime.ts +193 -0
- package/command-runner.ts +143 -0
- package/completion.cmd.ts +9 -0
- package/dist/cli-parser.js +5 -6
- package/dist/cli-parser.js.map +1 -1
- package/dist/cli.cmd.js +1 -1
- package/dist/cli.cmd.js.map +1 -1
- package/dist/cli.composition.d.ts +2 -2
- package/dist/cli.main.runtime.d.ts +6 -6
- package/dist/command-runner.d.ts +1 -1
- package/dist/completion.cmd.d.ts +1 -1
- package/dist/generate-doc-md.d.ts +2 -2
- package/dist/generate-doc-md.js +1 -2
- package/dist/generate-doc-md.js.map +1 -1
- package/dist/{preview-1703505948637.js → preview-1703647408454.js} +2 -2
- package/dist/yargs-adapter.d.ts +2 -2
- package/dist/yargs-adapter.js +2 -3
- package/dist/yargs-adapter.js.map +1 -1
- package/generate-doc-md.ts +167 -0
- package/get-command-id.ts +3 -0
- package/help.cmd.ts +18 -0
- package/help.ts +80 -0
- package/index.ts +8 -0
- package/legacy-command-adapter.ts +68 -0
- package/package.json +12 -19
- package/tsconfig.json +16 -21
- package/types/asset.d.ts +15 -3
- package/version.cmd.ts +21 -0
- package/yargs-adapter.ts +109 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { Command, CommandArg } from '@teambit/legacy/dist/cli/command';
|
|
2
|
+
import { CommandOptions } from '@teambit/legacy/dist/cli/legacy-command';
|
|
3
|
+
import { pick } from 'lodash';
|
|
4
|
+
import { getCommandId } from './get-command-id';
|
|
5
|
+
|
|
6
|
+
export type GenerateOpts = {
|
|
7
|
+
metadata?: Record<string, string>;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
type CommandObject = ReturnType<typeof oneCommandToObject> & { commands?: any };
|
|
11
|
+
|
|
12
|
+
export class GenerateCommandsDoc {
|
|
13
|
+
constructor(private commands: Command[], private options: GenerateOpts) {}
|
|
14
|
+
|
|
15
|
+
generate(): string {
|
|
16
|
+
const commands = this.getAllPublicCommandsSorted();
|
|
17
|
+
let output = `${this.getFrontmatter()}
|
|
18
|
+
# CLI Reference
|
|
19
|
+
|
|
20
|
+
Run the following to list all available Bit commands (alternatively, use the \`-h\` alias, instead of \`--help\`):
|
|
21
|
+
|
|
22
|
+
\`\`\`sh
|
|
23
|
+
bit --help
|
|
24
|
+
\`\`\`
|
|
25
|
+
|
|
26
|
+
Run the following to get help on a specific command:
|
|
27
|
+
|
|
28
|
+
\`\`\`sh
|
|
29
|
+
bit COMMAND --help
|
|
30
|
+
\`\`\`
|
|
31
|
+
|
|
32
|
+
Run the following to get help on a specific sub-command:
|
|
33
|
+
|
|
34
|
+
\`\`\`sh
|
|
35
|
+
bit COMMAND SUB_COMMAND --help
|
|
36
|
+
\`\`\`
|
|
37
|
+
`;
|
|
38
|
+
output += commands.map((cmd) => this.generateCommand(cmd)).join('\n');
|
|
39
|
+
|
|
40
|
+
return output;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
generateJson() {
|
|
44
|
+
return this.commandsToObjects();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
private commandsToObjects(commands: Command[] = this.commands): CommandObject[] {
|
|
48
|
+
return commands.map((command) => {
|
|
49
|
+
const cmdObject: CommandObject = oneCommandToObject(command);
|
|
50
|
+
if (command.commands?.length) {
|
|
51
|
+
cmdObject.commands = this.commandsToObjects(command.commands);
|
|
52
|
+
}
|
|
53
|
+
return cmdObject;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private getFrontmatter() {
|
|
58
|
+
const metadata = this.options.metadata;
|
|
59
|
+
if (!metadata) {
|
|
60
|
+
return '';
|
|
61
|
+
}
|
|
62
|
+
const metadataStr = Object.keys(metadata)
|
|
63
|
+
.map((key) => `${key}: ${metadata[key]}`)
|
|
64
|
+
.join('\n');
|
|
65
|
+
|
|
66
|
+
return `---
|
|
67
|
+
${metadataStr}
|
|
68
|
+
---
|
|
69
|
+
`;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
private getAllPublicCommandsSorted() {
|
|
73
|
+
const publicCommands = this.commands.filter((cmd) => !cmd.private);
|
|
74
|
+
return publicCommands.sort((a, b) => a.name.localeCompare(b.name));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
private generateCommand(cmd: Command) {
|
|
78
|
+
const commandName = getCommandId(cmd.name);
|
|
79
|
+
let result = `## ${commandName} \n\n`;
|
|
80
|
+
if (cmd.alias && cmd.alias.length > 0) {
|
|
81
|
+
result += `**Alias**: \`${cmd.alias}\` \n`;
|
|
82
|
+
}
|
|
83
|
+
result += `**Description**: ${this.formatDescription(cmd)}`;
|
|
84
|
+
result += `\`bit ${cmd.name}\` \n\n`;
|
|
85
|
+
|
|
86
|
+
if (cmd.commands && cmd.commands.length > 0) {
|
|
87
|
+
result += this.generateSubCommands(cmd.commands, cmd);
|
|
88
|
+
}
|
|
89
|
+
result += this.generateArguments(cmd.arguments);
|
|
90
|
+
result += this.generateOptions(cmd.options);
|
|
91
|
+
result += `--- \n`;
|
|
92
|
+
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
private generateSubCommands(subCommands: Command[], command: Command) {
|
|
97
|
+
let ret = '';
|
|
98
|
+
subCommands.forEach((subCommand) => {
|
|
99
|
+
const commandName = getCommandId(command.name);
|
|
100
|
+
const subcommandName = getCommandId(subCommand.name);
|
|
101
|
+
const usage = `${commandName} ${subCommand.name}`;
|
|
102
|
+
ret += `### ${commandName} ${subcommandName} \n`;
|
|
103
|
+
ret += `**Usage**: \`${usage}\` \n\n`;
|
|
104
|
+
ret += `**Description**: ${this.formatDescription(subCommand)}`;
|
|
105
|
+
|
|
106
|
+
ret += '\n';
|
|
107
|
+
ret += this.generateArguments(subCommand.arguments);
|
|
108
|
+
ret += this.generateOptions(subCommand.options);
|
|
109
|
+
});
|
|
110
|
+
return ret;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
private generateArguments(args?: CommandArg[]): string {
|
|
114
|
+
if (!args || !args.length) return '';
|
|
115
|
+
let output = `| **Arg** | **Description** | \n`;
|
|
116
|
+
output += `|---|:-----:|\n`;
|
|
117
|
+
args.forEach((arg) => {
|
|
118
|
+
const { name, description } = arg;
|
|
119
|
+
output += `|\`${name}\`|${(description || '').replaceAll('\n', ' ')}|\n`;
|
|
120
|
+
});
|
|
121
|
+
output += `\n`;
|
|
122
|
+
return output;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
private generateOptions(options: CommandOptions): string {
|
|
126
|
+
if (!options || options.length <= 0) return '';
|
|
127
|
+
let output = `| **Option** | **Option alias** | **Description**| \n`;
|
|
128
|
+
output += `|---|:-----:|---|\n`;
|
|
129
|
+
options.forEach((opt) => {
|
|
130
|
+
const [alias, flag, description] = opt;
|
|
131
|
+
const aliasFormatted = alias ? `\`-${alias}\`` : ' ';
|
|
132
|
+
const flagFormatted = `--${flag}`;
|
|
133
|
+
output += `|\`${flagFormatted}\`|${aliasFormatted}|${description.replaceAll('\n', ' ')}|\n`;
|
|
134
|
+
});
|
|
135
|
+
output += `\n`;
|
|
136
|
+
return output;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
private formatStringToMD(str: string): string {
|
|
140
|
+
return str.split('\n').join(' \n');
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
private formatDescription(command: Command): string {
|
|
144
|
+
const extendedDescription = command.extendedDescription
|
|
145
|
+
? ` \n${this.formatStringToMD(command.extendedDescription)}`
|
|
146
|
+
: '';
|
|
147
|
+
const description = this.formatStringToMD(command.description as string);
|
|
148
|
+
return `${description}${extendedDescription} \n\n`;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function oneCommandToObject(command: Command) {
|
|
153
|
+
return pick(command, [
|
|
154
|
+
'name',
|
|
155
|
+
'alias',
|
|
156
|
+
'options',
|
|
157
|
+
'description',
|
|
158
|
+
'extendedDescription',
|
|
159
|
+
'group',
|
|
160
|
+
'private',
|
|
161
|
+
'internal',
|
|
162
|
+
'remoteOp',
|
|
163
|
+
'skipWorkspace',
|
|
164
|
+
'arguments',
|
|
165
|
+
'examples',
|
|
166
|
+
]);
|
|
167
|
+
}
|
package/help.cmd.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Command, CommandOptions } from '@teambit/cli';
|
|
2
|
+
import { CLIMain } from './cli.main.runtime';
|
|
3
|
+
import { formatHelp } from './help';
|
|
4
|
+
|
|
5
|
+
export class HelpCmd implements Command {
|
|
6
|
+
name = 'help';
|
|
7
|
+
description = 'shows help';
|
|
8
|
+
alias = '$0'; // default command (meaning, if no args are provided, this will be used), see https://github.com/yargs/yargs/blob/master/docs/advanced.md#default-commands
|
|
9
|
+
loader = false;
|
|
10
|
+
group = 'general';
|
|
11
|
+
options = [['', 'internal', 'show internal commands']] as CommandOptions;
|
|
12
|
+
|
|
13
|
+
constructor(private cliMain: CLIMain) {}
|
|
14
|
+
|
|
15
|
+
async report(_, { internal }: { internal: boolean }) {
|
|
16
|
+
return formatHelp(this.cliMain.commands, this.cliMain.groups, internal);
|
|
17
|
+
}
|
|
18
|
+
}
|
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.
|
|
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.
|
|
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.
|
|
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/
|
|
32
|
-
"@types/
|
|
33
|
-
"@
|
|
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
|
-
"
|
|
38
|
-
"react": "^
|
|
39
|
-
"
|
|
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": ">=
|
|
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
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"DOM.Iterable",
|
|
8
|
-
"ScriptHost"
|
|
4
|
+
"esnext",
|
|
5
|
+
"dom",
|
|
6
|
+
"dom.Iterable"
|
|
9
7
|
],
|
|
10
|
-
"target": "
|
|
11
|
-
"module": "
|
|
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
|
-
"
|
|
14
|
+
"skipLibCheck": true,
|
|
20
15
|
"moduleResolution": "node",
|
|
21
16
|
"esModuleInterop": true,
|
|
22
|
-
"rootDir": ".",
|
|
23
17
|
"resolveJsonModule": true,
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
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
|
-
"
|
|
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<
|
|
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
|
+
}
|
package/yargs-adapter.ts
ADDED
|
@@ -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
|
+
}
|