-
-
Notifications
You must be signed in to change notification settings - Fork 169
/
versions.ts
56 lines (49 loc) · 2.18 KB
/
versions.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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}`);
}
}