-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocs.js
More file actions
84 lines (66 loc) · 1.73 KB
/
Copy pathdocs.js
File metadata and controls
84 lines (66 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { pathExists, readJson } from "fs-extra"
import { basename, join, resolve } from "path"
module.exports = function(dot) {
if (dot.docs) {
return
}
dot.state.docs = {
args: {},
dependencies: {},
returns: {},
}
dot.any("args", args)
dot.any("dependencies", dependencies)
dot.any("returns", returns)
dot("args", "docs", {
path: {
alias: ["_", "p"],
default: process.cwd(),
},
})
dot("dependencies", "docs", {
arg: ["@dot-event/args", "@dot-event/glob"],
})
dot.any("docs", docs)
}
async function docs(prop, arg, dot) {
let { path } = arg
path = resolve(Array.isArray(path) ? path[0] : path)
const pkgJsonPath = join(path, "package.json")
const readmePath = join(path, "README.md")
if (
!(await pathExists(pkgJsonPath)) ||
!(await pathExists(readmePath))
) {
return
}
const pkgPath = (await readJson(pkgJsonPath)).main
require(join(path, pkgPath))(dot)
const paths = await dot.glob(prop, {
absolute: true,
pattern: join(path, "docs/*.md"),
})
for (const doc of paths) {
const event = basename(doc, ".md")
const args = dot.state.docs.args[event]
const dependencies = dot.state.docs.dependencies[event]
const returns = dot.state.docs.returns[event]
dot("log", "info", event, "dependencies", {
arg: dependencies,
})
dot("log", "info", event, "args", args)
dot("log", "info", event, "returns", returns)
}
}
function args(prop, arg, dot) {
const state = dot.state.docs.args
state[prop[0]] = arg
}
function dependencies(prop, arg, dot) {
const state = dot.state.docs.dependencies
state[prop[0]] = arg
}
function returns(prop, arg, dot) {
const state = dot.state.docs.returns
state[prop[0]] = arg
}