( projectPaths: string[], authToken?: string, multichainProjectPath?: string, ipfsEndpoint?: string, directory?: string )
| 29 | } |
| 30 | |
| 31 | export async function uploadToIpfs( |
| 32 | projectPaths: string[], |
| 33 | authToken?: string, |
| 34 | multichainProjectPath?: string, |
| 35 | ipfsEndpoint?: string, |
| 36 | directory?: string |
| 37 | ): Promise<Map<string, string>> { |
| 38 | const projectToReader: Record<string, Reader> = {}; |
| 39 | |
| 40 | await Promise.all( |
| 41 | projectPaths.map(async (projectPath) => { |
| 42 | const reader = await ReaderFactory.create(projectPath); |
| 43 | projectToReader[projectPath] = reader; |
| 44 | }) |
| 45 | ); |
| 46 | |
| 47 | const contents: {path: string; content: string}[] = []; |
| 48 | |
| 49 | let ipfs: IPFSHTTPClientLite | undefined; |
| 50 | if (ipfsEndpoint) { |
| 51 | ipfs = new IPFSHTTPClientLite({url: ipfsEndpoint}); |
| 52 | } |
| 53 | |
| 54 | for (const project in projectToReader) { |
| 55 | const reader = projectToReader[project]; |
| 56 | const schema = await reader.getProjectSchema(); |
| 57 | |
| 58 | validateCommonProjectManifest(schema); |
| 59 | |
| 60 | const networkFamily = getProjectNetwork(schema); |
| 61 | const module = loadDependency(networkFamily, project); |
| 62 | assert(module, `Failed to load module for network ${networkFamily}`); |
| 63 | |
| 64 | let manifest; |
| 65 | |
| 66 | try { |
| 67 | manifest = module.parseProjectManifest(schema).asImpl; |
| 68 | } catch (e) { |
| 69 | throw new Error(`Failed to parse project manifest for network ${networkFamily}`, {cause: e}); |
| 70 | } |
| 71 | |
| 72 | if (manifest === null) { |
| 73 | throw new Error('Unable to parse project manifest'); |
| 74 | } |
| 75 | |
| 76 | assert(reader.root, 'Reader root is not set'); |
| 77 | // the JSON object conversion must occur on manifest.deployment |
| 78 | const deployment = await replaceFileReferences(reader.root, manifest.deployment, authToken, ipfs); |
| 79 | |
| 80 | // Use JSON.* to convert Map to Object |
| 81 | contents.push({ |
| 82 | path: path.join(directory ?? '', path.basename(project)), |
| 83 | content: deployment.toYaml(), |
| 84 | }); |
| 85 | } |
| 86 | |
| 87 | if (multichainProjectPath) { |
| 88 | const content = fs.readFileSync(multichainProjectPath); |
no test coverage detected