@cparra/apexdocs 2.25.0-alpha.9 → 3.0.0-alpha.1

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 (39) hide show
  1. package/dist/cli/generate.js +18 -19
  2. package/dist/defaults-jLXD2y8-.js +13 -0
  3. package/dist/index.d.ts +2 -1
  4. package/dist/index.js +1 -1
  5. package/package.json +1 -1
  6. package/src/cli/args.ts +1 -1
  7. package/src/cli/commands/markdown.ts +6 -12
  8. package/src/cli/generate.ts +3 -3
  9. package/src/core/markdown/__test__/test-helpers.ts +1 -0
  10. package/src/core/markdown/adapters/__tests__/interface-adapter.spec.ts +1 -0
  11. package/src/core/markdown/adapters/renderable-bundle.ts +13 -3
  12. package/src/core/markdown/generate-docs.ts +1 -0
  13. package/src/core/shared/types.d.ts +1 -0
  14. package/src/defaults.ts +1 -0
  15. package/src/index.ts +6 -1
  16. /package/examples/{plain-markdown → markdown}/.forceignore +0 -0
  17. /package/examples/{plain-markdown → markdown}/config/project-scratch-def.json +0 -0
  18. /package/examples/{plain-markdown → markdown}/docs/index.md +0 -0
  19. /package/examples/{plain-markdown → markdown}/docs/miscellaneous/BaseClass.md +0 -0
  20. /package/examples/{plain-markdown → markdown}/docs/miscellaneous/MultiInheritanceClass.md +0 -0
  21. /package/examples/{plain-markdown → markdown}/docs/miscellaneous/ParentInterface.md +0 -0
  22. /package/examples/{plain-markdown → markdown}/docs/miscellaneous/ReferencedEnum.md +0 -0
  23. /package/examples/{plain-markdown → markdown}/docs/miscellaneous/SampleException.md +0 -0
  24. /package/examples/{plain-markdown → markdown}/docs/miscellaneous/SampleInterface.md +0 -0
  25. /package/examples/{plain-markdown → markdown}/docs/miscellaneous/Url.md +0 -0
  26. /package/examples/{plain-markdown → markdown}/docs/sample-enums/SampleEnum.md +0 -0
  27. /package/examples/{plain-markdown → markdown}/docs/samplegroup/SampleClass.md +0 -0
  28. /package/examples/{plain-markdown → markdown}/force-app/classes/BaseClass.cls +0 -0
  29. /package/examples/{plain-markdown → markdown}/force-app/classes/MultiInheritanceClass.cls +0 -0
  30. /package/examples/{plain-markdown → markdown}/force-app/classes/ParentInterface.cls +0 -0
  31. /package/examples/{plain-markdown → markdown}/force-app/classes/ReferencedEnum.cls +0 -0
  32. /package/examples/{plain-markdown → markdown}/force-app/classes/SampleClass.cls +0 -0
  33. /package/examples/{plain-markdown → markdown}/force-app/classes/SampleEnum.cls +0 -0
  34. /package/examples/{plain-markdown → markdown}/force-app/classes/SampleException.cls +0 -0
  35. /package/examples/{plain-markdown → markdown}/force-app/classes/SampleInterface.cls +0 -0
  36. /package/examples/{plain-markdown → markdown}/force-app/classes/Url.cls +0 -0
  37. /package/examples/{plain-markdown → markdown}/package-lock.json +0 -0
  38. /package/examples/{plain-markdown → markdown}/package.json +0 -0
  39. /package/examples/{plain-markdown → markdown}/sfdx-project.json +0 -0
@@ -5,13 +5,13 @@ var _function = require('fp-ts/function');
5
5
  var E = require('fp-ts/Either');
6
6
  var TE = require('fp-ts/TaskEither');
7
7
  var yaml = require('js-yaml');
8
+ var path = require('path');
8
9
  var apexReflection = require('@cparra/apex-reflection');
9
10
  var O = require('fp-ts/Option');
10
11
  var fastXmlParser = require('fast-xml-parser');
11
12
  var Handlebars = require('handlebars');
12
- var defaults = require('../defaults-DUwru49Q.js');
13
+ var defaults = require('../defaults-jLXD2y8-.js');
13
14
  var fs = require('fs');
14
- var path = require('path');
15
15
  var chalk = require('chalk');
16
16
  var logUpdate = require('log-update');
17
17
  var cosmiconfig = require('cosmiconfig');
@@ -38,9 +38,9 @@ function _interopNamespaceDefault(e) {
38
38
  var E__namespace = /*#__PURE__*/_interopNamespaceDefault(E);
39
39
  var TE__namespace = /*#__PURE__*/_interopNamespaceDefault(TE);
40
40
  var yaml__namespace = /*#__PURE__*/_interopNamespaceDefault(yaml);
41
+ var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
41
42
  var O__namespace = /*#__PURE__*/_interopNamespaceDefault(O);
42
43
  var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
43
- var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
44
44
  var yargs__namespace = /*#__PURE__*/_interopNamespaceDefault(yargs);
45
45
 
46
46
  function apply(fn, ...front) {
@@ -570,7 +570,7 @@ function singleGroup(headingLevel, groupName, adapter, members, linkGenerator) {
570
570
  }
571
571
 
572
572
  function parsedFilesToRenderableBundle(config, parsedFiles, references) {
573
- const referenceFinder = apply(linkGenerator, references);
573
+ const referenceFinder = apply(linkGenerator, references, config.documentationRootDir);
574
574
  function toReferenceGuide(parsedFiles2) {
575
575
  return parsedFiles2.reduce(
576
576
  addToReferenceGuide(referenceFinder, config, references),
@@ -604,11 +604,15 @@ function addToReferenceGuide(findLinkFromHome, config, references) {
604
604
  return acc;
605
605
  };
606
606
  }
607
- const linkGenerator = (references, referenceName) => {
607
+ const linkGenerator = (references, documentationRootDir, referenceName) => {
608
608
  const reference = references[referenceName];
609
609
  return reference ? (
610
610
  // Starting the path with a "/" will ensure the link will always be relative to the root of the site.
611
- { __type: "link", title: reference.displayName, url: `/${reference.pathFromRoot}` }
611
+ {
612
+ __type: "link",
613
+ title: reference.displayName,
614
+ url: path__namespace.join("/", documentationRootDir, reference.pathFromRoot)
615
+ }
612
616
  ) : referenceName;
613
617
  };
614
618
  function getTypeGroup$1(type, config) {
@@ -2859,27 +2863,17 @@ const markdownOptions = {
2859
2863
  array: true,
2860
2864
  alias: "p",
2861
2865
  default: defaults.defaults.scope,
2862
- describe: "A list of scopes to document. Values should be separated by a space, e.g --scope global public namespaceaccessible. Annotations are supported and should be passed lowercased and without the @ symbol, e.g. namespaceaccessible auraenabled. Note that this setting is ignored if generating an OpenApi REST specification since that looks for classes annotated with @RestResource."
2866
+ describe: "A list of scopes to document. Values should be separated by a space, e.g --scope global public namespaceaccessible. Annotations are supported and should be passed lowercased and without the @ symbol, e.g. namespaceaccessible auraenabled."
2863
2867
  },
2864
2868
  defaultGroupName: {
2865
2869
  type: "string",
2866
2870
  default: defaults.defaults.defaultGroupName,
2867
2871
  describe: "Defines the @group name to be used when a file does not specify it."
2868
2872
  },
2869
- openApiTitle: {
2870
- type: "string",
2871
- default: "Apex REST Api",
2872
- describe: 'If using "openapi" as the target generator, this allows you to specify the OpenApi title value.'
2873
- },
2874
2873
  namespace: {
2875
2874
  type: "string",
2876
2875
  describe: "The package namespace, if any. If this value is provided the namespace will be added as a prefix to all of the parsed files. If generating an OpenApi definition, it will be added to the file's Server Url."
2877
2876
  },
2878
- openApiFileName: {
2879
- type: "string",
2880
- describe: 'If using "openapi" as the target generator, this allows you to specify the name of the output file.',
2881
- default: "openapi"
2882
- },
2883
2877
  sortMembersAlphabetically: {
2884
2878
  type: "boolean",
2885
2879
  describe: "Whether to sort members alphabetically.",
@@ -2889,6 +2883,11 @@ const markdownOptions = {
2889
2883
  type: "boolean",
2890
2884
  describe: "Whether to include the file's meta.xml information: Whether it is active and and the API version",
2891
2885
  default: defaults.defaults.includeMetadata
2886
+ },
2887
+ documentationRootDir: {
2888
+ type: "string",
2889
+ describe: "The root directory of the documentation. This is used to generate the correct relative paths.",
2890
+ default: defaults.defaults.documentationRootDir
2892
2891
  }
2893
2892
  };
2894
2893
 
@@ -2955,10 +2954,10 @@ function extractArgs() {
2955
2954
  }
2956
2955
 
2957
2956
  function main() {
2958
- function cathError(error) {
2957
+ function catchError(error) {
2959
2958
  console.error(error);
2960
2959
  process.exit(1);
2961
2960
  }
2962
- extractArgs().then((config) => Apexdocs.generate(config).catch(cathError)).catch(cathError);
2961
+ extractArgs().then((config) => Apexdocs.generate(config).catch(catchError)).catch(catchError);
2963
2962
  }
2964
2963
  main();
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ const defaults = {
4
+ targetGenerator: "markdown",
5
+ targetDir: "./docs/",
6
+ scope: ["global"],
7
+ defaultGroupName: "Miscellaneous",
8
+ includeMetadata: false,
9
+ sortMembersAlphabetically: false,
10
+ documentationRootDir: ""
11
+ };
12
+
13
+ exports.defaults = defaults;
package/dist/index.d.ts CHANGED
@@ -19,6 +19,7 @@ type UserDefinedMarkdownConfig = {
19
19
  namespace?: string;
20
20
  sortMembersAlphabetically: boolean;
21
21
  includeMetadata: boolean;
22
+ documentationRootDir: string;
22
23
  } & Partial<ConfigurableHooks>;
23
24
 
24
25
  type SourceFileMetadata = {
@@ -93,7 +94,7 @@ type TransformDocPage = (
93
94
  doc: DocPageData,
94
95
  ) => Partial<ConfigurableDocPageData> | Promise<Partial<ConfigurableDocPageData>>;
95
96
 
96
- type ConfigurableMarkdownConfig = Omit<SetOptional<UserDefinedMarkdownConfig, 'targetDir' | 'scope' | 'defaultGroupName' | 'includeMetadata' | 'sortMembersAlphabetically'>, 'targetGenerator'>;
97
+ type ConfigurableMarkdownConfig = Omit<SetOptional<UserDefinedMarkdownConfig, 'targetDir' | 'scope' | 'defaultGroupName' | 'includeMetadata' | 'sortMembersAlphabetically' | 'documentationRootDir'>, 'targetGenerator'>;
97
98
  declare function defineMarkdownConfig(config: ConfigurableMarkdownConfig): UserDefinedMarkdownConfig;
98
99
  declare function skip(): Skip;
99
100
 
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var defaults = require('./defaults-DUwru49Q.js');
3
+ var defaults = require('./defaults-jLXD2y8-.js');
4
4
 
5
5
  var __defProp = Object.defineProperty;
6
6
  var __defProps = Object.defineProperties;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cparra/apexdocs",
3
- "version": "2.25.0-alpha.9",
3
+ "version": "3.0.0-alpha.1",
4
4
  "description": "Library with CLI capabilities to generate documentation for Salesforce Apex classes.",
5
5
  "keywords": [
6
6
  "apex",
package/src/cli/args.ts CHANGED
@@ -26,7 +26,7 @@ function _extractYargs(config?: CosmiconfigResult) {
26
26
  .command('markdown', 'Generate documentation from Apex classes as a Markdown site.', (yargs) =>
27
27
  yargs.options(markdownOptions),
28
28
  )
29
- .command('openapi', 'Generate an OpenApi REST specification from Apex classes.')
29
+ .command('openapi', 'Generate an OpenApi REST specification from Apex classes.') // TODO: Add OpenApi specific options
30
30
  .demandCommand()
31
31
  .parseSync();
32
32
  }
@@ -21,30 +21,19 @@ export const markdownOptions: { [key: string]: Options } = {
21
21
  default: defaults.scope,
22
22
  describe:
23
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
- 'Note that this setting is ignored if generating an OpenApi REST specification since that looks for classes annotated with @RestResource.',
24
+ 'Annotations are supported and should be passed lowercased and without the @ symbol, e.g. namespaceaccessible auraenabled.',
26
25
  },
27
26
  defaultGroupName: {
28
27
  type: 'string',
29
28
  default: defaults.defaultGroupName,
30
29
  describe: 'Defines the @group name to be used when a file does not specify it.',
31
30
  },
32
- openApiTitle: {
33
- type: 'string',
34
- default: 'Apex REST Api',
35
- describe: 'If using "openapi" as the target generator, this allows you to specify the OpenApi title value.',
36
- },
37
31
  namespace: {
38
32
  type: 'string',
39
33
  describe:
40
34
  'The package namespace, if any. If this value is provided the namespace will be added as a prefix to all of the parsed files. ' +
41
35
  "If generating an OpenApi definition, it will be added to the file's Server Url.",
42
36
  },
43
- openApiFileName: {
44
- type: 'string',
45
- describe: 'If using "openapi" as the target generator, this allows you to specify the name of the output file.',
46
- default: 'openapi',
47
- },
48
37
  sortMembersAlphabetically: {
49
38
  type: 'boolean',
50
39
  describe: 'Whether to sort members alphabetically.',
@@ -55,4 +44,9 @@ export const markdownOptions: { [key: string]: Options } = {
55
44
  describe: "Whether to include the file's meta.xml information: Whether it is active and and the API version",
56
45
  default: defaults.includeMetadata,
57
46
  },
47
+ documentationRootDir: {
48
+ type: 'string',
49
+ describe: 'The root directory of the documentation. This is used to generate the correct relative paths.',
50
+ default: defaults.documentationRootDir,
51
+ },
58
52
  };
@@ -3,14 +3,14 @@ import { Apexdocs } from '../application/Apexdocs';
3
3
  import { extractArgs } from './args';
4
4
 
5
5
  function main() {
6
- function cathError(error: Error) {
6
+ function catchError(error: Error) {
7
7
  console.error(error);
8
8
  process.exit(1);
9
9
  }
10
10
 
11
11
  extractArgs()
12
- .then((config) => Apexdocs.generate(config).catch(cathError))
13
- .catch(cathError);
12
+ .then((config) => Apexdocs.generate(config).catch(catchError))
13
+ .catch(catchError);
14
14
  }
15
15
 
16
16
  main();
@@ -18,5 +18,6 @@ export function generateDocs(apexBundles: UnparsedSourceFile[], config?: Partial
18
18
  sortMembersAlphabetically: true,
19
19
  referenceGuideTemplate: referenceGuideTemplate,
20
20
  ...config,
21
+ documentationRootDir: '',
21
22
  });
22
23
  }
@@ -15,6 +15,7 @@ const defaultMarkdownGeneratorConfig: MarkdownGeneratorConfig = {
15
15
  defaultGroupName: 'Miscellaneous',
16
16
  referenceGuideTemplate: '',
17
17
  sortMembersAlphabetically: false,
18
+ documentationRootDir: '',
18
19
  };
19
20
 
20
21
  describe('Conversion from InterfaceMirror to InterfaceSource understandable by the templating engine', () => {
@@ -5,13 +5,14 @@ import { adaptDescribable } from './documentables';
5
5
  import { MarkdownGeneratorConfig } from '../generate-docs';
6
6
  import { apply } from '#utils/fp';
7
7
  import { Type } from '@cparra/apex-reflection';
8
+ import * as path from 'path';
8
9
 
9
10
  export function parsedFilesToRenderableBundle(
10
11
  config: MarkdownGeneratorConfig,
11
12
  parsedFiles: ParsedFile[],
12
13
  references: Record<string, DocPageReference>,
13
14
  ): RenderableBundle {
14
- const referenceFinder = apply(linkGenerator, references);
15
+ const referenceFinder = apply(linkGenerator, references, config.documentationRootDir);
15
16
 
16
17
  function toReferenceGuide(parsedFiles: ParsedFile[]): Record<string, ReferenceGuideReference[]> {
17
18
  return parsedFiles.reduce<Record<string, ReferenceGuideReference[]>>(
@@ -54,11 +55,20 @@ function addToReferenceGuide(
54
55
  };
55
56
  }
56
57
 
57
- const linkGenerator = (references: Record<string, DocPageReference>, referenceName: string): StringOrLink => {
58
+ const linkGenerator = (
59
+ references: Record<string, DocPageReference>,
60
+ documentationRootDir: string,
61
+ referenceName: string,
62
+ ): StringOrLink => {
58
63
  const reference: DocPageReference | undefined = references[referenceName];
64
+
59
65
  return reference
60
66
  ? // Starting the path with a "/" will ensure the link will always be relative to the root of the site.
61
- { __type: 'link', title: reference.displayName, url: `/${reference.pathFromRoot}` }
67
+ {
68
+ __type: 'link',
69
+ title: reference.displayName,
70
+ url: path.join('/', documentationRootDir, reference.pathFromRoot),
71
+ }
62
72
  : referenceName;
63
73
  };
64
74
 
@@ -42,6 +42,7 @@ export type MarkdownGeneratorConfig = Pick<
42
42
  | 'transformDocs'
43
43
  | 'transformDocPage'
44
44
  | 'transformReference'
45
+ | 'documentationRootDir'
45
46
  > & {
46
47
  referenceGuideTemplate: string;
47
48
  sortMembersAlphabetically: boolean;
@@ -21,6 +21,7 @@ export type UserDefinedMarkdownConfig = {
21
21
  namespace?: string;
22
22
  sortMembersAlphabetically: boolean;
23
23
  includeMetadata: boolean;
24
+ documentationRootDir: string;
24
25
  } & Partial<ConfigurableHooks>;
25
26
 
26
27
  export type UserDefinedOpenApiConfig = {
package/src/defaults.ts CHANGED
@@ -5,4 +5,5 @@ export const defaults = {
5
5
  defaultGroupName: 'Miscellaneous',
6
6
  includeMetadata: false,
7
7
  sortMembersAlphabetically: false,
8
+ documentationRootDir: '',
8
9
  };
package/src/index.ts CHANGED
@@ -12,7 +12,12 @@ import { defaults } from './defaults';
12
12
  type ConfigurableMarkdownConfig = Omit<
13
13
  SetOptional<
14
14
  UserDefinedMarkdownConfig,
15
- 'targetDir' | 'scope' | 'defaultGroupName' | 'includeMetadata' | 'sortMembersAlphabetically'
15
+ | 'targetDir'
16
+ | 'scope'
17
+ | 'defaultGroupName'
18
+ | 'includeMetadata'
19
+ | 'sortMembersAlphabetically'
20
+ | 'documentationRootDir'
16
21
  >,
17
22
  'targetGenerator'
18
23
  >;