Skip to content

Commit

Permalink
feat: use oclif/core v2 (#1081)
Browse files Browse the repository at this point in the history
* feat: use oclif/core v2

* chore: bump deps
  • Loading branch information
mdonnalley committed Jan 18, 2023
1 parent 72b7870 commit d8352ff
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 64 deletions.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"bugs": "https://github.com/oclif/oclif/issues",
"dependencies": {
"@oclif/core": "^1.24.2",
"@oclif/core": "^2.0.2-beta.6",
"@oclif/plugin-help": "^5.1.19",
"@oclif/plugin-not-found": "^2.3.7",
"@oclif/plugin-warn-if-update-available": "^2.0.14",
Expand All @@ -29,8 +29,9 @@
},
"devDependencies": {
"@oclif/plugin-legacy": "^1.2.7",
"@oclif/test": "^2.2.12",
"@oclif/test": "^2.3.0",
"@types/chai": "^4.3.4",
"@types/cli-progress": "^3.11.0",
"@types/execa": "^0.9.0",
"@types/fs-extra": "^9.0",
"@types/lodash": "^4.14.191",
Expand Down Expand Up @@ -140,4 +141,4 @@
"registry": "https://registry.npmjs.org"
},
"types": "lib/index.d.ts"
}
}
7 changes: 4 additions & 3 deletions src/commands/generate.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {Args} from '@oclif/core'
import CommandBase from './../command-base'

export default class Generate extends CommandBase {
Expand All @@ -6,9 +7,9 @@ This will clone the template repo 'oclif/hello-world' and update package propert

static flags = {}

static args = [
{name: 'name', required: true, description: 'directory name of new project'},
]
static args = {
name: Args.string({required: true, description: 'directory name of new project'}),
}

async run(): Promise<void> {
const {args} = await this.parse(Generate)
Expand Down
8 changes: 4 additions & 4 deletions src/commands/generate/command.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import CommandBase from './../../command-base'
import {Flags} from '@oclif/core'
import {Args, Flags} from '@oclif/core'

export default class GenerateCommand extends CommandBase {
static description = 'add a command to an existing CLI or plugin'
Expand All @@ -8,9 +8,9 @@ export default class GenerateCommand extends CommandBase {
force: Flags.boolean({description: 'overwrite existing files'}),
}

static args = [
{name: 'name', description: 'name of command', required: true},
]
static args = {
name: Args.string({description: 'name of command', required: true}),
}

async run(): Promise<void> {
const {args, flags} = await this.parse(GenerateCommand)
Expand Down
8 changes: 4 additions & 4 deletions src/commands/generate/hook.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import CommandBase from './../../command-base'
import {Flags} from '@oclif/core'
import {Args, Flags} from '@oclif/core'

export default class GenerateHook extends CommandBase {
static description = 'add a hook to an existing CLI or plugin'
Expand All @@ -9,9 +9,9 @@ export default class GenerateHook extends CommandBase {
event: Flags.string({description: 'event to run hook on', default: 'init'}),
}

static args = [
{name: 'name', description: 'name of hook (snake_case)', required: true},
]
static args = {
name: Args.string({description: 'name of hook (snake_case)', required: true}),
}

async run(): Promise<void> {
const {args, flags} = await this.parse(GenerateHook)
Expand Down
8 changes: 4 additions & 4 deletions src/commands/manifest.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {Command, Plugin} from '@oclif/core'
import {Args, Command, Plugin} from '@oclif/core'
import * as fs from 'fs-extra'
import * as path from 'path'

export default class Manifest extends Command {
static description = 'generates plugin manifest json'

static args = [
{name: 'path', description: 'path to plugin', default: '.'},
]
static args = {
path: Args.string({description: 'path to plugin', default: '.'}),
}

async run(): Promise<void> {
try {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/promote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as path from 'path'

import * as _ from 'lodash'

import {CliUx, Command, Flags} from '@oclif/core'
import {ux, Command, Flags} from '@oclif/core'

import aws from '../aws'
import * as Tarballs from '../tarballs'
Expand Down Expand Up @@ -145,7 +145,7 @@ export default class Promote extends Command {
Key: cloudChannelKey(unversionedExe),
},
)].concat(flags.indexes ? [appendToIndex({...indexDefaults, originalUrl: winCopySource, filename: unversionedExe})] : []))
CliUx.ux.action.stop('successfully')
ux.action.stop('successfully')
}))
}

Expand Down
22 changes: 9 additions & 13 deletions src/commands/readme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ USAGE
].join('\n').trim()
}

multiCommands(config: Interfaces.Config, commands: Interfaces.Command[], dir: string): string {
multiCommands(config: Interfaces.Config, commands: Command.Cached[], dir: string): string {
let topics = config.topics
topics = topics.filter(t => !t.hidden && !t.name.includes(':'))
topics = topics.filter(t => commands.find(c => c.id.startsWith(t.name)))
Expand All @@ -137,7 +137,7 @@ USAGE
].join('\n').trim() + '\n'
}

createTopicFile(file: string, config: Interfaces.Config, topic: Interfaces.Topic, commands: Interfaces.Command[]): void {
createTopicFile(file: string, config: Interfaces.Config, topic: Interfaces.Topic, commands: Command.Cached[]): void {
const bin = `\`${config.bin} ${topic.name}\``
const doc = [
bin,
Expand All @@ -150,7 +150,7 @@ USAGE
fs.outputFileSync(file, doc)
}

commands(config: Interfaces.Config, commands: Interfaces.Command[]): string {
commands(config: Interfaces.Config, commands: Command.Cached[]): string {
return [
...commands.map(c => {
const usage = this.commandUsage(config, c)
Expand All @@ -161,7 +161,7 @@ USAGE
].join('\n').trim()
}

renderCommand(config: Interfaces.Config, c: Interfaces.Command): string {
renderCommand(config: Interfaces.Config, c: Command.Cached): string {
this.debug('rendering command', c.id)
const title = template({config, command: c})(c.summary || c.description || '').trim().split('\n')[0]
const help = new this.HelpClass(config, {stripAnsi: true, maxWidth: columns})
Expand All @@ -184,7 +184,7 @@ USAGE
}
}

commandCode(config: Interfaces.Config, c: Interfaces.Command): string | undefined {
commandCode(config: Interfaces.Config, c: Command.Cached): string | undefined {
const pluginName = c.pluginName
if (!pluginName) return
const plugin = config.plugins.find(p => p.name === c.pluginName)
Expand Down Expand Up @@ -218,7 +218,7 @@ USAGE
/**
* fetches the path to a command
*/
private commandPath(plugin: Interfaces.Plugin, c: Interfaces.Command): string | undefined {
private commandPath(plugin: Interfaces.Plugin, c: Command.Cached): string | undefined {
const commandsDir = plugin.pjson.oclif.commands
if (!commandsDir) return
let p = path.join(plugin.root, commandsDir, ...c.id.split(':'))
Expand Down Expand Up @@ -247,22 +247,18 @@ USAGE
return p
}

private commandUsage(config: Interfaces.Config, command: Interfaces.Command): string {
const arg = (arg: Interfaces.Arg) => {
private commandUsage(config: Interfaces.Config, command: Command.Cached): string {
const arg = (arg: Command.Arg.Cached) => {
const name = arg.name.toUpperCase()
if (arg.required) return `${name}`
return `[${name}]`
}

// v2 commands have args as an object, so we need to normalize it to an array for forwards compatibility
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const normalized = Array.isArray(command.args) ? command.args ?? [] : Object.entries(command.args ?? {}).map(([name, arg]) => ({...arg, name}))
const id = toConfiguredId(command.id, config)
const defaultUsage = () => {
return compact([
id,
normalized.filter(a => !a.hidden).map(a => arg(a)).join(' '),
Object.values(command.args).filter(a => !a.hidden).map(a => arg(a)).join(' '),
]).join(' ')
}

Expand Down
8 changes: 4 additions & 4 deletions src/help-compatibility.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {Interfaces, HelpBase} from '@oclif/core'
import {Command, HelpBase} from '@oclif/core'

interface MaybeCompatibleHelp extends HelpBase {
formatCommand?: (command: Interfaces.Command) => string;
command?: (command: Interfaces.Command) => string;
formatCommand?: (command: Command.Cached) => string;
command?: (command: Command.Cached) => string;
}

class IncompatibleHelpError extends Error {
Expand All @@ -16,7 +16,7 @@ export class HelpCompatibilityWrapper {
this.inner = inner
}

formatCommand(command: Interfaces.Command): string {
formatCommand(command: Command.Cached): string {
if (this.inner.formatCommand) {
return this.inner.formatCommand(command)
}
Expand Down
4 changes: 2 additions & 2 deletions src/log.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {CliUx} from '@oclif/core'
import {ux} from '@oclif/core'
import * as util from 'util'
import {prettifyPaths} from './util'

Expand All @@ -7,5 +7,5 @@ debug.new = (name: string) => require('debug')(`oclif:${name}`)

export function log(format: string, ...args: any[]): void {
args = args.map((arg: any) => prettifyPaths(arg))
debug.enabled ? debug(format, ...args) : CliUx.ux.log(`oclif: ${util.format(format, ...args)}`)
debug.enabled ? debug(format, ...args) : ux.log(`oclif: ${util.format(format, ...args)}`)
}
4 changes: 2 additions & 2 deletions src/tarballs/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {CliUx, Interfaces, Config} from '@oclif/core'
import {ux, Interfaces, Config} from '@oclif/core'

import * as path from 'path'
import * as semver from 'semver'
Expand Down Expand Up @@ -57,7 +57,7 @@ export async function buildConfig(root: string, options: {xz?: boolean; targets?
const targets = compact(options.targets || updateConfig.node.targets || TARGETS)
.filter(t => {
if (t === 'darwin-arm64' && semver.lt(nodeVersion, '16.0.0')) {
CliUx.ux.warn('darwin-arm64 is only supported for node >=16.0.0. Skipping...')
ux.warn('darwin-arm64 is only supported for node >=16.0.0. Skipping...')
return false
}

Expand Down
58 changes: 35 additions & 23 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -526,13 +526,12 @@
widest-line "^3.1.0"
wrap-ansi "^7.0.0"

"@oclif/core@^1.24.2":
version "1.24.2"
resolved "https://registry.yarnpkg.com/@oclif/core/-/core-1.24.2.tgz#1d2e4b8b27db7e98b0c1d7b367934196a2f2c202"
integrity sha512-0wfAa6HG4sJ4j5c4/GV4BWZwALtJyw2ZO6titnrWKcowxU1BWd8mBM45ilTPnDhClMowz7+8EtK4kqUGc1rNwA==
"@oclif/core@^2.0.2-beta.6":
version "2.0.2-beta.6"
resolved "https://registry.yarnpkg.com/@oclif/core/-/core-2.0.2-beta.6.tgz#d794d53886683f37ab712092ff88741981b2c02f"
integrity sha512-g3M/I2VrZaN6Ba8qyn2KggGoxDc2ys88LV/7+cGhxpaK98ZVWlgPCTLNHyY1DiA0KSDTTBhUsPV+Uis5mbHB4g==
dependencies:
"@oclif/linewrap" "^1.0.0"
"@oclif/screen" "^3.0.4"
"@types/cli-progress" "^3.11.0"
ansi-escapes "^4.3.2"
ansi-styles "^4.3.0"
cardinal "^2.1.1"
Expand All @@ -558,6 +557,7 @@
supports-hyperlinks "^2.2.0"
tslib "^2.4.1"
widest-line "^3.1.0"
wordwrap "^1.0.0"
wrap-ansi "^7.0.0"

"@oclif/[email protected]", "@oclif/errors@^1.2.2", "@oclif/errors@^1.3.3", "@oclif/errors@^1.3.5":
Expand Down Expand Up @@ -654,18 +654,13 @@
resolved "https://registry.yarnpkg.com/@oclif/screen/-/screen-3.0.3.tgz#e679ad10535e31d333f809f7a71335cc9aef1e55"
integrity sha512-KX8gMYA9ujBPOd1HFsV9e0iEx7Uoj8AG/3YsW4TtWQTg4lJvr82qNm7o/cFQfYRIt+jw7Ew/4oL4A22zOT+IRA==

"@oclif/screen@^3.0.4":
version "3.0.4"
resolved "https://registry.yarnpkg.com/@oclif/screen/-/screen-3.0.4.tgz#663db0ecaf23f3184e7f01886ed578060e4a7f1c"
integrity sha512-IMsTN1dXEXaOSre27j/ywGbBjrzx0FNd1XmuhCWCB9NTPrhWI1Ifbz+YLSEcstfQfocYsrbrIessxXb2oon4lA==

"@oclif/test@^2.2.12":
version "2.2.12"
resolved "https://registry.yarnpkg.com/@oclif/test/-/test-2.2.12.tgz#bb97a8c678b349e0e323013be67d68f619e6aaf2"
integrity sha512-6s1XwvBTXHdVjVZY/qDgMl74NVvoy8MQoknqT/YfR9K3P/6fPW4xeZqemtvrvU4heM5kzSShta5sk0I28MXHMg==
"@oclif/test@^2.3.0":
version "2.3.0"
resolved "https://registry.yarnpkg.com/@oclif/test/-/test-2.3.0.tgz#c62efef4e4fa2ec3d44a3a79b58cc9e43898413b"
integrity sha512-DgoEOY/Y1FvNwA1J0Sy7u6jZSHbDutw6kNOWqVizlf1wSJiHKV6Ia9DyhHsg2Nb4EZ+1AKcetC0fI7ixLxxJHw==
dependencies:
"@oclif/core" "^1.20.4"
fancy-test "^2.0.7"
"@oclif/core" "^2.0.2-beta.6"
fancy-test "^2.0.11"

"@octokit/auth-token@^2.4.4":
version "2.5.0"
Expand Down Expand Up @@ -820,6 +815,13 @@
resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.3.4.tgz#e913e8175db8307d78b4e8fa690408ba6b65dee4"
integrity sha512-KnRanxnpfpjUTqTCXslZSEdLfXExwgNxYPdiO2WGUj8+HDjFi8R3k5RVKPeSCzLjCcshCAtVO2QBbVuAV4kTnw==

"@types/cli-progress@^3.11.0":
version "3.11.0"
resolved "https://registry.yarnpkg.com/@types/cli-progress/-/cli-progress-3.11.0.tgz#ec79df99b26757c3d1c7170af8422e0fc95eef7e"
integrity sha512-XhXhBv1R/q2ahF3BM7qT5HLzJNlIL0wbcGyZVjqOTqAybAnsLisd7gy1UCyIqpL+5Iv6XhlSyzjLCnI2sIdbCg==
dependencies:
"@types/node" "*"

"@types/debug@*":
version "4.1.5"
resolved "https://registry.yarnpkg.com/@types/debug/-/debug-4.1.5.tgz#b14efa8852b7768d898906613c23f688713e02cd"
Expand Down Expand Up @@ -1867,7 +1869,7 @@ color-support@^1.1.2:

[email protected], [email protected]:
version "1.4.0"
resolved "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz#c50491479d4c1bdaed2c9ced32cf7c7dc2360f78"
resolved "https://registry.yarnpkg.com/colors/-/colors-1.4.0.tgz#c50491479d4c1bdaed2c9ced32cf7c7dc2360f78"
integrity sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==

[email protected]:
Expand Down Expand Up @@ -2767,18 +2769,18 @@ fancy-test@^1.4.10:
nock "^13.0.0"
stdout-stderr "^0.1.9"

fancy-test@^2.0.7:
version "2.0.7"
resolved "https://registry.yarnpkg.com/fancy-test/-/fancy-test-2.0.7.tgz#a5e8e23113384c5550914da4f429d10822622521"
integrity sha512-E9qiHMi/Wf3y0PLwoRbgr8SRTcvQY+6gx9d/qaVNT6N5AQ79iZr08ftY2Ki5KRC5LS02GoVD/CYT4t/KwwC/Pw==
fancy-test@^2.0.11:
version "2.0.12"
resolved "https://registry.yarnpkg.com/fancy-test/-/fancy-test-2.0.12.tgz#a93cd92ffc23f70b069c39f19940d34f64c6ca67"
integrity sha512-S7qVQNaViLTMzn71huZvrUCV59ldq+enQ1EQOkdNbl4q4Om97gwqbYKvZoglsnzCWRRFaFP+qHynpdqaLdiZqg==
dependencies:
"@types/chai" "*"
"@types/lodash" "*"
"@types/node" "*"
"@types/sinon" "*"
lodash "^4.17.13"
mock-stdin "^1.0.0"
nock "^13.0.0"
nock "^13.3.0"
stdout-stderr "^0.1.9"

fast-deep-equal@^3.1.1, fast-deep-equal@^3.1.3:
Expand Down Expand Up @@ -4504,6 +4506,16 @@ nock@^13.0.0:
lodash.set "^4.3.2"
propagate "^2.0.0"

nock@^13.3.0:
version "13.3.0"
resolved "https://registry.yarnpkg.com/nock/-/nock-13.3.0.tgz#b13069c1a03f1ad63120f994b04bfd2556925768"
integrity sha512-HHqYQ6mBeiMc+N038w8LkMpDCRquCHWeNmN3v6645P3NhN2+qXOBqvPqo7Rt1VyCMzKhJ733wZqw5B7cQVFNPg==
dependencies:
debug "^4.1.0"
json-stringify-safe "^5.0.1"
lodash "^4.17.21"
propagate "^2.0.0"

node-fetch@^2.6.1:
version "2.6.7"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad"
Expand Down

0 comments on commit d8352ff

Please sign in to comment.