@cparra/apexdocs 3.0.0-rc.0 → 3.1.0

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.
Files changed (226) hide show
  1. package/README.md +61 -576
  2. package/dist/cli/generate.js +73 -3094
  3. package/dist/defaults-BcE8DTat.js +13 -0
  4. package/dist/defaults-D07y_bq4.js +40 -0
  5. package/dist/defaults-gPzwP66p.js +14 -0
  6. package/dist/index.d.ts +35 -3
  7. package/dist/index.js +90 -2
  8. package/dist/logger-BEbUIfqN.js +3282 -0
  9. package/dist/logger-BGuf1PnL.js +3281 -0
  10. package/dist/logger-CWBRF2za.js +3284 -0
  11. package/dist/logger-CdBmDEN1.js +3283 -0
  12. package/dist/logger-Ce4QqPFR.js +3278 -0
  13. package/dist/logger-CyEVYaAC.js +3284 -0
  14. package/dist/logger-D7a83ycP.js +3277 -0
  15. package/dist/logger-DGaHeBKk.js +3279 -0
  16. package/dist/logger-Dqhl_lO_.js +3278 -0
  17. package/dist/logger-aySSWi0G.js +3280 -0
  18. package/dist/logger-qLCcAtiy.js +3284 -0
  19. package/package.json +5 -2
  20. package/.github/workflows/ci.yaml +0 -22
  21. package/.github/workflows/close_stale.yml +0 -22
  22. package/.prettierrc.js +0 -7
  23. package/__mocks__/chalk.js +0 -12
  24. package/__mocks__/log-update.js +0 -6
  25. package/eslint.config.mjs +0 -10
  26. package/examples/markdown/.forceignore +0 -12
  27. package/examples/markdown/config/project-scratch-def.json +0 -5
  28. package/examples/markdown/docs/index.md +0 -109
  29. package/examples/markdown/docs/miscellaneous/BaseClass.md +0 -16
  30. package/examples/markdown/docs/miscellaneous/MultiInheritanceClass.md +0 -72
  31. package/examples/markdown/docs/miscellaneous/ParentInterface.md +0 -15
  32. package/examples/markdown/docs/miscellaneous/ReferencedEnum.md +0 -8
  33. package/examples/markdown/docs/miscellaneous/SampleException.md +0 -24
  34. package/examples/markdown/docs/miscellaneous/SampleInterface.md +0 -116
  35. package/examples/markdown/docs/miscellaneous/Url.md +0 -311
  36. package/examples/markdown/docs/sample-enums/SampleEnum.md +0 -36
  37. package/examples/markdown/docs/samplegroup/SampleClass.md +0 -170
  38. package/examples/markdown/force-app/classes/BaseClass.cls +0 -3
  39. package/examples/markdown/force-app/classes/MultiInheritanceClass.cls +0 -1
  40. package/examples/markdown/force-app/classes/ParentInterface.cls +0 -3
  41. package/examples/markdown/force-app/classes/ReferencedEnum.cls +0 -3
  42. package/examples/markdown/force-app/classes/SampleClass.cls +0 -72
  43. package/examples/markdown/force-app/classes/SampleEnum.cls +0 -30
  44. package/examples/markdown/force-app/classes/SampleException.cls +0 -17
  45. package/examples/markdown/force-app/classes/SampleInterface.cls +0 -50
  46. package/examples/markdown/force-app/classes/Url.cls +0 -196
  47. package/examples/markdown/package-lock.json +0 -665
  48. package/examples/markdown/package.json +0 -20
  49. package/examples/markdown/sfdx-project.json +0 -12
  50. package/examples/markdown-jsconfig/.forceignore +0 -12
  51. package/examples/markdown-jsconfig/apexdocs.config.mjs +0 -21
  52. package/examples/markdown-jsconfig/config/project-scratch-def.json +0 -5
  53. package/examples/markdown-jsconfig/docs/index.md +0 -12
  54. package/examples/markdown-jsconfig/docs/miscellaneous/Url.md +0 -315
  55. package/examples/markdown-jsconfig/force-app/classes/Url.cls +0 -196
  56. package/examples/markdown-jsconfig/package-lock.json +0 -665
  57. package/examples/markdown-jsconfig/package.json +0 -15
  58. package/examples/markdown-jsconfig/sfdx-project.json +0 -12
  59. package/examples/open-api/config/project-scratch-def.json +0 -13
  60. package/examples/open-api/docs/openapi.json +0 -582
  61. package/examples/open-api/force-app/main/default/classes/ChildClass.cls +0 -42
  62. package/examples/open-api/force-app/main/default/classes/SampleClass.cls +0 -167
  63. package/examples/open-api/force-app/main/default/restapi/SampleRestResource.cls +0 -195
  64. package/examples/open-api/force-app/main/default/restapi/SampleRestResourceToSkip.cls +0 -35
  65. package/examples/open-api/force-app/main/default/restapi/SampleRestResourceWithInnerClass.cls +0 -24
  66. package/examples/open-api/force-app/main/default/restapi/SampleRestResourceWithoutApexDocs.cls +0 -15
  67. package/examples/open-api/force-app/main/default/restapi/references/Reference1.cls +0 -9
  68. package/examples/open-api/force-app/main/default/restapi/references/Reference2.cls +0 -9
  69. package/examples/open-api/force-app/main/default/restapi/references/Reference3.cls +0 -3
  70. package/examples/open-api/force-app/main/default/restapi/references/Reference4.cls +0 -3
  71. package/examples/open-api/force-app/main/default/restapi/references/Reference5.cls +0 -3
  72. package/examples/open-api/force-app/main/default/restapi/references/Reference6.cls +0 -6
  73. package/examples/open-api/force-app/main/default/restapi/references/Reference7.cls +0 -3
  74. package/examples/open-api/package-lock.json +0 -724
  75. package/examples/open-api/package.json +0 -20
  76. package/examples/open-api/sfdx-project.json +0 -12
  77. package/examples/vitepress/.forceignore +0 -12
  78. package/examples/vitepress/apexdocs.config.ts +0 -111
  79. package/examples/vitepress/config/project-scratch-def.json +0 -13
  80. package/examples/vitepress/docs/.vitepress/cache/deps/@theme_index.js +0 -259
  81. package/examples/vitepress/docs/.vitepress/cache/deps/@theme_index.js.map +0 -7
  82. package/examples/vitepress/docs/.vitepress/cache/deps/_metadata.json +0 -40
  83. package/examples/vitepress/docs/.vitepress/cache/deps/chunk-574YRH25.js +0 -11474
  84. package/examples/vitepress/docs/.vitepress/cache/deps/chunk-574YRH25.js.map +0 -7
  85. package/examples/vitepress/docs/.vitepress/cache/deps/chunk-E5DZZB2I.js +0 -9172
  86. package/examples/vitepress/docs/.vitepress/cache/deps/chunk-E5DZZB2I.js.map +0 -7
  87. package/examples/vitepress/docs/.vitepress/cache/deps/package.json +0 -3
  88. package/examples/vitepress/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js +0 -4339
  89. package/examples/vitepress/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js.map +0 -7
  90. package/examples/vitepress/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js +0 -567
  91. package/examples/vitepress/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js.map +0 -7
  92. package/examples/vitepress/docs/.vitepress/cache/deps/vue.js +0 -323
  93. package/examples/vitepress/docs/.vitepress/cache/deps/vue.js.map +0 -7
  94. package/examples/vitepress/docs/.vitepress/config.mts +0 -21
  95. package/examples/vitepress/docs/.vitepress/sidebar.json +0 -119
  96. package/examples/vitepress/docs/api-examples.md +0 -49
  97. package/examples/vitepress/docs/index-frontmatter.md +0 -16
  98. package/examples/vitepress/docs/index.md +0 -56
  99. package/examples/vitepress/docs/markdown-examples.md +0 -85
  100. package/examples/vitepress/docs/miscellaneous/BaseClass.md +0 -20
  101. package/examples/vitepress/docs/miscellaneous/MultiInheritanceClass.md +0 -76
  102. package/examples/vitepress/docs/miscellaneous/ParentInterface.md +0 -19
  103. package/examples/vitepress/docs/miscellaneous/ReferencedEnum.md +0 -15
  104. package/examples/vitepress/docs/miscellaneous/SampleException.md +0 -28
  105. package/examples/vitepress/docs/miscellaneous/SampleInterface.md +0 -116
  106. package/examples/vitepress/docs/miscellaneous/Url.md +0 -317
  107. package/examples/vitepress/docs/sample-enums/SampleEnum.md +0 -40
  108. package/examples/vitepress/docs/samplegroup/SampleClass.md +0 -174
  109. package/examples/vitepress/force-app/main/default/classes/BaseClass.cls +0 -3
  110. package/examples/vitepress/force-app/main/default/classes/MultiInheritanceClass.cls +0 -1
  111. package/examples/vitepress/force-app/main/default/classes/ParentInterface.cls +0 -3
  112. package/examples/vitepress/force-app/main/default/classes/ReferencedEnum.cls +0 -5
  113. package/examples/vitepress/force-app/main/default/classes/SampleClass.cls +0 -72
  114. package/examples/vitepress/force-app/main/default/classes/SampleEnum.cls +0 -30
  115. package/examples/vitepress/force-app/main/default/classes/SampleException.cls +0 -17
  116. package/examples/vitepress/force-app/main/default/classes/SampleInterface.cls +0 -46
  117. package/examples/vitepress/force-app/main/default/classes/Url.cls +0 -198
  118. package/examples/vitepress/package-lock.json +0 -2574
  119. package/examples/vitepress/package.json +0 -18
  120. package/examples/vitepress/sfdx-project.json +0 -12
  121. package/jest.config.js +0 -10
  122. package/jest.d.ts +0 -7
  123. package/src/application/Apexdocs.ts +0 -72
  124. package/src/application/__tests__/apex-file-reader.spec.ts +0 -87
  125. package/src/application/apex-file-reader.ts +0 -55
  126. package/src/application/file-system.ts +0 -69
  127. package/src/application/file-writer.ts +0 -43
  128. package/src/application/generators/markdown.ts +0 -45
  129. package/src/application/generators/openapi.ts +0 -71
  130. package/src/cli/args.ts +0 -46
  131. package/src/cli/commands/markdown.ts +0 -51
  132. package/src/cli/commands/openapi.ts +0 -36
  133. package/src/cli/generate.ts +0 -16
  134. package/src/core/__test__/manifest.spec.ts +0 -16
  135. package/src/core/manifest.ts +0 -90
  136. package/src/core/markdown/__test__/expect-extensions.ts +0 -32
  137. package/src/core/markdown/__test__/generating-class-docs.spec.ts +0 -605
  138. package/src/core/markdown/__test__/generating-docs.spec.ts +0 -111
  139. package/src/core/markdown/__test__/generating-enum-docs.spec.ts +0 -321
  140. package/src/core/markdown/__test__/generating-interface-docs.spec.ts +0 -397
  141. package/src/core/markdown/__test__/generating-reference-guide.spec.ts +0 -180
  142. package/src/core/markdown/__test__/inheritance-chain.test.ts +0 -54
  143. package/src/core/markdown/__test__/test-helpers.ts +0 -23
  144. package/src/core/markdown/adapters/__tests__/documentables.spec.ts +0 -109
  145. package/src/core/markdown/adapters/__tests__/interface-adapter.spec.ts +0 -148
  146. package/src/core/markdown/adapters/__tests__/link-generator.spec.ts +0 -130
  147. package/src/core/markdown/adapters/__tests__/references.spec.ts +0 -136
  148. package/src/core/markdown/adapters/apex-types.ts +0 -238
  149. package/src/core/markdown/adapters/documentables.ts +0 -115
  150. package/src/core/markdown/adapters/fields-and-properties.ts +0 -45
  151. package/src/core/markdown/adapters/generate-link.ts +0 -82
  152. package/src/core/markdown/adapters/inline.ts +0 -143
  153. package/src/core/markdown/adapters/methods-and-constructors.ts +0 -133
  154. package/src/core/markdown/adapters/reference-guide.ts +0 -37
  155. package/src/core/markdown/adapters/renderable-bundle.ts +0 -61
  156. package/src/core/markdown/adapters/renderable-to-page-data.ts +0 -89
  157. package/src/core/markdown/adapters/type-utils.ts +0 -13
  158. package/src/core/markdown/adapters/types.d.ts +0 -180
  159. package/src/core/markdown/generate-docs.ts +0 -212
  160. package/src/core/markdown/reflection/__test__/filter-scope.spec.ts +0 -306
  161. package/src/core/markdown/reflection/filter-scope.ts +0 -13
  162. package/src/core/markdown/reflection/inheritance-chain-expanion.ts +0 -22
  163. package/src/core/markdown/reflection/inheritance-chain.ts +0 -23
  164. package/src/core/markdown/reflection/inherited-member-expansion.ts +0 -105
  165. package/src/core/markdown/reflection/reflect-source.ts +0 -123
  166. package/src/core/markdown/reflection/sort-members.ts +0 -59
  167. package/src/core/markdown/templates/class-template.ts +0 -75
  168. package/src/core/markdown/templates/constructors-partial-template.ts +0 -32
  169. package/src/core/markdown/templates/documentable-partial-template.ts +0 -26
  170. package/src/core/markdown/templates/enum-template.ts +0 -12
  171. package/src/core/markdown/templates/fieldsPartialTemplate.ts +0 -23
  172. package/src/core/markdown/templates/grouped-members-partial-template.ts +0 -6
  173. package/src/core/markdown/templates/hookable.ts +0 -7
  174. package/src/core/markdown/templates/interface-template.ts +0 -16
  175. package/src/core/markdown/templates/methods-partial-template.ts +0 -43
  176. package/src/core/markdown/templates/reference-guide.ts +0 -14
  177. package/src/core/markdown/templates/template.ts +0 -114
  178. package/src/core/markdown/templates/type-doc-partial.ts +0 -27
  179. package/src/core/markdown/utils.ts +0 -3
  180. package/src/core/openApiSettings.ts +0 -41
  181. package/src/core/openapi/__tests__/manifest-factory.spec.ts +0 -16
  182. package/src/core/openapi/__tests__/open-api-docs-processor.spec.ts +0 -56
  183. package/src/core/openapi/__tests__/open-api.spec.ts +0 -22
  184. package/src/core/openapi/apex-doc-types.ts +0 -26
  185. package/src/core/openapi/apex-type-wrappers/ClassMirrorWrapper.ts +0 -12
  186. package/src/core/openapi/apex-type-wrappers/MethodMirrorWrapper.ts +0 -11
  187. package/src/core/openapi/apex-type-wrappers/__tests__/ClassMirrorWrapper.spec.ts +0 -15
  188. package/src/core/openapi/file-container.ts +0 -13
  189. package/src/core/openapi/manifest-factory.ts +0 -16
  190. package/src/core/openapi/open-api-docs-processor.ts +0 -93
  191. package/src/core/openapi/open-api-types.ts +0 -119
  192. package/src/core/openapi/open-api.ts +0 -45
  193. package/src/core/openapi/openapi-type-file.ts +0 -12
  194. package/src/core/openapi/parser.ts +0 -160
  195. package/src/core/openapi/parsers/Builder.ts +0 -40
  196. package/src/core/openapi/parsers/MethodParser.ts +0 -249
  197. package/src/core/openapi/parsers/ParameterObjectBuilder.ts +0 -13
  198. package/src/core/openapi/parsers/ReferenceBuilder.ts +0 -299
  199. package/src/core/openapi/parsers/RequestBodyBuilder.ts +0 -19
  200. package/src/core/openapi/parsers/ResponsesBuilder.ts +0 -21
  201. package/src/core/openapi/parsers/__tests__/MethodParser.spec.ts +0 -44
  202. package/src/core/openapi/parsers/__tests__/ParameterObjectBuilder.spec.ts +0 -68
  203. package/src/core/openapi/parsers/__tests__/ReferenceBuilder.spec.ts +0 -751
  204. package/src/core/openapi/parsers/__tests__/RequestBodyBuilder.spec.ts +0 -64
  205. package/src/core/openapi/parsers/__tests__/ResponsesBuilder.spec.ts +0 -55
  206. package/src/core/openapi/transpiler.ts +0 -17
  207. package/src/core/openapi/types-repository.ts +0 -54
  208. package/src/core/parse-apex-metadata.ts +0 -30
  209. package/src/core/shared/types.d.ts +0 -148
  210. package/src/core/shared/utils.ts +0 -5
  211. package/src/defaults.ts +0 -9
  212. package/src/index.ts +0 -49
  213. package/src/test-helpers/AnnotationBuilder.ts +0 -29
  214. package/src/test-helpers/ClassMirrorBuilder.ts +0 -69
  215. package/src/test-helpers/DocCommentAnnotationBuilder.ts +0 -24
  216. package/src/test-helpers/DocCommentBuilder.ts +0 -36
  217. package/src/test-helpers/FieldMirrorBuilder.ts +0 -59
  218. package/src/test-helpers/InterfaceMirrorBuilder.ts +0 -39
  219. package/src/test-helpers/MethodMirrorBuilder.ts +0 -77
  220. package/src/test-helpers/SettingsBuilder.ts +0 -17
  221. package/src/util/error-logger.ts +0 -92
  222. package/src/util/fp.ts +0 -3
  223. package/src/util/logger.ts +0 -44
  224. package/src/util/string-utils.ts +0 -7
  225. package/tsconfig.json +0 -25
  226. package/tslint.json +0 -6
@@ -1,18 +0,0 @@
1
- {
2
- "name": "vitepress-example",
3
- "scripts": {
4
- "docs:clean": "rimraf --glob 'docs/!(.vitepress|index-frontmatter.md|api-examples.md|markdown-examples.md)'",
5
- "apexdocs:build": "npm run docs:clean && ts-node ../../src/cli/generate.ts markdown",
6
- "docs:build": "vitepress build docs",
7
- "docs:gen": "npm run docs:clean && npm run docs:build",
8
- "docs:dev": "vitepress dev docs",
9
- "docs:preview": "vitepress preview docs"
10
- },
11
- "devDependencies": {
12
- "ts-node": "^10.9.2",
13
- "vitepress": "^1.3.1"
14
- },
15
- "dependencies": {
16
- "rimraf": "^5.0.7"
17
- }
18
- }
@@ -1,12 +0,0 @@
1
- {
2
- "packageDirectories": [
3
- {
4
- "path": "force-app",
5
- "default": true
6
- }
7
- ],
8
- "name": "vitepress",
9
- "namespace": "",
10
- "sfdcLoginUrl": "https://login.salesforce.com",
11
- "sourceApiVersion": "61.0"
12
- }
package/jest.config.js DELETED
@@ -1,10 +0,0 @@
1
- module.exports = {
2
- preset: 'ts-jest',
3
- testEnvironment: 'node',
4
- modulePathIgnorePatterns: ['<rootDir>/dist/'],
5
- moduleNameMapper: {
6
- '^chalk$': '<rootDir>/__mocks__/chalk.js',
7
- '^log-update$': '<rootDir>/__mocks__/log-update.js',
8
- '#utils/(.*)$': '<rootDir>/src/util/$1',
9
- },
10
- };
package/jest.d.ts DELETED
@@ -1,7 +0,0 @@
1
- declare namespace jest {
2
- interface Matchers<R> {
3
- documentationBundleHasLength(length: number): R;
4
- firstDocContains(content: string): R;
5
- firstDocContainsNot(content: string): R;
6
- }
7
- }
@@ -1,72 +0,0 @@
1
- import markdown from './generators/markdown';
2
- import openApi from './generators/openapi';
3
-
4
- import { ApexFileReader } from './apex-file-reader';
5
- import { DefaultFileSystem } from './file-system';
6
- import { Logger } from '#utils/logger';
7
- import { UnparsedSourceFile, UserDefinedConfig, UserDefinedMarkdownConfig } from '../core/shared/types';
8
- import { pipe } from 'fp-ts/function';
9
- import * as TE from 'fp-ts/TaskEither';
10
- import { ReflectionError } from '../core/markdown/reflection/reflect-source';
11
-
12
- /**
13
- * Application entry-point to generate documentation out of Apex source files.
14
- */
15
- export class Apexdocs {
16
- /**
17
- * Generates documentation out of Apex source files.
18
- */
19
- static async generate(config: UserDefinedConfig): Promise<void> {
20
- Logger.logSingle(`Generating ${config.targetGenerator} documentation...`);
21
-
22
- try {
23
- const fileBodies = await ApexFileReader.processFiles(
24
- new DefaultFileSystem(),
25
- config.sourceDir,
26
- config.targetGenerator === 'markdown' ? config.includeMetadata : false,
27
- );
28
-
29
- switch (config.targetGenerator) {
30
- case 'markdown':
31
- await generateMarkdownDocumentation(fileBodies, config)();
32
- break;
33
- case 'openapi':
34
- await openApi(fileBodies, config);
35
- break;
36
- }
37
- } catch (error) {
38
- Logger.logSingle(`❌ An error occurred while generating the documentation: ${error}`, 'red');
39
- }
40
- }
41
- }
42
-
43
- function generateMarkdownDocumentation(fileBodies: UnparsedSourceFile[], config: UserDefinedMarkdownConfig) {
44
- return pipe(
45
- markdown(fileBodies, config),
46
- TE.map(() => Logger.logSingle('✔️ Documentation generated successfully!')),
47
- TE.mapLeft((error) => {
48
- if (error._tag === 'HookError') {
49
- Logger.error('Error(s) occurred while processing hooks. Please review the following issues:');
50
- Logger.error(error.error);
51
- return;
52
- }
53
-
54
- if (error._tag === 'FileWritingError') {
55
- Logger.error(error.message);
56
- Logger.error(error.error);
57
- return;
58
- }
59
-
60
- const errorMessages = [
61
- 'Error(s) occurred while parsing files. Please review the following issues:',
62
- ...error.errors.map(formatReflectionError),
63
- ].join('\n');
64
-
65
- Logger.error(errorMessages);
66
- }),
67
- );
68
- }
69
-
70
- function formatReflectionError(error: ReflectionError) {
71
- return `Source file: ${error.file}\n${error.message}\n`;
72
- }
@@ -1,87 +0,0 @@
1
- import { ApexFileReader } from '../apex-file-reader';
2
-
3
- describe('File Reader', () => {
4
- it('returns an empty list when there are no files in the directory', async () => {
5
- const result = await ApexFileReader.processFiles(
6
- {
7
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
8
- isDirectory(_: string): Promise<boolean> {
9
- return Promise.resolve(false);
10
- },
11
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
12
- joinPath(_: string): string {
13
- return '';
14
- },
15
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
16
- readDirectory(_: string): Promise<string[]> {
17
- return Promise.resolve([]);
18
- },
19
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
20
- readFile(_: string): Promise<string> {
21
- return Promise.resolve('');
22
- },
23
- exists(): boolean {
24
- return true;
25
- },
26
- },
27
- '',
28
- false,
29
- );
30
- expect(result.length).toBe(0);
31
- });
32
-
33
- it('returns an empty list when there are no Apex files in the directory', async () => {
34
- const result = await ApexFileReader.processFiles(
35
- {
36
- isDirectory(): Promise<boolean> {
37
- return Promise.resolve(false);
38
- },
39
- joinPath(): string {
40
- return '';
41
- },
42
- readDirectory(): Promise<string[]> {
43
- return Promise.resolve(['SomeFile.md']);
44
- },
45
- readFile(): Promise<string> {
46
- return Promise.resolve('');
47
- },
48
- exists(): boolean {
49
- return true;
50
- },
51
- },
52
- '',
53
- false,
54
- );
55
- expect(result.length).toBe(0);
56
- });
57
-
58
- it('returns the file contents for an Apex file', async () => {
59
- const result = await ApexFileReader.processFiles(
60
- {
61
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
62
- isDirectory(_: string): Promise<boolean> {
63
- return Promise.resolve(false);
64
- },
65
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
66
- joinPath(_: string): string {
67
- return 'SomeApexFile.cls';
68
- },
69
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
70
- readDirectory(_: string): Promise<string[]> {
71
- return Promise.resolve(['SomeApexFile.cls']);
72
- },
73
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
74
- readFile(_: string): Promise<string> {
75
- return Promise.resolve('public class MyClass{}');
76
- },
77
- exists(): boolean {
78
- return true;
79
- },
80
- },
81
- '',
82
- false,
83
- );
84
- expect(result.length).toBe(1);
85
- expect(result[0].content).toBe('public class MyClass{}');
86
- });
87
- });
@@ -1,55 +0,0 @@
1
- import { FileSystem } from './file-system';
2
- import { UnparsedSourceFile } from '../core/shared/types';
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 async processFiles(
14
- fileSystem: FileSystem,
15
- rootPath: string,
16
- includeMetadata: boolean,
17
- ): Promise<UnparsedSourceFile[]> {
18
- const filePaths = await this.getFilePaths(fileSystem, rootPath);
19
- const apexFilePaths = filePaths.filter((filePath) => this.isApexFile(filePath));
20
- const filePromises = apexFilePaths.map((filePath) => this.processFile(fileSystem, filePath, includeMetadata));
21
- return Promise.all(filePromises);
22
- }
23
-
24
- private static async getFilePaths(fileSystem: FileSystem, rootPath: string): Promise<string[]> {
25
- const directoryContents = await fileSystem.readDirectory(rootPath);
26
- const paths: string[] = [];
27
- for (const filePath of directoryContents) {
28
- const currentPath = fileSystem.joinPath(rootPath, filePath);
29
- if (await fileSystem.isDirectory(currentPath)) {
30
- paths.push(...(await this.getFilePaths(fileSystem, currentPath)));
31
- }
32
- paths.push(currentPath);
33
- }
34
- return paths;
35
- }
36
-
37
- private static async processFile(
38
- fileSystem: FileSystem,
39
- filePath: string,
40
- includeMetadata: boolean,
41
- ): Promise<UnparsedSourceFile> {
42
- const rawTypeContent = await fileSystem.readFile(filePath);
43
- const metadataPath = `${filePath}-meta.xml`;
44
- let rawMetadataContent = null;
45
- if (includeMetadata) {
46
- rawMetadataContent = fileSystem.exists(metadataPath) ? await fileSystem.readFile(metadataPath) : null;
47
- }
48
-
49
- return { filePath, content: rawTypeContent, metadataContent: rawMetadataContent };
50
- }
51
-
52
- private static isApexFile(currentFile: string): boolean {
53
- return currentFile.endsWith(APEX_FILE_EXTENSION);
54
- }
55
- }
@@ -1,69 +0,0 @@
1
- import * as fs from 'fs';
2
- import * as path from 'path';
3
-
4
- export interface FileSystem {
5
- isDirectory: (path: string) => Promise<boolean>;
6
- readDirectory: (sourceDirectory: string) => Promise<string[]>;
7
- readFile: (path: string) => Promise<string>;
8
- joinPath: (...paths: string[]) => string;
9
- exists: (path: string) => boolean;
10
- }
11
-
12
- function stat(path: string): Promise<fs.Stats> {
13
- return new Promise((resolve, reject) => {
14
- fs.stat(path, (err, stats) => {
15
- if (err) {
16
- reject(err);
17
- } else {
18
- resolve(stats);
19
- }
20
- });
21
- });
22
- }
23
-
24
- function readdir(path: string): Promise<string[]> {
25
- return new Promise((resolve, reject) => {
26
- fs.readdir(path, (err, files) => {
27
- if (err) {
28
- reject(err);
29
- } else {
30
- resolve(files);
31
- }
32
- });
33
- });
34
- }
35
-
36
- function readFile(path: string): Promise<string> {
37
- return new Promise((resolve, reject) => {
38
- fs.readFile(path, (err, data) => {
39
- if (err) {
40
- reject(err);
41
- } else {
42
- resolve(data.toString());
43
- }
44
- });
45
- });
46
- }
47
-
48
- export class DefaultFileSystem implements FileSystem {
49
- async isDirectory(pathToRead: string): Promise<boolean> {
50
- const stats = await stat(pathToRead);
51
- return stats.isDirectory();
52
- }
53
-
54
- readDirectory(sourceDirectory: string): Promise<string[]> {
55
- return readdir(sourceDirectory);
56
- }
57
-
58
- readFile(pathToRead: string): Promise<string> {
59
- return readFile(pathToRead);
60
- }
61
-
62
- joinPath(...paths: string[]): string {
63
- return path.join(...paths);
64
- }
65
-
66
- exists(path: string): boolean {
67
- return fs.existsSync(path);
68
- }
69
- }
@@ -1,43 +0,0 @@
1
- import * as fs from 'fs';
2
- import * as path from 'path';
3
- import * as TE from 'fp-ts/lib/TaskEither';
4
- import { PageData } from '../core/shared/types';
5
- import { pipe } from 'fp-ts/function';
6
-
7
- const mkdir: (path: fs.PathLike, options: fs.MakeDirectoryOptions) => TE.TaskEither<NodeJS.ErrnoException, void> =
8
- TE.taskify(fs.mkdir);
9
-
10
- const writeFile: (
11
- path: fs.PathOrFileDescriptor,
12
- data: string,
13
- options?: fs.WriteFileOptions,
14
- ) => TE.TaskEither<NodeJS.ErrnoException, void> = TE.taskify(fs.writeFile);
15
-
16
- export function writeFiles(files: PageData[], outputDir: string, onWriteCallback?: (file: PageData) => void) {
17
- return pipe(
18
- files,
19
- TE.traverseArray((file) => writeSingle(file, outputDir, onWriteCallback)),
20
- );
21
- }
22
-
23
- function writeSingle(file: PageData, outputDir: string, onWriteCallback?: (file: PageData) => void) {
24
- const ensureDirectoryExists = ({ outputDocPath }: PageData) =>
25
- mkdir(path.dirname(outputDocPath), { recursive: true });
26
-
27
- const writeContents = (file: PageData) => writeFile(file.outputDocPath, file.content, 'utf8');
28
-
29
- return pipe(
30
- resolveTargetLocation(file, outputDir),
31
- (file) => TE.right(file),
32
- TE.tapIO(ensureDirectoryExists),
33
- TE.flatMap(writeContents),
34
- TE.map(() => onWriteCallback?.(file)),
35
- );
36
- }
37
-
38
- function resolveTargetLocation(file: PageData, outputDir: string): PageData {
39
- return {
40
- ...file,
41
- outputDocPath: path.join(outputDir, file.outputDocPath),
42
- };
43
- }
@@ -1,45 +0,0 @@
1
- import { generateDocs } from '../../core/markdown/generate-docs';
2
- import { pipe } from 'fp-ts/function';
3
- import {
4
- PageData,
5
- PostHookDocumentationBundle,
6
- UnparsedSourceFile,
7
- UserDefinedMarkdownConfig,
8
- } from '../../core/shared/types';
9
- import { referenceGuideTemplate } from '../../core/markdown/templates/reference-guide';
10
- import * as TE from 'fp-ts/TaskEither';
11
- import { isSkip } from '../../core/shared/utils';
12
- import { writeFiles } from '../file-writer';
13
-
14
- class FileWritingError {
15
- readonly _tag = 'FileWritingError';
16
-
17
- constructor(
18
- public message: string,
19
- public error: unknown,
20
- ) {}
21
- }
22
-
23
- export default function generate(bundles: UnparsedSourceFile[], config: UserDefinedMarkdownConfig) {
24
- return pipe(
25
- generateDocumentationBundle(bundles, config),
26
- TE.flatMap((files) => writeFilesToSystem(files, config.targetDir)),
27
- );
28
- }
29
-
30
- function generateDocumentationBundle(bundles: UnparsedSourceFile[], config: UserDefinedMarkdownConfig) {
31
- return generateDocs(bundles, {
32
- ...config,
33
- referenceGuideTemplate: referenceGuideTemplate,
34
- });
35
- }
36
-
37
- function writeFilesToSystem(files: PostHookDocumentationBundle, outputDir: string) {
38
- return pipe(
39
- [files.referenceGuide, ...files.docs].filter((file) => !isSkip(file)),
40
- (files) => writeFiles(files as PageData[], outputDir),
41
- TE.mapLeft((error) => {
42
- return new FileWritingError('An error occurred while writing files to the system.', error);
43
- }),
44
- );
45
- }
@@ -1,71 +0,0 @@
1
- import { createManifest } from '../../core/openapi/manifest-factory';
2
- import { RawBodyParser } from '../../core/openapi/parser';
3
- import { TypesRepository } from '../../core/openapi/types-repository';
4
- import Transpiler from '../../core/openapi/transpiler';
5
- import { Logger } from '#utils/logger';
6
- import ErrorLogger from '#utils/error-logger';
7
- import { reflect, ReflectionResult } from '@cparra/apex-reflection';
8
- import Manifest from '../../core/manifest';
9
- import { PageData, UnparsedSourceFile, UserDefinedOpenApiConfig } from '../../core/shared/types';
10
- import { OpenApiDocsProcessor } from '../../core/openapi/open-api-docs-processor';
11
- import { writeFiles } from '../file-writer';
12
- import { pipe } from 'fp-ts/function';
13
- import * as TE from 'fp-ts/TaskEither';
14
- import { OpenApiSettings } from '../../core/openApiSettings';
15
-
16
- export default async function openApi(fileBodies: UnparsedSourceFile[], config: UserDefinedOpenApiConfig) {
17
- OpenApiSettings.build({
18
- sourceDirectory: config.sourceDir,
19
- outputDir: config.targetDir,
20
- openApiFileName: config.fileName,
21
- openApiTitle: config.title,
22
- namespace: config.namespace,
23
- version: config.apiVersion,
24
- });
25
-
26
- const manifest = createManifest(new RawBodyParser(fileBodies), reflectionWithLogger);
27
- TypesRepository.getInstance().populateAll(manifest.types);
28
- const filteredTypes = filterByScopes(manifest);
29
- const processor = new OpenApiDocsProcessor();
30
- Transpiler.generate(filteredTypes, processor);
31
- const generatedFiles = processor.fileBuilder().files();
32
-
33
- await pipe(
34
- writeFiles(generatedFiles, config.targetDir, (file: PageData) => {
35
- Logger.logSingle(`${file.outputDocPath} processed.`, 'green');
36
- }),
37
- TE.map(() => Logger.logSingle('✔️ Documentation generated successfully!')),
38
- TE.mapError((error) => Logger.error(error)),
39
- )();
40
-
41
- // Logs any errors that the types might have in their doc comment's error field
42
- ErrorLogger.logErrors(filteredTypes);
43
- }
44
-
45
- function reflectionWithLogger(apexBundle: UnparsedSourceFile): ReflectionResult {
46
- const result = reflect(apexBundle.content);
47
- if (result.error) {
48
- Logger.error(`${apexBundle.filePath} - Parsing error ${result.error?.message}`);
49
- }
50
- return result;
51
- }
52
-
53
- function filterByScopes(manifest: Manifest) {
54
- // If we are dealing with an OpenApi generator, we ignore the passed in access modifiers, and instead
55
- // we only keep classes annotated as @RestResource
56
- const filteredTypes = manifest.filteredByAccessModifierAndAnnotations([
57
- 'restresource',
58
- 'httpdelete',
59
- 'httpget',
60
- 'httppatch',
61
- 'httppost',
62
- 'httpput',
63
- ]);
64
- const filteredLogMessage = `Filtered ${
65
- manifest.types.length - filteredTypes.length
66
- } file(s), only keeping classes annotated as @RestResource.`;
67
-
68
- Logger.logSingle(filteredLogMessage, 'green');
69
- Logger.logSingle(`Creating documentation for ${filteredTypes.length} file(s)`, 'green');
70
- return filteredTypes;
71
- }
package/src/cli/args.ts DELETED
@@ -1,46 +0,0 @@
1
- import { cosmiconfig, CosmiconfigResult } from 'cosmiconfig';
2
- import * as yargs from 'yargs';
3
- import { UserDefinedMarkdownConfig } from '../core/shared/types';
4
- import { TypeScriptLoader } from 'cosmiconfig-typescript-loader';
5
- import { markdownOptions } from './commands/markdown';
6
- import { openApiOptions } from './commands/openapi';
7
-
8
- /**
9
- * Extracts configuration from a configuration file or the package.json
10
- * through cosmiconfig.
11
- */
12
- function _extractConfig(): Promise<CosmiconfigResult> {
13
- return cosmiconfig('apexdocs', {
14
- loaders: {
15
- '.ts': TypeScriptLoader(),
16
- },
17
- }).search();
18
- }
19
-
20
- /**
21
- * Extracts arguments from the command line.
22
- * @param config The configuration object from the configuration file, if any.
23
- */
24
- function _extractYargs(config?: CosmiconfigResult) {
25
- return yargs
26
- .config(config?.config)
27
- .command('markdown', 'Generate documentation from Apex classes as a Markdown site.', (yargs) =>
28
- yargs.options(markdownOptions),
29
- )
30
- .command('openapi', 'Generate an OpenApi REST specification from Apex classes.', () =>
31
- yargs.options(openApiOptions),
32
- )
33
- .demandCommand()
34
- .parseSync();
35
- }
36
-
37
- /**
38
- * Combines the extracted configuration and arguments.
39
- */
40
- export async function extractArgs(): Promise<UserDefinedMarkdownConfig> {
41
- const config = await _extractConfig();
42
- const cliArgs = _extractYargs(config);
43
- const commandName = cliArgs._[0];
44
-
45
- return { ...config?.config, ...cliArgs, targetGenerator: commandName as 'markdown' | 'openapi' };
46
- }
@@ -1,51 +0,0 @@
1
- import { Options } from 'yargs';
2
- import { defaults } from '../../defaults';
3
-
4
- export const markdownOptions: { [key: string]: Options } = {
5
- sourceDir: {
6
- type: 'string',
7
- alias: 's',
8
- demandOption: true,
9
- describe: 'The directory location which contains your apex .cls classes.',
10
- },
11
- targetDir: {
12
- type: 'string',
13
- alias: 't',
14
- default: defaults.targetDir,
15
- describe: 'The directory location where documentation will be generated to.',
16
- },
17
- scope: {
18
- type: 'string',
19
- array: true,
20
- alias: 'p',
21
- default: defaults.scope,
22
- describe:
23
- 'A list of scopes to document. Values should be separated by a space, e.g --scope global public namespaceaccessible. ' +
24
- 'Annotations are supported and should be passed lowercased and without the @ symbol, e.g. namespaceaccessible auraenabled.',
25
- },
26
- defaultGroupName: {
27
- type: 'string',
28
- default: defaults.defaultGroupName,
29
- describe: 'Defines the @group name to be used when a file does not specify it.',
30
- },
31
- namespace: {
32
- type: 'string',
33
- describe: 'The package namespace, if any. If provided, it will be added to the generated files.',
34
- },
35
- sortMembersAlphabetically: {
36
- type: 'boolean',
37
- describe: 'Whether to sort members alphabetically.',
38
- default: defaults.sortMembersAlphabetically,
39
- },
40
- includeMetadata: {
41
- type: 'boolean',
42
- describe: "Whether to include the file's meta.xml information: Whether it is active and and the API version",
43
- default: defaults.includeMetadata,
44
- },
45
- linkingStrategy: {
46
- type: 'string',
47
- describe: 'The strategy to use when linking to other documentation pages.',
48
- choices: ['relative', 'no-link', 'none'],
49
- default: defaults.linkingStrategy,
50
- },
51
- };
@@ -1,36 +0,0 @@
1
- import { Options } from 'yargs';
2
- import { defaults } from '../../defaults';
3
-
4
- export const openApiOptions: { [key: string]: Options } = {
5
- sourceDir: {
6
- type: 'string',
7
- alias: 's',
8
- demandOption: true,
9
- describe: 'The directory location which contains your apex .cls classes.',
10
- },
11
- targetDir: {
12
- type: 'string',
13
- alias: 't',
14
- default: defaults.targetDir,
15
- describe: 'The directory location where the OpenApi file will be generated.',
16
- },
17
- fileName: {
18
- type: 'string',
19
- default: 'openapi',
20
- describe: 'The name of the OpenApi file to be generated.',
21
- },
22
- namespace: {
23
- type: 'string',
24
- describe: 'The package namespace, if any. This will be added to the API file Server Url.',
25
- },
26
- title: {
27
- type: 'string',
28
- default: 'Apex REST API',
29
- describe: 'The title of the OpenApi file.',
30
- },
31
- apiVersion: {
32
- type: 'string',
33
- default: '1.0.0',
34
- describe: 'The version of the OpenApi file.',
35
- },
36
- };
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env node
2
- import { Apexdocs } from '../application/Apexdocs';
3
- import { extractArgs } from './args';
4
-
5
- function main() {
6
- function catchError(error: Error) {
7
- console.error(error);
8
- process.exit(1);
9
- }
10
-
11
- extractArgs()
12
- .then((config) => Apexdocs.generate(config).catch(catchError))
13
- .catch(catchError);
14
- }
15
-
16
- main();
@@ -1,16 +0,0 @@
1
- import Manifest from '../manifest';
2
- import { EnumMirror } from '@cparra/apex-reflection';
3
-
4
- const sampleEnum: EnumMirror = {
5
- annotations: [],
6
- name: 'SampleEnum',
7
- type_name: 'enum',
8
- access_modifier: 'public',
9
- values: [],
10
- };
11
-
12
- it('holds a list of types', () => {
13
- const types = [sampleEnum];
14
- const manifest = new Manifest(types);
15
- expect(manifest.types).toBe(types);
16
- });