1
+ /* eslint-disable no-console */
2
+ /* eslint-disable @typescript-eslint/no-misused-promises */
3
+ /* eslint-disable no-await-in-loop */
4
+ /* eslint-disable guard-for-in */
5
+ /* eslint-disable no-restricted-syntax */
1
6
/*-----------------------------------------------------------------------------------------------
2
7
* Copyright (c) Red Hat, Inc. All rights reserved.
3
8
* Licensed under the MIT License. See LICENSE file in the project root for license information.
4
9
*-----------------------------------------------------------------------------------------------*/
5
- /* eslint-disable no-console */
6
10
7
- // import { CancellationToken } from 'vscode';
8
11
import { exec } from 'child_process' ;
9
12
import { tmpdir } from 'os' ;
10
13
import { join , resolve } from 'path' ;
11
14
import { existsSync } from 'fs-extra' ;
12
15
import { fromFile } from 'hasha' ;
13
16
import { sync } from 'mkdirp' ;
17
+ import { exit } from 'shelljs' ;
14
18
import configData = require( '../src/cli/cli-config.json' ) ;
15
19
import { DownloadUtil } from '../src/util/download' ;
16
- // import { Config } from '../src/cli/cli-config';
17
- // import loadJSON from '../src/util/parse';
18
-
19
- // const configData = '../src/cli/cli-config.json';
20
20
21
21
async function downloadFileAndCreateSha256 (
22
22
targetFolder : string ,
@@ -29,7 +29,6 @@ async function downloadFileAndCreateSha256(
29
29
}
30
30
const currentFile = join ( targetFolder , fileName ) ;
31
31
console . log ( `${ currentFile } download started from ${ reqURL } ` ) ;
32
- // const token: CancellationToken = null;
33
32
await DownloadUtil . downloadFile ( reqURL , currentFile , ( current ) => console . log ( `${ current } %` ) ) ;
34
33
const currentSHA256 = await fromFile ( currentFile , { algorithm : 'sha256' } ) ;
35
34
if ( currentSHA256 === sha256sum ) {
@@ -39,13 +38,12 @@ async function downloadFileAndCreateSha256(
39
38
}
40
39
}
41
40
42
- function verifyTools ( ) : void {
43
- Object . keys ( configData ) . forEach ( ( key ) => {
41
+ async function verifyTools ( ) : Promise < void > {
42
+ for ( const key in configData ) {
44
43
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
45
- Object . keys ( configData [ key ] . platform ) . forEach ( ( OS ) => {
44
+ for ( const OS in configData [ key ] . platform ) {
46
45
const targetFolder = resolve ( tmpdir ( ) , OS ) ;
47
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
48
- downloadFileAndCreateSha256 (
46
+ await downloadFileAndCreateSha256 (
49
47
targetFolder ,
50
48
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
51
49
configData [ key ] . platform [ OS ] . dlFileName ,
@@ -54,37 +52,27 @@ function verifyTools(): void {
54
52
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
55
53
configData [ key ] . platform [ OS ] . sha256sum ,
56
54
) ;
57
- } ) ;
58
- } ) ;
55
+ }
56
+ }
59
57
}
60
- // function verifyTools(): void {
61
- // loadJSON<KnConfig>(configData).then((data: KnConfig): void => {
62
- // Object.keys(data).forEach((key) => {
63
- // Object.keys(data[key].platform).forEach((OS) => {
64
- // const targetFolder = resolve(tmpdir(), OS);
65
- // downloadFileAndCreateSha256(
66
- // targetFolder,
67
- // data[key].platform[OS].dlFileName,
68
- // data[key].platform[OS].url,
69
- // data[key].platform[OS].sha256sum,
70
- // );
71
- // });
72
- // });
73
- // });
74
- // }
75
58
76
59
const fileCheckRegex = / \w * c l i - c o n f i g .j s o n / ;
77
60
78
- exec ( 'git diff --name-only origin/main -- .' , ( error , stdout ) => {
61
+ exec ( 'git diff --name-only origin/main -- .' , async ( error , stdout ) => {
79
62
if ( error ) {
80
63
throw error ;
81
64
}
82
65
console . log ( 'The changed files:' ) ;
83
66
console . log ( stdout ) ;
84
67
if ( fileCheckRegex . test ( stdout ) ) {
85
- console . log ( 'cli-config.json is changed, starting download verification' ) ;
86
- verifyTools ( ) ;
68
+ console . log ( 'tools.json is changed, starting download verification' ) ;
69
+ try {
70
+ await verifyTools ( ) ;
71
+ } catch ( err ) {
72
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
73
+ exit ( 1 ) ;
74
+ }
87
75
} else {
88
- console . log ( 'cli-config .json is not changed, skipping download verification' ) ;
76
+ console . log ( 'tools .json is not changed, skipping download verification' ) ;
89
77
}
90
78
} ) ;
0 commit comments