Class: Config
Class that exposes Cubist project configurations (and resolves and validates path names, network configurations, etc.).
All cubist applications have a JSON config file (DEFAULT_FILENAME), which specifies the kind of project (ProjType]) the application code is written in, where build output should be written to, and where deployment scripts and information should be generated.
Example configuration file:
{
"type": "TypeScript",
"build_dir": "build",
"deploy_dir": "deploy",
"contracts": {
"root_dir": "contracts",
"targets": {
"ethereum" : {
"files": ["./contracts/StorageReceiver.sol"]
},
"polygon": {
"files": ["./contracts/StorageSender.sol"]
}
},
"import_dirs": [
"node_modules"
]
},
"allow_import_from_external": true,
"network_profiles": {
"default": {
"ethereum": { "url": "http://127.0.0.1:8545/" },
"polygon": { "url": "http://127.0.0.1:9545" }
}
}
}
You can load config files with nearest, which finds the JSON file in the current directory or any parent directory:
const cfg = Config.nearest();
Alternatively, you can load the default config in the directory with from_dir:
const cfg = Config.from_dir("/path/to/my-app");
Alternatively, you can just use from_file if you have the filename of the config file:
const cfg = Config.from_file("/path/to/cubist-config.json");
This class exposes a subset of the functionality available in our Rust SDK. In particular, this class is only intended to be used to read configurations from the file system. This means that every Config object should be treated as effectively read-only.
Most users don't need to use this class; the class you likely want to use is Cubist, which transparently loads configurations.
Exports
Properties
Accessors
Methods
- build_dir
- contracts
- deploy_dir
- generate_types
- network_for_target
- network_profile
- network_profile_by_name
- project_dir
- targets
- from_dir
- from_file
- nearest
Properties
DEFAULT_FILENAME
▪ Static
Readonly
DEFAULT_FILENAME: "cubist-config.json"
Defined in
submodules/cubist-node-sdk/src/config.ts:251
Accessors
allow_import_from_external
• get
allow_import_from_external(): boolean
Allows or disables imports from external sources (GitHub and npm/Yarn).
Returns
boolean
Defined in
submodules/cubist-node-sdk/src/config.ts:271
current_network_profile
• get
current_network_profile(): string
Selected network profile. If omitted, defaults to "default". A network
profile with the same name must be defined in network_profiles
.
Returns
string
Defined in
submodules/cubist-node-sdk/src/config.ts:265
type
• get
type(): ProjType
Project type
Returns
Defined in
submodules/cubist-node-sdk/src/config.ts:258
Methods
build_dir
▸ build_dir(): string
Get the absolute build directory.
Returns
string
the absolute build directory.
Defined in
submodules/cubist-node-sdk/src/config.ts:345
contracts
▸ contracts(): ContractsConfig
Get contracts config with paths "canonicalized" (cleaned up and absolute).
Returns
the contracts config.
Defined in
submodules/cubist-node-sdk/src/config.ts:361
deploy_dir
▸ deploy_dir(): string
Get the absolute deploy directory.
Returns
string
the absolute deploy directory.
Defined in
submodules/cubist-node-sdk/src/config.ts:318
generate_types
▸ generate_types(): Promise
<void
>
Generate TypeScript types for the configuration.
Returns
Promise
<void
>
Defined in
submodules/cubist-node-sdk/src/config.ts:411
network_for_target
▸ network_for_target(target
): EndpointConfig
Return configured network (if any) for a given target.
Parameters
Name | Type | Description |
---|---|---|
target | Target | the target name. |
Returns
the network config if it exists.
Defined in
submodules/cubist-node-sdk/src/config.ts:377
network_profile
▸ network_profile(): NetworkProfile
Return the currently selected network profile.
Returns
the current network profile.
Defined in
submodules/cubist-node-sdk/src/config.ts:396
network_profile_by_name
▸ network_profile_by_name(name
): NetworkProfile
Return the network profile by name.
Parameters
Name | Type | Description |
---|---|---|
name | string | profile name |
Returns
corresponding to a given name.
Defined in
submodules/cubist-node-sdk/src/config.ts:404
project_dir
▸ project_dir(): string
Get the absolute project directory.
Returns
string
the absolute project directory.
Defined in
submodules/cubist-node-sdk/src/config.ts:311
targets
▸ targets(): Target
[]
Return all targets.
Returns
Target
[]
the targets.
Defined in
submodules/cubist-node-sdk/src/config.ts:369
from_dir
▸ Static
from_dir(dir
): Config
Create configuration from directory (using default filename).
Parameters
Name | Type | Description |
---|---|---|
dir | string | the directory. |
Returns
the configuration.
Defined in
submodules/cubist-node-sdk/src/config.ts:293
from_file
▸ Static
from_file(config_path
): Config
Create configuration from JSON file.
Parameters
Name | Type | Description |
---|---|---|
config_path | string | Path to the configuration file. |
Returns
the configuration.
Defined in
submodules/cubist-node-sdk/src/config.ts:302
nearest
▸ Static
nearest(): Config
Create configuration from config file in the current directory or some parent directory.
Returns
the configuration.