diff --git a/scopes/harmony/bit/load-bit.ts b/scopes/harmony/bit/load-bit.ts index d46bf05fa150..5f3dfd165a21 100644 --- a/scopes/harmony/bit/load-bit.ts +++ b/scopes/harmony/bit/load-bit.ts @@ -210,19 +210,20 @@ function getMainAspect() { */ function shouldLoadInSafeMode() { const currentCommand = process.argv[2]; - const commandsToAlwaysRunInSafeMode = ['remote']; - // only legacy commands can ignore all aspects and load only the CLI aspect. // harmony commands need the aspects to be loaded and register to the CLI aspect in order to work properly. const commandsThatCanRunInSafeMode = [ - ...commandsToAlwaysRunInSafeMode, 'dependents', + 'remote', 'doctor', 'cat-version-history', + 'cat-component', + 'cat-scope', + 'cat-object', + 'config', 'run-action', ]; const hasSafeModeFlag = process.argv.includes('--safe-mode'); - const isSafeModeCommand = commandsToAlwaysRunInSafeMode.includes(currentCommand) || isClearCacheCommand(); - return isSafeModeCommand || (hasSafeModeFlag && commandsThatCanRunInSafeMode.includes(currentCommand)); + return isClearCacheCommand() || (hasSafeModeFlag && commandsThatCanRunInSafeMode.includes(currentCommand)); } function isClearCacheCommand() { diff --git a/scopes/harmony/cli/cli.cmd.ts b/scopes/harmony/cli/cli.cmd.ts index 5f12033f6e67..70349449eb9e 100644 --- a/scopes/harmony/cli/cli.cmd.ts +++ b/scopes/harmony/cli/cli.cmd.ts @@ -1,6 +1,5 @@ // eslint-disable-next-line max-classes-per-file -import type { Command } from '@teambit/legacy/dist/cli/command'; -import type { CommandOptions } from '@teambit/legacy/dist/cli/legacy-command'; +import type { Command, CommandOptions } from '@teambit/legacy/dist/cli/command'; import legacyLogger from '@teambit/legacy/dist/logger/logger'; import { handleErrorAndExit } from '@teambit/legacy/dist/cli/handle-errors'; import { loadConsumerIfExist } from '@teambit/legacy/dist/consumer'; diff --git a/scopes/harmony/cli/cli.main.runtime.ts b/scopes/harmony/cli/cli.main.runtime.ts index 73eae2ef1963..2c7d7012e08f 100644 --- a/scopes/harmony/cli/cli.main.runtime.ts +++ b/scopes/harmony/cli/cli.main.runtime.ts @@ -1,5 +1,4 @@ import { Slot, SlotRegistry } from '@teambit/harmony'; -import { buildRegistry } from '@teambit/legacy/dist/cli'; import legacyLogger from '@teambit/legacy/dist/logger/logger'; import { CLIArgs, Flags, Command } from '@teambit/legacy/dist/cli/command'; import pMapSeries from 'p-map-series'; @@ -10,7 +9,6 @@ import { Logger, LoggerAspect, LoggerMain } from '@teambit/logger'; import { clone } from 'lodash'; import { CLIAspect, MainRuntime } from './cli.aspect'; import { getCommandId } from './get-command-id'; -import { LegacyCommandAdapter } from './legacy-command-adapter'; import { CLIParser, findCommandByArgv } from './cli-parser'; import { CompletionCmd } from './completion.cmd'; import { CliCmd, CliGenerateCmd } from './cli.cmd'; @@ -185,15 +183,12 @@ export class CLIMain { ) { const logger = loggerMain.createLogger(CLIAspect.id); const cliMain = new CLIMain(commandsSlot, onStartSlot, onCommandStartSlot, onBeforeExitSlot, logger); - const legacyRegistry = buildRegistry(); await ensureWorkspaceAndScope(); - const legacyCommands = legacyRegistry.commands; - const legacyCommandsAdapters = legacyCommands.map((command) => new LegacyCommandAdapter(command, cliMain)); const cliGenerateCmd = new CliGenerateCmd(cliMain); const cliCmd = new CliCmd(cliMain); const helpCmd = new HelpCmd(cliMain); cliCmd.commands.push(cliGenerateCmd); - cliMain.register(...legacyCommandsAdapters, new CompletionCmd(), cliCmd, helpCmd, new VersionCmd()); + cliMain.register(new CompletionCmd(), cliCmd, helpCmd, new VersionCmd()); return cliMain; } } diff --git a/scopes/harmony/cli/command-runner.ts b/scopes/harmony/cli/command-runner.ts index 9e75e5577341..9736fd6b2685 100644 --- a/scopes/harmony/cli/command-runner.ts +++ b/scopes/harmony/cli/command-runner.ts @@ -1,6 +1,5 @@ import logger, { shouldDisableLoader } from '@teambit/legacy/dist/logger/logger'; import { CLIArgs, Command, Flags } from '@teambit/legacy/dist/cli/command'; -import { parseCommandName } from '@teambit/legacy/dist/cli/command-registry'; import loader from '@teambit/legacy/dist/cli/loader'; import { handleErrorAndExit } from '@teambit/legacy/dist/cli/handle-errors'; import { TOKEN_FLAG_NAME } from '@teambit/legacy/dist/constants'; @@ -108,3 +107,8 @@ export class CommandRunner { return process.stdout.write(data, async () => logger.exitAfterFlush(exitCode, this.commandName, data)); } } + +export function parseCommandName(commandName: string): string { + if (!commandName) return ''; + return commandName.split(' ')[0]; +} diff --git a/scopes/harmony/cli/generate-doc-md.ts b/scopes/harmony/cli/generate-doc-md.ts index d2763fe406ce..a60bfb725b7b 100644 --- a/scopes/harmony/cli/generate-doc-md.ts +++ b/scopes/harmony/cli/generate-doc-md.ts @@ -1,5 +1,4 @@ -import { Command, CommandArg } from '@teambit/legacy/dist/cli/command'; -import { CommandOptions } from '@teambit/legacy/dist/cli/legacy-command'; +import { CommandOptions, Command, CommandArg } from '@teambit/legacy/dist/cli/command'; import { pick } from 'lodash'; import { getCommandId } from './get-command-id'; diff --git a/scopes/harmony/cli/help.cmd.ts b/scopes/harmony/cli/help.cmd.ts index 6c7831360e03..28091614307d 100644 --- a/scopes/harmony/cli/help.cmd.ts +++ b/scopes/harmony/cli/help.cmd.ts @@ -1,5 +1,4 @@ -import type { Command } from '@teambit/legacy/dist/cli/command'; -import type { CommandOptions } from '@teambit/legacy/dist/cli/legacy-command'; +import type { Command, CommandOptions } from '@teambit/legacy/dist/cli/command'; import { CLIMain } from './cli.main.runtime'; import { formatHelp } from './help'; diff --git a/scopes/harmony/cli/index.ts b/scopes/harmony/cli/index.ts index fc2b890a9801..98d38dd3c391 100644 --- a/scopes/harmony/cli/index.ts +++ b/scopes/harmony/cli/index.ts @@ -1,8 +1,7 @@ import { CLIAspect, MainRuntime } from './cli.aspect'; export type { CLIMain, CommandList, CommandsSlot } from './cli.main.runtime'; -export type { Command, CLIArgs, Flags, GenericObject } from '@teambit/legacy/dist/cli/command'; -export type { CommandOptions } from '@teambit/legacy/dist/cli/legacy-command'; +export type { Command, CLIArgs, Flags, GenericObject, CommandOptions } from '@teambit/legacy/dist/cli/command'; export * from './exceptions'; export { CLIAspect as default, MainRuntime, CLIAspect }; diff --git a/scopes/harmony/cli/legacy-command-adapter.ts b/scopes/harmony/cli/legacy-command-adapter.ts deleted file mode 100644 index eef81931772d..000000000000 --- a/scopes/harmony/cli/legacy-command-adapter.ts +++ /dev/null @@ -1,66 +0,0 @@ -import { CommandOptions, LegacyCommand } from '@teambit/legacy/dist/cli/legacy-command'; -import type { Command, GenericObject } from '@teambit/legacy/dist/cli/command'; -import { CLIMain } from './cli.main.runtime'; - -export class LegacyCommandAdapter implements Command { - alias: string; - name: string; - description: string; - options: CommandOptions; - extendedDescription?: string; - group?: string; - loader?: boolean; - commands: Command[]; - private?: boolean; - skipWorkspace?: boolean; - helpUrl?: string; - loadAspects?: boolean; - _packageManagerArgs?: string[]; - constructor(private cmd: LegacyCommand, cliExtension: CLIMain) { - this.name = cmd.name; - this.description = cmd.description; - this.helpUrl = cmd.helpUrl; - this.options = cmd.opts || []; - this.alias = cmd.alias; - this.extendedDescription = cmd.extendedDescription; - this.skipWorkspace = cmd.skipWorkspace; - this.group = cmd.group; - this.loader = cmd.loader; - this.private = cmd.private; - this.loadAspects = false; - this.commands = (cmd.commands || []).map((sub) => new LegacyCommandAdapter(sub, cliExtension)); - } - - private async action(params: any, options: { [key: string]: any }): Promise { - const res = await this.cmd.action(params, options, this._packageManagerArgs); - let data = res; - let code = 0; - if (res && res.__code !== undefined) { - data = res.data; - code = res.__code; - } - const report = this.cmd.report(data, params, options); - return { - code, - report, - }; - } - - async report(params: any, options: { [key: string]: any }): Promise<{ data: string; code: number }> { - const actionResult = await this.action(params, options); - return { data: actionResult.report, code: actionResult.code }; - } - - async json(params: any, options: { [key: string]: any }): Promise { - const actionResult = await this.action(params, options); - return { - data: JSON.parse(actionResult.report), - code: actionResult.code, - }; - } -} - -type ActionResult = { - code: number; - report: string; -}; diff --git a/scopes/harmony/cli/version.cmd.ts b/scopes/harmony/cli/version.cmd.ts index c163f5510891..9185d5d8acc2 100644 --- a/scopes/harmony/cli/version.cmd.ts +++ b/scopes/harmony/cli/version.cmd.ts @@ -1,5 +1,4 @@ -import type { Command } from '@teambit/legacy/dist/cli/command'; -import type { CommandOptions } from '@teambit/legacy/dist/cli/legacy-command'; +import type { CommandOptions, Command } from '@teambit/legacy/dist/cli/command'; import { getHarmonyVersion } from '@teambit/legacy/dist/bootstrap'; export class VersionCmd implements Command { diff --git a/scopes/harmony/global-config/config-cmd.ts b/scopes/harmony/global-config/config-cmd.ts index a7cf3c879ba4..51e41bcf121f 100644 --- a/scopes/harmony/global-config/config-cmd.ts +++ b/scopes/harmony/global-config/config-cmd.ts @@ -27,6 +27,7 @@ class ConfigGet implements Command { description = 'get a value from global configuration'; alias = ''; options = [] as CommandOptions; + loadAspects = false; async report([key]: [string]) { const value = await config.get(key); @@ -39,6 +40,7 @@ class ConfigList implements Command { description = 'list all configuration(s)'; alias = ''; options = [] as CommandOptions; + loadAspects = false; async report() { const conf: { [key: string]: string } = await config.list(); @@ -55,6 +57,7 @@ class ConfigDel implements Command { description = 'delete given key from global configuration'; alias = ''; options = [] as CommandOptions; + loadAspects = false; async report([key]: [string]) { await config.del(key); @@ -68,6 +71,7 @@ export class ConfigCmd implements Command { extendedDescription = `${BASE_DOCS_DOMAIN}reference/config/bit-config`; group = 'general'; alias = ''; + loadAspects = false; commands = [new ConfigSet(), new ConfigDel(), new ConfigGet(), new ConfigList()]; options = [] as CommandOptions; diff --git a/scopes/harmony/global-config/global-config.main.runtime.ts b/scopes/harmony/global-config/global-config.main.runtime.ts index e431159e207f..3200298f1022 100644 --- a/scopes/harmony/global-config/global-config.main.runtime.ts +++ b/scopes/harmony/global-config/global-config.main.runtime.ts @@ -23,6 +23,7 @@ import { GlobalConfigAspect } from './global-config.aspect'; import { GlobalsCmd } from './globals.cmd'; import { SystemCmd, SystemLogCmd, SystemTailLogCmd } from './system.cmd'; import { ConfigCmd } from './config-cmd'; +import { RemoteCmd } from './remote-cmd'; export class GlobalConfigMain { static runtime = MainRuntime; @@ -90,7 +91,7 @@ export class GlobalConfigMain { const globalConfig = new GlobalConfigMain(); const systemCmd = new SystemCmd(); systemCmd.commands = [new SystemLogCmd(), new SystemTailLogCmd()]; - cli.register(new GlobalsCmd(globalConfig), systemCmd, new ConfigCmd()); + cli.register(new GlobalsCmd(globalConfig), systemCmd, new ConfigCmd(), new RemoteCmd()); return globalConfig; } } diff --git a/src/cli/commands/public-cmds/remote-cmd.ts b/scopes/harmony/global-config/remote-cmd.ts similarity index 51% rename from src/cli/commands/public-cmds/remote-cmd.ts rename to scopes/harmony/global-config/remote-cmd.ts index 2f3ce701530e..0387ac3048d4 100644 --- a/src/cli/commands/public-cmds/remote-cmd.ts +++ b/scopes/harmony/global-config/remote-cmd.ts @@ -3,58 +3,50 @@ import chalk from 'chalk'; import Table from 'cli-table'; import { forEach, isEmpty } from 'lodash'; +import { add, list, remove } from './remote'; +import { Command, CommandOptions } from '@teambit/cli'; -import { remoteAdd, remoteList, remoteRm } from '../../../api/consumer'; -import { Group } from '../../command-groups'; -import { CommandOptions, LegacyCommand } from '../../legacy-command'; - -class RemoteAdd implements LegacyCommand { +class RemoteAdd implements Command { name = 'add '; description = 'add a bare-scope as a remote'; extendedDescription = `supported protocols are [file, http]. for example: "http://localhost:3000", "file:///tmp/local-scope"`; alias = ''; - opts = [['g', 'global', 'configure a remote bit scope']] as CommandOptions; - - action([url]: [string], { global }: { global: boolean }): Promise { - return remoteAdd(url, global); - } + loadAspects = false; + options = [['g', 'global', 'configure a remote bit scope']] as CommandOptions; - report({ name, host }: { name: string; host: string }): string { + async report([url]: [string], { global }: { global: boolean }) { + const { name, host }: { name: string; host: string } = await add(url, global); return chalk.green(`added remote scope '${chalk.bold(name)}' with host '${chalk.bold(host)}'`); } } -class RemoteRm implements LegacyCommand { +class RemoteRm implements Command { name = 'del '; description = 'remove a tracked bit remote'; alias = ''; - opts = [['g', 'global', 'remove a globally configured remote scope']] as CommandOptions; + loadAspects = false; + options = [['g', 'global', 'remove a globally configured remote scope']] as CommandOptions; - action([name]: [string], { global }: { global: boolean }): Promise { - return remoteRm(name, global); - } - - report(name: string): string { + async report([name]: [string], { global }: { global: boolean }) { + await remove(name, global); return chalk.green(`successfully removed remote ${chalk.bold(name)}`); } } -export default class Remote implements LegacyCommand { +export class RemoteCmd implements Command { name = 'remote'; description = 'manage set of tracked bit scope(s)'; - group: Group = 'collaborate'; + group = 'collaborate'; helpUrl = 'reference/scope/remote-scopes'; alias = ''; - opts = [['g', 'global', 'see globally configured remotes']] as CommandOptions; + loadAspects = false; + options = [['g', 'global', 'see globally configured remotes']] as CommandOptions; // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! commands = [new RemoteAdd(), new RemoteRm()]; - action(args: string[], { global }: { global: boolean }): Promise { - return remoteList(global); - } - - report(remotes: { [key: string]: string }): string { + async report(args: string[], { global }: { global: boolean }) { + const remotes: { [key: string]: string } = await list(global); if (isEmpty(remotes)) return chalk.red('no configured remotes found in scope'); const table = new Table({ head: ['scope name', 'host'], style: { head: ['cyan'] } }); diff --git a/src/api/consumer/lib/remote.ts b/scopes/harmony/global-config/remote.ts similarity index 83% rename from src/api/consumer/lib/remote.ts rename to scopes/harmony/global-config/remote.ts index 0b93e82abaad..49567606a987 100644 --- a/src/api/consumer/lib/remote.ts +++ b/scopes/harmony/global-config/remote.ts @@ -1,15 +1,15 @@ import { BitError } from '@teambit/bit-error'; -import { GlobalRemotes } from '../../../global-config'; -import { Remote } from '../../../remotes'; -import { loadScope } from '../../../scope'; -import { getScopeRemotes } from '../../../scope/scope-remotes'; +import { GlobalRemotes } from '@teambit/legacy/dist/global-config'; +import { Remote } from '@teambit/legacy/dist/remotes'; +import { loadScope } from '@teambit/legacy/dist/scope'; +import { getScopeRemotes } from '@teambit/legacy/dist/scope/scope-remotes'; function buildRemote(url: string): Remote { // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! return new Remote(url); } -export function add(url: string, global: boolean) { +export async function add(url: string, global: boolean) { const remote = buildRemote(url); return remote.scope().then((scopeDesc) => { remote.name = scopeDesc.name; @@ -56,7 +56,7 @@ export async function remove(name: string, global: boolean) { return name; } -export function list(global: boolean) { +export async function list(global: boolean) { if (global) { return GlobalRemotes.load().then((globalRemotes) => globalRemotes.toPlainObject()); } @@ -66,5 +66,3 @@ export function list(global: boolean) { return getScopeRemotes(scope).then((remotes) => remotes.toPlainObject()); }); } - -export function refresh() {} diff --git a/src/api/consumer/index.ts b/src/api/consumer/index.ts deleted file mode 100644 index 30f6652ffc64..000000000000 --- a/src/api/consumer/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { add as remoteAdd, list as remoteList, remove as remoteRm } from './lib/remote'; - -export { remoteAdd, remoteList, remoteRm }; diff --git a/src/cli/command-registry-builder.ts b/src/cli/command-registry-builder.ts deleted file mode 100644 index 1bb9d13b057f..000000000000 --- a/src/cli/command-registry-builder.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { BIT_DESCRIPTION, BIT_USAGE, BIT_VERSION } from '../constants'; -import CommandRegistry from './command-registry'; -import Remote from './commands/public-cmds/remote-cmd'; - -export default function registerCommands(): CommandRegistry { - return new CommandRegistry(BIT_USAGE, BIT_DESCRIPTION, BIT_VERSION, [new Remote()]); -} diff --git a/src/cli/command-registry.ts b/src/cli/command-registry.ts deleted file mode 100644 index e577f1439de7..000000000000 --- a/src/cli/command-registry.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { LegacyCommand } from './legacy-command'; - -export function parseCommandName(commandName: string): string { - if (!commandName) return ''; - return commandName.split(' ')[0]; -} - -export default class CommandRegistry { - version: string; - usage: string; - description: string; - commands: LegacyCommand[]; - - constructor(usage: string, description: string, version: string, commands: LegacyCommand[]) { - this.usage = usage; - this.description = description; - this.version = version; - this.commands = commands; - } -} diff --git a/src/cli/command.ts b/src/cli/command.ts index 867ffe625765..9b50f036b72b 100644 --- a/src/cli/command.ts +++ b/src/cli/command.ts @@ -1,5 +1,7 @@ import { Group } from './command-groups'; -import { CommandOptions } from './legacy-command'; + +type CommandOption = [string, string, string]; +export type CommandOptions = Array; export interface Command { /** diff --git a/src/cli/index.ts b/src/cli/index.ts deleted file mode 100644 index 90bb6a34207e..000000000000 --- a/src/cli/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { default as buildRegistry } from './command-registry-builder'; -export { default as CommandRegistry } from './command-registry'; diff --git a/src/cli/legacy-command.ts b/src/cli/legacy-command.ts deleted file mode 100644 index 4ae27ca1c66b..000000000000 --- a/src/cli/legacy-command.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { Group } from './command-groups'; - -export type CommandOption = [string, string, string]; -export type CommandOptions = Array; - -export interface LegacyCommand { - name: string; - description: string; // for "bit help" - extendedDescription?: string; // for the command itself - helpUrl?: string; - alias: string; - opts?: CommandOptions; - commands?: LegacyCommand[]; - private?: boolean; - loader?: boolean; - skipWorkspace?: boolean; - internal?: boolean; // used for serialize the error it returns - remoteOp?: boolean; // Used for adding the token option globally - group?: Group; // for grouping in the "bit help" page - - action(params: any, opts: { [key: string]: any }, packageManagerArgs?: string[]): Promise; - - report(data: any, params: any, opts: { [key: string]: any }): string; -} diff --git a/src/constants.ts b/src/constants.ts index a8a302495786..3b4636d082a5 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -259,9 +259,6 @@ export const BITMAP_PREFIX_MESSAGE = `/** * See the docs (${BASE_DOCS_DOMAIN}reference/components/removing-components) for more information, or use "bit remove --help". */\n\n`; -export const BIT_DESCRIPTION = - 'bit is a free and open source tool designed for easy use, maintenance and discovery of code components.'; - /** * bit commands */