Skip to content

Commit

Permalink
feat: remove cli-ux (#405)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Jan 27, 2022
1 parent f889267 commit 734b552
Show file tree
Hide file tree
Showing 9 changed files with 1,516 additions and 884 deletions.
11 changes: 5 additions & 6 deletions package.json
Expand Up @@ -5,10 +5,9 @@
"author": "Salesforce",
"bugs": "https://github.com/oclif/plugin-plugins/issues",
"dependencies": {
"@oclif/color": "^0.1.2",
"@oclif/core": "^1.1.1",
"@oclif/color": "^1.0.1",
"@oclif/core": "^1.2.0",
"chalk": "^4.1.2",
"cli-ux": "^6.0.6",
"debug": "^4.1.0",
"fs-extra": "^9.0",
"http-call": "^5.2.2",
Expand All @@ -20,8 +19,8 @@
},
"devDependencies": {
"@commitlint/config-conventional": "^12.1.4",
"@oclif/plugin-help": "5.1.10",
"@oclif/test": "2.0.3",
"@oclif/plugin-help": "^5.1.10",
"@oclif/test": "^2.0.3",
"@types/chai": "^4.3.0",
"@types/fs-extra": "^9.0",
"@types/mocha": "^8.2.3",
Expand All @@ -38,7 +37,7 @@
"husky": "6",
"mocha": "^9.1.3",
"nock": "^13.2.1",
"oclif": "2.1.0",
"oclif": "^2.3.0",
"ts-node": "^10.4.0",
"typescript": "4.5.4"
},
Expand Down
5 changes: 2 additions & 3 deletions src/commands/plugins/index.ts
@@ -1,6 +1,5 @@
import color from '@oclif/color'
import {Command, Flags, Plugin} from '@oclif/core'
import {cli} from 'cli-ux'
import {Command, Flags, Plugin, CliUx} from '@oclif/core'

import Plugins from '../../plugins'
import {sortBy} from '../../util'
Expand Down Expand Up @@ -43,7 +42,7 @@ export default class PluginsIndex extends Command {
}

private createTree(plugin: Plugin) {
const tree = cli.tree()
const tree = CliUx.ux.tree()
for (const p of plugin.children) {
const name = this.formatPlugin(p)
tree.insert(name, this.createTree(p))
Expand Down
5 changes: 2 additions & 3 deletions src/commands/plugins/inspect.ts
@@ -1,8 +1,7 @@
import * as path from 'path'
import {Command, Flags, Plugin} from '@oclif/core'
import {Command, Flags, Plugin, CliUx} from '@oclif/core'
import * as chalk from 'chalk'
import * as fs from 'fs-extra'
import {cli} from 'cli-ux'

import Plugins from '../../plugins'
import {sortBy} from '../../util'
Expand Down Expand Up @@ -85,7 +84,7 @@ export default class PluginsInspect extends Command {

async inspect(pluginName: string, verbose = false): Promise<void> {
const plugin = this.findPlugin(pluginName)
const tree = cli.tree()
const tree = CliUx.ux.tree()
const pluginHeader = chalk.bold.cyan(plugin.name)
tree.insert(pluginHeader)
tree.nodes[pluginHeader].insert(`version ${plugin.version}`)
Expand Down
11 changes: 5 additions & 6 deletions src/commands/plugins/install.ts
@@ -1,6 +1,5 @@
import {Command, Flags} from '@oclif/core'
import {Command, Flags, CliUx} from '@oclif/core'
import * as chalk from 'chalk'
import cli from 'cli-ux'

import Plugins from '../../plugins'

Expand Down Expand Up @@ -57,23 +56,23 @@ e.g. If you have a core plugin that has a 'hello' command, installing a user-ins
})
try {
if (p.type === 'npm') {
cli.action.start(
CliUx.ux.action.start(
`Installing plugin ${chalk.cyan(this.plugins.friendlyName(p.name))}`,
)
plugin = await this.plugins.install(p.name, {
tag: p.tag,
force: flags.force,
})
} else {
cli.action.start(`Installing plugin ${chalk.cyan(p.url)}`)
CliUx.ux.action.start(`Installing plugin ${chalk.cyan(p.url)}`)
plugin = await this.plugins.install(p.url, {force: flags.force})
}
} catch (error) {
cli.action.stop(chalk.bold.red('failed'))
CliUx.ux.action.stop(chalk.bold.red('failed'))
throw error
}

cli.action.stop(`installed v${plugin.version}`)
CliUx.ux.action.stop(`installed v${plugin.version}`)
}
}
/* eslint-enable no-await-in-loop */
Expand Down
7 changes: 3 additions & 4 deletions src/commands/plugins/link.ts
@@ -1,6 +1,5 @@
import {Command, Flags} from '@oclif/core'
import {Command, Flags, CliUx} from '@oclif/core'
import * as chalk from 'chalk'
import cli from 'cli-ux'

import Plugins from '../../plugins'

Expand All @@ -27,8 +26,8 @@ e.g. If you have a user-installed or core plugin that has a 'hello' command, ins
async run(): Promise<void> {
const {flags, args} = await this.parse(PluginsLink)
this.plugins.verbose = flags.verbose
cli.action.start(`Linking plugin ${chalk.cyan(args.path)}`)
CliUx.ux.action.start(`Linking plugin ${chalk.cyan(args.path)}`)
await this.plugins.link(args.path)
cli.action.stop()
CliUx.ux.action.stop()
}
}
9 changes: 4 additions & 5 deletions src/commands/plugins/uninstall.ts
@@ -1,6 +1,5 @@
import {Command, Flags, Plugin, Interfaces} from '@oclif/core'
import {Command, Flags, Plugin, Interfaces, CliUx} from '@oclif/core'
import * as chalk from 'chalk'
import cli from 'cli-ux'

import Plugins from '../../plugins'

Expand Down Expand Up @@ -37,7 +36,7 @@ export default class PluginsUninstall extends Command {
if (argv.length === 0) argv.push('.')
for (const plugin of argv) {
const friendly = this.removeTags(this.plugins.friendlyName(plugin))
cli.action.start(`Uninstalling ${friendly}`)
CliUx.ux.action.start(`Uninstalling ${friendly}`)
const unfriendly = await this.plugins.hasPlugin(this.removeTags(plugin))
if (!unfriendly) {
const p = this.config.plugins.find(p => p.name === plugin) as Plugin | undefined
Expand All @@ -52,11 +51,11 @@ export default class PluginsUninstall extends Command {
const {name} = unfriendly as Interfaces.PJSON.User | Interfaces.PJSON.PluginTypes.Link
await this.plugins.uninstall(name)
} catch (error) {
cli.action.stop(chalk.bold.red('failed'))
CliUx.ux.action.stop(chalk.bold.red('failed'))
throw error
}

cli.action.stop()
CliUx.ux.action.stop()
}
}
/* eslint-enable no-await-in-loop */
Expand Down
13 changes: 6 additions & 7 deletions src/plugins.ts
@@ -1,5 +1,4 @@
import {Errors, Config, Interfaces} from '@oclif/core'
import cli from 'cli-ux'
import {Errors, Config, Interfaces, CliUx} from '@oclif/core'
import * as fs from 'fs'
import * as fse from 'fs-extra'
import loadJSON from 'load-json-file'
Expand Down Expand Up @@ -111,7 +110,7 @@ export default class Plugins {

async link(p: string): Promise<void> {
const c = await Config.load(path.resolve(p))
cli.action.start(`${this.config.name}: linking plugin ${c.name}`)
CliUx.ux.action.start(`${this.config.name}: linking plugin ${c.name}`)
if (!c.valid && !this.config.plugins.find(p => p.name === '@oclif/plugin-legacy')) {
throw new Errors.CLIError('plugin is not a valid oclif plugin')
}
Expand Down Expand Up @@ -141,7 +140,7 @@ export default class Plugins {
await this.yarn.exec(['remove', name], {cwd: this.config.dataDir, verbose: this.verbose})
}
} catch (error: any) {
cli.warn(error)
CliUx.ux.warn(error)
} finally {
await this.remove(name)
}
Expand All @@ -153,7 +152,7 @@ export default class Plugins {
async update(): Promise<void> {
let plugins = (await this.list()).filter((p): p is Interfaces.PJSON.PluginTypes.User => p.type === 'user')
if (plugins.length === 0) return
cli.action.start(`${this.config.name}: Updating plugins`)
CliUx.ux.action.start(`${this.config.name}: Updating plugins`)

// migrate deprecated plugins
const aliases = this.config.pjson.oclif.aliases || {}
Expand All @@ -178,7 +177,7 @@ export default class Plugins {
await this.refresh(path.join(this.config.dataDir, 'node_modules', p.name))
}

cli.action.stop()
CliUx.ux.action.stop()
}
/* eslint-enable no-await-in-loop */

Expand All @@ -195,7 +194,7 @@ export default class Plugins {
const f = await loadJSON<{nodeVersion: string}>(path.join(this.config.dataDir, 'node_modules', '.yarn-integrity'))
return f.nodeVersion
} catch (error: any) {
if (error.code !== 'ENOENT') cli.warn(error)
if (error.code !== 'ENOENT') CliUx.ux.warn(error)
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/yarn.ts
@@ -1,5 +1,4 @@
import {Interfaces} from '@oclif/core'
import ux from 'cli-ux'
import {Interfaces, CliUx} from '@oclif/core'
import NpmRunPath from 'npm-run-path'
import * as path from 'path'

Expand All @@ -24,7 +23,7 @@ export default class Yarn {
forked.stdout.setEncoding('utf8')
forked.stdout.on('data', (d: any) => {
if (options.verbose) process.stdout.write(d)
else ux.action.status = d.replace(/\n$/, '').split('\n').pop()
else CliUx.ux.action.status = d.replace(/\n$/, '').split('\n').pop()
})

forked.on('error', reject)
Expand Down

0 comments on commit 734b552

Please sign in to comment.