-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
87 lines (73 loc) · 1.93 KB
/
index.ts
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
85
86
87
import fs from "fs"
import chalk from "chalk"
import meow from "meow"
import { Analyzer, generateAnalysis } from "polymer-analyzer"
import { FsUrlLoader, PackageUrlResolver } from "polymer-analyzer"
if (require.main === module) {
main()
}
export function main() {
cli().catch(error => {
console.error(error.stack || error.message || error)
process.exit(1)
})
}
export async function cli() {
const help = `
Usage
$ oo [directory]
Examples
$ oo .
`
const cli = meow(help, {})
if (cli.input.length === 0) {
cli.showHelp(0)
}
else {
console.log(chalk.green("*** " + (cli.pkg as any).description + " ***"))
console.log("")
const path = cli.input[0]
const result = await analyze(path)
console.log(result)
fs.writeFileSync("analysis.md", result)
}
}
export async function analyze(path: string): Promise<string> {
const analyzer = createForDirectory(path)
const input = await analyzer.analyzePackage()
const result = generateAnalysis(input, analyzer.urlResolver)
// console.log(process.cwd())
// console.log(JSON.stringify(result, null, 2))
const lines: string[] = []
if (result.elements) {
result.elements.forEach(it => {
lines.push(`## ${it.name}`)
lines.push("")
lines.push(`> element defined in ${it.path})`)
lines.push("")
if (it.description) {
lines.push(it.description)
lines.push("")
}
})
}
if (result.mixins) {
result.mixins.forEach(it => {
lines.push(`## ${it.name}`)
lines.push("")
lines.push(`> mixin defined in ${it.path})`)
lines.push("")
if (it.description) {
lines.push(it.description)
lines.push("")
}
})
}
return lines.join("\n")
}
export function createForDirectory(dirname: string): Analyzer {
return new Analyzer({
urlLoader: new FsUrlLoader(dirname),
urlResolver: new PackageUrlResolver({ packageDir: dirname })
})
}