( workingDir: string, args: MigrateSubgraphInputs, logger: Logger )
| 50 | }); |
| 51 | |
| 52 | async function migrateSubgraphAdapter( |
| 53 | workingDir: string, |
| 54 | args: MigrateSubgraphInputs, |
| 55 | logger: Logger |
| 56 | ): Promise<z.infer<typeof migrateSubgraphOutputs>> { |
| 57 | const gitMatch = extractGitInfo(args.input); |
| 58 | |
| 59 | const parsedSubqlPath = path.parse(path.resolve(workingDir, args.output)); |
| 60 | // We don't need to check output directory is existing or not |
| 61 | const subqlDir = parsedSubqlPath.ext === '' ? args.output : parsedSubqlPath.dir; |
| 62 | let subgraphDir: string; |
| 63 | let tempSubgraphDir: string | undefined; |
| 64 | if (gitMatch) { |
| 65 | tempSubgraphDir = await makeTempDir(); |
| 66 | const {branch, link} = gitMatch; |
| 67 | // clone the subdirectory project |
| 68 | if (args.gitSubDirectory) { |
| 69 | subgraphDir = path.join(tempSubgraphDir, args.gitSubDirectory); |
| 70 | await git(tempSubgraphDir).init().addRemote('origin', link); |
| 71 | await git(tempSubgraphDir).raw('sparse-checkout', 'set', args.gitSubDirectory); |
| 72 | assert(branch, 'Branch is required for git subdirectory'); |
| 73 | await git(tempSubgraphDir).raw('pull', 'origin', branch); |
| 74 | } else { |
| 75 | subgraphDir = tempSubgraphDir; |
| 76 | await git().clone(link, subgraphDir, branch ? ['-b', branch, '--single-branch'] : ['--single-branch']); |
| 77 | } |
| 78 | logger.info( |
| 79 | `* Pull subgraph project from git: ${link}, branch: ${branch ?? 'default branch'}${ |
| 80 | args.gitSubDirectory ? `, subdirectory:${args.gitSubDirectory}` : '.' |
| 81 | }` |
| 82 | ); |
| 83 | } else { |
| 84 | // will return false if directory not exist |
| 85 | if (lstatSync(path.resolve(workingDir, args.input), {throwIfNoEntry: false})?.isDirectory()) { |
| 86 | if (args.gitSubDirectory) { |
| 87 | logger.warn(`Git sub directory only works with git path, not local directories.`); |
| 88 | } |
| 89 | subgraphDir = args.input; |
| 90 | } else { |
| 91 | throw new Error(`Subgraph project should be a git ssh/link or file directory`); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | const subgraphManifestPath = path.join(subgraphDir, DEFAULT_SUBGRAPH_MANIFEST); |
| 96 | const subgraphSchemaPath = path.join(subgraphDir, DEFAULT_SUBGRAPH_SCHEMA); |
| 97 | const subqlManifestPath = path.join(subqlDir, DEFAULT_SUBQL_MANIFEST); |
| 98 | const subqlSchemaPath = path.join(subqlDir, DEFAULT_SUBQL_SCHEMA); |
| 99 | |
| 100 | try { |
| 101 | const subgraphManifest = readSubgraphManifest(subgraphManifestPath, subgraphDir); |
| 102 | improveProjectInfo(subgraphDir, subgraphManifest); |
| 103 | subgraphValidation(subgraphManifest); |
| 104 | const chainInfo = await extractNetworkFromManifest(subgraphManifest); |
| 105 | await prepareProject(chainInfo, subqlDir); |
| 106 | await migrateAbis(subgraphManifest, subgraphDir, subqlDir); |
| 107 | await migrateManifest(chainInfo, subgraphManifest, subqlManifestPath); |
| 108 | // render package.json |
| 109 | await preparePackage(subqlDir, { |
no test coverage detected