11#!/usr/bin/env node
22/*
3- * Licensed under the Apache License, Version 2.0 (the " License" );
3+ * Licensed under the Apache License, Version 2.0 (the ' License' );
44 * you may not use this file except in compliance with the License.
55 * You may obtain a copy of the License at
66 *
77 * http://www.apache.org/licenses/LICENSE-2.0
88 *
99 * Unless required by applicable law or agreed to in writing, software
10- * distributed under the License is distributed on an " AS IS" BASIS,
10+ * distributed under the License is distributed on an ' AS IS' BASIS,
1111 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212 * See the License for the specific language governing permissions and
1313 * limitations under the License.
@@ -19,11 +19,11 @@ const chalk = require('chalk');
1919const clear = require ( 'clear' ) ;
2020const figlet = require ( 'figlet' ) ;
2121const util = require ( '../lib/util' ) ;
22-
2322const loopback = require ( 'loopback' ) ;
2423const boot = require ( 'loopback-boot' ) ;
25-
2624const app = module . exports = loopback ( ) ;
25+ process . env . SUPPRESS_NO_CONFIG_WARNING = true ;
26+
2727app . start = function ( ) {
2828
2929 // start the web server
@@ -37,41 +37,70 @@ app.start = function() {
3737 } ) ;
3838} ;
3939
40- // clear the console and display a nice welcome message
41- clear ( ) ;
42- console . log (
43- chalk . yellow (
44- figlet . textSync ( 'Fabric-Composer' , { horizontalLayout : 'full' } )
45- )
46- ) ;
4740
48- // Get details of the server that we want to run
49- util . getFabricDetails ( function ( answers ) {
50- // augment the app with the extra config that we've just collected
51- let ds = {
52- 'name' : 'Composer' , // not sure this matters
53- 'connectionProfileName' : answers . profilename ,
54- 'businessNetworkIdentifier' : answers . businessNetworkId ,
55- 'participantId' : answers . userid ,
56- 'participantPwd' : answers . secret
57- } ;
58- app . cfg = ds ;
59- boot ( app , __dirname , function ( err ) {
60- if ( err ) {
61- throw err ;
62- }
63-
64- // start the server if `$ node server.js`
65- if ( require . main === module ) {
66- app . start ( ) ;
67- }
41+ const yargs = require ( 'yargs' )
42+ . wrap ( null )
43+ . usage ( 'Usage: $0 -p connection profile -b business network identifier -u participant id -s participant password' )
44+ . option ( 'c' , { alias : 'connectionProfile' , describe : 'connection profile Name' , type : 'string' } )
45+ . option ( 'b' , { alias : 'businessNetwork' , describe : 'business network identifier' , type : 'string' } )
46+ . option ( 'i' , { alias : 'participantId' , describe : 'participant id' , type : 'string' } )
47+ . option ( 'p' , { alias : 'participantPwd' , describe : 'participant password' , type : 'string' } )
48+ . help ( 'h' )
49+ . alias ( 'h' , 'help' )
50+ . argv ;
51+
52+ // see if we need to run interactively
53+ if ( yargs . c === undefined && yargs . b === undefined && yargs . i === undefined && yargs . p === undefined ) {
54+ // Gather some args interactively
55+ clear ( ) ;
56+ console . log (
57+ chalk . yellow (
58+ figlet . textSync ( 'Fabric-Composer' , { horizontalLayout : 'full' } )
59+ )
60+ ) ;
61+ // Get details of the server that we want to run
62+ util . getFabricDetails ( function ( answers ) {
63+ // augment the app with the extra config that we've just collected
64+ let ds = {
65+ 'name' : 'Composer' , // not sure this matters
66+ 'connectionProfileName' : answers . profilename ,
67+ 'businessNetworkIdentifier' : answers . businessNetworkId ,
68+ 'participantId' : answers . userid ,
69+ 'participantPwd' : answers . secret
70+ } ;
71+ app . cfg = ds ;
72+ boot ( app , __dirname , function ( err ) {
73+ if ( err ) {
74+ throw err ;
75+ }
76+ // start the server if `$ node server.js`
77+ if ( require . main === module ) {
78+ app . start ( ) ;
79+ }
80+ } ) ;
6881 } ) ;
69- } ) ;
70-
71-
72-
73-
74-
75-
76-
7782
83+ } else {
84+ // make sure we have args for all required parms otherwise error
85+ if ( yargs . c === undefined || yargs . b === undefined || yargs . i === undefined || yargs . p === undefined ) {
86+ console . log ( 'Error: Missing parameter. Please run compposer-rest-server -h to see usage details' ) ;
87+ } else {
88+ let ds = {
89+ 'name' : 'Composer' , // not sure this matters
90+ 'connectionProfileName' : yargs . c ,
91+ 'businessNetworkIdentifier' : yargs . b ,
92+ 'participantId' : yargs . i ,
93+ 'participantPwd' : yargs . p
94+ } ;
95+ app . cfg = ds ;
96+ boot ( app , __dirname , function ( err ) {
97+ if ( err ) {
98+ throw err ;
99+ }
100+ // start the server if `$ node server.js`
101+ if ( require . main === module ) {
102+ app . start ( ) ;
103+ }
104+ } ) ;
105+ }
106+ }
0 commit comments