@cparra/apexdocs 3.10.0 → 3.11.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.
package/README.md CHANGED
@@ -351,10 +351,62 @@ There are hooks for both Markdown and Changelog operations (but not for OpenApi)
351
351
 
352
352
  #### Markdown Hooks
353
353
 
354
+ ##### **macros**
355
+
356
+ Allows defining custom macros that can be used in the documentation.
357
+
358
+ Macros are reusable pieces of text that can be injected into the documentation,
359
+ allowing you to define common pieces of text that you can use across multiple files.
360
+
361
+ A common use case is injecting copyright or license information, without
362
+ having to copy-paste the same text across multiple classes, polluting your
363
+ source code.
364
+
365
+ A macro can be defined in your documentation using the `{{macro_name}}` syntax.
366
+ In the configuration file, you can then define the macro behavior as a key-value pair, where the key is the name of the macro, and the value is a function that returns the text to inject in place of the macro.
367
+
368
+ **Type**
369
+
370
+ ```typescript
371
+ type MacroSourceMetadata = {
372
+ type: 'apex' | 'customobject' | 'customfield' | 'custommetadata' | 'trigger';
373
+ name: string;
374
+ filePath: string;
375
+ };
376
+
377
+ type MacroFunction = (metadata: MacroSourceMetadata) => string;
378
+ ```
379
+
380
+ Notice that the `metadata` object contains information about the source of the file for which the macro is being injected. This allows you to optionally
381
+ return different text based on the source of the file.
382
+
383
+ Example: Injecting a copyright notice
384
+
385
+ ```typescript
386
+ //...
387
+ macros: {
388
+ copyright: () => {
389
+ return `Copyright (c) ${new Date().getFullYear()} My Name`;
390
+ }
391
+ }
392
+ //...
393
+ ```
394
+
395
+ And then in your source code, you can use the macro like this:
396
+
397
+ ```apex
398
+ /**
399
+ * {{copyright}}
400
+ * @description This is a class
401
+ */
402
+ public class MyClass {
403
+ //...
404
+ }
405
+ ```
406
+
354
407
  ##### **transformReferenceGuide**
355
408
 
356
- Allows changing the Allows changing the frontmatter and content of the reference guide, or even if creating a reference
357
- guide page should be skipped.
409
+ Allows changing the frontmatter and content of the reference guide, or if creating a reference guide page altogether should be skipped.
358
410
 
359
411
  **Type**
360
412
 
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict';
3
3
 
4
- var logger$1 = require('../logger-D2kLvcfb.js');
4
+ var logger$1 = require('../logger-C1Ezw_pW.js');
5
5
  var module$1 = require('module');
6
6
  var cosmiconfig = require('cosmiconfig');
7
7
  var E = require('fp-ts/Either');
package/dist/index.d.ts CHANGED
@@ -11,6 +11,14 @@ type LinkingStrategy =
11
11
  // No logic will be applied, the reference path will be used as is.
12
12
  | 'none';
13
13
 
14
+ type MacroSourceMetadata = {
15
+ type: 'apex' | 'customobject' | 'customfield' | 'custommetadata' | 'trigger';
16
+ name: string;
17
+ filePath: string;
18
+ };
19
+
20
+ type MacroFunction = (metadata: MacroSourceMetadata) => string;
21
+
14
22
  type CliConfigurableMarkdownConfig = {
15
23
  sourceDir: string;
16
24
  targetDir: string;
@@ -152,6 +160,7 @@ type Skip = {
152
160
  * The configurable hooks that can be used to modify the output of the Markdown generator.
153
161
  */
154
162
  type MarkdownConfigurableHooks = {
163
+ macros: Record<string, MacroFunction>;
155
164
  transformReferenceGuide: TransformReferenceGuide;
156
165
  transformDocs: TransformDocs;
157
166
  transformDocPage: TransformDocPage;
@@ -232,4 +241,4 @@ type ConfigurableChangelogConfig = Omit<Partial<UserDefinedChangelogConfig>, 'ta
232
241
  */
233
242
  declare function defineChangelogConfig(config: ConfigurableChangelogConfig): Partial<UserDefinedChangelogConfig>;
234
243
 
235
- export { type ChangeLogPageData, type ChangelogConfigurableHooks, type ConfigurableChangelogConfig, type ConfigurableDocPageData, type ConfigurableDocPageReference, type ConfigurableMarkdownConfig, type ConfigurableOpenApiConfig, type DocPageData, type DocPageReference, type MarkdownConfigurableHooks, type ReferenceGuidePageData, type Skip, type SourceChangelog, type TransformChangelogPage, type TransformDocPage, type TransformDocs, type TransformReference, type TransformReferenceGuide, defineChangelogConfig, defineMarkdownConfig, defineOpenApiConfig, process, skip };
244
+ export { type ChangeLogPageData, type ChangelogConfigurableHooks, type ConfigurableChangelogConfig, type ConfigurableDocPageData, type ConfigurableDocPageReference, type ConfigurableMarkdownConfig, type ConfigurableOpenApiConfig, type DocPageData, type DocPageReference, type MacroFunction, type MacroSourceMetadata, type MarkdownConfigurableHooks, type ReferenceGuidePageData, type Skip, type SourceChangelog, type TransformChangelogPage, type TransformDocPage, type TransformDocs, type TransformReference, type TransformReferenceGuide, defineChangelogConfig, defineMarkdownConfig, defineOpenApiConfig, process, skip };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var logger = require('./logger-D2kLvcfb.js');
3
+ var logger = require('./logger-C1Ezw_pW.js');
4
4
  var E = require('fp-ts/Either');
5
5
  require('fp-ts/function');
6
6
  require('fp-ts/TaskEither');
@@ -2590,7 +2590,8 @@ function generateDocs(unparsedBundles, config) {
2590
2590
  );
2591
2591
  }
2592
2592
  return _function.pipe(
2593
- generateForApex(filterApexSourceFiles(unparsedBundles), config),
2593
+ TE__namespace.right(replaceMacros(unparsedBundles, config.macros)),
2594
+ TE__namespace.flatMap((unparsedBundles2) => generateForApex(filterApexSourceFiles(unparsedBundles2), config)),
2594
2595
  TE__namespace.chain((parsedApexFiles) => {
2595
2596
  return _function.pipe(
2596
2597
  reflectCustomFieldsAndObjectsAndMetadataRecords(
@@ -2624,6 +2625,25 @@ function generateDocs(unparsedBundles, config) {
2624
2625
  TE__namespace.map(postHookCompile$1)
2625
2626
  );
2626
2627
  }
2628
+ function replaceMacros(unparsedBundles, macros) {
2629
+ if (!macros) {
2630
+ return unparsedBundles;
2631
+ }
2632
+ return unparsedBundles.map((bundle) => {
2633
+ return __spreadProps$8(__spreadValues$8({}, bundle), {
2634
+ content: Object.entries(macros).reduce((acc, [macroName, macroFunction]) => {
2635
+ return acc.replace(
2636
+ new RegExp(`{{${macroName}}}`, "g"),
2637
+ macroFunction({
2638
+ type: bundle.type,
2639
+ name: bundle.name,
2640
+ filePath: bundle.filePath
2641
+ })
2642
+ );
2643
+ }, bundle.content)
2644
+ });
2645
+ });
2646
+ }
2627
2647
  function generateForApex(apexBundles, config) {
2628
2648
  const filterOutOfScope = apply(filterScope, config.scope);
2629
2649
  const removeExcluded = apply(removeExcludedTags, config.excludeTags);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cparra/apexdocs",
3
- "version": "3.10.0",
3
+ "version": "3.11.0",
4
4
  "description": "Library with CLI capabilities to generate documentation for Salesforce Apex classes.",
5
5
  "keywords": [
6
6
  "apex",