Skip to content

Commit d4c9847

Browse files
committed
feat: add versions visual comparison
1 parent 501e09c commit d4c9847

File tree

4 files changed

+2734
-48
lines changed

4 files changed

+2734
-48
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ Synopsis: `vf-core-service-discovery run [options]`
128128
| `-d`, `--disabled` | array | `[]` | List of disabled steps (from getConfig, getChangelog getDependents) |
129129
| `-o`, `--only-outdated` | boolean | `false` | Display only outdated components |
130130
| `-m`, `--format` | string | `''` | Specifies the formatting for the results |
131+
| `-c`, `--compare-versions` | boolean | `false` | Shows the visual difference between different component versions |
131132

132133
#### Custom formatting
133134

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
"mkdirp": "^1.0.4",
7373
"rimraf": "^3.0.2",
7474
"semver": "^7.3.4",
75+
"vf-core-service-discovery-versions-comparison": "^0.2.1",
7576
"winston": "^3.3.3",
7677
"yaml": "^1.10.0",
7778
"yargs": "^16.1.1"

src/cli/run.ts

+47
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
/* eslint-disable @typescript-eslint/no-var-requires */
2+
import { promisify } from 'util';
3+
import path from 'path';
24
import chalk from 'chalk';
35
import boxen from 'boxen';
6+
import rimraf from 'rimraf';
7+
import compareVersions from 'vf-core-service-discovery-versions-comparison';
48
import ServiceDiscovery from '..';
59
import { Reporter } from '../types';
10+
import { PassThrough } from 'stream';
11+
12+
const rimrafP = promisify(rimraf);
613

714
interface Arguments {
815
verbose: boolean;
916
'log-file': string;
1017
force: boolean;
1118
profile: boolean;
1219
'only-outdated': boolean;
20+
'compare-versions': boolean;
1321
reporters: string[];
1422
disabled: string[];
1523
format: string;
@@ -62,6 +70,12 @@ export const builder = {
6270
default: '',
6371
alias: 'm',
6472
},
73+
'compare-versions': {
74+
description: "Compare components' versions",
75+
type: 'boolean',
76+
default: false,
77+
alias: 'c',
78+
},
6579
};
6680

6781
export async function handler(argv: Arguments): Promise<void> {
@@ -89,6 +103,39 @@ export async function handler(argv: Arguments): Promise<void> {
89103
for (const report of reporters) {
90104
await report(items, argv.format);
91105
}
106+
107+
const discoveryItemsForComparison = items
108+
.map((item) => item.discoveryItem)
109+
.filter((item) => item.version !== item.packageJson?.version);
110+
111+
if (argv['compare-versions'] && discoveryItemsForComparison.length > 0) {
112+
const temporaryWebServerFilesDirectory = path.join(process.cwd(), 'vf-core-service-discovery-tmp');
113+
const logStream = new PassThrough({ encoding: 'utf-8' });
114+
115+
logStream.on('data', (data) => {
116+
console.log(data);
117+
});
118+
119+
await compareVersions(
120+
temporaryWebServerFilesDirectory,
121+
{
122+
components: discoveryItemsForComparison.map((item) => ({
123+
name: item.name,
124+
nameWithoutPrefix: item.nameWithoutPrefix,
125+
installedVersion: item.version,
126+
latestVersion: item.packageJson?.version,
127+
})),
128+
},
129+
logStream,
130+
);
131+
132+
// TODO: check windows
133+
process.on('SIGINT', async () => {
134+
console.log(`Deleting temporary web server files directory: ${temporaryWebServerFilesDirectory}`);
135+
await rimrafP(temporaryWebServerFilesDirectory);
136+
process.exit();
137+
});
138+
}
92139
} catch (error) {
93140
console.log(error);
94141
process.exit(1);

0 commit comments

Comments
 (0)