-
-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
2 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { Flags } from '@oclif/core'; | ||
import Command from '../../base'; | ||
|
||
export default class Versions extends Command { | ||
static description = 'Show versions of AsyncAPI tools used'; | ||
|
||
static flags = { | ||
help: Flags.help({ char: 'h' }), | ||
}; | ||
|
||
async run() { | ||
const dependencies: string[] = []; | ||
let dependency = ''; | ||
|
||
// Preparation of the array with all dependencies '@asyncapi/*' along with | ||
// their versions. | ||
for (const key in this.config.pjson.dependencies) { | ||
// Making sure with .indexOf() that only package names which START with | ||
// string '@asyncapi' are considered. | ||
if (key.indexOf('@asyncapi', 0) === 0) { | ||
// Avoiding obvious crash on manual removal or alteration of an | ||
// '@asyncapi' package. | ||
try { | ||
// Goofy name `importedPJSON` is chosen to distinguish from name `pjson` | ||
// used in `@oclif` source code. | ||
const importedPJSON = await import(`${key}/package.json`); | ||
dependencies.push(`${key}/${importedPJSON.default.version}`); | ||
} catch (e) { | ||
dependencies.push(`${key}/` + '`package.json` not found'); | ||
} | ||
} | ||
} | ||
|
||
// Showing information available with `--version` flag. | ||
this.log(this.config.userAgent); | ||
|
||
// Iteration through the array containing all dependencies '@asyncapi/*' | ||
// along with their versions. | ||
for (let i = 0; i < dependencies.length; i++) { | ||
// Minimization of the theoretical possibility of a Generic Object | ||
// Injection Sink, at the same time disabling eslint parsing for this | ||
// line since it is actually a false positive. | ||
// https://github.com/eslint-community/eslint-plugin-security/issues/21#issuecomment-530184612 | ||
// https://github.com/eslint-community/eslint-plugin-security/issues/21#issuecomment-1157887653 | ||
// https://web.archive.org/web/20150430062816/https://blog.liftsecurity.io/2015/01/15/the-dangers-of-square-bracket-notation | ||
dependency = dependencies[i]; // eslint-disable-line | ||
if (i !== dependencies.length - 1) { | ||
this.log(` ├${dependency}`); | ||
} else { | ||
this.log(` └${dependency}\n`); | ||
} | ||
} | ||
|
||
this.log(`Repository: ${this.config.pjson.homepage}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { test } from '@oclif/test'; | ||
|
||
describe('versions', () => { | ||
describe('config:versions', () => { | ||
test | ||
.stderr() | ||
.stdout() | ||
.command(['config:versions']) | ||
.it('should show versions of AsyncAPI tools used', (ctx, done) => { | ||
expect(ctx.stdout).toContain('@asyncapi/cli/'); | ||
expect(ctx.stdout).toContain('├@asyncapi/'); | ||
expect(ctx.stdout).toContain('└@asyncapi/'); | ||
expect(ctx.stderr).toEqual(''); | ||
done(); | ||
}); | ||
|
||
test | ||
.stderr() | ||
.stdout() | ||
.command(['config:versions']) | ||
.it('should show address of repository of AsyncAPI CLI', (ctx, done) => { | ||
expect(ctx.stdout).toContain('https://github.com/asyncapi/cli'); | ||
expect(ctx.stderr).toEqual(''); | ||
done(); | ||
}); | ||
}); | ||
}); |