Browse Source

gen-docs WIP

Daniel Zlotin 6 years ago
parent
commit
76533af4d1

+ 2
- 2
docs/_sidebar.md View File

@@ -2,10 +2,10 @@
2 2
   - [Installing](/docs/Installing)
3 3
   - [Working Locally](/docs/WorkingLocally)
4 4
   - [Usage](/docs/Usage)
5
-- API
5
+- Guide
6 6
   - [Top Level](/docs/top-level-api)
7 7
   - [Screen](/docs/screen-api)
8
-  - [Layout types](/docs/layout-types)
8
+  - [Layout Types](/docs/layout-types)
9 9
   - [Styling](/docs/styling)
10 10
 - Migration from v1
11 11
   - [Top Level](/docs/top-level-api-migration)

+ 188
- 0
docs/api/Navigation.md View File

@@ -0,0 +1,188 @@
1
+# Navigation
2
+
3
+## Properties
4
+
5
+- Element (any)
6
+
7
+## Methods
8
+
9
+### `registerComponent(componentName: string, getComponentClassFunc: ComponentProvider): void`
10
+
11
+[source](/lib/src//Navigation.ts#52)
12
+
13
+Every navigation component in your app must be registered with a unique name.
14
+The component itself is a traditional React component extending React.Component.
15
+
16
+#### Arguments
17
+- componentName (string)
18
+- getComponentClassFunc (ComponentProvider)
19
+
20
+#### Returns
21
+- (void)
22
+
23
+### `setRoot(layout: any): Promise<any>`
24
+
25
+[source](/lib/src//Navigation.ts#59)
26
+
27
+Reset the app to a new layout
28
+
29
+#### Arguments
30
+- layout (any)
31
+
32
+#### Returns
33
+- (Promise<any>)
34
+
35
+### `setDefaultOptions(options: any): void`
36
+
37
+[source](/lib/src//Navigation.ts#66)
38
+
39
+Set default options to all screens. Useful for declaring a consistent style across the app.
40
+
41
+#### Arguments
42
+- options (any)
43
+
44
+#### Returns
45
+- (void)
46
+
47
+### `mergeOptions(componentId: string, options: any): void`
48
+
49
+[source](/lib/src//Navigation.ts#73)
50
+
51
+Change a component's navigation options
52
+
53
+#### Arguments
54
+- componentId (string)
55
+- options (any)
56
+
57
+#### Returns
58
+- (void)
59
+
60
+### `showModal(layout: any): Promise<any>`
61
+
62
+[source](/lib/src//Navigation.ts#80)
63
+
64
+Show a screen as a modal.
65
+
66
+#### Arguments
67
+- layout (any)
68
+
69
+#### Returns
70
+- (Promise<any>)
71
+
72
+### `dismissModal(componentId: string): Promise<any>`
73
+
74
+[source](/lib/src//Navigation.ts#87)
75
+
76
+Dismiss a modal by componentId. The dismissed modal can be anywhere in the stack.
77
+
78
+#### Arguments
79
+- componentId (string)
80
+
81
+#### Returns
82
+- (Promise<any>)
83
+
84
+### `dismissAllModals(): Promise<any>`
85
+
86
+[source](/lib/src//Navigation.ts#94)
87
+
88
+Dismiss all Modals
89
+
90
+#### Returns
91
+- (Promise<any>)
92
+
93
+### `push(componentId: string, layout: any): Promise<any>`
94
+
95
+[source](/lib/src//Navigation.ts#101)
96
+
97
+Push a new layout into this screen's navigation stack.
98
+
99
+#### Arguments
100
+- componentId (string)
101
+- layout (any)
102
+
103
+#### Returns
104
+- (Promise<any>)
105
+
106
+### `pop(componentId: string, params: any): Promise<any>`
107
+
108
+[source](/lib/src//Navigation.ts#108)
109
+
110
+Pop a component from the stack, regardless of it's position.
111
+
112
+#### Arguments
113
+- componentId (string)
114
+- params (any)
115
+
116
+#### Returns
117
+- (Promise<any>)
118
+
119
+### `popTo(componentId: string): Promise<any>`
120
+
121
+[source](/lib/src//Navigation.ts#115)
122
+
123
+Pop the stack to a given component
124
+
125
+#### Arguments
126
+- componentId (string)
127
+
128
+#### Returns
129
+- (Promise<any>)
130
+
131
+### `popToRoot(componentId: string): Promise<any>`
132
+
133
+[source](/lib/src//Navigation.ts#122)
134
+
135
+Pop the component's stack to root.
136
+
137
+#### Arguments
138
+- componentId (string)
139
+
140
+#### Returns
141
+- (Promise<any>)
142
+
143
+### `setStackRoot(componentId: string, layout: any): Promise<any>`
144
+
145
+[source](/lib/src//Navigation.ts#129)
146
+
147
+Sets new root component to stack.
148
+
149
+#### Arguments
150
+- componentId (string)
151
+- layout (any)
152
+
153
+#### Returns
154
+- (Promise<any>)
155
+
156
+### `showOverlay(layout: any): Promise<any>`
157
+
158
+[source](/lib/src//Navigation.ts#136)
159
+
160
+Show overlay on top of the entire app
161
+
162
+#### Arguments
163
+- layout (any)
164
+
165
+#### Returns
166
+- (Promise<any>)
167
+
168
+### `dismissOverlay(componentId: string): Promise<any>`
169
+
170
+[source](/lib/src//Navigation.ts#143)
171
+
172
+dismiss overlay by componentId
173
+
174
+#### Arguments
175
+- componentId (string)
176
+
177
+#### Returns
178
+- (Promise<any>)
179
+
180
+### `events(): EventsRegistry`
181
+
182
+[source](/lib/src//Navigation.ts#150)
183
+
184
+Obtain the events registry instance
185
+
186
+#### Returns
187
+- (EventsRegistry)
188
+

+ 1
- 1
package.json View File

@@ -44,7 +44,7 @@
44 44
     "prerelease": "npm run build",
45 45
     "release": "node ./scripts/release",
46 46
     "local-docs": "node ./scripts/local-docs",
47
-    "gen-docs": "echo 'This is a work in progress'"
47
+    "gen-docs": "echo 'this is a work in progress!!!' && ts-node ./scripts/gen-docs/Main"
48 48
   },
49 49
   "peerDependencies": {
50 50
     "react": "*",

+ 0
- 7
scripts/gen-doc.js View File

@@ -1,7 +0,0 @@
1
-const exec = require('shell-utils').exec;
2
-
3
-run();
4
-
5
-function run() {
6
-  exec.execSync(`ts-node `);
7
-}

+ 33
- 0
scripts/gen-docs/Main.ts View File

@@ -0,0 +1,33 @@
1
+import * as fs from 'fs';
2
+import { ReflectionsReader } from './ReflectionsReader';
3
+import { MarkdownCreator } from './MarkdownCreator';
4
+import * as Handlebars from 'handlebars';
5
+
6
+const MD_RELATIVE_LINK = `/lib/src/`;
7
+const OUTPUT_DIR = `${__dirname}/../../docs/api`;
8
+const TEMPLATES_DIR = `${__dirname}/templates`;
9
+const TSCONFIG = JSON.parse(fs.readFileSync(`${__dirname}/../../tsconfig.json`).toString());
10
+
11
+class Main {
12
+  public run() {
13
+    const handlebarsFn = this.setupHandlebars();
14
+
15
+    const reflection = new ReflectionsReader(TSCONFIG).read('./lib/src/Navigation.ts');
16
+    const markdown = new MarkdownCreator(MD_RELATIVE_LINK, handlebarsFn).create(reflection);
17
+
18
+    fs.writeFileSync(`${OUTPUT_DIR}/Navigation.md`, markdown, { encoding: 'utf8' });
19
+  }
20
+
21
+  private setupHandlebars() {
22
+    const mainTemplate = fs.readFileSync(`${TEMPLATES_DIR}/main.hbs`).toString();
23
+    const classTemplate = fs.readFileSync(`${TEMPLATES_DIR}/class.hbs`).toString();
24
+    const methodTemplate = fs.readFileSync(`${TEMPLATES_DIR}/method.hbs`).toString();
25
+
26
+    Handlebars.registerPartial('class', classTemplate);
27
+    Handlebars.registerPartial('method', methodTemplate);
28
+
29
+    return Handlebars.compile(mainTemplate, { strict: true, noEscape: true });
30
+  }
31
+}
32
+
33
+new Main().run();

scripts/gen-doc/MarkdownCreator.ts → scripts/gen-docs/MarkdownCreator.ts View File

@@ -2,10 +2,8 @@ import * as Handlebars from 'handlebars';
2 2
 import * as Typedoc from 'typedoc';
3 3
 import * as fs from 'fs';
4 4
 
5
-const TEMPLATES_DIR = `./src/templates`;
6
-
7 5
 export class MarkdownCreator {
8
-  constructor(private handlebarsFn: HandlebarsTemplateDelegate<any>) { }
6
+  constructor(private mdRelativeLinkPath: string, private handlebarsFn: HandlebarsTemplateDelegate<any>) { }
9 7
 
10 8
   public create(reflection: Typedoc.DeclarationReflection) {
11 9
     const context = {
@@ -25,7 +23,7 @@ export class MarkdownCreator {
25 23
       name: methodReflection.name,
26 24
       arguments: this.readArguments(methodReflection.signatures[0].parameters || []),
27 25
       returnType: methodReflection.signatures[0].type.toString(),
28
-      source: `/docs/api/${methodReflection.sources[0].fileName}#${methodReflection.sources[0].line}`,
26
+      source: `${this.mdRelativeLinkPath}/${methodReflection.sources[0].fileName}#${methodReflection.sources[0].line}`,
29 27
       comment: methodReflection.signatures[0].comment ? methodReflection.signatures[0].comment.shortText : ''
30 28
     }));
31 29
   }
@@ -44,13 +42,4 @@ export class MarkdownCreator {
44 42
       type: propReflection.type.toString()
45 43
     }));
46 44
   }
47
-
48
-  private setupTemplates() {
49
-    const mainTemplate = fs.readFileSync(`${TEMPLATES_DIR}/main.hbs`).toString();
50
-    const classTemplate = fs.readFileSync(`${TEMPLATES_DIR}/class.hbs`).toString();
51
-    const methodTemplate = fs.readFileSync(`${TEMPLATES_DIR}/method.hbs`).toString();
52
-    Handlebars.registerPartial('class', classTemplate);
53
-    Handlebars.registerPartial('method', methodTemplate);
54
-    return Handlebars.compile(mainTemplate, { strict: true });
55
-  }
56 45
 }

scripts/gen-doc/ReflectionsReader.ts → scripts/gen-docs/ReflectionsReader.ts View File

@@ -4,6 +4,7 @@ const OPTIONS = {
4 4
   excludeExternals: true,
5 5
   excludePrivate: true,
6 6
   includeDeclarations: true,
7
+  mode: 'modules',
7 8
   module: 'commonjs',
8 9
   readme: 'none',
9 10
   target: 'ES6'
@@ -12,13 +13,14 @@ const OPTIONS = {
12 13
 export class ReflectionsReader {
13 14
   private typedocApp: Typedoc.Application;
14 15
 
15
-  constructor() {
16
-    this.typedocApp = new Typedoc.Application(OPTIONS);
16
+  constructor(tsconfig) {
17
+    this.typedocApp = new Typedoc.Application({ ...OPTIONS, ...tsconfig.compilerOptions });
17 18
   }
18 19
 
19 20
   public read(modulePath: string): Typedoc.DeclarationReflection {
20 21
     const expandedFiles = this.typedocApp.expandInputFiles([modulePath]);
21 22
     const projectReflection = this.typedocApp.convert(expandedFiles);
23
+    // console.log(JSON.stringify(this.typedocApp.serializer.projectToObject(projectReflection)));
22 24
     const externalModule = projectReflection.getChildrenByKind(Typedoc.ReflectionKind.ExternalModule)[0];
23 25
     const classReflection = externalModule.getChildrenByKind(Typedoc.ReflectionKind.Class)[0];
24 26
     return classReflection;

scripts/gen-doc/templates/class.hbs → scripts/gen-docs/templates/class.hbs View File


scripts/gen-doc/templates/main.hbs → scripts/gen-docs/templates/main.hbs View File


scripts/gen-doc/templates/method.hbs → scripts/gen-docs/templates/method.hbs View File