(reader: Reader, root: string, file: string, data: string, ext = 'js')
| 191 | } |
| 192 | |
| 193 | export async function saveFile(reader: Reader, root: string, file: string, data: string, ext = 'js'): Promise<string> { |
| 194 | if (!(reader instanceof IPFSReader || reader instanceof GithubReader)) { |
| 195 | throw new Error('Only IPFS and Github readers can save remote files'); |
| 196 | } |
| 197 | const resolved = path.resolve(root, file.replace('ipfs://', '')); |
| 198 | const outputPath = ext ? `${resolved}.${ext}` : resolved; |
| 199 | if (fs.existsSync(outputPath)) { |
| 200 | return outputPath; |
| 201 | } |
| 202 | await fs.promises.writeFile(outputPath, data); |
| 203 | return outputPath; |
| 204 | } |
| 205 | |
| 206 | export async function loadDataSourceScript(reader: Reader, file?: string): Promise<string> { |
| 207 | let entry = file; |
no outgoing calls
no test coverage detected