( reader: Reader, root: string, file: string, )
| 36 | } |
| 37 | |
| 38 | export async function getChainTypes( |
| 39 | reader: Reader, |
| 40 | root: string, |
| 41 | file: string, |
| 42 | ): Promise<ChainTypes> { |
| 43 | // If the project is load from local, we will direct load them |
| 44 | let raw: unknown; |
| 45 | if (reader instanceof LocalReader) { |
| 46 | raw = loadChainTypes(file, root); |
| 47 | } else { |
| 48 | // If it is stored in ipfs or other resources, we will use the corresponding reader to read the file |
| 49 | // Because ipfs not provide extension of the file, it is difficult to determine its format |
| 50 | // We will use yaml.load to try to load the script and parse them to supported chain types |
| 51 | // if it failed, we will give it another attempt, and assume the script written in js |
| 52 | // we will download it to a temp folder, and load them within sandbox |
| 53 | const res = await reader.getFile(file); |
| 54 | try { |
| 55 | raw = yaml.load(res); |
| 56 | } catch (e) { |
| 57 | const chainTypesPath = await saveFile(reader, root, file, res); |
| 58 | raw = loadChainTypesFromJs(chainTypesPath); //root not required, as it been packed in single js |
| 59 | } |
| 60 | } |
| 61 | return parseChainTypes(raw); |
| 62 | } |
| 63 | |
| 64 | export function loadChainTypes(file: string, projectRoot: string): unknown { |
| 65 | const { ext } = path.parse(file); |
no test coverage detected