-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
39 lines (33 loc) · 953 Bytes
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const fs = require("fs");
const {findFileInDirectory} = require("./find");
const getDefaultConfigPath = () => {
const currentWorkingDirectory = process.cwd();
return `${currentWorkingDirectory}/flow.json`
}
const getConfig = (path) => {
const data = fs.readFileSync(path, 'utf8')
try {
return JSON.parse(data)
} catch (parseError) {
throw new Error(`Failed to parse config file ${parseError}`)
}
}
const getContractCode = (contractName) => {
const path = findFileInDirectory(`${__dirname}/contracts`, `${contractName}.cdc`)
return fs.readFileSync(path, 'utf8')
}
const writeConfig = (path, config) => {
const jsonData = JSON.stringify(config, null, 2)
fs.writeFileSync(path, jsonData);
}
const getProjectConfig = () => {
const configLocation = `${__dirname}/flow.json`
return getConfig(configLocation)
}
module.exports = {
getContractCode,
getDefaultConfigPath,
getConfig,
getProjectConfig,
writeConfig
}