11import * as Generator from "yeoman-generator" ;
22import * as chalk from "chalk" ;
3- import { GlobalJson , FabloConfigJson } from "../types/FabloConfigJson" ;
3+ import { FabloConfigJson } from "../types/FabloConfigJson" ;
44
55const DEFAULT_FABLO_CONFIG : FabloConfigJson = {
66 $schema : "https://github.com/hyperledger-labs/fablo/releases/download/2.2.0/schema.json" ,
@@ -58,17 +58,7 @@ const DEFAULT_FABLO_CONFIG: FabloConfigJson = {
5858 ] ,
5959 } ,
6060 ] ,
61- chaincodes : [
62- {
63- name : "chaincode1" ,
64- version : "0.0.1" ,
65- lang : "node" ,
66- channel : "my-channel1" ,
67- directory : "./chaincodes/chaincode-kv-node" ,
68- endorsement : "AND ('Org1MSP.member')" ,
69- privateData : [ ] ,
70- } ,
71- ] ,
61+ chaincodes : [ ] ,
7262 hooks : { } ,
7363} ;
7464
@@ -77,42 +67,52 @@ export default class InitGenerator extends Generator {
7767 super ( args , opts ) ;
7868 }
7969
80- async copySampleConfig ( ) : Promise < void > {
81- let fabloConfigJson = { ...DEFAULT_FABLO_CONFIG } ;
70+ async generateConfig ( ) : Promise < void > {
71+ const fabloConfigJson = { ...DEFAULT_FABLO_CONFIG } ;
8272
83- const shouldInitWithNodeChaincode = this . args . length && this . args . find ( ( v ) => v === "node" ) ;
73+ // Add Node.js chaincode if requested
74+ const shouldInitWithNodeChaincode = this . args . includes ( "node" ) ;
8475 if ( shouldInitWithNodeChaincode ) {
85- console . log ( "Creating sample Node.js chaincode" ) ;
86- this . fs . copy ( this . templatePath ( "chaincodes" ) , this . destinationPath ( "chaincodes" ) ) ;
87- // force build on Node 12, since dev deps (@theledger/fabric-mock-stub) may not work on 16
76+ console . log ( "Adding Node.js chaincode configuration" ) ;
77+ fabloConfigJson . chaincodes = [
78+ {
79+ name : "chaincode1" ,
80+ version : "0.0.1" ,
81+ lang : "node" ,
82+ channel : "my-channel1" ,
83+ directory : "./chaincodes/chaincode-kv-node" ,
84+ privateData : [ ] ,
85+ } ,
86+ ] ;
87+
88+ // Create chaincode directory and .nvmrc
8889 this . fs . write ( this . destinationPath ( "chaincodes/chaincode-kv-node/.nvmrc" ) , "12" ) ;
89- } else {
90- fabloConfigJson = { ...fabloConfigJson , chaincodes : [ ] } ;
9190 }
9291
93- const shouldAddFabloRest = this . args . length && this . args . find ( ( v ) => v === "rest" ) ;
92+ // Add Fablo REST if requested
93+ const shouldAddFabloRest = this . args . includes ( "rest" ) ;
9494 if ( shouldAddFabloRest ) {
95- const orgs = fabloConfigJson . orgs . map ( ( org ) => ( { ...org , tools : { fabloRest : true } } ) ) ;
96- fabloConfigJson = { ...fabloConfigJson , orgs } ;
97- } else {
98- const orgs = fabloConfigJson . orgs . map ( ( org ) => ( { ...org , tools : { } } ) ) ;
99- fabloConfigJson = { ...fabloConfigJson , orgs } ;
95+ fabloConfigJson . orgs = fabloConfigJson . orgs . map ( ( org ) => ( {
96+ ...org ,
97+ tools : { fabloRest : true } ,
98+ } ) ) ;
10099 }
101100
102- const shouldUseKubernetes = this . args . length && this . args . find ( ( v ) => v === "kubernetes" || v === "k8s" ) ;
103- const shouldRunInDevMode = this . args . length && this . args . find ( ( v ) => v === "dev" ) ;
104- const global : GlobalJson = {
101+ // Configure engine and dev mode
102+ const shouldUseKubernetes = this . args . some ( ( arg ) => [ "kubernetes" , "k8s" ] . includes ( arg ) ) ;
103+ const shouldRunInDevMode = this . args . includes ( "dev" ) ;
104+ fabloConfigJson . global = {
105105 ...fabloConfigJson . global ,
106106 engine : shouldUseKubernetes ? "kubernetes" : "docker" ,
107- peerDevMode : ! ! shouldRunInDevMode ,
107+ peerDevMode : shouldRunInDevMode ,
108108 } ;
109- fabloConfigJson = { ...fabloConfigJson , global } ;
110109
110+ // Write the final config
111111 this . fs . write ( this . destinationPath ( "fablo-config.json" ) , JSON . stringify ( fabloConfigJson , undefined , 2 ) ) ;
112112
113113 this . on ( "end" , ( ) => {
114114 console . log ( "===========================================================" ) ;
115- console . log ( chalk . bold ( "Sample config file created! :)" ) ) ;
115+ console . log ( chalk . bold ( "Fablo config file created! :)" ) ) ;
116116 console . log ( "You can start your network with 'fablo up' command" ) ;
117117 console . log ( "===========================================================" ) ;
118118 } ) ;
0 commit comments