Skip to content

Commit 6e9443f

Browse files
committed
inital extend-config
Signed-off-by: OsamaRab3 <osrab3@gmail.com>
1 parent 5fe9009 commit 6e9443f

File tree

10 files changed

+67
-57
lines changed

10 files changed

+67
-57
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Capabilities, OrdererGroup, OrgConfig } from "../types/FabloConfigExtended";
1+
import { Capabilities, OrdererGroup, OrgConfig } from "../../types/FabloConfigExtended";
22

33
export default {
44
global: {

src/extend-config/extendChaincodesConfig.ts renamed to src/commands/extend-config/extendChaincodesConfig.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { ChaincodeJson } from "../types/FabloConfigJson";
2-
import { ChaincodeConfig, ChannelConfig, Global, PrivateCollectionConfig } from "../types/FabloConfigExtended";
1+
import { ChaincodeJson } from "../../types/FabloConfigJson";
2+
import { ChaincodeConfig, ChannelConfig, Global, PrivateCollectionConfig } from "../../types/FabloConfigExtended";
33
import defaults from "./defaults";
4-
import { version } from "../repositoryUtils";
4+
import { version } from "../../repositoryUtils";
55

66
const createPrivateCollectionConfig = (
77
fabricVersion: string,

src/extend-config/extendChannelsConfig.ts renamed to src/commands/extend-config/extendChannelsConfig.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { ChannelConfig, OrdererGroup, OrgConfig } from "../types/FabloConfigExtended";
2-
import { ChannelJson } from "../types/FabloConfigJson";
1+
import { ChannelConfig, OrdererGroup, OrgConfig } from "../../types/FabloConfigExtended";
2+
import { ChannelJson } from "../../types/FabloConfigJson";
33
import * as _ from "lodash";
44
import defaults from "./defaults";
55

src/extend-config/extendConfig.ts renamed to src/commands/extend-config/extendConfig.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { FabloConfigJson } from "../types/FabloConfigJson";
2-
import { FabloConfigExtended } from "../types/FabloConfigExtended";
1+
import { FabloConfigJson } from "../../types/FabloConfigJson";
2+
import { FabloConfigExtended } from "../../types/FabloConfigExtended";
33
import { extendOrgsConfig } from "./extendOrgsConfig";
44
import extendGlobal from "./extendGlobal";
55
import extendChannelsConfig from "./extendChannelsConfig";

src/extend-config/extendGlobal.ts renamed to src/commands/extend-config/extendGlobal.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Used https://github.com/hyperledger/fabric/blob/v1.4.8/sampleconfig/configtx.yaml for values
2-
import { Capabilities, FabricVersions, Global } from "../types/FabloConfigExtended";
3-
import { version } from "../repositoryUtils";
4-
import { GlobalJson } from "../types/FabloConfigJson";
2+
import { Capabilities, FabricVersions, Global } from "../../types/FabloConfigExtended";
3+
import { version } from "../../repositoryUtils";
4+
import { GlobalJson } from "../../types/FabloConfigJson";
55
import defaults from "./defaults";
66

77
const getNetworkCapabilities = (fabricVersion: string): Capabilities => {
@@ -38,16 +38,16 @@ const getVersions = (fabricVersion: string): FabricVersions => {
3838
};
3939
};
4040

41-
const getEnvVarOrThrow = (name: string): string => {
42-
const value = process.env[name];
43-
if (!value || !value.length) throw new Error(`Missing environment variable ${name}`);
44-
return value;
45-
};
41+
// const getEnvVarOrThrow = (name: string): string => {
42+
// const value = process.env[name];
43+
// if (!value || !value.length) throw new Error(`Missing environment variable ${name}`);
44+
// return value;
45+
// };
4646

47-
const getPathsFromEnv = () => ({
48-
fabloConfig: getEnvVarOrThrow("FABLO_CONFIG"),
49-
chaincodesBaseDir: getEnvVarOrThrow("CHAINCODES_BASE_DIR"),
50-
});
47+
// const getPathsFromEnv = () => ({
48+
// fabloConfig: getEnvVarOrThrow("FABLO_CONFIG"),
49+
// chaincodesBaseDir: getEnvVarOrThrow("CHAINCODES_BASE_DIR"),
50+
// });
5151

5252
const extendGlobal = (globalJson: GlobalJson): Global => {
5353
const engine = globalJson.engine ?? "docker";
@@ -66,7 +66,10 @@ const extendGlobal = (globalJson: GlobalJson): Global => {
6666
...globalJson,
6767
...getVersions(globalJson.fabricVersion),
6868
engine,
69-
paths: getPathsFromEnv(),
69+
paths: {
70+
fabloConfig:"fablo-config.json",
71+
chaincodesBaseDir:"./chaincodes",
72+
},
7073
monitoring,
7174
capabilities: getNetworkCapabilities(globalJson.fabricVersion),
7275
tools: { ...explorer },

src/extend-config/extendHooksConfig.ts renamed to src/commands/extend-config/extendHooksConfig.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { HooksJson } from "../types/FabloConfigJson";
2-
import { HooksConfig } from "../types/FabloConfigExtended";
1+
import { HooksJson } from "../../types/FabloConfigJson";
2+
import { HooksConfig } from "../../types/FabloConfigExtended";
33

44
const extendHooksConfig = (hooksJson: HooksJson | undefined): HooksConfig => {
55
const postGenerate = typeof hooksJson?.postGenerate === "string" ? hooksJson.postGenerate : "";

src/extend-config/extendOrgsConfig.ts renamed to src/commands/extend-config/extendOrgsConfig.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import defaults from "./defaults";
2-
import { CAJson, OrdererJson, OrgJson, PeerJson } from "../types/FabloConfigJson";
2+
import { CAJson, OrdererJson, OrgJson, PeerJson } from "../../types/FabloConfigJson";
33
import {
44
CAConfig,
55
ExplorerConfig,
@@ -11,8 +11,8 @@ import {
1111
OrgConfig,
1212
PeerConfig,
1313
PeerDbConfig,
14-
} from "../types/FabloConfigExtended";
15-
import { version } from "../repositoryUtils";
14+
} from "../../types/FabloConfigExtended";
15+
import { version } from "../../repositoryUtils";
1616
import _ = require("lodash");
1717

1818
const extendCaConfig = (
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { Args, Command } from "@oclif/core";
2+
import * as fs from "fs-extra";
3+
import * as path from "path";
4+
5+
import parseFabloConfig from "../../utils/parseFabloConfig";
6+
import extendConfig from "./extendConfig";
7+
import { getNetworkCapabilities } from "./extendGlobal";
8+
9+
10+
11+
export default class ExtendConfig extends Command {
12+
static override description = "Reads a Fablo config file, extends it, and prints the result";
13+
14+
static override args = {
15+
config: Args.string({
16+
default: "../../network/fablo-config.json",
17+
description: "Fablo config file path",
18+
required: false,
19+
}),
20+
};
21+
async writing (args: { config?: string }): Promise<void> {
22+
const configPath = args?.config ?? "../../network/fablo-config.json";
23+
const fabloConfigPath = path.isAbsolute(configPath) ? configPath : path.join(process.cwd(), configPath);
24+
const json = parseFabloConfig(fs.readFileSync(fabloConfigPath).toString());
25+
const configExtended = extendConfig(json);
26+
this.log(JSON.stringify(configExtended, undefined, 2));
27+
}
28+
public async run(): Promise<void> {
29+
const { args } = await this.parse(ExtendConfig);
30+
await this.writing(args);
31+
32+
}
33+
34+
}
35+
36+
export { extendConfig, getNetworkCapabilities };
37+

src/extend-config/mergeOrdererGroups.ts renamed to src/commands/extend-config/mergeOrdererGroups.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { OrdererConfig, OrdererGroup, OrgConfig } from "../types/FabloConfigExtended";
1+
import { OrdererConfig, OrdererGroup, OrgConfig } from "../../types/FabloConfigExtended";
22
import * as _ from "lodash";
33

44
export const mergeOrdererGroups = (orgs: OrgConfig[]): OrdererGroup[] => {

src/extend-config/index.ts

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)