Kaynağa Gözat

docs support enum generationg

Daniel Zlotin 6 yıl önce
ebeveyn
işleme
6e45d79192

+ 11
- 0
docs/api/LayoutType.md Dosyayı Görüntüle

@@ -0,0 +1,11 @@
1
+# LayoutType
2
+
3
+- BottomTabs
4
+- Component
5
+- ExternalComponent
6
+- SideMenuCenter
7
+- SideMenuLeft
8
+- SideMenuRight
9
+- SideMenuRoot
10
+- Stack
11
+- TopTabs

+ 1
- 0
docs/api/README.md Dosyayı Görüntüle

@@ -14,3 +14,4 @@
14 14
 - [CommandsObserver](/api/CommandsObserver)
15 15
 - [ComponentEventsObserver](/api/ComponentEventsObserver)
16 16
 - [EventsRegistry](/api/EventsRegistry)
17
+- [LayoutType](/api/LayoutType)

+ 1
- 0
docs/api/_sidebar.md Dosyayı Görüntüle

@@ -14,3 +14,4 @@
14 14
 - [CommandsObserver](/api/CommandsObserver)
15 15
 - [ComponentEventsObserver](/api/ComponentEventsObserver)
16 16
 - [EventsRegistry](/api/EventsRegistry)
17
+- [LayoutType](/api/LayoutType)

+ 8
- 4
scripts/gen-docs/ClassParser.ts Dosyayı Görüntüle

@@ -28,11 +28,15 @@ export interface ClassContext {
28 28
 export class ClassParser {
29 29
   constructor(private sourceLinkPrefix: string) { }
30 30
 
31
-  public parseClass(reflection: Typedoc.DeclarationReflection): ClassContext {
31
+  public parseClasses(classReflections: Typedoc.DeclarationReflection[]): ClassContext[] {
32
+    return classReflections.map((r) => this.parseClass(r));
33
+  }
34
+
35
+  private parseClass(classReflection: Typedoc.DeclarationReflection): ClassContext {
32 36
     return {
33
-      name: reflection.name,
34
-      properties: this.parseProperties(reflection),
35
-      methods: this.parseMethods(reflection)
37
+      name: classReflection.name,
38
+      properties: this.parseProperties(classReflection),
39
+      methods: this.parseMethods(classReflection)
36 40
     };
37 41
   }
38 42
 

+ 19
- 0
scripts/gen-docs/EnumParser.ts Dosyayı Görüntüle

@@ -0,0 +1,19 @@
1
+import { DeclarationReflection, ReflectionKind } from 'typedoc';
2
+
3
+export interface EnumContext {
4
+  name: string;
5
+  values: string[];
6
+}
7
+
8
+export class EnumParser {
9
+  public parse(enumReflections: DeclarationReflection[]): EnumContext[] {
10
+    return enumReflections.map((r) => this.parseEnum(r));
11
+  }
12
+
13
+  private parseEnum(enumReflection: DeclarationReflection): EnumContext {
14
+    return {
15
+      name: enumReflection.name,
16
+      values: enumReflection.getChildrenByKind(ReflectionKind.EnumMember).map((child) => child.name)
17
+    };
18
+  }
19
+}

+ 5
- 2
scripts/gen-docs/Main.ts Dosyayı Görüntüle

@@ -3,6 +3,7 @@ import { ReflectionsReader } from './ReflectionsReader';
3 3
 import { ClassParser } from './ClassParser';
4 4
 import { MarkdownWriter } from './MarkdownWriter';
5 5
 import { ReflectionKind } from 'typedoc';
6
+import { EnumParser } from './EnumParser';
6 7
 
7 8
 const INPUT_DIR = `${__dirname}/../../lib/src`;
8 9
 const OUTPUT_DIR = `${__dirname}/../../docs/api`;
@@ -16,9 +17,11 @@ class Main {
16 17
     const markdownWriter = new MarkdownWriter(TEMPLATES_DIR, OUTPUT_DIR);
17 18
     const reflections = new ReflectionsReader(TSCONFIG_PATH).read(INPUT_DIR);
18 19
 
19
-    const parsedClasses = reflections.classReflections.map((c) => classParser.parseClass(c));
20
+    const parsedClasses = classParser.parseClasses(reflections.classReflections);
21
+    const parsedEnums = new EnumParser().parse(reflections.enumReflections);
20 22
     markdownWriter.writeClasses(parsedClasses);
21
-    markdownWriter.writeMenu(parsedClasses);
23
+    markdownWriter.writeEnums(parsedEnums);
24
+    markdownWriter.writeMenu(parsedClasses, parsedEnums);
22 25
   }
23 26
 }
24 27
 

+ 21
- 4
scripts/gen-docs/MarkdownWriter.ts Dosyayı Görüntüle

@@ -1,25 +1,37 @@
1
+import * as _ from 'lodash';
1 2
 import * as Handlebars from 'handlebars';
2 3
 import * as fs from 'fs';
3 4
 import { ClassContext } from './ClassParser';
5
+import { EnumContext } from './EnumParser';
4 6
 
5 7
 export class MarkdownWriter {
6 8
   private classFn;
9
+  private enumFn;
7 10
   private menuFn;
8 11
   constructor(private templatesDir: string, private outputDir: string) {
9 12
     this.classFn = this.setupClassHandlebars();
13
+    this.enumFn = this.setupEnumHandlebars();
10 14
     this.menuFn = this.setupMenuHandlebars();
11 15
   }
12 16
 
13 17
   public writeClasses(classContexts: ClassContext[]) {
14 18
     classContexts.forEach((c) => {
15
-      const classMarkdown = this.classFn(c);
16
-      fs.writeFileSync(`${this.outputDir}/${c.name}.md`, classMarkdown, { encoding: 'utf8' });
19
+      const markdown = this.classFn(c);
20
+      fs.writeFileSync(`${this.outputDir}/${c.name}.md`, markdown, { encoding: 'utf8' });
17 21
     });
18 22
   }
19 23
 
20
-  public writeMenu(classContexts: ClassContext[]) {
24
+  public writeEnums(enumContexts: EnumContext[]) {
25
+    enumContexts.forEach((c) => {
26
+      const markdown = this.enumFn(c);
27
+      fs.writeFileSync(`${this.outputDir}/${c.name}.md`, markdown, { encoding: 'utf8' });
28
+    });
29
+  }
30
+
31
+  public writeMenu(classContexts: ClassContext[], enumContexts: EnumContext[]) {
21 32
     const files = classContexts.map((c) => ({ name: c.name, path: `/api/${c.name}` }));
22
-    const menuMarkdown = this.menuFn({ files });
33
+    const files2 = enumContexts.map((c) => ({ name: c.name, path: `/api/${c.name}` }));
34
+    const menuMarkdown = this.menuFn({ files: _.concat(files, files2) });
23 35
     fs.writeFileSync(`${this.outputDir}/_sidebar.md`, menuMarkdown, { encoding: 'utf8' });
24 36
     fs.writeFileSync(`${this.outputDir}/README.md`, menuMarkdown, { encoding: 'utf8' });
25 37
   }
@@ -36,6 +48,11 @@ export class MarkdownWriter {
36 48
     return Handlebars.compile('{{> class}}', { strict: true, noEscape: true });
37 49
   }
38 50
 
51
+  private setupEnumHandlebars() {
52
+    const enumTemplate = fs.readFileSync(`${this.templatesDir}/enum.hbs`).toString();
53
+    return Handlebars.compile(enumTemplate, { strict: true, noEscape: true });
54
+  }
55
+
39 56
   private setupMenuHandlebars() {
40 57
     const template = fs.readFileSync(`${this.templatesDir}/menu.hbs`).toString();
41 58
     return Handlebars.compile(template, { strict: true, noEscape: true });

+ 8
- 5
scripts/gen-docs/ReflectionsReader.ts Dosyayı Görüntüle

@@ -13,6 +13,7 @@ const OPTIONS = {
13 13
 
14 14
 export interface Reflections {
15 15
   classReflections: DeclarationReflection[];
16
+  enumReflections: DeclarationReflection[];
16 17
 }
17 18
 
18 19
 export class ReflectionsReader {
@@ -30,10 +31,12 @@ export class ReflectionsReader {
30 31
     // console.log(JSON.stringify(this.typedocApp.serializer.projectToObject(projectReflection)));
31 32
 
32 33
     const externalModules = this.externalModulesWithoutTestsAndMocks(projectReflection);
33
-    const classReflections = this.classReflections(externalModules);
34
+    const classReflections = this.reflections(externalModules, ReflectionKind.Class);
35
+    const enumReflections = this.reflections(externalModules, ReflectionKind.Enum);
34 36
 
35 37
     return {
36
-      classReflections
38
+      classReflections,
39
+      enumReflections
37 40
     };
38 41
   }
39 42
 
@@ -42,8 +45,8 @@ export class ReflectionsReader {
42 45
       .filter((m) => !m.name.endsWith('.mock"') && !m.name.endsWith('.test"'));
43 46
   }
44 47
 
45
-  private classReflections(externalModules: DeclarationReflection[]): DeclarationReflection[] {
46
-    return externalModules.filter((m) => m.getChildrenByKind(ReflectionKind.Class).length === 1)
47
-      .map((m) => m.getChildrenByKind(ReflectionKind.Class)[0]);
48
+  private reflections(externalModules: DeclarationReflection[], kind: ReflectionKind): DeclarationReflection[] {
49
+    return externalModules.filter((m) => m.getChildrenByKind(kind).length === 1)
50
+      .map((m) => m.getChildrenByKind(kind)[0]);
48 51
   }
49 52
 }

+ 5
- 0
scripts/gen-docs/templates/enum.hbs Dosyayı Görüntüle

@@ -0,0 +1,5 @@
1
+# {{name}}
2
+
3
+{{#each values}}
4
+- {{this}}
5
+{{/each}}