|
@@ -1,116 +0,0 @@
|
1
|
|
-import * as _ from 'lodash';
|
2
|
|
-import * as Typedoc from 'typedoc';
|
3
|
|
-import * as Handlebars from 'handlebars';
|
4
|
|
-import * as fs from 'fs';
|
5
|
|
-
|
6
|
|
-const ROOT_DIR = `${__dirname}/..`;
|
7
|
|
-const SRC_DIR = `${ROOT_DIR}/lib/src`;
|
8
|
|
-const DOCS_DIR = `${ROOT_DIR}/docs`;
|
9
|
|
-const TEMPLATES_DIR = `${DOCS_DIR}/templates`;
|
10
|
|
-const API_DIR = `${DOCS_DIR}/api`;
|
11
|
|
-
|
12
|
|
-class Main {
|
13
|
|
- public generateApiDocsMarkdown() {
|
14
|
|
- const moduleName = 'Navigation';
|
15
|
|
- const reflections = new ReflectionsReader().read(moduleName);
|
16
|
|
- const classRef = new Parser().parseClass(reflections);
|
17
|
|
- new MarkdownCreator().create(classRef);
|
18
|
|
- }
|
19
|
|
-}
|
20
|
|
-
|
21
|
|
-class MarkdownCreator {
|
22
|
|
- private handlebarsFn: HandlebarsTemplateDelegate<any>;
|
23
|
|
- constructor() {
|
24
|
|
- this.handlebarsFn = this.setupHandlebars();
|
25
|
|
- }
|
26
|
|
-
|
27
|
|
- public create(context: ClassReflection) {
|
28
|
|
-
|
29
|
|
- const result = this.handlebarsFn(context);
|
30
|
|
-
|
31
|
|
- // console.log(result);
|
32
|
|
- API_DIR.toString();
|
33
|
|
- }
|
34
|
|
-
|
35
|
|
- private setupHandlebars(): HandlebarsTemplateDelegate<any> {
|
36
|
|
- const mainTemplate = readFile(`${TEMPLATES_DIR}/main.hbs`);
|
37
|
|
- const classTemplate = readFile(`${TEMPLATES_DIR}/class.hbs`);
|
38
|
|
- const methodTemplate = readFile(`${TEMPLATES_DIR}/method.hbs`);
|
39
|
|
- Handlebars.registerPartial('class', classTemplate);
|
40
|
|
- Handlebars.registerPartial('method', methodTemplate);
|
41
|
|
- return Handlebars.compile(mainTemplate, { strict: true });
|
42
|
|
- }
|
43
|
|
-}
|
44
|
|
-
|
45
|
|
-interface ClassReflection {
|
46
|
|
- name: string;
|
47
|
|
- methods: MethodReflection[];
|
48
|
|
-}
|
49
|
|
-
|
50
|
|
-interface MethodReflection {
|
51
|
|
- name: string;
|
52
|
|
- argumentValues: string[];
|
53
|
|
- returnValue: string;
|
54
|
|
- comment: string;
|
55
|
|
- source: string;
|
56
|
|
-}
|
57
|
|
-
|
58
|
|
-class Parser {
|
59
|
|
- public parseClass(reflections): ClassReflection {
|
60
|
|
- const theModuleRaw = reflections.children[0];
|
61
|
|
- const theClassRaw = theModuleRaw.children[0];
|
62
|
|
-
|
63
|
|
- const methods = this.parseMethods(theClassRaw);
|
64
|
|
- const result = {
|
65
|
|
- name: theClassRaw.name,
|
66
|
|
- methods
|
67
|
|
- };
|
68
|
|
- return result;
|
69
|
|
- }
|
70
|
|
-
|
71
|
|
- private parseMethods(theClassRaw): MethodReflection[] {
|
72
|
|
- const methodsRaw = _.filter(theClassRaw.children, (child) => child.kind === Typedoc.ReflectionKind.Method);
|
73
|
|
- methodsRaw.toString();
|
74
|
|
- const result = [{
|
75
|
|
- name: 'theName',
|
76
|
|
- argumentValues: ['asd', 'zxc'],
|
77
|
|
- returnValue: 'returnVal',
|
78
|
|
- comment: 'bla bla bla',
|
79
|
|
- source: 'fromHere'
|
80
|
|
- }];
|
81
|
|
-
|
82
|
|
- return result;
|
83
|
|
- }
|
84
|
|
-}
|
85
|
|
-
|
86
|
|
-class ReflectionsReader {
|
87
|
|
- private typedocApp: Typedoc.Application;
|
88
|
|
- constructor() {
|
89
|
|
- const tsconfig = JSON.parse(readFile(`${ROOT_DIR}/tsconfig.json`));
|
90
|
|
- this.typedocApp = new Typedoc.Application({
|
91
|
|
- excludeExternals: true,
|
92
|
|
- excludePrivate: true,
|
93
|
|
- excludeProtected: true,
|
94
|
|
- includeDeclarations: true,
|
95
|
|
- module: 'commonjs',
|
96
|
|
- readme: 'none',
|
97
|
|
- target: 'ES6',
|
98
|
|
- ...tsconfig.compilerOptions
|
99
|
|
- });
|
100
|
|
- }
|
101
|
|
- read(moduleName) {
|
102
|
|
- return this.typedocApp.serializer.projectToObject(
|
103
|
|
- this.typedocApp.convert(
|
104
|
|
- this.typedocApp.expandInputFiles(
|
105
|
|
- [`${SRC_DIR}/${moduleName}.ts`]
|
106
|
|
- )
|
107
|
|
- )
|
108
|
|
- );
|
109
|
|
- }
|
110
|
|
-}
|
111
|
|
-
|
112
|
|
-function readFile(f) {
|
113
|
|
- return fs.readFileSync(f).toString();
|
114
|
|
-}
|
115
|
|
-
|
116
|
|
-new Main().generateApiDocsMarkdown();
|