@teambit/cli 0.0.386 → 0.0.390
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/package.json +20 -5
- package/tsconfig.json +1 -1
- package/bin/bit +0 -2
- package/cli-parser.ts +0 -191
- package/cli.aspect.ts +0 -9
- package/cli.cmd.ts +0 -96
- package/cli.main.runtime.ts +0 -140
- package/command-runner.ts +0 -142
- package/completion.cmd.ts +0 -9
- package/exceptions/already-exists.ts +0 -7
- package/exceptions/command-not-found.ts +0 -22
- package/exceptions/index.ts +0 -1
- package/generate-doc-md.ts +0 -89
- package/get-command-id.ts +0 -3
- package/help.cmd.ts +0 -18
- package/help.ts +0 -80
- package/index.ts +0 -5
- package/legacy-command-adapter.ts +0 -67
- package/package-tar/teambit-cli-0.0.386.tgz +0 -0
- package/types/asset.d.ts +0 -29
- package/types/style.d.ts +0 -42
- package/yargs-adapter.ts +0 -95
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.390",
|
|
4
4
|
"homepage": "https://bit.dev/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.390"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"chalk": "2.4.2",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"pad-right": "0.2.2",
|
|
19
19
|
"@babel/runtime": "7.12.18",
|
|
20
20
|
"core-js": "^3.0.0",
|
|
21
|
-
"@teambit/bit-error": "0.0.
|
|
21
|
+
"@teambit/bit-error": "0.0.376"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@types/didyoumean": "1.2.0",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"@types/node": "12.20.4"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"@teambit/legacy": "1.0.
|
|
35
|
+
"@teambit/legacy": "1.0.176",
|
|
36
36
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
37
37
|
"react": "^16.8.0 || ^17.0.0"
|
|
38
38
|
},
|
|
@@ -60,12 +60,27 @@
|
|
|
60
60
|
"react": "-"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
|
-
"@teambit/legacy": "1.0.
|
|
63
|
+
"@teambit/legacy": "1.0.176",
|
|
64
64
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
65
65
|
"react": "^16.8.0 || ^17.0.0"
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
},
|
|
69
|
+
"files": [
|
|
70
|
+
"dist",
|
|
71
|
+
"!dist/tsconfig.tsbuildinfo",
|
|
72
|
+
"**/*.md",
|
|
73
|
+
"**/*.mdx",
|
|
74
|
+
"**/*.js",
|
|
75
|
+
"**/*.json",
|
|
76
|
+
"**/*.sass",
|
|
77
|
+
"**/*.scss",
|
|
78
|
+
"**/*.less",
|
|
79
|
+
"**/*.css",
|
|
80
|
+
"**/*.css",
|
|
81
|
+
"**/*.jpeg",
|
|
82
|
+
"**/*.gif"
|
|
83
|
+
],
|
|
69
84
|
"private": false,
|
|
70
85
|
"engines": {
|
|
71
86
|
"node": ">=12.22.0"
|
package/tsconfig.json
CHANGED
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
"skipLibCheck": true,
|
|
16
16
|
"moduleResolution": "node",
|
|
17
17
|
"esModuleInterop": true,
|
|
18
|
-
"outDir": "dist",
|
|
19
18
|
"composite": true,
|
|
20
19
|
"emitDeclarationOnly": true,
|
|
20
|
+
"outDir": "dist",
|
|
21
21
|
"experimentalDecorators": true,
|
|
22
22
|
"emitDecoratorMetadata": true,
|
|
23
23
|
"allowSyntheticDefaultImports": true,
|
package/bin/bit
DELETED
package/cli-parser.ts
DELETED
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
import didYouMean from 'didyoumean';
|
|
2
|
-
import yargs, { CommandModule } from 'yargs';
|
|
3
|
-
import { Command } from '@teambit/legacy/dist/cli/command';
|
|
4
|
-
import { GroupsType } from '@teambit/legacy/dist/cli/command-groups';
|
|
5
|
-
import { loadConsumerIfExist } from '@teambit/legacy/dist/consumer';
|
|
6
|
-
import logger from '@teambit/legacy/dist/logger/logger';
|
|
7
|
-
import loader from '@teambit/legacy/dist/cli/loader';
|
|
8
|
-
import chalk from 'chalk';
|
|
9
|
-
import { getCommandId } from './get-command-id';
|
|
10
|
-
import { formatHelp } from './help';
|
|
11
|
-
import { GLOBAL_GROUP, STANDARD_GROUP, YargsAdapter } from './yargs-adapter';
|
|
12
|
-
import { CommandNotFound } from './exceptions/command-not-found';
|
|
13
|
-
|
|
14
|
-
export class CLIParser {
|
|
15
|
-
constructor(private commands: Command[], private groups: GroupsType, public parser = yargs) {}
|
|
16
|
-
|
|
17
|
-
async parse(args = process.argv.slice(2)) {
|
|
18
|
-
this.throwForNonExistsCommand(args[0]);
|
|
19
|
-
|
|
20
|
-
yargs(args);
|
|
21
|
-
yargs.help(false);
|
|
22
|
-
this.configureParser();
|
|
23
|
-
this.commands.forEach((command: Command) => {
|
|
24
|
-
if (command.commands && command.commands.length) {
|
|
25
|
-
this.parseCommandWithSubCommands(command);
|
|
26
|
-
} else {
|
|
27
|
-
const yargsCommand = this.getYargsCommand(command);
|
|
28
|
-
yargs.command(yargsCommand);
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
this.configureGlobalFlags();
|
|
32
|
-
this.setHelpMiddleware();
|
|
33
|
-
this.handleCommandFailure();
|
|
34
|
-
this.configureCompletion();
|
|
35
|
-
yargs.strict(); // don't allow non-exist flags and non-exist commands
|
|
36
|
-
|
|
37
|
-
yargs
|
|
38
|
-
// .recommendCommands() // don't use it, it brings the global help of yargs, we have a custom one
|
|
39
|
-
.wrap(null);
|
|
40
|
-
|
|
41
|
-
await yargs.parse();
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
private setHelpMiddleware() {
|
|
45
|
-
yargs.middleware((argv) => {
|
|
46
|
-
if (argv._.length === 0 && argv.help) {
|
|
47
|
-
// this is the main help page
|
|
48
|
-
this.printHelp();
|
|
49
|
-
process.exit(0);
|
|
50
|
-
}
|
|
51
|
-
if (argv.help) {
|
|
52
|
-
loader.off(); // stop the "loading bit..." before showing help if needed
|
|
53
|
-
// this is a command help page
|
|
54
|
-
yargs.showHelp(logCommandHelp);
|
|
55
|
-
if (!logger.isDaemon) process.exit(0);
|
|
56
|
-
}
|
|
57
|
-
}, true);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
private handleCommandFailure() {
|
|
61
|
-
yargs.fail((msg, err) => {
|
|
62
|
-
loader.stop();
|
|
63
|
-
if (err) {
|
|
64
|
-
throw err;
|
|
65
|
-
}
|
|
66
|
-
yargs.showHelp(logCommandHelp);
|
|
67
|
-
// eslint-disable-next-line no-console
|
|
68
|
-
console.log(`\n${chalk.yellow(msg)}`);
|
|
69
|
-
if (!logger.isDaemon) process.exit(1);
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
private configureCompletion() {
|
|
74
|
-
const commandsToShowComponentIdsForCompletion = [
|
|
75
|
-
'show',
|
|
76
|
-
'diff',
|
|
77
|
-
'tag',
|
|
78
|
-
'export',
|
|
79
|
-
'env',
|
|
80
|
-
'envs',
|
|
81
|
-
'compile',
|
|
82
|
-
'build',
|
|
83
|
-
'test',
|
|
84
|
-
'lint',
|
|
85
|
-
'log',
|
|
86
|
-
'dependents',
|
|
87
|
-
'dependencies',
|
|
88
|
-
];
|
|
89
|
-
// @ts-ignore
|
|
90
|
-
yargs.completion('completion', async function (current, argv, completionFilter, done) {
|
|
91
|
-
if (!current.startsWith('-') && commandsToShowComponentIdsForCompletion.includes(argv._[1])) {
|
|
92
|
-
const consumer = await loadConsumerIfExist();
|
|
93
|
-
done(consumer?.bitmapIdsFromCurrentLane.map((id) => id.toStringWithoutVersion()));
|
|
94
|
-
} else {
|
|
95
|
-
completionFilter();
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
private printHelp() {
|
|
101
|
-
const help = formatHelp(this.commands, this.groups);
|
|
102
|
-
// eslint-disable-next-line no-console
|
|
103
|
-
console.log(help);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
private configureParser() {
|
|
107
|
-
yargs.parserConfiguration({
|
|
108
|
-
// 'strip-dashed': true, // we can't enable it, otherwise, the completion doesn't work
|
|
109
|
-
'strip-aliased': true,
|
|
110
|
-
'boolean-negation': false,
|
|
111
|
-
'populate--': true,
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
private parseCommandWithSubCommands(command: Command) {
|
|
116
|
-
const yarnCommand = this.getYargsCommand(command);
|
|
117
|
-
yarnCommand.builder = () => {
|
|
118
|
-
command.commands?.forEach((cmd) => {
|
|
119
|
-
const subCommand = this.getYargsCommand(cmd);
|
|
120
|
-
yargs.command(subCommand);
|
|
121
|
-
});
|
|
122
|
-
return yargs;
|
|
123
|
-
};
|
|
124
|
-
yargs.command(yarnCommand);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
private getYargsCommand(command: Command): CommandModule {
|
|
128
|
-
const yarnCommand = new YargsAdapter(command);
|
|
129
|
-
yarnCommand.handler = yarnCommand.handler.bind(yarnCommand);
|
|
130
|
-
|
|
131
|
-
return yarnCommand;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
private configureGlobalFlags() {
|
|
135
|
-
yargs
|
|
136
|
-
.option('help', {
|
|
137
|
-
alias: 'h',
|
|
138
|
-
describe: 'show help',
|
|
139
|
-
group: GLOBAL_GROUP,
|
|
140
|
-
})
|
|
141
|
-
.option('version', {
|
|
142
|
-
global: false,
|
|
143
|
-
alias: 'v',
|
|
144
|
-
describe: 'show version',
|
|
145
|
-
group: GLOBAL_GROUP,
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
private throwForNonExistsCommand(commandName: string) {
|
|
150
|
-
if (!commandName || commandName.startsWith('-')) {
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
const commandsNames = this.commands.map((c) => getCommandId(c.name));
|
|
154
|
-
const aliases = this.commands.map((c) => c.alias).filter((a) => a);
|
|
155
|
-
const existingGlobalFlags = ['-V', '--version'];
|
|
156
|
-
const validCommands = [...commandsNames, ...aliases, ...existingGlobalFlags];
|
|
157
|
-
const commandExist = validCommands.includes(commandName);
|
|
158
|
-
|
|
159
|
-
if (!commandExist) {
|
|
160
|
-
didYouMean.returnFirstMatch = true;
|
|
161
|
-
const suggestions = didYouMean(
|
|
162
|
-
commandName,
|
|
163
|
-
this.commands.filter((c) => !c.private).map((c) => getCommandId(c.name))
|
|
164
|
-
);
|
|
165
|
-
const suggestion = suggestions && Array.isArray(suggestions) ? suggestions[0] : suggestions;
|
|
166
|
-
|
|
167
|
-
throw new CommandNotFound(commandName, suggestion as string);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* color the flags with green.
|
|
174
|
-
* there is no API to get the options, so it is done by regex.
|
|
175
|
-
* see https://github.com/yargs/yargs/issues/1956
|
|
176
|
-
*/
|
|
177
|
-
function logCommandHelp(help: string) {
|
|
178
|
-
const replacer = (_, p1, p2) => `${p1}${chalk.green(p2)}`;
|
|
179
|
-
const lines = help.split('\n');
|
|
180
|
-
let passedOptions = false;
|
|
181
|
-
for (let i = 0; i < lines.length; i += 1) {
|
|
182
|
-
const line = lines[i];
|
|
183
|
-
if (line.startsWith(STANDARD_GROUP)) {
|
|
184
|
-
passedOptions = true;
|
|
185
|
-
} else if (passedOptions) {
|
|
186
|
-
lines[i] = line.replace(/(--)([\w-]+)/, replacer).replace(/(-)([\w-]+)/, replacer);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
// eslint-disable-next-line no-console
|
|
190
|
-
console.log(lines.join('\n'));
|
|
191
|
-
}
|
package/cli.aspect.ts
DELETED
package/cli.cmd.ts
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line max-classes-per-file
|
|
2
|
-
import { Command, CommandOptions } from '@teambit/cli';
|
|
3
|
-
import logger from '@teambit/legacy/dist/logger/logger';
|
|
4
|
-
import { handleErrorAndExit } from '@teambit/legacy/dist/cli/handle-errors';
|
|
5
|
-
import { loadConsumerIfExist } from '@teambit/legacy/dist/consumer';
|
|
6
|
-
import readline from 'readline';
|
|
7
|
-
import { CLIParser } from './cli-parser';
|
|
8
|
-
import { CLIMain } from './cli.main.runtime';
|
|
9
|
-
import { GenerateCommandsDoc, GenerateOpts } from './generate-doc-md';
|
|
10
|
-
|
|
11
|
-
export class CliGenerateCmd implements Command {
|
|
12
|
-
name = 'generate';
|
|
13
|
-
description = 'EXPERIMENTAL. generate an .md file with all commands details';
|
|
14
|
-
alias = '';
|
|
15
|
-
loader = false;
|
|
16
|
-
group = 'general';
|
|
17
|
-
options = [
|
|
18
|
-
[
|
|
19
|
-
'',
|
|
20
|
-
'metadata',
|
|
21
|
-
'metadata/front-matter to place at the top of the .md file, enter as an object e.g. --metadata.id=cli --metadata.title=commands',
|
|
22
|
-
],
|
|
23
|
-
] as CommandOptions;
|
|
24
|
-
|
|
25
|
-
constructor(private cliMain: CLIMain) {}
|
|
26
|
-
|
|
27
|
-
async report(args, { metadata }: GenerateOpts): Promise<string> {
|
|
28
|
-
return new GenerateCommandsDoc(this.cliMain.commands, { metadata }).generate();
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export class CliCmd implements Command {
|
|
33
|
-
name = 'cli';
|
|
34
|
-
description = 'EXPERIMENTAL. enters bit cli program and generates commands list';
|
|
35
|
-
alias = '';
|
|
36
|
-
commands: Command[] = [];
|
|
37
|
-
loader = false;
|
|
38
|
-
group = 'general';
|
|
39
|
-
options = [] as CommandOptions;
|
|
40
|
-
|
|
41
|
-
constructor(private cliMain: CLIMain) {}
|
|
42
|
-
|
|
43
|
-
async report(): Promise<string> {
|
|
44
|
-
logger.isDaemon = true;
|
|
45
|
-
const rl = readline.createInterface({
|
|
46
|
-
input: process.stdin,
|
|
47
|
-
output: process.stdout,
|
|
48
|
-
prompt: 'bit > ',
|
|
49
|
-
completer: (line, cb) => completer(line, cb, this.cliMain),
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
const cliParser = new CLIParser(this.cliMain.commands, this.cliMain.groups);
|
|
53
|
-
|
|
54
|
-
rl.prompt();
|
|
55
|
-
|
|
56
|
-
return new Promise((resolve) => {
|
|
57
|
-
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
58
|
-
rl.on('line', async (line) => {
|
|
59
|
-
const cmd = line.trim().split(' ');
|
|
60
|
-
try {
|
|
61
|
-
await cliParser.parse(cmd);
|
|
62
|
-
} catch (err: any) {
|
|
63
|
-
await handleErrorAndExit(err, cmd[0]);
|
|
64
|
-
}
|
|
65
|
-
rl.prompt();
|
|
66
|
-
}).on('close', () => {
|
|
67
|
-
resolve('Have a great day!');
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function completer(line: string, cb: Function, cliMain: CLIMain) {
|
|
74
|
-
const lineSplit = line.split(' ');
|
|
75
|
-
let values: string[] = [];
|
|
76
|
-
if (lineSplit.length <= 1) {
|
|
77
|
-
values = completeCommand(line, cliMain);
|
|
78
|
-
cb(null, [values, line]);
|
|
79
|
-
}
|
|
80
|
-
loadConsumerIfExist()
|
|
81
|
-
.then((consumer) => {
|
|
82
|
-
const comps = consumer?.bitmapIdsFromCurrentLane.map((id) => id.toStringWithoutVersion()) || [];
|
|
83
|
-
values = comps.filter((c) => c.includes(lineSplit[1]));
|
|
84
|
-
// eslint-disable-next-line promise/no-callback-in-promise
|
|
85
|
-
cb(null, [values, line]);
|
|
86
|
-
})
|
|
87
|
-
.catch((err) => {
|
|
88
|
-
// eslint-disable-next-line promise/no-callback-in-promise
|
|
89
|
-
cb(err, [[], line]);
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function completeCommand(line: string, cliMain: CLIMain): string[] {
|
|
94
|
-
const commands = cliMain.commands.filter((cmd) => cmd.name.startsWith(line));
|
|
95
|
-
return commands.map((c) => c.name).map((name) => name.split(' ')[0]);
|
|
96
|
-
}
|
package/cli.main.runtime.ts
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import { Slot, SlotRegistry } from '@teambit/harmony';
|
|
2
|
-
import { buildRegistry } from '@teambit/legacy/dist/cli';
|
|
3
|
-
import { Command } from '@teambit/legacy/dist/cli/command';
|
|
4
|
-
import LegacyLoadExtensions from '@teambit/legacy/dist/legacy-extensions/extensions-loader';
|
|
5
|
-
import { groups, GroupsType } from '@teambit/legacy/dist/cli/command-groups';
|
|
6
|
-
import { clone } from 'lodash';
|
|
7
|
-
import { CLIAspect, MainRuntime } from './cli.aspect';
|
|
8
|
-
import { AlreadyExistsError } from './exceptions/already-exists';
|
|
9
|
-
import { getCommandId } from './get-command-id';
|
|
10
|
-
import { LegacyCommandAdapter } from './legacy-command-adapter';
|
|
11
|
-
import { CLIParser } from './cli-parser';
|
|
12
|
-
import { CompletionCmd } from './completion.cmd';
|
|
13
|
-
import { CliCmd, CliGenerateCmd } from './cli.cmd';
|
|
14
|
-
import { HelpCmd } from './help.cmd';
|
|
15
|
-
|
|
16
|
-
export type CommandList = Array<Command>;
|
|
17
|
-
export type OnStart = (hasWorkspace: boolean) => Promise<void>;
|
|
18
|
-
|
|
19
|
-
export type OnStartSlot = SlotRegistry<OnStart>;
|
|
20
|
-
export type CommandsSlot = SlotRegistry<CommandList>;
|
|
21
|
-
|
|
22
|
-
export class CLIMain {
|
|
23
|
-
public groups: GroupsType = clone(groups); // if it's not cloned, it is cached across loadBit() instances
|
|
24
|
-
|
|
25
|
-
constructor(private commandsSlot: CommandsSlot, private onStartSlot: OnStartSlot) {}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* registers a new command in to the CLI.
|
|
29
|
-
*/
|
|
30
|
-
register(...commands: CommandList) {
|
|
31
|
-
commands.forEach((command) => {
|
|
32
|
-
this.setDefaults(command);
|
|
33
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
34
|
-
command.commands!.forEach((cmd) => this.setDefaults(cmd));
|
|
35
|
-
});
|
|
36
|
-
this.commandsSlot.register(commands);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* helpful for having the same command name in different environments (legacy and Harmony)
|
|
41
|
-
*/
|
|
42
|
-
unregister(commandName: string) {
|
|
43
|
-
this.commandsSlot.toArray().forEach(([aspectId, commands]) => {
|
|
44
|
-
const filteredCommands = commands.filter((command) => {
|
|
45
|
-
return getCommandId(command.name) !== commandName;
|
|
46
|
-
});
|
|
47
|
-
this.commandsSlot.map.set(aspectId, filteredCommands);
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* list of all registered commands. (legacy and new).
|
|
53
|
-
*/
|
|
54
|
-
get commands(): CommandList {
|
|
55
|
-
return this.commandsSlot.values().flat();
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* when running `bit help`, commands are grouped by categories.
|
|
60
|
-
* this method helps registering a new group by providing its name and a description.
|
|
61
|
-
* the name is what needs to be assigned to the `group` property of the Command interface.
|
|
62
|
-
* the description is what shown in the `bit help` output.
|
|
63
|
-
*/
|
|
64
|
-
registerGroup(name: string, description: string) {
|
|
65
|
-
if (this.groups[name]) {
|
|
66
|
-
throw new AlreadyExistsError('group', name);
|
|
67
|
-
}
|
|
68
|
-
this.groups[name] = description;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
registerOnStart(onStartFn: OnStart) {
|
|
72
|
-
this.onStartSlot.register(onStartFn);
|
|
73
|
-
return this;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* execute commands registered to this aspect.
|
|
78
|
-
*/
|
|
79
|
-
async run(hasWorkspace: boolean) {
|
|
80
|
-
await this.invokeOnStart(hasWorkspace);
|
|
81
|
-
const CliParser = new CLIParser(this.commands, this.groups);
|
|
82
|
-
await CliParser.parse();
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
private async invokeOnStart(hasWorkspace: boolean) {
|
|
86
|
-
const onStartFns = this.onStartSlot.values();
|
|
87
|
-
const promises = onStartFns.map(async (onStart) => onStart(hasWorkspace));
|
|
88
|
-
return Promise.all(promises);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
private setDefaults(command: Command) {
|
|
92
|
-
command.alias = command.alias || '';
|
|
93
|
-
command.description = command.description || '';
|
|
94
|
-
command.shortDescription = command.shortDescription || '';
|
|
95
|
-
command.group = command.group || 'ungrouped';
|
|
96
|
-
command.options = command.options || [];
|
|
97
|
-
command.private = command.private || false;
|
|
98
|
-
command.commands = command.commands || [];
|
|
99
|
-
if (command.loader === undefined) {
|
|
100
|
-
if (command.internal) {
|
|
101
|
-
command.loader = false;
|
|
102
|
-
} else {
|
|
103
|
-
command.loader = true;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
static dependencies = [];
|
|
109
|
-
static runtime = MainRuntime;
|
|
110
|
-
static slots = [Slot.withType<CommandList>(), Slot.withType<OnStart>()];
|
|
111
|
-
|
|
112
|
-
static async provider(deps, config, [commandsSlot, onStartSlot]: [CommandsSlot, OnStartSlot]) {
|
|
113
|
-
const cliMain = new CLIMain(commandsSlot, onStartSlot);
|
|
114
|
-
const legacyExtensions = await LegacyLoadExtensions();
|
|
115
|
-
// Make sure to register all the hooks actions in the global hooks manager
|
|
116
|
-
legacyExtensions.forEach((extension) => {
|
|
117
|
-
extension.registerHookActionsOnHooksManager();
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
const extensionsCommands = legacyExtensions.reduce((acc, curr) => {
|
|
121
|
-
if (curr.commands && curr.commands.length) {
|
|
122
|
-
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
|
|
123
|
-
acc = acc.concat(curr.commands);
|
|
124
|
-
}
|
|
125
|
-
return acc;
|
|
126
|
-
}, []);
|
|
127
|
-
|
|
128
|
-
const legacyRegistry = buildRegistry(extensionsCommands);
|
|
129
|
-
const legacyCommands = legacyRegistry.commands.concat(legacyRegistry.extensionsCommands || []);
|
|
130
|
-
const legacyCommandsAdapters = legacyCommands.map((command) => new LegacyCommandAdapter(command, cliMain));
|
|
131
|
-
const cliGenerateCmd = new CliGenerateCmd(cliMain);
|
|
132
|
-
const cliCmd = new CliCmd(cliMain);
|
|
133
|
-
const helpCmd = new HelpCmd(cliMain);
|
|
134
|
-
cliCmd.commands.push(cliGenerateCmd);
|
|
135
|
-
cliMain.register(...legacyCommandsAdapters, new CompletionCmd(), cliCmd, helpCmd);
|
|
136
|
-
return cliMain;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
CLIAspect.addRuntime(CLIMain);
|
package/command-runner.ts
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { render } from 'ink';
|
|
2
|
-
import { migrate } from '@teambit/legacy/dist/api/consumer';
|
|
3
|
-
import logger, { LoggerLevel } from '@teambit/legacy/dist/logger/logger';
|
|
4
|
-
import { CLIArgs, Command, Flags, RenderResult } from '@teambit/legacy/dist/cli/command';
|
|
5
|
-
import { parseCommandName } from '@teambit/legacy/dist/cli/command-registry';
|
|
6
|
-
import loader from '@teambit/legacy/dist/cli/loader';
|
|
7
|
-
import { handleErrorAndExit } from '@teambit/legacy/dist/cli/handle-errors';
|
|
8
|
-
import { TOKEN_FLAG_NAME } from '@teambit/legacy/dist/constants';
|
|
9
|
-
import globalFlags from '@teambit/legacy/dist/cli/global-flags';
|
|
10
|
-
import { Analytics } from '@teambit/legacy/dist/analytics/analytics';
|
|
11
|
-
|
|
12
|
-
export class CommandRunner {
|
|
13
|
-
private commandName: string;
|
|
14
|
-
constructor(private command: Command, private args: CLIArgs, private flags: Flags) {
|
|
15
|
-
this.commandName = parseCommandName(this.command.name);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* run command using one of the handler, "json"/"report"/"render". once done, exit the process.
|
|
20
|
-
*/
|
|
21
|
-
async runCommand() {
|
|
22
|
-
try {
|
|
23
|
-
this.bootstrapCommand();
|
|
24
|
-
await this.runMigrateIfNeeded();
|
|
25
|
-
this.determineConsoleWritingDuringCommand();
|
|
26
|
-
if (this.flags.json) {
|
|
27
|
-
return await this.runJsonHandler();
|
|
28
|
-
}
|
|
29
|
-
if (this.shouldRunRender()) {
|
|
30
|
-
return await this.runRenderHandler();
|
|
31
|
-
}
|
|
32
|
-
if (this.command.report) {
|
|
33
|
-
return await this.runReportHandler();
|
|
34
|
-
}
|
|
35
|
-
} catch (err: any) {
|
|
36
|
-
return handleErrorAndExit(err, this.commandName, this.command.internal);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
throw new Error(`command "${this.commandName}" doesn't implement "render" nor "report" methods`);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
private bootstrapCommand() {
|
|
43
|
-
Analytics.init(this.commandName, this.flags, this.args);
|
|
44
|
-
logger.info(`[*] started a new command: "${this.commandName}" with the following data:`, {
|
|
45
|
-
args: this.args,
|
|
46
|
-
flags: this.flags,
|
|
47
|
-
});
|
|
48
|
-
const token = this.flags[TOKEN_FLAG_NAME];
|
|
49
|
-
if (token) {
|
|
50
|
-
globalFlags.token = token.toString();
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* when both "render" and "report" were implemented, check whether it's a terminal.
|
|
56
|
-
* if it's a terminal, use "render", if not, use "report" because "report" is just a string
|
|
57
|
-
*/
|
|
58
|
-
private shouldRunRender() {
|
|
59
|
-
const isTerminal = process.stdout.isTTY;
|
|
60
|
-
if (this.command.report && !isTerminal) {
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
return Boolean(this.command.render);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* this works for both, Harmony commands and Legacy commands (the legacy-command-adapter
|
|
68
|
-
* implements json() method)
|
|
69
|
-
*/
|
|
70
|
-
private async runJsonHandler() {
|
|
71
|
-
if (!this.flags.json) return null;
|
|
72
|
-
if (!this.command.json) throw new Error(`command "${this.commandName}" doesn't implement "json" method`);
|
|
73
|
-
const result = await this.command.json(this.args, this.flags);
|
|
74
|
-
const code = result.code || 0;
|
|
75
|
-
const data = result.data || result;
|
|
76
|
-
return this.writeAndExit(JSON.stringify(data, null, 2), code);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
private async runRenderHandler() {
|
|
80
|
-
if (!this.command.render) throw new Error('runRenderHandler expects command.render to be implemented');
|
|
81
|
-
const result = await this.command.render(this.args, this.flags);
|
|
82
|
-
loader.off();
|
|
83
|
-
|
|
84
|
-
const { data, code } = toRenderResult(result);
|
|
85
|
-
|
|
86
|
-
const { waitUntilExit } = render(data);
|
|
87
|
-
await waitUntilExit();
|
|
88
|
-
return logger.exitAfterFlush(code, this.commandName);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
private async runReportHandler() {
|
|
92
|
-
if (!this.command.report) throw new Error('runReportHandler expects command.report to be implemented');
|
|
93
|
-
const result = await this.command.report(this.args, this.flags);
|
|
94
|
-
loader.off();
|
|
95
|
-
const data = typeof result === 'string' ? result : result.data;
|
|
96
|
-
const exitCode = typeof result === 'string' ? 0 : result.code;
|
|
97
|
-
return this.writeAndExit(`${data}\n`, exitCode);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* the loader and logger.console write output to the console during the command execution.
|
|
102
|
-
* for internals commands, such as, _put, _fetch, the command.loader = false.
|
|
103
|
-
*/
|
|
104
|
-
private determineConsoleWritingDuringCommand() {
|
|
105
|
-
if (this.command.loader && !this.flags.json && !this.flags['get-yargs-completions']) {
|
|
106
|
-
loader.on();
|
|
107
|
-
loader.start(`running command "${this.commandName}"...`);
|
|
108
|
-
logger.shouldWriteToConsole = true;
|
|
109
|
-
} else {
|
|
110
|
-
loader.off();
|
|
111
|
-
logger.shouldWriteToConsole = false;
|
|
112
|
-
}
|
|
113
|
-
if (this.flags.log) {
|
|
114
|
-
const logValue = typeof this.flags.log === 'string' ? this.flags.log : undefined;
|
|
115
|
-
logger.switchToConsoleLogger(logValue as LoggerLevel);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
private async writeAndExit(data: string, exitCode: number) {
|
|
120
|
-
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
121
|
-
return process.stdout.write(data, async () => logger.exitAfterFlush(exitCode, this.commandName));
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
private async runMigrateIfNeeded(): Promise<any> {
|
|
125
|
-
// @ts-ignore LegacyCommandAdapter has .migration
|
|
126
|
-
if (this.command.migration) {
|
|
127
|
-
logger.debug('Checking if a migration is needed');
|
|
128
|
-
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
|
|
129
|
-
return migrate(null, false);
|
|
130
|
-
}
|
|
131
|
-
return null;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
function toRenderResult(obj: RenderResult | React.ReactElement) {
|
|
136
|
-
return isRenderResult(obj) ? obj : { data: obj, code: 0 };
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
function isRenderResult(obj: RenderResult | any): obj is RenderResult {
|
|
140
|
-
// eslint-disable-next-line no-prototype-builtins
|
|
141
|
-
return typeof obj === 'object' && typeof obj.code === 'number' && obj.hasOwnProperty('data');
|
|
142
|
-
}
|
package/completion.cmd.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Command } from '@teambit/legacy/dist/cli/command';
|
|
2
|
-
|
|
3
|
-
export class CompletionCmd implements Command {
|
|
4
|
-
name = 'completion';
|
|
5
|
-
description = 'enable bash/zsh-completion shortcuts for commands and options';
|
|
6
|
-
alias = '';
|
|
7
|
-
group = 'general';
|
|
8
|
-
options = [];
|
|
9
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { BitError } from '@teambit/bit-error';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
|
|
4
|
-
export class CommandNotFound extends BitError {
|
|
5
|
-
commandName: string;
|
|
6
|
-
suggestion?: string;
|
|
7
|
-
constructor(commandName: string, suggestion?: string) {
|
|
8
|
-
super(`command ${commandName} was not found`);
|
|
9
|
-
this.commandName = commandName;
|
|
10
|
-
this.suggestion = suggestion;
|
|
11
|
-
}
|
|
12
|
-
report() {
|
|
13
|
-
let output = chalk.yellow(
|
|
14
|
-
`warning: '${chalk.bold(this.commandName)}' is not a valid command.
|
|
15
|
-
see 'bit help' for additional information`
|
|
16
|
-
);
|
|
17
|
-
if (this.suggestion) {
|
|
18
|
-
output += `\nDid you mean ${chalk.bold(this.suggestion)}?`;
|
|
19
|
-
}
|
|
20
|
-
return output;
|
|
21
|
-
}
|
|
22
|
-
}
|
package/exceptions/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { AlreadyExistsError } from './already-exists';
|
package/generate-doc-md.ts
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { Command } from '@teambit/legacy/dist/cli/command';
|
|
2
|
-
import { CommandOptions } from '@teambit/legacy/dist/cli/legacy-command';
|
|
3
|
-
import { getCommandId } from './get-command-id';
|
|
4
|
-
|
|
5
|
-
export type GenerateOpts = {
|
|
6
|
-
metadata?: Record<string, string>;
|
|
7
|
-
};
|
|
8
|
-
export class GenerateCommandsDoc {
|
|
9
|
-
constructor(private commands: Command[], private options: GenerateOpts) {}
|
|
10
|
-
|
|
11
|
-
generate(): string {
|
|
12
|
-
const commands = this.getAllPublicCommandsSorted();
|
|
13
|
-
const metadata = {
|
|
14
|
-
id: 'cli-all',
|
|
15
|
-
title: 'CLI Commands',
|
|
16
|
-
...this.options.metadata,
|
|
17
|
-
};
|
|
18
|
-
const metadataStr = Object.keys(metadata)
|
|
19
|
-
.map((key) => `${key}: ${metadata[key]}`)
|
|
20
|
-
.join('\n');
|
|
21
|
-
let output = `---
|
|
22
|
-
${metadataStr}
|
|
23
|
-
---
|
|
24
|
-
|
|
25
|
-
Commands that are marked as workspace only must be executed inside a workspace. Commands that are marked as not workspace only, can be executed from anywhere and will run on a remote server.
|
|
26
|
-
`;
|
|
27
|
-
output += commands.map((cmd) => this.generateCommand(cmd)).join('\n');
|
|
28
|
-
|
|
29
|
-
return output;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
private getAllPublicCommandsSorted() {
|
|
33
|
-
const publicCommands = this.commands.filter((cmd) => !cmd.private);
|
|
34
|
-
return publicCommands.sort((a, b) => a.name.localeCompare(b.name));
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
private generateCommand(cmd: Command) {
|
|
38
|
-
const commandName = getCommandId(cmd.name);
|
|
39
|
-
let result = `## ${commandName} \n\n`;
|
|
40
|
-
if (cmd.alias && cmd.alias.length > 0) {
|
|
41
|
-
result += `**Alias**: \`${cmd.alias}\` \n`;
|
|
42
|
-
}
|
|
43
|
-
result += `**Workspace only**: ${cmd.skipWorkspace ? 'no' : 'yes'} \n`;
|
|
44
|
-
result += `**Description**: ${this.formatDescription(cmd.description as string)}`;
|
|
45
|
-
result += `\`bit ${cmd.name}\` \n\n`;
|
|
46
|
-
|
|
47
|
-
if (cmd.commands && cmd.commands.length > 0) {
|
|
48
|
-
result += this.generateSubCommands(cmd.commands);
|
|
49
|
-
}
|
|
50
|
-
result += this.generateOptions(cmd.options);
|
|
51
|
-
result += `--- \n`;
|
|
52
|
-
|
|
53
|
-
return result;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
private generateSubCommands(subCommands: Command[]) {
|
|
57
|
-
let ret = '';
|
|
58
|
-
subCommands.forEach((subCommand) => {
|
|
59
|
-
// @ts-ignore
|
|
60
|
-
const name = subCommand.name.match(/^([\w-]+)/)[0];
|
|
61
|
-
const usage = subCommand.name;
|
|
62
|
-
ret += `### ${name} \n`;
|
|
63
|
-
ret += `**Usage**: \`${usage}\` \n\n`;
|
|
64
|
-
ret += `**Description**: ${this.formatDescription(subCommand.description as string)}`;
|
|
65
|
-
|
|
66
|
-
ret += '\n';
|
|
67
|
-
ret += this.generateOptions(subCommand.options);
|
|
68
|
-
});
|
|
69
|
-
return ret;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
private generateOptions(options: CommandOptions): string {
|
|
73
|
-
if (!options || options.length <= 0) return '';
|
|
74
|
-
let output = `| **Option** | **Option alias** | **Description**| \n`;
|
|
75
|
-
output += `|---|:-----:|---|\n`;
|
|
76
|
-
options.forEach((opt) => {
|
|
77
|
-
const [alias, flag, description] = opt;
|
|
78
|
-
const aliasFormatted = alias ? `\`-${alias}\`` : ' ';
|
|
79
|
-
const flagFormatted = `--${flag}`;
|
|
80
|
-
output += `|\`${flagFormatted}\`|${aliasFormatted}|${description}|\n`;
|
|
81
|
-
});
|
|
82
|
-
output += `\n`;
|
|
83
|
-
return output;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
private formatDescription(description: string): string {
|
|
87
|
-
return `${description.split('\n').join(' \n')} \n\n`;
|
|
88
|
-
}
|
|
89
|
-
}
|
package/get-command-id.ts
DELETED
package/help.cmd.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
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 = [] as CommandOptions;
|
|
12
|
-
|
|
13
|
-
constructor(private cliMain: CLIMain) {}
|
|
14
|
-
|
|
15
|
-
async report() {
|
|
16
|
-
return formatHelp(this.cliMain.commands, this.cliMain.groups);
|
|
17
|
-
}
|
|
18
|
-
}
|
package/help.ts
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
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) {
|
|
23
|
-
const helpProps = groupCommands(commands, groups);
|
|
24
|
-
const commandsStr = formatCommandsHelp(helpProps);
|
|
25
|
-
|
|
26
|
-
return `${getHeader()}
|
|
27
|
-
|
|
28
|
-
${commandsStr}
|
|
29
|
-
|
|
30
|
-
${getFooter()}`;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function groupCommands(commands: CommandList, groups: GroupsType): HelpProps {
|
|
34
|
-
const help: HelpProps = commands
|
|
35
|
-
.filter((command) => !command.private && (command.shortDescription || 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.shortDescription || 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://harmony-docs.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
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export type { CLIMain, CommandList } from './cli.main.runtime';
|
|
2
|
-
export { Command, CLIArgs, Flags, GenericObject } from '@teambit/legacy/dist/cli/command';
|
|
3
|
-
export { CommandOptions } from '@teambit/legacy/dist/cli/legacy-command';
|
|
4
|
-
export * from './exceptions';
|
|
5
|
-
export { CLIAspect, MainRuntime } from './cli.aspect';
|
|
@@ -1,67 +0,0 @@
|
|
|
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
|
-
shortDescription?: string;
|
|
11
|
-
group?: string;
|
|
12
|
-
loader?: boolean;
|
|
13
|
-
commands: Command[];
|
|
14
|
-
private?: boolean;
|
|
15
|
-
migration?: boolean;
|
|
16
|
-
internal?: boolean;
|
|
17
|
-
skipWorkspace?: boolean;
|
|
18
|
-
_packageManagerArgs?: string[];
|
|
19
|
-
constructor(private cmd: LegacyCommand, cliExtension: CLIMain) {
|
|
20
|
-
this.name = cmd.name;
|
|
21
|
-
this.description = cmd.description;
|
|
22
|
-
this.options = cmd.opts || [];
|
|
23
|
-
this.alias = cmd.alias;
|
|
24
|
-
this.shortDescription = cmd.shortDescription;
|
|
25
|
-
this.skipWorkspace = cmd.skipWorkspace;
|
|
26
|
-
this.group = cmd.group;
|
|
27
|
-
this.loader = cmd.loader;
|
|
28
|
-
this.private = cmd.private;
|
|
29
|
-
|
|
30
|
-
this.migration = cmd.migration;
|
|
31
|
-
this.internal = cmd.internal;
|
|
32
|
-
this.commands = (cmd.commands || []).map((sub) => new LegacyCommandAdapter(sub, cliExtension));
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
private async action(params: any, options: { [key: string]: any }): Promise<ActionResult> {
|
|
36
|
-
const res = await this.cmd.action(params, options, this._packageManagerArgs);
|
|
37
|
-
let data = res;
|
|
38
|
-
let code = 0;
|
|
39
|
-
if (res && res.__code !== undefined) {
|
|
40
|
-
data = res.data;
|
|
41
|
-
code = res.__code;
|
|
42
|
-
}
|
|
43
|
-
const report = this.cmd.report(data, params, options);
|
|
44
|
-
return {
|
|
45
|
-
code,
|
|
46
|
-
report,
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
async report(params: any, options: { [key: string]: any }): Promise<{ data: string; code: number }> {
|
|
51
|
-
const actionResult = await this.action(params, options);
|
|
52
|
-
return { data: actionResult.report, code: actionResult.code };
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
async json(params: any, options: { [key: string]: any }): Promise<GenericObject> {
|
|
56
|
-
const actionResult = await this.action(params, options);
|
|
57
|
-
return {
|
|
58
|
-
data: JSON.parse(actionResult.report),
|
|
59
|
-
code: actionResult.code,
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
type ActionResult = {
|
|
65
|
-
code: number;
|
|
66
|
-
report: string;
|
|
67
|
-
};
|
|
Binary file
|
package/types/asset.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
declare module '*.png' {
|
|
2
|
-
const value: any;
|
|
3
|
-
export = value;
|
|
4
|
-
}
|
|
5
|
-
declare module '*.svg' {
|
|
6
|
-
import type { FunctionComponent, SVGProps } from 'react';
|
|
7
|
-
|
|
8
|
-
export const ReactComponent: FunctionComponent<SVGProps<SVGSVGElement> & { title?: string }>;
|
|
9
|
-
const src: string;
|
|
10
|
-
export default src;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
// @TODO Gilad
|
|
14
|
-
declare module '*.jpg' {
|
|
15
|
-
const value: any;
|
|
16
|
-
export = value;
|
|
17
|
-
}
|
|
18
|
-
declare module '*.jpeg' {
|
|
19
|
-
const value: any;
|
|
20
|
-
export = value;
|
|
21
|
-
}
|
|
22
|
-
declare module '*.gif' {
|
|
23
|
-
const value: any;
|
|
24
|
-
export = value;
|
|
25
|
-
}
|
|
26
|
-
declare module '*.bmp' {
|
|
27
|
-
const value: any;
|
|
28
|
-
export = value;
|
|
29
|
-
}
|
package/types/style.d.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
declare module '*.module.css' {
|
|
2
|
-
const classes: { readonly [key: string]: string };
|
|
3
|
-
export default classes;
|
|
4
|
-
}
|
|
5
|
-
declare module '*.module.scss' {
|
|
6
|
-
const classes: { readonly [key: string]: string };
|
|
7
|
-
export default classes;
|
|
8
|
-
}
|
|
9
|
-
declare module '*.module.sass' {
|
|
10
|
-
const classes: { readonly [key: string]: string };
|
|
11
|
-
export default classes;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
declare module '*.module.less' {
|
|
15
|
-
const classes: { readonly [key: string]: string };
|
|
16
|
-
export default classes;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
declare module '*.less' {
|
|
20
|
-
const classes: { readonly [key: string]: string };
|
|
21
|
-
export default classes;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
declare module '*.css' {
|
|
25
|
-
const classes: { readonly [key: string]: string };
|
|
26
|
-
export default classes;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
declare module '*.sass' {
|
|
30
|
-
const classes: { readonly [key: string]: string };
|
|
31
|
-
export default classes;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
declare module '*.scss' {
|
|
35
|
-
const classes: { readonly [key: string]: string };
|
|
36
|
-
export default classes;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
declare module '*.mdx' {
|
|
40
|
-
const component: any;
|
|
41
|
-
export default component;
|
|
42
|
-
}
|
package/yargs-adapter.ts
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
|
-
import { Command } from '@teambit/legacy/dist/cli/command';
|
|
3
|
-
import { Arguments, CommandBuilder, CommandModule } from 'yargs';
|
|
4
|
-
import { TOKEN_FLAG } from '@teambit/legacy/dist/constants';
|
|
5
|
-
import { camelCase } from 'lodash';
|
|
6
|
-
import { CommandRunner } from './command-runner';
|
|
7
|
-
|
|
8
|
-
export const GLOBAL_GROUP = 'Global';
|
|
9
|
-
export const STANDARD_GROUP = 'Options';
|
|
10
|
-
|
|
11
|
-
export class YargsAdapter implements CommandModule {
|
|
12
|
-
command: string;
|
|
13
|
-
describe?: string;
|
|
14
|
-
aliases?: string;
|
|
15
|
-
builder: CommandBuilder;
|
|
16
|
-
constructor(private commanderCommand: Command) {
|
|
17
|
-
this.command = commanderCommand.name;
|
|
18
|
-
this.describe = chalk.yellow(commanderCommand.description as string);
|
|
19
|
-
this.aliases = commanderCommand.alias;
|
|
20
|
-
this.builder = this.optionsToBuilder(commanderCommand);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
handler(argv: Arguments) {
|
|
24
|
-
const enteredArgs = getArgsFromCommandName(this.commanderCommand.name);
|
|
25
|
-
const argsValues = enteredArgs.map((a) => argv[a]) as any[];
|
|
26
|
-
// a workaround to get a flag syntax such as "--all [version]" work with yargs.
|
|
27
|
-
const flags = Object.keys(argv).reduce((acc, current) => {
|
|
28
|
-
if (current === '_' || current === '$0' || current === '--') return acc;
|
|
29
|
-
// const flagName = current.split(' ')[0];
|
|
30
|
-
const val = typeof argv[current] === 'string' && !argv[current] ? true : argv[current];
|
|
31
|
-
acc[current] = val;
|
|
32
|
-
return acc;
|
|
33
|
-
}, {});
|
|
34
|
-
this.commanderCommand._packageManagerArgs = (argv['--'] || []) as string[];
|
|
35
|
-
|
|
36
|
-
const commandRunner = new CommandRunner(this.commanderCommand, argsValues, flags);
|
|
37
|
-
return commandRunner.runCommand();
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
private optionsToBuilder(command: Command) {
|
|
41
|
-
const option = command.options.reduce((acc, [alias, opt, desc]) => {
|
|
42
|
-
const optName = opt.split(' ')[0];
|
|
43
|
-
acc[optName] = {
|
|
44
|
-
alias,
|
|
45
|
-
describe: desc,
|
|
46
|
-
group: STANDARD_GROUP,
|
|
47
|
-
type: opt.includes(' ') ? 'string' : 'boolean',
|
|
48
|
-
requiresArg: opt.includes('<'),
|
|
49
|
-
};
|
|
50
|
-
return acc;
|
|
51
|
-
}, {});
|
|
52
|
-
const globalOptions = this.getGlobalOptions(command);
|
|
53
|
-
|
|
54
|
-
return { ...option, ...globalOptions };
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
private getGlobalOptions(command: Command): Record<string, any> {
|
|
58
|
-
const globalOptions: Record<string, any> = {};
|
|
59
|
-
if (command.remoteOp) {
|
|
60
|
-
globalOptions[TOKEN_FLAG] = {
|
|
61
|
-
describe: 'authentication token',
|
|
62
|
-
group: GLOBAL_GROUP,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
if (!command.internal) {
|
|
66
|
-
globalOptions.log = {
|
|
67
|
-
describe:
|
|
68
|
-
'print log messages to the screen, options are: [trace, debug, info, warn, error, fatal], the default is info',
|
|
69
|
-
group: GLOBAL_GROUP,
|
|
70
|
-
};
|
|
71
|
-
globalOptions['safe-mode'] = {
|
|
72
|
-
describe:
|
|
73
|
-
'bootstrap the bare-minimum with only the CLI aspect. useful mainly for low-level commands when bit refuses to load',
|
|
74
|
-
group: GLOBAL_GROUP,
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
return globalOptions;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function getArgsFromCommandName(commandName: string) {
|
|
82
|
-
const commandSplit = commandName.split(' ');
|
|
83
|
-
commandSplit.shift(); // remove the first element, it's the command-name
|
|
84
|
-
|
|
85
|
-
return commandSplit.map((existArg) => {
|
|
86
|
-
const trimmed = existArg.trim();
|
|
87
|
-
if ((!trimmed.startsWith('<') && !trimmed.startsWith('[')) || (!trimmed.endsWith('>') && !trimmed.endsWith(']'))) {
|
|
88
|
-
throw new Error(`expect arg "${trimmed}" of "${commandName}" to be wrapped with "[]" or "<>"`);
|
|
89
|
-
}
|
|
90
|
-
// remove the opening and closing brackets
|
|
91
|
-
const withoutBrackets = trimmed.slice(1, -1);
|
|
92
|
-
|
|
93
|
-
return camelCase(withoutBrackets);
|
|
94
|
-
});
|
|
95
|
-
}
|