Skip to content

Commit c5c8932

Browse files
committed
fix and update
1 parent d4c0721 commit c5c8932

File tree

2 files changed

+32
-33
lines changed

2 files changed

+32
-33
lines changed

e2e/__snapshots__/fabloCommands.test.ts.snap

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ exports[`extend config should extend custom config 1`] = `
44
"Validation errors count: 0
55
Validation warnings count: 0
66
===========================================================
7-
Could not check for updates. Url: 'https://api.github.com/repos/hyperledger-labs/fablo/releases' not available
87
{
98
"global": {
109
"fabricVersion": "2.4.3",

src/init/index.ts

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as Generator from "yeoman-generator";
22
import * as chalk from "chalk";
3-
import { GlobalJson, FabloConfigJson } from "../types/FabloConfigJson";
3+
import { FabloConfigJson } from "../types/FabloConfigJson";
44

55
const 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

Comments
 (0)