@cparra/apexdocs 3.0.0-alpha.6 → 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.
package/dist/cli/generate.js
CHANGED
|
@@ -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');
|
|
@@ -1526,7 +1525,7 @@ var __spreadValues$7 = (a, b) => {
|
|
|
1526
1525
|
return a;
|
|
1527
1526
|
};
|
|
1528
1527
|
var __spreadProps$7 = (a, b) => __defProps$7(a, __getOwnPropDescs$7(b));
|
|
1529
|
-
var __async$
|
|
1528
|
+
var __async$2 = (__this, __arguments, generator) => {
|
|
1530
1529
|
return new Promise((resolve, reject) => {
|
|
1531
1530
|
var fulfilled = (value) => {
|
|
1532
1531
|
try {
|
|
@@ -1578,7 +1577,7 @@ function generateDocs(apexBundles, config) {
|
|
|
1578
1577
|
}
|
|
1579
1578
|
function transformReferenceHook(config) {
|
|
1580
1579
|
function _execute(references, parsedFiles, transformReference) {
|
|
1581
|
-
return __async$
|
|
1580
|
+
return __async$2(this, null, function* () {
|
|
1582
1581
|
return {
|
|
1583
1582
|
references: yield execTransformReferenceHook(Object.values(references), transformReference),
|
|
1584
1583
|
parsedFiles
|
|
@@ -1599,8 +1598,8 @@ function transformDocumentationBundleHook(config) {
|
|
|
1599
1598
|
function passThroughHook(value) {
|
|
1600
1599
|
return value;
|
|
1601
1600
|
}
|
|
1602
|
-
const execTransformReferenceHook = (_0, ..._1) => __async$
|
|
1603
|
-
const hooked = references.map((reference) => __async$
|
|
1601
|
+
const execTransformReferenceHook = (_0, ..._1) => __async$2(void 0, [_0, ..._1], function* (references, hook = passThroughHook) {
|
|
1602
|
+
const hooked = references.map((reference) => __async$2(void 0, null, function* () {
|
|
1604
1603
|
const hookedResult = yield hook(reference);
|
|
1605
1604
|
return __spreadValues$7(__spreadValues$7({}, reference), hookedResult);
|
|
1606
1605
|
}));
|
|
@@ -1610,24 +1609,24 @@ const execTransformReferenceHook = (_0, ..._1) => __async$3(void 0, [_0, ..._1],
|
|
|
1610
1609
|
return acc;
|
|
1611
1610
|
}, {});
|
|
1612
1611
|
});
|
|
1613
|
-
const documentationBundleHook = (bundle, config) => __async$
|
|
1612
|
+
const documentationBundleHook = (bundle, config) => __async$2(void 0, null, function* () {
|
|
1614
1613
|
return {
|
|
1615
1614
|
referenceGuide: yield transformReferenceGuide(bundle.referenceGuide, config.transformReferenceGuide),
|
|
1616
1615
|
docs: yield transformDocs(bundle.docs, config.transformDocs, config.transformDocPage)
|
|
1617
1616
|
};
|
|
1618
1617
|
});
|
|
1619
|
-
const transformReferenceGuide = (_0, ..._1) => __async$
|
|
1618
|
+
const transformReferenceGuide = (_0, ..._1) => __async$2(void 0, [_0, ..._1], function* (referenceGuide, hook = passThroughHook) {
|
|
1620
1619
|
const result = yield hook(referenceGuide);
|
|
1621
1620
|
if (isSkip(result)) {
|
|
1622
1621
|
return result;
|
|
1623
1622
|
}
|
|
1624
1623
|
return __spreadValues$7(__spreadValues$7({}, referenceGuide), yield hook(referenceGuide));
|
|
1625
1624
|
});
|
|
1626
|
-
const transformDocs = (_0, ..._1) => __async$
|
|
1625
|
+
const transformDocs = (_0, ..._1) => __async$2(void 0, [_0, ..._1], function* (docs, transformDocsHook = passThroughHook, transformDocPageHook = passThroughHook) {
|
|
1627
1626
|
const transformed = yield transformDocsHook(docs);
|
|
1628
1627
|
return Promise.all(transformed.map((doc) => transformDocPage(doc, transformDocPageHook)));
|
|
1629
1628
|
});
|
|
1630
|
-
const transformDocPage = (_0, ..._1) => __async$
|
|
1629
|
+
const transformDocPage = (_0, ..._1) => __async$2(void 0, [_0, ..._1], function* (doc, hook = passThroughHook) {
|
|
1631
1630
|
return __spreadValues$7(__spreadValues$7({}, doc), yield hook(doc));
|
|
1632
1631
|
});
|
|
1633
1632
|
function postHookCompile(bundle) {
|
|
@@ -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,17 +1733,8 @@ class Logger {
|
|
|
1734
1733
|
static getChalkFn(color) {
|
|
1735
1734
|
return color === "green" ? chalk.green : chalk.red;
|
|
1736
1735
|
}
|
|
1737
|
-
// TODO: This isn't really working and I don't think its worth it. Let's just completely remove the ora dependency.
|
|
1738
|
-
static startSpinner(text) {
|
|
1739
|
-
this.spinner.text = text;
|
|
1740
|
-
this.spinner.start();
|
|
1741
|
-
}
|
|
1742
|
-
static succeedSpinner(text) {
|
|
1743
|
-
this.spinner.succeed(text);
|
|
1744
|
-
}
|
|
1745
1736
|
}
|
|
1746
1737
|
Logger.currentFrame = 0;
|
|
1747
|
-
Logger.spinner = ora();
|
|
1748
1738
|
|
|
1749
1739
|
const referenceGuideTemplate = `
|
|
1750
1740
|
# Apex Reference Guide
|
|
@@ -1780,45 +1770,35 @@ var __spreadValues$5 = (a, b) => {
|
|
|
1780
1770
|
return a;
|
|
1781
1771
|
};
|
|
1782
1772
|
var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1773
|
+
class FileWritingError {
|
|
1774
|
+
constructor(message, error) {
|
|
1775
|
+
this.message = message;
|
|
1776
|
+
this.error = error;
|
|
1777
|
+
this._tag = "FileWritingError";
|
|
1778
|
+
}
|
|
1779
|
+
}
|
|
1780
|
+
function generate(bundles, config) {
|
|
1781
|
+
return _function.pipe(
|
|
1782
|
+
generateDocumentationBundle(bundles, config),
|
|
1783
|
+
TE__namespace.flatMap((files) => writeFilesToSystem(files, config.targetDir)),
|
|
1784
|
+
TE__namespace.mapLeft((error) => {
|
|
1785
|
+
if (error._tag === "HookError") {
|
|
1786
|
+
Logger.error("Error(s) occurred while processing hooks. Please review the following issues:");
|
|
1787
|
+
Logger.error(error.error);
|
|
1788
|
+
return;
|
|
1790
1789
|
}
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
} catch (e) {
|
|
1796
|
-
reject(e);
|
|
1790
|
+
if (error._tag === "FileWritingError") {
|
|
1791
|
+
Logger.error(error.message);
|
|
1792
|
+
Logger.error(error.error);
|
|
1793
|
+
return;
|
|
1797
1794
|
}
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
return _function.pipe(
|
|
1806
|
-
generateDocumentationBundle(bundles, config),
|
|
1807
|
-
TE__namespace.map((files) => writeFilesToSystem(files, config.targetDir)),
|
|
1808
|
-
TE__namespace.mapLeft((error) => {
|
|
1809
|
-
if (error._tag === "HookError") {
|
|
1810
|
-
Logger.error("Error(s) occurred while processing hooks. Please review the following issues:");
|
|
1811
|
-
Logger.error(error.error);
|
|
1812
|
-
return;
|
|
1813
|
-
}
|
|
1814
|
-
const errorMessages = [
|
|
1815
|
-
"Error(s) occurred while parsing files. Please review the following issues:",
|
|
1816
|
-
...error.errors.map(formatReflectionError)
|
|
1817
|
-
].join("\n");
|
|
1818
|
-
Logger.error(errorMessages);
|
|
1819
|
-
})
|
|
1820
|
-
)();
|
|
1821
|
-
});
|
|
1795
|
+
const errorMessages = [
|
|
1796
|
+
"Error(s) occurred while parsing files. Please review the following issues:",
|
|
1797
|
+
...error.errors.map(formatReflectionError)
|
|
1798
|
+
].join("\n");
|
|
1799
|
+
Logger.error(errorMessages);
|
|
1800
|
+
})
|
|
1801
|
+
)();
|
|
1822
1802
|
}
|
|
1823
1803
|
function generateDocumentationBundle(bundles, config) {
|
|
1824
1804
|
return generateDocs(bundles, __spreadProps$5(__spreadValues$5({}, config), {
|
|
@@ -1826,12 +1806,15 @@ function generateDocumentationBundle(bundles, config) {
|
|
|
1826
1806
|
}));
|
|
1827
1807
|
}
|
|
1828
1808
|
function writeFilesToSystem(files, outputDir) {
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
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
|
+
}
|
|
1835
1818
|
}
|
|
1836
1819
|
function formatReflectionError(error) {
|
|
1837
1820
|
return `Source file: ${error.file}
|
|
@@ -2890,8 +2873,7 @@ class Apexdocs {
|
|
|
2890
2873
|
*/
|
|
2891
2874
|
static generate(config) {
|
|
2892
2875
|
return __async$1(this, null, function* () {
|
|
2893
|
-
Logger.logSingle(
|
|
2894
|
-
Logger.startSpinner("Processing files...");
|
|
2876
|
+
Logger.logSingle(`Generating ${config.targetGenerator} documentation...`);
|
|
2895
2877
|
try {
|
|
2896
2878
|
const fileBodies = ApexFileReader.processFiles(new DefaultFileSystem(), config.sourceDir, config.includeMetadata);
|
|
2897
2879
|
switch (config.targetGenerator) {
|
|
@@ -2902,8 +2884,9 @@ class Apexdocs {
|
|
|
2902
2884
|
openApi(fileBodies, config);
|
|
2903
2885
|
break;
|
|
2904
2886
|
}
|
|
2905
|
-
|
|
2906
|
-
|
|
2887
|
+
Logger.logSingle("\u2714\uFE0F Documentation generated successfully!");
|
|
2888
|
+
} catch (error) {
|
|
2889
|
+
Logger.logSingle("\u274C An error occurred while generating the documentation.", "red");
|
|
2907
2890
|
}
|
|
2908
2891
|
});
|
|
2909
2892
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cparra/apexdocs",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
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(
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
|
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
|
-
|
|
16
|
+
class FileWritingError {
|
|
17
|
+
readonly _tag = 'FileWritingError';
|
|
18
|
+
constructor(
|
|
19
|
+
public message: string,
|
|
20
|
+
public error: unknown,
|
|
21
|
+
) {}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export default function generate(bundles: UnparsedSourceFile[], config: UserDefinedMarkdownConfig) {
|
|
17
25
|
return pipe(
|
|
18
26
|
generateDocumentationBundle(bundles, config),
|
|
19
|
-
TE.
|
|
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 async function generate(bundles: UnparsedSourceFile[], config: Us
|
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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) {
|
package/src/util/logger.ts
CHANGED
|
@@ -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,15 +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
|
-
// TODO: This isn't really working and I don't think its worth it. Let's just completely remove the ora dependency.
|
|
48
|
-
|
|
49
|
-
public static startSpinner(text: string) {
|
|
50
|
-
this.spinner.text = text;
|
|
51
|
-
this.spinner.start();
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
public static succeedSpinner(text: string) {
|
|
55
|
-
this.spinner.succeed(text);
|
|
56
|
-
}
|
|
57
44
|
}
|