vue-styleguidist / vue-styleguidist
1 1
import * as path from 'path'
2
import { SafeDocgenCLIConfig, Templates, RenderedUsage } from './config'
3 1
import singleMd, { DocgenCLIConfigWithOutFile } from './singleMd'
4 1
import multiMd from './multiMd'
5 1
import extractConfig from './extractConfig'
6 1
import getSources from './getSources'
7

8 1
export { SafeDocgenCLIConfig as DocgenCLIConfig, Templates, RenderedUsage, extractConfig }
9

10
export interface DocgenCLIConfigWithComponents extends SafeDocgenCLIConfig {
11
	components: string | string[]
12
}
13

14 1
function hasComponents(config: SafeDocgenCLIConfig): config is DocgenCLIConfigWithComponents {
15 1
	return !!config.components
16
}
17

18 1
export default async (config: SafeDocgenCLIConfig) => {
19
	// if at a level that has no components (top level) just give up
20 1
	if (!hasComponents(config)) {
21 0
		return
22
	}
23

24
	// if componentsRoot is not specified we start with current cwd
25 1
	config.componentsRoot = path.resolve(config.cwd, config.componentsRoot)
26
	// outdir can be specified as relative to cwd so absolutize it
27 1
	config.outDir = path.resolve(config.cwd, config.outDir)
28
	// outfile needs to be absolutized too. relative the outDir will allow us to
29
	// specify the root dir of docs no top of pages and build the path as we go
30
	// avoiding to repeat the start path
31 1
	config.outFile = config.outFile ? path.resolve(config.outDir, config.outFile) : undefined
32

33
	// then create the watcher if necessary
34 1
	const { watcher, componentFiles, docMap } = await getSources(
35
		config.components,
36
		config.componentsRoot,
37
		config.getDocFileName,
38
		config.apiOptions
39
	)
40

41 1
	if (config.outFile) {
42
		// create one combined documentation file
43 1
		await singleMd(componentFiles, watcher, config as DocgenCLIConfigWithOutFile, docMap)
44
	} else {
45
		// create one documentation file per component
46 1
		await multiMd(componentFiles, watcher, config, docMap)
47
	}
48

49 1
	if (!config.watch) {
50 1
		watcher.close()
51
	}
52
}

Read our documentation on viewing source code .

Loading