@oclif/plugin-version 2.0.18 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/lib/commands/version.d.ts +0 -2
- package/lib/commands/version.js +73 -26
- package/oclif.manifest.json +1 -1
- package/package.json +5 -5
- package/npm-shrinkwrap.json +0 -11959
package/README.md
CHANGED
|
@@ -27,7 +27,7 @@ FLAG DESCRIPTIONS
|
|
|
27
27
|
Additionally shows the architecture, node version, operating system, and versions of plugins that the CLI is using.
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
-
_See code: [src/commands/version.ts](https://github.com/oclif/plugin-version/blob/v2.0
|
|
30
|
+
_See code: [src/commands/version.ts](https://github.com/oclif/plugin-version/blob/v2.1.0/src/commands/version.ts)_
|
|
31
31
|
<!-- commandsstop -->
|
|
32
32
|
|
|
33
33
|
# Contributing
|
package/lib/commands/version.js
CHANGED
|
@@ -1,5 +1,57 @@
|
|
|
1
1
|
import { Command, Flags } from '@oclif/core';
|
|
2
|
+
import { Ansis } from 'ansis';
|
|
3
|
+
import { exec } from 'node:child_process';
|
|
2
4
|
import { EOL } from 'node:os';
|
|
5
|
+
const ansis = new Ansis();
|
|
6
|
+
async function getNpmDetails(pkg) {
|
|
7
|
+
return new Promise((resolve) => {
|
|
8
|
+
exec(`npm view ${pkg} --json`, (error, stdout) => {
|
|
9
|
+
if (error) {
|
|
10
|
+
resolve(false);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
resolve(JSON.parse(stdout));
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
function daysAgo(date) {
|
|
19
|
+
const now = new Date();
|
|
20
|
+
const then = new Date(date);
|
|
21
|
+
const diff = now.getTime() - then.getTime();
|
|
22
|
+
return Math.floor(diff / (1000 * 60 * 60 * 24));
|
|
23
|
+
}
|
|
24
|
+
function humanReadableDate(date) {
|
|
25
|
+
return new Date(date).toDateString();
|
|
26
|
+
}
|
|
27
|
+
async function formatPlugins(config, plugins) {
|
|
28
|
+
const sorted = Object.entries(plugins)
|
|
29
|
+
.map(([name, plugin]) => ({ name, ...plugin }))
|
|
30
|
+
.sort((a, b) => (a.name > b.name ? 1 : -1));
|
|
31
|
+
return Promise.all(sorted.map(async (plugin) => {
|
|
32
|
+
const base = `${getFriendlyName(config, plugin.name)} ${ansis.dim(plugin.version)} ${ansis.dim(`(${plugin.type})`)} ${plugin.type === 'link' ? ansis.dim(plugin.root) : ''}`.trim();
|
|
33
|
+
if (plugin.type === 'user') {
|
|
34
|
+
const npmDetails = await getNpmDetails(plugin.name);
|
|
35
|
+
const publishedString = npmDetails
|
|
36
|
+
? ansis.dim(` published ${daysAgo(npmDetails.time[plugin.version])} days ago (${humanReadableDate(npmDetails.time[plugin.version])})`)
|
|
37
|
+
: '';
|
|
38
|
+
const notLatestWarning = npmDetails && plugin.version !== npmDetails['dist-tags'].latest
|
|
39
|
+
? ansis.red(` (latest is ${npmDetails['dist-tags'].latest})`)
|
|
40
|
+
: '';
|
|
41
|
+
return `${base}${publishedString}${notLatestWarning}`;
|
|
42
|
+
}
|
|
43
|
+
return base;
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
function getFriendlyName(config, name) {
|
|
47
|
+
const { scope } = config.pjson.oclif;
|
|
48
|
+
if (!scope)
|
|
49
|
+
return name;
|
|
50
|
+
const match = name.match(`@${scope}/plugin-(.+)`);
|
|
51
|
+
if (!match)
|
|
52
|
+
return name;
|
|
53
|
+
return match[1];
|
|
54
|
+
}
|
|
3
55
|
export default class Version extends Command {
|
|
4
56
|
static enableJsonFlag = true;
|
|
5
57
|
static flags = {
|
|
@@ -14,52 +66,47 @@ export default class Version extends Command {
|
|
|
14
66
|
const versionDetail = { ...theRest };
|
|
15
67
|
let output = `${this.config.userAgent}`;
|
|
16
68
|
if (flags.verbose) {
|
|
17
|
-
|
|
69
|
+
const details = await getNpmDetails(this.config.pjson.name);
|
|
70
|
+
const cliPublishedString = details
|
|
71
|
+
? ansis.dim(` published ${daysAgo(details.time[details.version])} days ago (${humanReadableDate(details.time[details.version])})`)
|
|
72
|
+
: '';
|
|
73
|
+
const notLatestWarning = details && this.config.version !== details['dist-tags'].latest
|
|
74
|
+
? ansis.red(` (latest is ${details['dist-tags'].latest})`)
|
|
75
|
+
: '';
|
|
76
|
+
versionDetail.pluginVersions = await formatPlugins(this.config, pluginVersions ?? {});
|
|
18
77
|
versionDetail.shell ??= 'unknown';
|
|
19
|
-
output = ` CLI Version:
|
|
20
|
-
\t${versionDetail.cliVersion}
|
|
78
|
+
output = ` ${ansis.bold('CLI Version')}:
|
|
79
|
+
\t${versionDetail.cliVersion}${cliPublishedString}${notLatestWarning}
|
|
21
80
|
|
|
22
|
-
Architecture:
|
|
81
|
+
${ansis.bold('Architecture')}:
|
|
23
82
|
\t${versionDetail.architecture}
|
|
24
83
|
|
|
25
|
-
Node Version:
|
|
84
|
+
${ansis.bold('Node Version')}:
|
|
26
85
|
\t${versionDetail.nodeVersion}
|
|
27
86
|
|
|
28
|
-
Plugin Version:
|
|
29
|
-
\t${
|
|
87
|
+
${ansis.bold('Plugin Version')}:
|
|
88
|
+
\t${(versionDetail.pluginVersions ?? []).join(EOL + '\t')}
|
|
30
89
|
|
|
31
|
-
OS and Version:
|
|
90
|
+
${ansis.bold('OS and Version')}:
|
|
32
91
|
\t${versionDetail.osVersion}
|
|
33
92
|
|
|
34
|
-
Shell:
|
|
93
|
+
${ansis.bold('Shell')}:
|
|
35
94
|
\t${versionDetail.shell}
|
|
36
95
|
|
|
37
|
-
Root Path:
|
|
96
|
+
${ansis.bold('Root Path')}:
|
|
38
97
|
\t${versionDetail.rootPath}
|
|
39
98
|
`;
|
|
40
99
|
}
|
|
41
100
|
this.log(output);
|
|
42
101
|
return flags.verbose
|
|
43
|
-
?
|
|
102
|
+
? {
|
|
103
|
+
...versionDetail,
|
|
104
|
+
pluginVersions: versionDetail.pluginVersions?.map((plugin) => ansis.strip(plugin)),
|
|
105
|
+
}
|
|
44
106
|
: {
|
|
45
107
|
architecture: versionDetail.architecture,
|
|
46
108
|
cliVersion: versionDetail.cliVersion,
|
|
47
109
|
nodeVersion: versionDetail.nodeVersion,
|
|
48
110
|
};
|
|
49
111
|
}
|
|
50
|
-
formatPlugins(plugins) {
|
|
51
|
-
return Object.entries(plugins)
|
|
52
|
-
.map(([name, plugin]) => ({ name, ...plugin }))
|
|
53
|
-
.sort((a, b) => (a.name > b.name ? 1 : -1))
|
|
54
|
-
.map((plugin) => `${this.getFriendlyName(plugin.name)} ${plugin.version} (${plugin.type}) ${plugin.type === 'link' ? plugin.root : ''}`.trim());
|
|
55
|
-
}
|
|
56
|
-
getFriendlyName(name) {
|
|
57
|
-
const { scope } = this.config.pjson.oclif;
|
|
58
|
-
if (!scope)
|
|
59
|
-
return name;
|
|
60
|
-
const match = name.match(`@${scope}/plugin-(.+)`);
|
|
61
|
-
if (!match)
|
|
62
|
-
return name;
|
|
63
|
-
return match[1];
|
|
64
|
-
}
|
|
65
112
|
}
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oclif/plugin-version",
|
|
3
3
|
"description": "A command that shows the CLI version",
|
|
4
|
-
"version": "2.0
|
|
4
|
+
"version": "2.1.0",
|
|
5
5
|
"author": "Salesforce",
|
|
6
6
|
"bugs": "https://github.com/oclif/plugin-version/issues",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@oclif/core": "^3.26.5"
|
|
8
|
+
"@oclif/core": "^3.26.5",
|
|
9
|
+
"ansis": "^3.2.0"
|
|
9
10
|
},
|
|
10
11
|
"devDependencies": {
|
|
11
12
|
"@commitlint/config-conventional": "^18",
|
|
@@ -35,7 +36,6 @@
|
|
|
35
36
|
},
|
|
36
37
|
"files": [
|
|
37
38
|
"oclif.manifest.json",
|
|
38
|
-
"npm-shrinkwrap.json",
|
|
39
39
|
"/lib"
|
|
40
40
|
],
|
|
41
41
|
"homepage": "https://github.com/oclif/plugin-version",
|
|
@@ -53,12 +53,12 @@
|
|
|
53
53
|
"repository": "oclif/plugin-version",
|
|
54
54
|
"scripts": {
|
|
55
55
|
"build": "shx rm -rf lib && tsc",
|
|
56
|
-
"clean": "shx rm -f oclif.manifest.json
|
|
56
|
+
"clean": "shx rm -f oclif.manifest.json",
|
|
57
57
|
"compile": "tsc",
|
|
58
58
|
"lint": "eslint . --ext .ts",
|
|
59
59
|
"postpack": "yarn run clean",
|
|
60
60
|
"posttest": "yarn lint",
|
|
61
|
-
"prepack": "yarn build && oclif manifest && oclif readme
|
|
61
|
+
"prepack": "yarn build && oclif manifest && oclif readme",
|
|
62
62
|
"prepare": "husky && yarn build",
|
|
63
63
|
"pretest": "yarn build --noEmit && tsc -p test --noEmit",
|
|
64
64
|
"test": "mocha --forbid-only \"test/**/*.test.ts\"",
|