Skip to content

Commit

Permalink
feat: use oclif/core (#299)
Browse files Browse the repository at this point in the history
  • Loading branch information
RasPhilCo authored Sep 24, 2021
1 parent bcf3ed2 commit b66bc0c
Show file tree
Hide file tree
Showing 7 changed files with 2,785 additions and 52 deletions.
18 changes: 18 additions & 0 deletions bin/dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env node

const oclif = require('@oclif/core')

const path = require('path')
const project = path.join(__dirname, '..', 'tsconfig.json')

// In dev mode -> use ts-node and dev plugins
process.env.NODE_ENV = 'development'

require('ts-node').register({project})

// In dev mode, always show stack traces
// Waiting for https://github.com/oclif/core/pull/147
// oclif.settings.debug = true;

// Start the CLI
oclif.run().then(oclif.flush).catch(oclif.Errors.handle)
3 changes: 3 additions & 0 deletions bin/dev.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off

node "%~dp0\dev" %*
5 changes: 3 additions & 2 deletions bin/run
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env node

require('@oclif/command').run()
.catch(require('@oclif/errors/handle'))
const oclif = require('@oclif/core')

oclif.run().then(require('@oclif/core/flush')).catch(require('@oclif/core/handle'))
12 changes: 5 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
"bugs": "https://github.com/oclif/plugin-update/issues",
"dependencies": {
"@oclif/color": "^0.1.0",
"@oclif/command": "^1.7.0",
"@oclif/config": "^1.16.0",
"@oclif/errors": "^1.3.4",
"@oclif/core": "^0.5.39",
"@types/semver": "^7.3.4",
"cli-ux": "^5.5.1",
"cross-spawn": "^7.0.3",
Expand All @@ -21,8 +19,7 @@
"tar-fs": "^2.1.1"
},
"devDependencies": {
"@oclif/dev-cli": "^1.26.0",
"@oclif/plugin-help": "^3",
"@oclif/plugin-help": "^5.1.0",
"@oclif/test": "^1.2.8",
"@types/chai": "^4.2.15",
"@types/cross-spawn": "^6.0.2",
Expand All @@ -40,6 +37,7 @@
"eslint-config-oclif-typescript": "^0.2.0",
"globby": "^11.0.2",
"mocha": "^8.3.2",
"oclif": "^2.0.0-main.5",
"qqjs": "^0.3.11",
"ts-node": "^9.1.1",
"tslib": "^2.1.0",
Expand Down Expand Up @@ -74,9 +72,9 @@
"pretest": "yarn build --noEmit && tsc -p test --noEmit",
"test": "mocha --forbid-only \"test/**/*.test.ts\"",
"posttest": "yarn lint",
"prepack": "yarn build && oclif-dev manifest",
"prepack": "yarn build && oclif manifest",
"postpack": "rm -f oclif.manifest.json",
"version": "oclif-dev readme && git add README.md",
"version": "oclif readme && git add README.md",
"build": "rm -rf lib && tsc"
}
}
10 changes: 5 additions & 5 deletions src/commands/update.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import color from '@oclif/color'
import Command, {flags} from '@oclif/command'
import {Command, Flags} from '@oclif/core'
import {IManifest} from '@oclif/dev-cli'
import cli from 'cli-ux'
import * as spawn from 'cross-spawn'
Expand All @@ -16,9 +16,9 @@ export default class UpdateCommand extends Command {

static args = [{name: 'channel', optional: true}]

static flags: flags.Input<any> = {
autoupdate: flags.boolean({hidden: true}),
'from-local': flags.boolean({description: 'interactively choose an already installed version'}),
static flags = {
autoupdate: Flags.boolean({hidden: true}),
'from-local': Flags.boolean({description: 'interactively choose an already installed version'}),
}

private autoupdate!: boolean
Expand All @@ -34,7 +34,7 @@ export default class UpdateCommand extends Command {
private readonly clientBin = path.join(this.clientRoot, 'bin', this.config.windows ? `${this.config.bin}.cmd` : this.config.bin)

async run() {
const {args, flags} = this.parse(UpdateCommand)
const {args, flags} = await this.parse(UpdateCommand)
this.autoupdate = Boolean(flags.autoupdate)

if (this.autoupdate) await this.debounce()
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/init.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as Config from '@oclif/config'
import {Interfaces} from '@oclif/core'
import cli from 'cli-ux'
import * as spawn from 'cross-spawn'
import * as fs from 'fs-extra'
Expand All @@ -17,7 +17,7 @@ async function mtime(f: string) {
return mtime
}

export const init: Config.Hook<'init'> = async function (opts) {
export const init: Interfaces.Hook<'init'> = async function (opts) {
if (opts.id === 'update') return
if (opts.config.scopedEnvVarTrue('DISABLE_AUTOUPDATE')) return
const binPath = this.config.binPath || this.config.bin
Expand Down
Loading

0 comments on commit b66bc0c

Please sign in to comment.