MCPcopy
hub / github.com/vercel/next.js / pullDocs

Function pullDocs

packages/next-codemod/lib/agents-md.ts:63–108  ·  view source on GitHub ↗
(options: PullOptions)

Source from the content-addressed store, hash-verified

61}
62
63export async function pullDocs(options: PullOptions): Promise<PullResult> {
64 const { cwd, version: versionOverride, docsDir } = options
65
66 let nextjsVersion: string
67
68 if (versionOverride) {
69 nextjsVersion = versionOverride
70 } else {
71 const versionResult = getNextjsVersion(cwd)
72 if (!versionResult.version) {
73 return {
74 success: false,
75 error: versionResult.error || 'Could not detect Next.js version',
76 }
77 }
78 nextjsVersion = versionResult.version
79 }
80
81 const docsPath =
82 docsDir ?? fs.mkdtempSync(path.join(os.tmpdir(), 'next-agents-md-'))
83 const useTempDir = !docsDir
84
85 try {
86 if (useTempDir && fs.existsSync(docsPath)) {
87 fs.rmSync(docsPath, { recursive: true })
88 }
89
90 const tag = versionToGitHubTag(nextjsVersion)
91 await cloneDocsFolder(tag, docsPath)
92
93 return {
94 success: true,
95 docsPath,
96 nextjsVersion,
97 }
98 } catch (error) {
99 if (useTempDir && fs.existsSync(docsPath)) {
100 fs.rmSync(docsPath, { recursive: true })
101 }
102
103 return {
104 success: false,
105 error: error instanceof Error ? error.message : String(error),
106 }
107 }
108}
109
110async function cloneDocsFolder(tag: string, destDir: string): Promise<void> {
111 const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'next-agents-md-'))

Callers 1

runAgentsMdFunction · 0.90

Calls 5

getNextjsVersionFunction · 0.85
versionToGitHubTagFunction · 0.85
cloneDocsFolderFunction · 0.85
StringFunction · 0.50
joinMethod · 0.45

Tested by

no test coverage detected