@cparra/apexdocs 1.13.4 → 2.0.0-alpha.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +12 -0
- package/.prettierrc.js +7 -0
- package/README.md +344 -277
- package/ROADMAP.md +18 -0
- package/docs/Gemfile.lock +1 -1
- package/docs/Sample-Classes/SampleClass.md +138 -30
- package/docs/Sample-Interfaces/SampleInterface.md +21 -4
- package/docs/index.md +1 -9
- package/examples/apex/SampleClass.cls +31 -6
- package/examples/apex/SampleInterface.cls +3 -2
- package/lib/application/Apexdocs.d.ts +11 -0
- package/lib/application/Apexdocs.js +41 -0
- package/lib/application/Apexdocs.js.map +1 -0
- package/lib/cli/generate.js +17 -21
- package/lib/cli/generate.js.map +1 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -0
- package/lib/model/file.d.ts +10 -0
- package/lib/model/file.js +23 -0
- package/lib/model/file.js.map +1 -0
- package/lib/model/manifest.d.ts +22 -0
- package/lib/model/manifest.js +41 -0
- package/lib/model/manifest.js.map +1 -0
- package/lib/model/markdown-file.d.ts +10 -0
- package/lib/model/markdown-file.js +52 -0
- package/lib/model/markdown-file.js.map +1 -0
- package/lib/model/markdown-generation-util/field-declaration-util.d.ts +3 -0
- package/lib/model/markdown-generation-util/field-declaration-util.js +33 -0
- package/lib/model/markdown-generation-util/field-declaration-util.js.map +1 -0
- package/lib/model/markdown-generation-util/index.d.ts +3 -0
- package/lib/model/markdown-generation-util/index.js +9 -0
- package/lib/model/markdown-generation-util/index.js.map +1 -0
- package/lib/model/markdown-generation-util/method-declaration-util.d.ts +3 -0
- package/lib/model/markdown-generation-util/method-declaration-util.js +97 -0
- package/lib/model/markdown-generation-util/method-declaration-util.js.map +1 -0
- package/lib/model/markdown-generation-util/type-declaration-util.d.ts +3 -0
- package/lib/model/markdown-generation-util/type-declaration-util.js +25 -0
- package/lib/model/markdown-generation-util/type-declaration-util.js.map +1 -0
- package/lib/model/markdown-home-file.d.ts +11 -0
- package/lib/model/markdown-home-file.js +50 -0
- package/lib/model/markdown-home-file.js.map +1 -0
- package/lib/model/markdown-type-file.d.ts +17 -0
- package/lib/model/markdown-type-file.js +62 -0
- package/lib/model/markdown-type-file.js.map +1 -0
- package/lib/service/apex-file-reader.d.ts +13 -0
- package/lib/service/apex-file-reader.js +39 -0
- package/lib/service/apex-file-reader.js.map +1 -0
- package/lib/service/file-system.d.ts +12 -0
- package/lib/service/file-system.js +21 -0
- package/lib/service/file-system.js.map +1 -0
- package/lib/service/file-writer.d.ts +4 -0
- package/lib/service/file-writer.js +25 -0
- package/lib/service/file-writer.js.map +1 -0
- package/lib/service/manifest-factory.d.ts +9 -0
- package/lib/service/manifest-factory.js +13 -0
- package/lib/service/manifest-factory.js.map +1 -0
- package/lib/service/parser.d.ts +9 -0
- package/lib/service/parser.js +17 -0
- package/lib/service/parser.js.map +1 -0
- package/lib/service/walkers/class-walker.d.ts +4 -0
- package/lib/service/walkers/class-walker.js +32 -0
- package/lib/service/walkers/class-walker.js.map +1 -0
- package/lib/service/walkers/enum-walker.d.ts +4 -0
- package/lib/service/walkers/enum-walker.js +10 -0
- package/lib/service/walkers/enum-walker.js.map +1 -0
- package/lib/service/walkers/interface-walker.d.ts +4 -0
- package/lib/service/walkers/interface-walker.js +14 -0
- package/lib/service/walkers/interface-walker.js.map +1 -0
- package/lib/service/walkers/walker-factory.d.ts +5 -0
- package/lib/service/walkers/walker-factory.js +19 -0
- package/lib/service/walkers/walker-factory.js.map +1 -0
- package/lib/service/walkers/walker.d.ts +16 -0
- package/lib/service/walkers/walker.js +9 -0
- package/lib/service/walkers/walker.js.map +1 -0
- package/lib/settings.d.ts +21 -0
- package/lib/settings.js +42 -0
- package/lib/settings.js.map +1 -0
- package/lib/transpiler/file-container.d.ts +6 -0
- package/lib/transpiler/file-container.js +15 -0
- package/lib/transpiler/file-container.js.map +1 -0
- package/lib/transpiler/markdown/class-file-generatorHelper.d.ts +6 -0
- package/lib/transpiler/markdown/class-file-generatorHelper.js +17 -0
- package/lib/transpiler/markdown/class-file-generatorHelper.js.map +1 -0
- package/lib/transpiler/markdown/docsify/docsify-docs-processor.d.ts +4 -0
- package/lib/transpiler/markdown/docsify/docsify-docs-processor.js +10 -0
- package/lib/transpiler/markdown/docsify/docsify-docs-processor.js.map +1 -0
- package/lib/transpiler/markdown/jekyll/jekyll-docsProcessor.d.ts +8 -0
- package/lib/transpiler/markdown/jekyll/jekyll-docsProcessor.js +24 -0
- package/lib/transpiler/markdown/jekyll/jekyll-docsProcessor.js.map +1 -0
- package/lib/transpiler/markdown/markdown-transpiler-base.d.ts +11 -0
- package/lib/transpiler/markdown/markdown-transpiler-base.js +23 -0
- package/lib/transpiler/markdown/markdown-transpiler-base.js.map +1 -0
- package/lib/transpiler/processor-type-transpiler.d.ts +8 -0
- package/lib/transpiler/processor-type-transpiler.js +6 -0
- package/lib/transpiler/processor-type-transpiler.js.map +1 -0
- package/lib/transpiler/transpiler.d.ts +5 -0
- package/lib/transpiler/transpiler.js +21 -0
- package/lib/transpiler/transpiler.js.map +1 -0
- package/lib/util/logger.d.ts +18 -0
- package/lib/util/logger.js +32 -0
- package/lib/util/logger.js.map +1 -0
- package/package.json +22 -11
- package/src/application/Apexdocs.ts +41 -0
- package/src/cli/generate.ts +52 -64
- package/src/index.ts +1 -1
- package/src/model/__tests__/manifest.spec.ts +15 -0
- package/src/model/file.ts +23 -0
- package/src/model/manifest.ts +60 -0
- package/src/model/markdown-file.ts +56 -0
- package/src/model/markdown-generation-util/field-declaration-util.ts +42 -0
- package/src/model/markdown-generation-util/index.ts +3 -0
- package/src/model/markdown-generation-util/method-declaration-util.ts +128 -0
- package/src/model/markdown-generation-util/type-declaration-util.ts +29 -0
- package/src/model/markdown-home-file.ts +48 -0
- package/src/model/markdown-type-file.ts +75 -0
- package/src/service/__tests__/apex-file-reader.spec.ts +79 -0
- package/src/service/__tests__/manifest-factory.spec.ts +16 -0
- package/src/service/apex-file-reader.ts +45 -0
- package/src/service/file-system.ts +28 -0
- package/src/service/file-writer.ts +25 -0
- package/src/service/manifest-factory.ts +12 -0
- package/src/service/parser.ts +18 -0
- package/src/service/walkers/class-walker.ts +31 -0
- package/src/service/walkers/enum-walker.ts +8 -0
- package/src/service/walkers/interface-walker.ts +12 -0
- package/src/service/walkers/walker-factory.ts +18 -0
- package/src/service/walkers/walker.ts +35 -0
- package/src/settings.ts +57 -0
- package/src/transpiler/file-container.ts +13 -0
- package/src/transpiler/markdown/class-file-generatorHelper.ts +16 -0
- package/src/transpiler/markdown/docsify/docsify-docs-processor.ts +7 -0
- package/src/transpiler/markdown/jekyll/jekyll-docsProcessor.ts +22 -0
- package/src/transpiler/markdown/markdown-transpiler-base.ts +28 -0
- package/src/transpiler/processor-type-transpiler.ts +12 -0
- package/src/transpiler/transpiler.ts +18 -0
- package/src/util/logger.ts +31 -0
- package/tsconfig.json +9 -3
- package/.prettierrc +0 -5
- package/examples/config/config.json +0 -5
- package/lib/AsJsDocsProcessor.d.ts +0 -9
- package/lib/AsJsDocsProcessor.js +0 -61
- package/lib/ClassFileGeneratorHelper.d.ts +0 -5
- package/lib/ClassFileGeneratorHelper.js +0 -25
- package/lib/ClassFileGeneratorHelper.test.d.ts +0 -1
- package/lib/ClassFileGeneratorHelper.test.js +0 -32
- package/lib/Configuration.d.ts +0 -34
- package/lib/Configuration.js +0 -37
- package/lib/DocsProcessor.d.ts +0 -6
- package/lib/DocsProcessor.js +0 -9
- package/lib/DocsifyDocsProcessor.d.ts +0 -4
- package/lib/DocsifyDocsProcessor.js +0 -9
- package/lib/DocsifyDocsProcessor.test.d.ts +0 -1
- package/lib/DocsifyDocsProcessor.test.js +0 -7
- package/lib/FileManager.d.ts +0 -6
- package/lib/FileManager.js +0 -28
- package/lib/JekyllDocsProcessor.d.ts +0 -8
- package/lib/JekyllDocsProcessor.js +0 -20
- package/lib/JekyllDocsProcessor.test.d.ts +0 -1
- package/lib/JekyllDocsProcessor.test.js +0 -21
- package/lib/JsHelper.d.ts +0 -12
- package/lib/JsHelper.js +0 -72
- package/lib/MarkdownDocsProcessor.d.ts +0 -22
- package/lib/MarkdownDocsProcessor.js +0 -358
- package/lib/MarkdownHelper.d.ts +0 -13
- package/lib/MarkdownHelper.js +0 -78
- package/lib/Settings.d.ts +0 -22
- package/lib/Settings.js +0 -51
- package/lib/Settings.test.d.ts +0 -1
- package/lib/Settings.test.js +0 -38
- package/lib/command/Generate.d.ts +0 -2
- package/lib/command/Generate.js +0 -54
- package/lib/command/__test__/Generte.test.d.ts +0 -1
- package/lib/command/__test__/Generte.test.js +0 -30
- package/lib/model/ApexModel.d.ts +0 -30
- package/lib/model/ApexModel.js +0 -85
- package/lib/model/ClassModel.d.ts +0 -39
- package/lib/model/ClassModel.js +0 -125
- package/lib/model/EnumModel.d.ts +0 -6
- package/lib/model/EnumModel.js +0 -28
- package/lib/model/MethodModel.d.ts +0 -18
- package/lib/model/MethodModel.js +0 -74
- package/lib/model/PropertyModel.d.ts +0 -6
- package/lib/model/PropertyModel.js +0 -40
- package/lib/model/__test__/ClassModel.test.d.ts +0 -1
- package/lib/model/__test__/ClassModel.test.js +0 -79
- package/lib/model/__test__/MethodModel.test.d.ts +0 -1
- package/lib/model/__test__/MethodModel.test.js +0 -55
- package/lib/model/__test__/PropertyModel.test.d.ts +0 -1
- package/lib/model/__test__/PropertyModel.test.js +0 -25
- package/lib/parser/ClassParser.d.ts +0 -5
- package/lib/parser/ClassParser.js +0 -79
- package/lib/parser/EnumParser.d.ts +0 -5
- package/lib/parser/EnumParser.js +0 -45
- package/lib/parser/FileParser.d.ts +0 -8
- package/lib/parser/FileParser.js +0 -210
- package/lib/parser/MethodParser.d.ts +0 -5
- package/lib/parser/MethodParser.js +0 -109
- package/lib/parser/PropertyParser.d.ts +0 -5
- package/lib/parser/PropertyParser.js +0 -46
- package/lib/parser/__test__/ClassParser.test.d.ts +0 -1
- package/lib/parser/__test__/ClassParser.test.js +0 -52
- package/lib/parser/__test__/FileParser.test.d.ts +0 -1
- package/lib/parser/__test__/FileParser.test.js +0 -12
- package/lib/parser/__test__/MethodParser.test.d.ts +0 -1
- package/lib/parser/__test__/MethodParser.test.js +0 -69
- package/lib/parser/__test__/PropertyParser.test.d.ts +0 -1
- package/lib/parser/__test__/PropertyParser.test.js +0 -14
- package/lib/parser/__test__/testFileContents.d.ts +0 -1
- package/lib/parser/__test__/testFileContents.js +0 -82
- package/lib/utils.d.ts +0 -12
- package/lib/utils.js +0 -49
- package/lib/utils.test.d.ts +0 -1
- package/lib/utils.test.js +0 -35
- package/src/AsJsDocsProcessor.ts +0 -67
- package/src/ClassFileGeneratorHelper.test.ts +0 -44
- package/src/ClassFileGeneratorHelper.ts +0 -26
- package/src/Configuration.ts +0 -69
- package/src/DocsProcessor.ts +0 -9
- package/src/DocsifyDocsProcessor.test.ts +0 -6
- package/src/DocsifyDocsProcessor.ts +0 -7
- package/src/FileManager.ts +0 -32
- package/src/JekyllDocsProcessor.test.ts +0 -28
- package/src/JekyllDocsProcessor.ts +0 -22
- package/src/JsHelper.ts +0 -78
- package/src/MarkdownDocsProcessor.ts +0 -420
- package/src/MarkdownHelper.ts +0 -91
- package/src/Settings.test.ts +0 -54
- package/src/Settings.ts +0 -65
- package/src/command/Generate.ts +0 -69
- package/src/command/__test__/Generte.test.ts +0 -39
- package/src/model/ApexModel.ts +0 -102
- package/src/model/ClassModel.ts +0 -140
- package/src/model/EnumModel.ts +0 -27
- package/src/model/MethodModel.ts +0 -80
- package/src/model/PropertyModel.ts +0 -37
- package/src/model/__test__/ClassModel.test.ts +0 -100
- package/src/model/__test__/MethodModel.test.ts +0 -70
- package/src/model/__test__/PropertyModel.test.ts +0 -34
- package/src/parser/ClassParser.ts +0 -83
- package/src/parser/EnumParser.ts +0 -47
- package/src/parser/FileParser.ts +0 -250
- package/src/parser/MethodParser.ts +0 -119
- package/src/parser/PropertyParser.ts +0 -46
- package/src/parser/__test__/ClassParser.test.ts +0 -70
- package/src/parser/__test__/FileParser.test.ts +0 -14
- package/src/parser/__test__/MethodParser.test.ts +0 -90
- package/src/parser/__test__/PropertyParser.test.ts +0 -18
- package/src/parser/__test__/testFileContents.ts +0 -81
- package/src/utils.test.ts +0 -40
- package/src/utils.ts +0 -52
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Settings, SettingsConfig } from '../../settings';
|
|
2
|
+
import { ApexFileReader } from '../apex-file-reader';
|
|
3
|
+
|
|
4
|
+
describe('File Reader', () => {
|
|
5
|
+
beforeEach(() => {
|
|
6
|
+
Settings.build({
|
|
7
|
+
sourceDirectory: '',
|
|
8
|
+
recursive: true,
|
|
9
|
+
configPath: '',
|
|
10
|
+
targetGenerator: 'jekyll',
|
|
11
|
+
group: true,
|
|
12
|
+
outputDir: '',
|
|
13
|
+
scope: [],
|
|
14
|
+
} as SettingsConfig);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('returns an empty list when there are no files in the directory', () => {
|
|
18
|
+
const result = ApexFileReader.processFiles({
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
20
|
+
isDirectory(_: string): boolean {
|
|
21
|
+
return false;
|
|
22
|
+
},
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
24
|
+
joinPath(_: string): string {
|
|
25
|
+
return '';
|
|
26
|
+
},
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
28
|
+
readDirectory(_: string): string[] {
|
|
29
|
+
return [];
|
|
30
|
+
},
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
32
|
+
readFile(_: string): string {
|
|
33
|
+
return '';
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
expect(result.length).toBe(0);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('returns an empty list when there are no Apex files in the directory', () => {
|
|
40
|
+
const result = ApexFileReader.processFiles({
|
|
41
|
+
isDirectory(_: string): boolean {
|
|
42
|
+
return false;
|
|
43
|
+
},
|
|
44
|
+
joinPath(_: string): string {
|
|
45
|
+
return '';
|
|
46
|
+
},
|
|
47
|
+
readDirectory(_: string): string[] {
|
|
48
|
+
return ['SomeFile.md'];
|
|
49
|
+
},
|
|
50
|
+
readFile(_: string): string {
|
|
51
|
+
return '';
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
expect(result.length).toBe(0);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('returns the file contents for an Apex file', () => {
|
|
58
|
+
const result = ApexFileReader.processFiles({
|
|
59
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
60
|
+
isDirectory(_: string): boolean {
|
|
61
|
+
return false;
|
|
62
|
+
},
|
|
63
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
64
|
+
joinPath(_: string): string {
|
|
65
|
+
return '';
|
|
66
|
+
},
|
|
67
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
68
|
+
readDirectory(_: string): string[] {
|
|
69
|
+
return ['SomeApexFile.cls'];
|
|
70
|
+
},
|
|
71
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
72
|
+
readFile(_: string): string {
|
|
73
|
+
return 'public class MyClass{}';
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
expect(result.length).toBe(1);
|
|
77
|
+
expect(result[0]).toBe('public class MyClass{}');
|
|
78
|
+
});
|
|
79
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createManifest } from '../manifest-factory';
|
|
2
|
+
import { Type } from '@cparra/apex-reflection';
|
|
3
|
+
import { TypeParser } from '../parser';
|
|
4
|
+
|
|
5
|
+
class TestParser implements TypeParser {
|
|
6
|
+
parse(): Type[] {
|
|
7
|
+
return [];
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
it('creates a manifest from the result of a type parser', () => {
|
|
12
|
+
const manifest = createManifest(new TestParser(), (typeBody: string) => {
|
|
13
|
+
return {};
|
|
14
|
+
});
|
|
15
|
+
expect(manifest.types.length).toBe(0);
|
|
16
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Settings } from '../settings';
|
|
2
|
+
import { FileSystem } from './file-system';
|
|
3
|
+
|
|
4
|
+
const APEX_FILE_EXTENSION = '.cls';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Reads from .cls files and returns their raw body.
|
|
8
|
+
*/
|
|
9
|
+
export class ApexFileReader {
|
|
10
|
+
/**
|
|
11
|
+
* Reads from .cls files and returns their raw body.
|
|
12
|
+
*/
|
|
13
|
+
static processFiles(fileSystem: FileSystem): string[] {
|
|
14
|
+
let bodies: string[] = [];
|
|
15
|
+
|
|
16
|
+
const directoryContents = fileSystem.readDirectory(this.sourceDirectory);
|
|
17
|
+
|
|
18
|
+
directoryContents.forEach((currentFilePath) => {
|
|
19
|
+
const currentPath = fileSystem.joinPath(this.sourceDirectory, currentFilePath);
|
|
20
|
+
if (this.readRecursively && fileSystem.isDirectory(currentPath)) {
|
|
21
|
+
bodies = bodies.concat(this.processFiles(fileSystem));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (!this.isApexFile(currentFilePath)) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const rawFile = fileSystem.readFile(currentPath);
|
|
29
|
+
bodies.push(rawFile);
|
|
30
|
+
});
|
|
31
|
+
return bodies;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
private static isApexFile(currentFile: string): boolean {
|
|
35
|
+
return currentFile.endsWith(APEX_FILE_EXTENSION);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private static get sourceDirectory() {
|
|
39
|
+
return Settings.getInstance().sourceDirectory;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
private static get readRecursively() {
|
|
43
|
+
return Settings.getInstance().recursive;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
|
|
4
|
+
export interface FileSystem {
|
|
5
|
+
readDirectory: (sourceDirectory: string) => string[];
|
|
6
|
+
isDirectory: (path: string) => boolean;
|
|
7
|
+
readFile: (path: string) => string;
|
|
8
|
+
joinPath: (...paths: string[]) => string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export class DefaultFileSystem implements FileSystem {
|
|
12
|
+
isDirectory(pathToRead: string): boolean {
|
|
13
|
+
return fs.statSync(pathToRead).isDirectory();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
readDirectory(sourceDirectory: string): string[] {
|
|
17
|
+
return fs.readdirSync(sourceDirectory);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
readFile(pathToRead: string): string {
|
|
21
|
+
const rawFile = fs.readFileSync(pathToRead);
|
|
22
|
+
return rawFile.toString();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
joinPath(...paths: string[]): string {
|
|
26
|
+
return path.join(...paths);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import { File } from '../model/file';
|
|
4
|
+
import { Settings } from '../settings';
|
|
5
|
+
|
|
6
|
+
export class FileWriter {
|
|
7
|
+
static write(files: File[], onWriteCallback: (fileName: string) => void) {
|
|
8
|
+
const outputDir = Settings.getInstance().outputDir;
|
|
9
|
+
if (!fs.existsSync(outputDir)) {
|
|
10
|
+
fs.mkdirSync(outputDir);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
files.forEach((file) => {
|
|
14
|
+
const dirPath = path.join(outputDir, file.dir);
|
|
15
|
+
if (!fs.existsSync(dirPath)) {
|
|
16
|
+
fs.mkdirSync(dirPath);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const filePath = path.join(dirPath, `${file.fileName}${file.fileExtension()}`);
|
|
20
|
+
fs.writeFile(filePath, file.body, 'utf8', () => {
|
|
21
|
+
onWriteCallback(file.fileName);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import Manifest from '../model/manifest';
|
|
2
|
+
import { TypeParser } from './parser';
|
|
3
|
+
import { ReflectionResult } from '@cparra/apex-reflection';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Builds a new Manifest object, sourcing its types from the received TypeParser.
|
|
7
|
+
* @param typeParser In charge of returning the list of reflected types.
|
|
8
|
+
* @param reflect Reflection function.
|
|
9
|
+
*/
|
|
10
|
+
export function createManifest(typeParser: TypeParser, reflect: (typeBody: string) => ReflectionResult): Manifest {
|
|
11
|
+
return new Manifest(typeParser.parse(reflect));
|
|
12
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Type, ReflectionResult } from '@cparra/apex-reflection';
|
|
2
|
+
|
|
3
|
+
export interface TypeParser {
|
|
4
|
+
parse(reflect: (typeBody: string) => ReflectionResult): Type[];
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export class RawBodyParser implements TypeParser {
|
|
8
|
+
constructor(public typeBodies: string[]) {}
|
|
9
|
+
|
|
10
|
+
parse(reflect: (typeBody: string) => ReflectionResult): Type[] {
|
|
11
|
+
return this.typeBodies
|
|
12
|
+
.map((rawBody) => reflect(rawBody))
|
|
13
|
+
.filter((reflectionResult) => {
|
|
14
|
+
return reflectionResult.typeMirror;
|
|
15
|
+
})
|
|
16
|
+
.map((reflectionResult) => reflectionResult.typeMirror!);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Walker, WalkerListener } from './walker';
|
|
2
|
+
import { ClassMirror } from '@cparra/apex-reflection';
|
|
3
|
+
|
|
4
|
+
export class ClassWalker extends Walker {
|
|
5
|
+
walk(listener: WalkerListener): void {
|
|
6
|
+
listener.onTypeDeclaration(this.type);
|
|
7
|
+
const classMirror = this.type as ClassMirror;
|
|
8
|
+
|
|
9
|
+
if (classMirror.constructors.length) {
|
|
10
|
+
listener.onConstructorDeclaration(this.type.name, classMirror.constructors);
|
|
11
|
+
}
|
|
12
|
+
if (classMirror.fields.length) {
|
|
13
|
+
listener.onFieldsDeclaration(classMirror.fields);
|
|
14
|
+
}
|
|
15
|
+
if (classMirror.properties.length) {
|
|
16
|
+
listener.onPropertiesDeclaration(classMirror.properties);
|
|
17
|
+
}
|
|
18
|
+
if (classMirror.methods.length) {
|
|
19
|
+
listener.onMethodsDeclaration(classMirror.methods);
|
|
20
|
+
}
|
|
21
|
+
if (classMirror.enums.length) {
|
|
22
|
+
listener.onInnerEnumsDeclaration(classMirror.enums);
|
|
23
|
+
}
|
|
24
|
+
if (classMirror.classes.length) {
|
|
25
|
+
listener.onInnerClassesDeclaration(classMirror.classes);
|
|
26
|
+
}
|
|
27
|
+
if (classMirror.interfaces.length) {
|
|
28
|
+
listener.onInnerInterfacesDeclaration(classMirror.interfaces);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Walker, WalkerListener } from './walker';
|
|
2
|
+
import { InterfaceMirror } from '@cparra/apex-reflection';
|
|
3
|
+
|
|
4
|
+
export class InterfaceWalker extends Walker {
|
|
5
|
+
walk(listener: WalkerListener): void {
|
|
6
|
+
listener.onTypeDeclaration(this.type);
|
|
7
|
+
const interfaceMirror = this.type as InterfaceMirror;
|
|
8
|
+
if (interfaceMirror.methods.length) {
|
|
9
|
+
listener.onMethodsDeclaration(interfaceMirror.methods);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Type } from '@cparra/apex-reflection';
|
|
2
|
+
import { Walker } from './walker';
|
|
3
|
+
import { ClassWalker } from './class-walker';
|
|
4
|
+
import { EnumWalker } from './enum-walker';
|
|
5
|
+
import { InterfaceWalker } from './interface-walker';
|
|
6
|
+
|
|
7
|
+
export class WalkerFactory {
|
|
8
|
+
static get(type: Type): Walker {
|
|
9
|
+
switch (type.type_name) {
|
|
10
|
+
case 'class':
|
|
11
|
+
return new ClassWalker(type);
|
|
12
|
+
case 'enum':
|
|
13
|
+
return new EnumWalker(type);
|
|
14
|
+
case 'interface':
|
|
15
|
+
return new InterfaceWalker(type);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ClassMirror,
|
|
3
|
+
ConstructorMirror,
|
|
4
|
+
EnumMirror,
|
|
5
|
+
FieldMirror,
|
|
6
|
+
InterfaceMirror,
|
|
7
|
+
MethodMirror,
|
|
8
|
+
PropertyMirror,
|
|
9
|
+
Type,
|
|
10
|
+
} from '@cparra/apex-reflection';
|
|
11
|
+
import { Annotation } from '@cparra/apex-reflection/index';
|
|
12
|
+
|
|
13
|
+
export interface WalkerListener {
|
|
14
|
+
onTypeDeclaration(typeMirror: Type): void;
|
|
15
|
+
|
|
16
|
+
onConstructorDeclaration(className: string, constructors: ConstructorMirror[]): void;
|
|
17
|
+
|
|
18
|
+
onFieldsDeclaration(fields: FieldMirror[]): void;
|
|
19
|
+
|
|
20
|
+
onPropertiesDeclaration(properties: PropertyMirror[]): void;
|
|
21
|
+
|
|
22
|
+
onMethodsDeclaration(methods: MethodMirror[]): void;
|
|
23
|
+
|
|
24
|
+
onInnerEnumsDeclaration(enums: EnumMirror[]): void;
|
|
25
|
+
|
|
26
|
+
onInnerClassesDeclaration(classes: ClassMirror[]): void;
|
|
27
|
+
|
|
28
|
+
onInnerInterfacesDeclaration(interfaces: InterfaceMirror[]): void;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export abstract class Walker {
|
|
32
|
+
constructor(public type: Type) {}
|
|
33
|
+
|
|
34
|
+
abstract walk(listener: WalkerListener): void;
|
|
35
|
+
}
|
package/src/settings.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import ProcessorTypeTranspiler from './transpiler/processor-type-transpiler';
|
|
2
|
+
import { JekyllDocsProcessor } from './transpiler/markdown/jekyll/jekyll-docsProcessor';
|
|
3
|
+
import DocsifyDocsProcessor from './transpiler/markdown/docsify/docsify-docs-processor';
|
|
4
|
+
|
|
5
|
+
export type GeneratorChoices = 'jekyll' | 'docsify';
|
|
6
|
+
|
|
7
|
+
export interface SettingsConfig {
|
|
8
|
+
sourceDirectory: string;
|
|
9
|
+
recursive: boolean;
|
|
10
|
+
scope: string[];
|
|
11
|
+
outputDir: string;
|
|
12
|
+
targetGenerator: GeneratorChoices;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class Settings {
|
|
16
|
+
private static instance: Settings;
|
|
17
|
+
|
|
18
|
+
private constructor(public config: SettingsConfig) {}
|
|
19
|
+
|
|
20
|
+
public static build(config: SettingsConfig) {
|
|
21
|
+
Settings.instance = new Settings(config);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public static getInstance(): Settings {
|
|
25
|
+
if (!Settings.instance) {
|
|
26
|
+
throw new Error('Settings has not been initialized');
|
|
27
|
+
}
|
|
28
|
+
return Settings.instance;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
get sourceDirectory(): string {
|
|
32
|
+
return this.config.sourceDirectory;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
get recursive(): boolean {
|
|
36
|
+
return this.config.recursive;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
get scope(): string[] {
|
|
40
|
+
return this.config.scope;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
get outputDir(): string {
|
|
44
|
+
return this.config.outputDir;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
get typeTranspiler(): ProcessorTypeTranspiler {
|
|
48
|
+
switch (this.config.targetGenerator) {
|
|
49
|
+
case 'jekyll':
|
|
50
|
+
return new JekyllDocsProcessor();
|
|
51
|
+
case 'docsify':
|
|
52
|
+
return new DocsifyDocsProcessor();
|
|
53
|
+
default:
|
|
54
|
+
throw Error('Invalid target generator');
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Type } from '@cparra/apex-reflection';
|
|
2
|
+
|
|
3
|
+
export default class ClassFileGeneratorHelper {
|
|
4
|
+
public static getSanitizedGroup(classModel: Type) {
|
|
5
|
+
return this.getClassGroup(classModel).replace(/ /g, '-').replace('.', '');
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
public static getFileLink(classModel: Type) {
|
|
9
|
+
return `[${classModel.name}](/${this.getSanitizedGroup(classModel)}/${classModel.name}.md)`;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
private static getClassGroup(classModel: Type): string {
|
|
13
|
+
const groupAnnotation = classModel.docComment?.annotations.find((annotation) => annotation.name === 'group');
|
|
14
|
+
return groupAnnotation?.body ?? 'Misc';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { MarkdownTranspilerBase } from '../markdown-transpiler-base';
|
|
2
|
+
import { Type } from '@cparra/apex-reflection';
|
|
3
|
+
import { MarkdownHomeFile } from '../../../model/markdown-home-file';
|
|
4
|
+
import { MarkdownTypeFile } from '../../../model/markdown-type-file';
|
|
5
|
+
|
|
6
|
+
export class JekyllDocsProcessor extends MarkdownTranspilerBase {
|
|
7
|
+
homeFileName(): string {
|
|
8
|
+
return 'index';
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
onBeforeProcess = (types: Type[]) => {
|
|
12
|
+
this._fileContainer.pushFile(new MarkdownHomeFile(this.homeFileName(), types, this.frontMatterHeader));
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
onProcess(type: Type): void {
|
|
16
|
+
this._fileContainer.pushFile(new MarkdownTypeFile(type, 1, this.frontMatterHeader));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
get frontMatterHeader(): string {
|
|
20
|
+
return '---\nlayout: default\n---';
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import ProcessorTypeTranspiler from '../processor-type-transpiler';
|
|
2
|
+
import { Type } from '@cparra/apex-reflection';
|
|
3
|
+
import { FileContainer } from '../file-container';
|
|
4
|
+
import { MarkdownHomeFile } from '../../model/markdown-home-file';
|
|
5
|
+
import { MarkdownTypeFile } from '../../model/markdown-type-file';
|
|
6
|
+
|
|
7
|
+
export abstract class MarkdownTranspilerBase extends ProcessorTypeTranspiler {
|
|
8
|
+
protected readonly _fileContainer: FileContainer;
|
|
9
|
+
|
|
10
|
+
constructor() {
|
|
11
|
+
super();
|
|
12
|
+
this._fileContainer = new FileContainer();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
abstract homeFileName(): string;
|
|
16
|
+
|
|
17
|
+
fileBuilder(): FileContainer {
|
|
18
|
+
return this._fileContainer;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
onBeforeProcess = (types: Type[]) => {
|
|
22
|
+
this._fileContainer.pushFile(new MarkdownHomeFile(this.homeFileName(), types));
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
onProcess(type: Type): void {
|
|
26
|
+
this._fileContainer.pushFile(new MarkdownTypeFile(type));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Type } from '@cparra/apex-reflection';
|
|
2
|
+
import { FileContainer } from './file-container';
|
|
3
|
+
|
|
4
|
+
export default abstract class ProcessorTypeTranspiler {
|
|
5
|
+
onBeforeProcess: ((types: Type[]) => void) | undefined;
|
|
6
|
+
|
|
7
|
+
abstract onProcess(type: Type): void;
|
|
8
|
+
|
|
9
|
+
onAfterProcess: ((types: Type[]) => void) | undefined;
|
|
10
|
+
|
|
11
|
+
abstract fileBuilder(): FileContainer;
|
|
12
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Type } from '@cparra/apex-reflection';
|
|
2
|
+
import ProcessorTypeTranspiler from './processor-type-transpiler';
|
|
3
|
+
|
|
4
|
+
export default class Transpiler {
|
|
5
|
+
static generate(types: Type[], processor: ProcessorTypeTranspiler): void {
|
|
6
|
+
const sortedTypes = types.sort((apexTypeA, apexTypeB) => {
|
|
7
|
+
if (apexTypeA.name < apexTypeB.name) return -1;
|
|
8
|
+
if (apexTypeA.name > apexTypeB.name) return 1;
|
|
9
|
+
return 0;
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
processor.onBeforeProcess?.(sortedTypes);
|
|
13
|
+
sortedTypes.forEach((currentType) => {
|
|
14
|
+
processor.onProcess(currentType);
|
|
15
|
+
});
|
|
16
|
+
processor.onAfterProcess?.(sortedTypes);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as chalk from 'chalk';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Logs messages to the console.
|
|
5
|
+
*/
|
|
6
|
+
export class Logger {
|
|
7
|
+
/**
|
|
8
|
+
* Logs a message with optional arguments.
|
|
9
|
+
* @param message The message to log.
|
|
10
|
+
* @param args Optional arguments.
|
|
11
|
+
*/
|
|
12
|
+
public static log(message: string, ...args: string[]) {
|
|
13
|
+
this.logSingle(message);
|
|
14
|
+
args.forEach((arg) => {
|
|
15
|
+
this.logSingle(arg);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Logs an error message with optional arguments.
|
|
21
|
+
* @param message The error message to log.
|
|
22
|
+
* @param args Optional arguments.
|
|
23
|
+
*/
|
|
24
|
+
public static error(message: string, ...args: string[]) {
|
|
25
|
+
this.log(`${chalk.red(message)}`, ...args);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
private static logSingle(message: string) {
|
|
29
|
+
process.stdout.write(`${chalk.green(new Date().toLocaleString() + ': ')}${message}\n`);
|
|
30
|
+
}
|
|
31
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -4,8 +4,14 @@
|
|
|
4
4
|
"module": "commonjs",
|
|
5
5
|
"declaration": true,
|
|
6
6
|
"outDir": "./lib",
|
|
7
|
-
"strict": true
|
|
7
|
+
"strict": true,
|
|
8
|
+
"sourceMap": true
|
|
8
9
|
},
|
|
9
|
-
"include": [
|
|
10
|
-
|
|
10
|
+
"include": [
|
|
11
|
+
"src"
|
|
12
|
+
],
|
|
13
|
+
"exclude": [
|
|
14
|
+
"node_modules",
|
|
15
|
+
"**/__tests__/*"
|
|
16
|
+
]
|
|
11
17
|
}
|
package/.prettierrc
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import DocsProcessor from './DocsProcessor';
|
|
2
|
-
import JsHelper from './JsHelper';
|
|
3
|
-
import ClassModel from './model/ClassModel';
|
|
4
|
-
export default class AsJsDocsProcessor extends DocsProcessor {
|
|
5
|
-
process(classModel: ClassModel, outputDir: string): void;
|
|
6
|
-
generateDocsForClass(generator: JsHelper, classModel: ClassModel): void;
|
|
7
|
-
private addProperties;
|
|
8
|
-
private addInnerClasses;
|
|
9
|
-
}
|
package/lib/AsJsDocsProcessor.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const fs = require("fs");
|
|
4
|
-
const path = require("path");
|
|
5
|
-
const DocsProcessor_1 = require("./DocsProcessor");
|
|
6
|
-
const JsHelper_1 = require("./JsHelper");
|
|
7
|
-
class AsJsDocsProcessor extends DocsProcessor_1.default {
|
|
8
|
-
process(classModel, outputDir) {
|
|
9
|
-
const jsHelper = new JsHelper_1.default();
|
|
10
|
-
this.generateDocsForClass(jsHelper, classModel);
|
|
11
|
-
if (!fs.existsSync(outputDir)) {
|
|
12
|
-
fs.mkdirSync(outputDir);
|
|
13
|
-
}
|
|
14
|
-
const filePath = path.join(outputDir, `${classModel.getClassName()}.doc.js`);
|
|
15
|
-
fs.writeFile(filePath, jsHelper.contents, 'utf8', () => {
|
|
16
|
-
// tslint:disable-next-line:no-console
|
|
17
|
-
console.log(`${classModel.getClassName()} processed.`);
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
generateDocsForClass(generator, classModel) {
|
|
21
|
-
generator.initializeBlock();
|
|
22
|
-
generator.declareType(classModel.getClassName(false), classModel.getDescription());
|
|
23
|
-
this.addProperties(generator, classModel);
|
|
24
|
-
generator.finalizeBlock();
|
|
25
|
-
this.addInnerClasses(classModel, generator);
|
|
26
|
-
}
|
|
27
|
-
addProperties(generator, classModel) {
|
|
28
|
-
if (classModel.getProperties().length === 0) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
classModel
|
|
32
|
-
.getProperties()
|
|
33
|
-
.sort((propA, propB) => {
|
|
34
|
-
if (propA.getPropertyName() < propB.getPropertyName())
|
|
35
|
-
return -1;
|
|
36
|
-
if (propA.getPropertyName() > propB.getPropertyName())
|
|
37
|
-
return 1;
|
|
38
|
-
return 0;
|
|
39
|
-
})
|
|
40
|
-
.forEach(propertyModel => {
|
|
41
|
-
generator.declareProperty(propertyModel.getReturnType(), propertyModel.getPropertyName(), propertyModel.getDescription());
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
addInnerClasses(classModel, generator) {
|
|
45
|
-
if (classModel.getChildClasses().length > 0) {
|
|
46
|
-
classModel
|
|
47
|
-
.getChildClasses()
|
|
48
|
-
.sort((classA, classB) => {
|
|
49
|
-
if (classA.getClassName() < classB.getClassName())
|
|
50
|
-
return -1;
|
|
51
|
-
if (classA.getClassName() > classB.getClassName())
|
|
52
|
-
return 1;
|
|
53
|
-
return 0;
|
|
54
|
-
})
|
|
55
|
-
.forEach(innerClass => {
|
|
56
|
-
this.generateDocsForClass(generator, innerClass);
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
exports.default = AsJsDocsProcessor;
|