@@ -4,7 +4,7 @@ import * as os from 'node:os';
44import * as path from 'node:path' ;
55import { print } from 'gluegun' ;
66import ProgressBar from 'progress' ;
7- import { Command , Flags } from '@oclif/core' ;
7+ import { Args , Command , Flags } from '@oclif/core' ;
88import {
99 downloadGraphNodeRelease ,
1010 extractGz ,
@@ -16,43 +16,51 @@ import {
1616export default class NodeCommand extends Command {
1717 static description = 'Manage Graph node related operations' ;
1818
19- static flags = {
19+ static override flags = {
2020 help : Flags . help ( {
2121 char : 'h' ,
2222 } ) ,
23+ tag : Flags . string ( {
24+ summary : 'Tag of the Graph Node release to install.' ,
25+ } ) ,
26+ 'download-dir' : Flags . string ( {
27+ summary : 'Directory to download the Graph Node release to.' ,
28+ default : os . tmpdir ( ) ,
29+ } ) ,
2330 } ;
2431
25- static args = { } ;
32+ static override args = {
33+ install : Args . boolean ( {
34+ description : 'Install the Graph Node' ,
35+ } ) ,
36+ } ;
2637
2738 static examples = [ '$ graph node install' ] ;
2839
2940 static strict = false ;
3041
3142 async run ( ) {
32- const { argv } = await this . parse ( NodeCommand ) ;
33-
34- if ( argv . length > 0 ) {
35- const subcommand = argv [ 0 ] ;
36-
37- if ( subcommand === 'install' ) {
38- await installGraphNode ( ) ;
39- }
43+ const { flags, args } = await this . parse ( NodeCommand ) ;
4044
41- // If no valid subcommand is provided, show help
42- await this . config . runCommand ( 'help' , [ 'node' ] ) ;
45+ if ( args . install ) {
46+ await installGraphNode ( flags . tag ) ;
47+ return ;
4348 }
49+
50+ // If no valid subcommand is provided, show help
51+ await this . config . runCommand ( 'help' , [ 'node' ] ) ;
4452 }
4553}
4654
47- async function installGraphNode ( ) {
48- const latestRelease = await getLatestGraphNodeRelease ( ) ;
55+ async function installGraphNode ( tag ?: string ) {
56+ const latestRelease = tag || ( await getLatestGraphNodeRelease ( ) ) ;
4957 const tmpBase = os . tmpdir ( ) ;
5058 const tmpDir = await fs . promises . mkdtemp ( path . join ( tmpBase , 'graph-node-' ) ) ;
5159 let progressBar : ProgressBar | undefined ;
52- const downloadPath = await downloadGraphNodeRelease (
53- latestRelease ,
54- tmpDir ,
55- ( downloaded , total ) => {
60+
61+ let downloadPath : string ;
62+ try {
63+ downloadPath = await downloadGraphNodeRelease ( latestRelease , tmpDir , ( downloaded , total ) => {
5664 if ( ! total ) return ;
5765
5866 progressBar ||= new ProgressBar ( `Downloading ${ latestRelease } [:bar] :percent` , {
@@ -63,18 +71,21 @@ async function installGraphNode() {
6371 } ) ;
6472
6573 progressBar . tick ( downloaded - ( progressBar . curr || 0 ) ) ;
66- } ,
67- ) ;
74+ } ) ;
75+ } catch ( e ) {
76+ print . error ( e ) ;
77+ throw e ;
78+ }
6879
6980 let extractedPath : string ;
7081
82+ print . info ( `Extracting ${ downloadPath } ` ) ;
7183 if ( downloadPath . endsWith ( '.gz' ) ) {
7284 extractedPath = await extractGz ( downloadPath ) ;
73- print . info ( `Extracted ${ extractedPath } ` ) ;
7485 } else if ( downloadPath . endsWith ( '.zip' ) ) {
7586 extractedPath = await extractZipAndGetExe ( downloadPath , tmpDir ) ;
76- print . info ( `Extracted ${ extractedPath } ` ) ;
7787 } else {
88+ print . error ( `Unsupported file type: ${ downloadPath } ` ) ;
7889 throw new Error ( `Unsupported file type: ${ downloadPath } ` ) ;
7990 }
8091
@@ -85,6 +96,11 @@ async function installGraphNode() {
8596 await chmod ( movedPath , 0o755 ) ;
8697 }
8798
99+ print . info ( `Installed Graph Node ${ latestRelease } ` ) ;
100+ print . info (
101+ `Please add the following to your PATH: ${ path . dirname ( movedPath ) } if it's not already there or if you're using a custom download directory` ,
102+ ) ;
103+
88104 // Delete the temporary directory
89105 await fs . promises . rm ( tmpDir , { recursive : true , force : true } ) ;
90106}
0 commit comments