1414
1515'use strict' ;
1616
17+
1718const shell = require ( 'shelljs' ) ;
1819const path = require ( 'path' ) ;
1920/**
2021 * Composer dev hlf command
22+
2123 * @private
2224 */
2325class hlf {
@@ -32,18 +34,21 @@ class hlf {
3234
3335 let hlfCmdPromise = new Promise (
3436 function ( resolve , reject ) {
37+
3538 if ( hlf . runCmd ( argv ) === 0 ) {
3639 resolve ( 0 ) ; // fulfilled
3740 } else {
3841 reject ( 1 ) ; // reject
3942 }
43+
4044 }
4145 ) ;
4246
4347 return hlfCmdPromise ;
4448
4549 }
4650
51+
4752 /** @private
4853 * @param {String } cmdString The command string to run
4954 * @return {int } error code
@@ -53,13 +58,13 @@ class hlf {
5358 return shell . exec ( cmdString ) . code ;
5459 }
5560
61+
5662 /**
5763 * @param {Array } argv command arguments
5864 * @return {int } error code
5965 */
6066 static runCmd ( argv ) {
6167
62-
6368 if ( argv . start === undefined && argv . stop === undefined && argv . download === undefined && argv . delete === undefined && argv . purgeProfiles === undefined ) {
6469 return this . _cmd ( 'docker ps' ) ;
6570 }
@@ -77,6 +82,7 @@ class hlf {
7782 console . log ( 'Stopping Hyperledger Fabric' ) ;
7883 cmdString = 'docker-compose -f ' + composeYML + ' stop ' ;
7984 errorCode = this . _cmd ( cmdString ) ;
85+
8086 } else if ( argv . download ) {
8187 /*
8288 # Pull and tag the latest Hyperledger Fabric base image.
@@ -89,19 +95,24 @@ class hlf {
8995
9096 cmdString = 'docker tag hyperledger/fabric-baseimage:x86_64-0.1.0 hyperledger/fabric-baseimage:latest' ;
9197 errorCode = this . _cmd ( cmdString ) ;
98+
9299 } else if ( argv . delete ) {
93100 // todo put prompt here
94101 /*docker-compose kill && docker-compose down
95102 */
96103 console . log ( 'Killing and stoping Hypledger Fabric docker containers' ) ;
97104 cmdString = [ 'docker-compose' , '-f' , composeYML , 'kill && docker-compose' , '-f' , composeYML , 'down' ] . join ( ' ' ) ;
105+
98106 errorCode = this . _cmd ( cmdString ) ;
107+
99108 }
100109
101110 if ( argv . purgeProfiles && errorCode === 0 ) {
102111 console . log ( 'Deleting the default connection profile' ) ;
112+
103113 errorCode = shell . rm ( '-rf' , '~/.composer-connection-profiles/defaultProfile' ) . code ;
104114 errorCode = ( errorCode === 0 ) ? shell . rm ( '-r' , '~/.composer-credentials/*' ) . code : errorCode ;
115+
105116 }
106117
107118 return errorCode ;
0 commit comments