(file: string, projectRoot: string)
| 62 | } |
| 63 | |
| 64 | export function loadChainTypes(file: string, projectRoot: string): unknown { |
| 65 | const { ext } = path.parse(file); |
| 66 | const filePath = path.resolve(projectRoot, file); |
| 67 | if (fs.existsSync(filePath)) { |
| 68 | if (ext === '.js' || ext === '.cjs') { |
| 69 | //load can be self contained js file, or js depend on node_module which will require project root |
| 70 | return loadChainTypesFromJs(filePath, projectRoot); |
| 71 | } else if (ext === '.yaml' || ext === '.yml' || ext === '.json') { |
| 72 | return loadFromJsonOrYaml(filePath); |
| 73 | } else { |
| 74 | throw new Error(`Extension ${ext} not supported`); |
| 75 | } |
| 76 | } else { |
| 77 | throw new Error(`Load from file ${file} not exist`); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | export function loadChainTypesFromJs( |
| 82 | filePath: string, |
no test coverage detected