@cparra/apexdocs 3.0.0-alpha.5 → 3.0.0-alpha.7

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.
@@ -13,7 +13,6 @@ var Handlebars = require('handlebars');
13
13
  var defaults = require('../defaults-DGKfeZq-.js');
14
14
  var fs = require('fs');
15
15
  var chalk = require('chalk');
16
- var ora = require('ora');
17
16
  var cosmiconfig = require('cosmiconfig');
18
17
  var yargs = require('yargs');
19
18
  var cosmiconfigTypescriptLoader = require('cosmiconfig-typescript-loader');
@@ -1690,7 +1689,7 @@ class FileWriter {
1690
1689
  const { outputDocPath, content } = this.getTargetLocation(file, outputDir);
1691
1690
  fs__namespace.mkdirSync(path__namespace.dirname(outputDocPath), { recursive: true });
1692
1691
  fs__namespace.writeFileSync(outputDocPath, content, "utf8");
1693
- onWriteCallback(file);
1692
+ onWriteCallback == null ? void 0 : onWriteCallback(file);
1694
1693
  });
1695
1694
  }
1696
1695
  static getTargetLocation(file, outputDir) {
@@ -1734,16 +1733,8 @@ class Logger {
1734
1733
  static getChalkFn(color) {
1735
1734
  return color === "green" ? chalk.green : chalk.red;
1736
1735
  }
1737
- static startSpinner(text) {
1738
- this.spinner.text = text;
1739
- this.spinner.start();
1740
- }
1741
- static succeedSpinner(text) {
1742
- this.spinner.succeed(text);
1743
- }
1744
1736
  }
1745
1737
  Logger.currentFrame = 0;
1746
- Logger.spinner = ora();
1747
1738
 
1748
1739
  const referenceGuideTemplate = `
1749
1740
  # Apex Reference Guide
@@ -1779,16 +1770,28 @@ var __spreadValues$5 = (a, b) => {
1779
1770
  return a;
1780
1771
  };
1781
1772
  var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
1773
+ class FileWritingError {
1774
+ constructor(message, error) {
1775
+ this.message = message;
1776
+ this.error = error;
1777
+ this._tag = "FileWritingError";
1778
+ }
1779
+ }
1782
1780
  function generate(bundles, config) {
1783
1781
  return _function.pipe(
1784
1782
  generateDocumentationBundle(bundles, config),
1785
- TE__namespace.map((files) => writeFilesToSystem(files, config.targetDir)),
1783
+ TE__namespace.flatMap((files) => writeFilesToSystem(files, config.targetDir)),
1786
1784
  TE__namespace.mapLeft((error) => {
1787
1785
  if (error._tag === "HookError") {
1788
1786
  Logger.error("Error(s) occurred while processing hooks. Please review the following issues:");
1789
1787
  Logger.error(error.error);
1790
1788
  return;
1791
1789
  }
1790
+ if (error._tag === "FileWritingError") {
1791
+ Logger.error(error.message);
1792
+ Logger.error(error.error);
1793
+ return;
1794
+ }
1792
1795
  const errorMessages = [
1793
1796
  "Error(s) occurred while parsing files. Please review the following issues:",
1794
1797
  ...error.errors.map(formatReflectionError)
@@ -1803,12 +1806,15 @@ function generateDocumentationBundle(bundles, config) {
1803
1806
  }));
1804
1807
  }
1805
1808
  function writeFilesToSystem(files, outputDir) {
1806
- FileWriter.write(
1807
- [files.referenceGuide, ...files.docs].filter((file) => !isSkip(file)),
1808
- outputDir,
1809
- () => {
1810
- }
1811
- );
1809
+ try {
1810
+ FileWriter.write(
1811
+ [files.referenceGuide, ...files.docs].filter((file) => !isSkip(file)),
1812
+ outputDir
1813
+ );
1814
+ return TE__namespace.right(void 0);
1815
+ } catch (error) {
1816
+ return TE__namespace.left(new FileWritingError("An error occurred while writing files to the system.", error));
1817
+ }
1812
1818
  }
1813
1819
  function formatReflectionError(error) {
1814
1820
  return `Source file: ${error.file}
@@ -2867,8 +2873,7 @@ class Apexdocs {
2867
2873
  */
2868
2874
  static generate(config) {
2869
2875
  return __async$1(this, null, function* () {
2870
- Logger.logSingle("Initializing...");
2871
- Logger.startSpinner("Processing files...");
2876
+ Logger.logSingle(`Generating ${config.targetGenerator} documentation...`);
2872
2877
  try {
2873
2878
  const fileBodies = ApexFileReader.processFiles(new DefaultFileSystem(), config.sourceDir, config.includeMetadata);
2874
2879
  switch (config.targetGenerator) {
@@ -2879,8 +2884,9 @@ class Apexdocs {
2879
2884
  openApi(fileBodies, config);
2880
2885
  break;
2881
2886
  }
2882
- } finally {
2883
- Logger.succeedSpinner("Files processed.");
2887
+ Logger.logSingle("\u2714\uFE0F Documentation generated successfully!");
2888
+ } catch (error) {
2889
+ Logger.logSingle("\u274C An error occurred while generating the documentation.", "red");
2884
2890
  }
2885
2891
  });
2886
2892
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cparra/apexdocs",
3
- "version": "3.0.0-alpha.5",
3
+ "version": "3.0.0-alpha.7",
4
4
  "description": "Library with CLI capabilities to generate documentation for Salesforce Apex classes.",
5
5
  "keywords": [
6
6
  "apex",
@@ -68,7 +68,6 @@
68
68
  "fp-ts": "^2.16.8",
69
69
  "handlebars": "^4.7.8",
70
70
  "js-yaml": "^4.1.0",
71
- "ora": "^5.4.1",
72
71
  "type-fest": "^4.23.0",
73
72
  "yargs": "^17.7.2"
74
73
  },
@@ -14,8 +14,7 @@ export class Apexdocs {
14
14
  * Generates documentation out of Apex source files.
15
15
  */
16
16
  static async generate(config: UserDefinedConfig): Promise<void> {
17
- Logger.logSingle('Initializing...');
18
- Logger.startSpinner('Processing files...');
17
+ Logger.logSingle(`Generating ${config.targetGenerator} documentation...`);
19
18
 
20
19
  try {
21
20
  const fileBodies = ApexFileReader.processFiles(new DefaultFileSystem(), config.sourceDir, config.includeMetadata);
@@ -28,9 +27,10 @@ export class Apexdocs {
28
27
  openApi(fileBodies, config);
29
28
  break;
30
29
  }
31
- } finally {
32
- // TODO: Allow for failures
33
- Logger.succeedSpinner('Files processed.');
30
+
31
+ Logger.logSingle('✔️ Documentation generated successfully!');
32
+ } catch (error) {
33
+ Logger.logSingle('❌ An error occurred while generating the documentation.', 'red');
34
34
  }
35
35
  }
36
36
  }
@@ -3,12 +3,12 @@ import * as path from 'path';
3
3
  import { PageData } from '../core/shared/types';
4
4
 
5
5
  export class FileWriter {
6
- static write(files: PageData[], outputDir: string, onWriteCallback: (file: PageData) => void) {
6
+ static write(files: PageData[], outputDir: string, onWriteCallback?: (file: PageData) => void) {
7
7
  files.forEach((file) => {
8
8
  const { outputDocPath, content } = this.getTargetLocation(file, outputDir);
9
9
  fs.mkdirSync(path.dirname(outputDocPath), { recursive: true });
10
10
  fs.writeFileSync(outputDocPath, content, 'utf8');
11
- onWriteCallback(file);
11
+ onWriteCallback?.(file);
12
12
  });
13
13
  }
14
14
 
@@ -13,10 +13,18 @@ import { referenceGuideTemplate } from '../../core/markdown/templates/reference-
13
13
  import * as TE from 'fp-ts/TaskEither';
14
14
  import { isSkip } from '../../core/shared/utils';
15
15
 
16
+ class FileWritingError {
17
+ readonly _tag = 'FileWritingError';
18
+ constructor(
19
+ public message: string,
20
+ public error: unknown,
21
+ ) {}
22
+ }
23
+
16
24
  export default function generate(bundles: UnparsedSourceFile[], config: UserDefinedMarkdownConfig) {
17
25
  return pipe(
18
26
  generateDocumentationBundle(bundles, config),
19
- TE.map((files) => writeFilesToSystem(files, config.targetDir)),
27
+ TE.flatMap((files) => writeFilesToSystem(files, config.targetDir)),
20
28
  TE.mapLeft((error) => {
21
29
  if (error._tag === 'HookError') {
22
30
  Logger.error('Error(s) occurred while processing hooks. Please review the following issues:');
@@ -24,6 +32,12 @@ export default function generate(bundles: UnparsedSourceFile[], config: UserDefi
24
32
  return;
25
33
  }
26
34
 
35
+ if (error._tag === 'FileWritingError') {
36
+ Logger.error(error.message);
37
+ Logger.error(error.error);
38
+ return;
39
+ }
40
+
27
41
  const errorMessages = [
28
42
  'Error(s) occurred while parsing files. Please review the following issues:',
29
43
  ...error.errors.map(formatReflectionError),
@@ -42,16 +56,17 @@ function generateDocumentationBundle(bundles: UnparsedSourceFile[], config: User
42
56
  }
43
57
 
44
58
  function writeFilesToSystem(files: PostHookDocumentationBundle, outputDir: string) {
45
- FileWriter.write(
46
- [files.referenceGuide, ...files.docs]
47
- // Filter out any files that should be skipped
48
- .filter((file) => !isSkip(file)) as PageData[],
49
- outputDir,
50
- () => {
51
- // TODO: Don't do this here, send things back up.
52
- //Logger.logSingle(`${file.outputDocPath} processed.`, 'green');
53
- },
54
- );
59
+ try {
60
+ FileWriter.write(
61
+ [files.referenceGuide, ...files.docs]
62
+ // Filter out any files that should be skipped
63
+ .filter((file) => !isSkip(file)) as PageData[],
64
+ outputDir,
65
+ );
66
+ return TE.right(undefined);
67
+ } catch (error) {
68
+ return TE.left(new FileWritingError('An error occurred while writing files to the system.', error));
69
+ }
55
70
  }
56
71
 
57
72
  function formatReflectionError(error: ReflectionError) {
@@ -1,11 +1,9 @@
1
1
  import chalk from 'chalk';
2
- import ora from 'ora';
3
2
  /**
4
3
  * Logs messages to the console.
5
4
  */
6
5
  export class Logger {
7
6
  static currentFrame = 0;
8
- static spinner = ora();
9
7
 
10
8
  /**
11
9
  * Logs a message with optional arguments.
@@ -43,13 +41,4 @@ export class Logger {
43
41
  private static getChalkFn(color: 'green' | 'red') {
44
42
  return color === 'green' ? chalk.green : chalk.red;
45
43
  }
46
-
47
- public static startSpinner(text: string) {
48
- this.spinner.text = text;
49
- this.spinner.start();
50
- }
51
-
52
- public static succeedSpinner(text: string) {
53
- this.spinner.succeed(text);
54
- }
55
44
  }