Skip to content

Commit bb3b19e

Browse files
committed
@truffle/config migrated to typescript
1 parent 260e55e commit bb3b19e

File tree

13 files changed

+420
-883
lines changed

13 files changed

+420
-883
lines changed

packages/config/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules
22
yarn.lock
33
package-lock.json
4+
dist

packages/config/index.js

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

packages/config/package.json

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
"name": "@truffle/config",
33
"version": "1.1.21",
44
"description": "Utility for interacting with truffle-config.js files",
5-
"main": "index.js",
6-
"typings": "./typings/index.d.ts",
5+
"main": "dist/index.js",
6+
"typings": "dist/index.d.ts",
77
"scripts": {
8-
"test": "mocha"
8+
"build": "tsc",
9+
"prepare": "yarn build",
10+
"test": "yarn build && mocha --exit -r ts-node/register test/**/*.test.ts"
911
},
1012
"repository": "https://github.com/trufflesuite/truffle/tree/master/packages/config",
1113
"keywords": [
@@ -19,6 +21,14 @@
1921
"url": "https://github.com/trufflesuite/truffle/issues"
2022
},
2123
"homepage": "https://github.com/trufflesuite/truffle/tree/master/packages/config#readme",
24+
"devDependencies": {
25+
"@types/configstore": "^4.0.0",
26+
"@types/find-up": "^2.1.0",
27+
"@types/node": "^12.7.7",
28+
"mocha": "6.2.0",
29+
"ts-node": "^8.4.1",
30+
"typescript": "^3.6.3"
31+
},
2232
"dependencies": {
2333
"@truffle/error": "^0.0.7",
2434
"@truffle/provider": "^0.1.17",
@@ -29,8 +39,5 @@
2939
},
3040
"publishConfig": {
3141
"access": "public"
32-
},
33-
"devDependencies": {
34-
"mocha": "5.2.0"
3542
}
3643
}
Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
1-
const path = require("path");
2-
const _ = require("lodash");
3-
const Provider = require("@truffle/provider");
1+
import * as path from 'path';
2+
import lodash from 'lodash';
3+
import Provider from '@truffle/provider';
4+
import TruffleConfig from './';
5+
6+
export const getInitialConfig = ({
7+
truffleDirectory,
8+
workingDirectory,
9+
network,
10+
}: {
11+
truffleDirectory?: string;
12+
workingDirectory?: string;
13+
network?: string;
14+
}) => {
15+
const truffle_directory = truffleDirectory || path.resolve(path.join(__dirname, '../'));
16+
const working_directory = workingDirectory || process.cwd();
417

5-
// This is a list of multi-level keys with defaults
6-
// we need to _.merge. Using this list for safety
7-
// vs. just merging all objects.
8-
const _values = ({ truffleDirectory, workingDirectory, network }) => {
918
return {
10-
truffle_directory:
11-
truffleDirectory || path.resolve(path.join(__dirname, "../")),
12-
working_directory: workingDirectory || process.cwd(),
19+
truffle_directory,
20+
working_directory,
1321
network,
1422
networks: {},
1523
verboseRpc: false,
@@ -42,34 +50,38 @@ const _values = ({ truffleDirectory, workingDirectory, network }) => {
4250
vyper: {}
4351
},
4452
logger: {
45-
log() {}
53+
log() { }
4654
}
4755
};
4856
};
4957

50-
const configProps = ({ configObject }) => {
51-
const resolveDirectory = value => {
52-
return path.resolve(configObject.working_directory, value);
53-
};
58+
export const configProps = ({
59+
configObject
60+
}: {
61+
configObject: TruffleConfig
62+
}) => {
63+
const resolveDirectory = (value: string): string =>
64+
path.resolve(configObject.working_directory, value);
5465

5566
const defaultTXValues = {
5667
gas: 6721975,
5768
gasPrice: 20000000000, // 20 gwei,
58-
from: null
69+
from: null,
5970
};
71+
6072
return {
6173
// These are already set.
62-
truffle_directory() {},
63-
working_directory() {},
64-
network() {},
65-
networks() {},
66-
verboseRpc() {},
67-
build() {},
68-
resolver() {},
69-
artifactor() {},
70-
ethpm() {},
71-
logger() {},
72-
compilers() {},
74+
truffle_directory() { },
75+
working_directory() { },
76+
network() { },
77+
networks() { },
78+
verboseRpc() { },
79+
build() { },
80+
resolver() { },
81+
artifactor() { },
82+
ethpm() { },
83+
logger() { },
84+
compilers() { },
7385

7486
build_directory: {
7587
default: () => path.join(configObject.working_directory, "build"),
@@ -123,15 +135,15 @@ const configProps = ({ configObject }) => {
123135
throw new Error("Network not set. Cannot determine network to use.");
124136
}
125137

126-
let conf = configObject.networks[network];
138+
let config = configObject.networks[network];
127139

128-
if (conf === null || conf === undefined) {
140+
if (config === null || config === undefined) {
129141
config = {};
130142
}
131143

132-
conf = _.extend({}, defaultTXValues, conf);
144+
config = lodash.extend({}, defaultTXValues, config);
133145

134-
return conf;
146+
return config;
135147
},
136148
set() {
137149
throw new Error(
@@ -241,9 +253,4 @@ const configProps = ({ configObject }) => {
241253
}
242254
}
243255
};
244-
};
245-
246-
module.exports = {
247-
_values,
248-
configProps
249-
};
256+
};

0 commit comments

Comments
 (0)