Skip to content

Commit

Permalink
Merge pull request #79 from oclif/sh/enhance-version
Browse files Browse the repository at this point in the history
fix: export everything and enhance verbose details
  • Loading branch information
RodEsp authored Aug 18, 2022
2 parents 65f6220 + 3d88cd2 commit 12d2f51
Show file tree
Hide file tree
Showing 5 changed files with 2,037 additions and 2,026 deletions.
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@
"author": "Salesforce",
"bugs": "https://github.com/oclif/plugin-version/issues",
"dependencies": {
"@oclif/core": "^1.1.1"
"@oclif/core": "^1.14.1"
},
"devDependencies": {
"@commitlint/config-conventional": "^12.1.4",
"@oclif/plugin-help": "5.1.12",
"@oclif/test": "^2.0.3",
"@oclif/test": "^2.1.1",
"@types/chai": "^4.3.1",
"@types/mocha": "^8.0.0",
"@types/node": "^14.0.26",
"chai": "^4.2.0",
"@types/node": "^14.18.23",
"chai": "^4.3.6",
"commitlint": "^12.1.4",
"eslint": "^7.3.1",
"eslint-config-oclif": "^4",
"eslint-config-oclif-typescript": "^1.0.2",
"husky": "6",
"mocha": "^8.2.1",
"oclif": "2.1.0",
"oclif": "2.7.0",
"shx": "^0.3.4",
"ts-node": "^10.4.0",
"ts-node": "^10.9.1",
"typescript": "4.6.3"
},
"engines": {
Expand Down
12 changes: 11 additions & 1 deletion src/commands/version.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import {Command, Flags} from '@oclif/core'
import {EOL, type as osType, release as osRelease} from 'node:os'

interface VersionDetail {
export interface VersionDetail {
cliVersion: string;
architecture: string;
nodeVersion: string;
pluginVersions?: string[];
osVersion?: string;
shell?: string;
rootPath?: string;
}

export default class Version extends Command {
Expand Down Expand Up @@ -39,6 +41,8 @@ export default class Version extends Command {

versionDetail.pluginVersions = pluginVersions
versionDetail.osVersion = osVersion
versionDetail.shell = this.config.shell
versionDetail.rootPath = this.config.root

output = ` CLI Version:
\t${cliVersion}
Expand All @@ -54,6 +58,12 @@ export default class Version extends Command {
OS and Version:
\t${osVersion}
Shell:
\t${versionDetail.shell}
Root Path:
\t${versionDetail.rootPath}
`
}

Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default {}
export {VersionDetail, default as VersionCommand} from './commands/version'
49 changes: 25 additions & 24 deletions test/commands/version.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import {expect, test} from '@oclif/test'
import {type as osType, release as osRelease} from 'node:os'
import {type as osType, release as osRelease, userInfo as osUserInfo} from 'node:os'
import {sep} from 'node:path'

// eslint-disable-next-line unicorn/prefer-module
const pjson = require('../../package.json')

const getShell = () => osUserInfo().shell?.split(sep)?.pop() || 'unknown'

describe('version', () => {
const stdout = `@oclif/plugin-version/${pjson.version} ${process.platform}-${process.arch} node-${process.version}
`
Expand All @@ -19,22 +22,19 @@ describe('version', () => {
.stdout()
.command(['version', '--verbose'])
.end('runs version --verbose', output => {
expect(output.stdout).to.equal(` CLI Version:
\t@oclif/plugin-version/${pjson.version}
Architecture:
\t${process.platform}-${process.arch}
Node Version:
\tnode-${process.version}
Plugin Version:
\t
OS and Version:
\t${osType()} ${osRelease()}
`)
expect(output.stdout).to.contain(` CLI Version:
\t@oclif/plugin-version/${pjson.version}`)
expect(output.stdout).to.contain(` Architecture:
\t${process.platform}-${process.arch}`)
expect(output.stdout).to.contain(` Node Version:
\tnode-${process.version}`)
expect(output.stdout).to.contain(' Plugin Version:')
expect(output.stdout).to.contain(` OS and Version:
\t${osType()} ${osRelease()}`)
expect(output.stdout).to.contain(` Shell:
\t${getShell()}`)
expect(output.stdout).to.contain(` Root Path:
\t${process.cwd()}`)
})

test
Expand All @@ -52,12 +52,13 @@ describe('version', () => {
.stdout()
.command(['version', '--json', '--verbose'])
.end('runs version --verbose --json', output => {
expect(JSON.parse(output.stdout)).to.deep.equal({
architecture: `${process.platform}-${process.arch}`,
cliVersion: `@oclif/plugin-version/${pjson.version}`,
nodeVersion: `node-${process.version}`,
osVersion: `${osType()} ${osRelease()}`,
pluginVersions: [],
})
const json = JSON.parse(output.stdout)
expect(json).to.have.property('architecture', `${process.platform}-${process.arch}`)
expect(json).to.have.property('cliVersion', `@oclif/plugin-version/${pjson.version}`)
expect(json).to.have.property('nodeVersion', `node-${process.version}`)
expect(json).to.have.property('osVersion', `${osType()} ${osRelease()}`)
expect(json).to.have.property('pluginVersions')
expect(json).to.have.property('shell', getShell())
expect(json).to.have.property('rootPath', process.cwd())
})
})
Loading

0 comments on commit 12d2f51

Please sign in to comment.