1 1
import * as fs from 'fs'
2 1
import * as path from 'path'
3 1
import parseVue from './parseVue'
4

5 1
const readSeparateScriptFile = (fileName: string) => {
6 0
	return fs.readFileSync(fileName, { encoding: 'utf-8' })
7
}
8

9 1
export default function getComponentVueDoc(source: string, file: string): string | false {
10 0
	const parts = parseVue(source, file)
11

12 1
	if (parts.customBlocks) {
13 0
		const docBlocks = parts.customBlocks.filter(block => block.type === 'docs')[0]
14 1
		if (docBlocks && docBlocks.src) {
15 0
			const jsFilePath = path.join(path.dirname(file), docBlocks.src)
16 0
			return readSeparateScriptFile(jsFilePath)
17 1
		} else if (docBlocks && docBlocks.content) {
18 0
			return docBlocks.content
19
		}
20
	}
21 0
	return false
22
}

Read our documentation on viewing source code .

Loading