Skip to content

Commit

Permalink
Merge pull request #179 from oclif/re/oclif-core
Browse files Browse the repository at this point in the history
BREAKING CHANGE: update to oclif/core
  • Loading branch information
mdonnalley committed Aug 6, 2021
2 parents 074bcd4 + 82ae266 commit fedc128
Show file tree
Hide file tree
Showing 10 changed files with 695 additions and 422 deletions.
87 changes: 27 additions & 60 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,65 +1,32 @@
---
version: 2
jobs:
node-latest: &test
docker:
- image: node:latest
working_directory: ~/cli
steps:
- checkout
- restore_cache: &restore_cache
keys:
- v1-npm-{{checksum ".circleci/config.yml"}}-{{checksum "yarn.lock"}}
- v1-npm-{{checksum ".circleci/config.yml"}}
- run:
name: Install dependencies
command: yarn
- run:
name: Run tests
command: yarn test
node-12:
<<: *test
docker:
- image: node:12
node-10:
<<: *test
docker:
- image: node:10
release:
<<: *test
steps:
- add_ssh_keys
- checkout
- restore_cache: *restore_cache
- run:
name: Install release dependencies
command: |
yarn global add @oclif/semantic-release@3 semantic-release@17
yarn --frozen-lockfile
- run:
name: Cut release
command: |
export PATH=/usr/local/share/.config/yarn/global/node_modules/.bin:$PATH
semantic-release -e @oclif/semantic-release
- save_cache:
key: v1-yarn-{{checksum ".circleci/config.yml"}}-{{checksum "yarn.lock"}}
paths:
- ~/cli/node_modules
- /usr/local/share/.cache/yarn
- /usr/local/share/.config/yarn
version: 2.1

orbs:
release-management: salesforce/npm-release-management@4

workflows:
version: 2
"@oclif/test":
test-and-release:
jobs:
- node-latest
- node-12
- node-10
- release:
context: org-global
filters:
branches: {only: master}
- release-management/test-package:
matrix:
parameters:
os:
- linux
# - windows
node_version:
- latest
- lts
- maintenance
exclude:
- os: windows
node_version: lts
- os: windows
node_version: maintenance
- release-management/release-package:
github-release: true
tag: core-v1
requires:
- node-latest
- node-12
- node-10
- release-management/test-package
filters:
branches:
only: master
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
"fancy-test": "^1.4.3"
},
"devDependencies": {
"@oclif/command": "^1.6.0",
"@oclif/config": "^1.12.6",
"@oclif/errors": "^1.2.2",
"@oclif/core": "^0.5.27",
"@types/chai": "^4.1.7",
"@types/mocha": "^8.0.0",
"@types/node": "^14.0.14",
Expand All @@ -21,6 +19,7 @@
"globby": "^11.0.1",
"mocha": "^8.2.1",
"nock": "^13.0.1",
"shx": "^0.3.3",
"ts-node": "^9.0.0",
"typescript": "3.8.3"
},
Expand All @@ -38,7 +37,7 @@
"main": "lib/index.js",
"repository": "oclif/test",
"scripts": {
"build": "rm -rf lib && tsc",
"build": "shx rm -rf lib && tsc",
"lint": "eslint . --ext .ts --config .eslintrc",
"posttest": "yarn lint",
"prepublishOnly": "yarn run build",
Expand Down
4 changes: 2 additions & 2 deletions src/command.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 {loadConfig} from './load-config'

Expand All @@ -9,7 +9,7 @@ const castArray = <T>(input?: T | T[]): T[] => {

export function command(args: string[] | string, opts: loadConfig.Options = {}) {
return {
async run(ctx: {config: Config.IConfig; expectation: string}) {
async run(ctx: {config: Interfaces.Config; expectation: string}) {
// eslint-disable-next-line require-atomic-updates
if (!ctx.config || opts.reset) ctx.config = await loadConfig(opts).run({} as any)
args = castArray(args)
Expand Down
4 changes: 2 additions & 2 deletions src/hook.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 {loadConfig} from './load-config'

Expand All @@ -15,7 +15,7 @@ import {loadConfig} from './load-config'
* @param {object} hookOpts options to pass to hook. Config object will be passed automatically.
*/
export default (event: string, hookOpts: object = {}, options: loadConfig.Options = {}) => ({
async run(ctx: {config: Config.IConfig; expectation: string}) {
async run(ctx: {config: Interfaces.Config; expectation: string}) {
if (!event) throw new Error('no hook provided')
// eslint-disable-next-line require-atomic-updates
if (!ctx.config) ctx.config = await loadConfig(options).run({} as any)
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as Config from '@oclif/config'
import {Config} from '@oclif/core'
import {expect, fancy, FancyTypes} from 'fancy-test'

import {command} from './command'
Expand Down
6 changes: 3 additions & 3 deletions src/load-config.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as Config from '@oclif/config'
import {Interfaces, Config} from '@oclif/core'

/**
* loads CLI plugin/multi config
* @param {loadConfig.Options} opts options
* @return {Promise<Config.IConfig>} config
* @return {Promise<Interfaces.Config>} config
*/
export function loadConfig(opts: loadConfig.Options = {}) {
return {
async run(ctx: {config: Config.IConfig}) {
async run(ctx: {config: Interfaces.Config}) {
ctx.config = await Config.load(opts.root || loadConfig.root)
return ctx.config
},
Expand Down
7 changes: 0 additions & 7 deletions test/command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,4 @@ describe('command', () => {
.command(['foo:bar', '--name=foo'])
.do(output => expect(output.stdout).to.equal('hello foo!\n'))
.it()

test
.loadConfig({root})
.stdout()
.command(['foo:bar', '--name=foo'])
.do(output => expect(output.stdout).to.equal('hello foo!\n'))
.it()
})
6 changes: 3 additions & 3 deletions test/fixtures/multi/src/commands/exit.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
const {Command, flags} = require('@oclif/command')
const {Command, Flags} = require('@oclif/core')

class CLI extends Command {
async run() {
const {flags} = this.parse(CLI)
const {flags} = await this.parse(CLI)
const code = parseInt(flags.code || '1')
this.log(`exiting with code ${code}`)
this.exit(code)
}
}

CLI.flags = {
code: flags.string(),
code: Flags.string(),
}

module.exports = CLI
6 changes: 3 additions & 3 deletions test/fixtures/multi/src/commands/foo/bar.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
const {Command, flags} = require('@oclif/command')
const {Command, Flags} = require('@oclif/core')

class CLI extends Command {
constructor(args, opts) {
super(args, opts)
}

async run() {
const {flags} = this.parse(CLI)
const {flags} = await this.parse(CLI)
const name = flags.name || 'world'
this.log(`hello ${name}!`)
}
}

CLI.flags = {
name: flags.string({char: 'n', description: 'name to print'}),
name: Flags.string({char: 'n', description: 'name to print'}),
}

module.exports = CLI
Loading

0 comments on commit fedc128

Please sign in to comment.