@cparra/apexdocs 3.0.0-alpha.7 → 3.0.0-alpha.9
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 +264 -121
- package/package.json +2 -2
- package/src/application/Apexdocs.ts +5 -1
- package/src/application/__tests__/apex-file-reader.spec.ts +25 -25
- package/src/application/apex-file-reader.ts +32 -19
- package/src/application/file-system.ts +46 -10
- package/src/application/generators/markdown.ts +1 -1
- package/src/core/markdown/generate-docs.ts +11 -12
- package/src/core/markdown/reflection/reflect-source.ts +97 -20
- package/dist/defaults-DUwru49Q.js +0 -12
- package/dist/defaults-SH0Rsi5E.js +0 -11
- package/dist/defaults-jLXD2y8-.js +0 -13
- package/src/core/markdown/reflection/error-handling.ts +0 -37
package/dist/cli/generate.js
CHANGED
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
var _function = require('fp-ts/function');
|
|
5
|
-
var E = require('fp-ts/Either');
|
|
6
5
|
var TE = require('fp-ts/TaskEither');
|
|
7
6
|
var yaml = require('js-yaml');
|
|
8
7
|
var path = require('path');
|
|
8
|
+
var T = require('fp-ts/Task');
|
|
9
|
+
var A = require('fp-ts/lib/Array');
|
|
9
10
|
var apexReflection = require('@cparra/apex-reflection');
|
|
10
11
|
var O = require('fp-ts/Option');
|
|
11
12
|
var fastXmlParser = require('fast-xml-parser');
|
|
@@ -34,10 +35,11 @@ function _interopNamespaceDefault(e) {
|
|
|
34
35
|
return Object.freeze(n);
|
|
35
36
|
}
|
|
36
37
|
|
|
37
|
-
var E__namespace = /*#__PURE__*/_interopNamespaceDefault(E);
|
|
38
38
|
var TE__namespace = /*#__PURE__*/_interopNamespaceDefault(TE);
|
|
39
39
|
var yaml__namespace = /*#__PURE__*/_interopNamespaceDefault(yaml);
|
|
40
40
|
var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
|
|
41
|
+
var T__namespace = /*#__PURE__*/_interopNamespaceDefault(T);
|
|
42
|
+
var A__namespace = /*#__PURE__*/_interopNamespaceDefault(A);
|
|
41
43
|
var O__namespace = /*#__PURE__*/_interopNamespaceDefault(O);
|
|
42
44
|
var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
|
|
43
45
|
var yargs__namespace = /*#__PURE__*/_interopNamespaceDefault(yargs);
|
|
@@ -145,25 +147,25 @@ function isInlineCode(content) {
|
|
|
145
147
|
return Object.keys(content).includes("__type") && content.__type === "inline-code";
|
|
146
148
|
}
|
|
147
149
|
|
|
148
|
-
var __defProp$
|
|
149
|
-
var __defProps$
|
|
150
|
-
var __getOwnPropDescs$
|
|
151
|
-
var __getOwnPropSymbols$
|
|
152
|
-
var __hasOwnProp$
|
|
153
|
-
var __propIsEnum$
|
|
154
|
-
var __defNormalProp$
|
|
155
|
-
var __spreadValues$
|
|
150
|
+
var __defProp$g = Object.defineProperty;
|
|
151
|
+
var __defProps$g = Object.defineProperties;
|
|
152
|
+
var __getOwnPropDescs$g = Object.getOwnPropertyDescriptors;
|
|
153
|
+
var __getOwnPropSymbols$g = Object.getOwnPropertySymbols;
|
|
154
|
+
var __hasOwnProp$g = Object.prototype.hasOwnProperty;
|
|
155
|
+
var __propIsEnum$g = Object.prototype.propertyIsEnumerable;
|
|
156
|
+
var __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$g(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
157
|
+
var __spreadValues$g = (a, b) => {
|
|
156
158
|
for (var prop in b || (b = {}))
|
|
157
|
-
if (__hasOwnProp$
|
|
158
|
-
__defNormalProp$
|
|
159
|
-
if (__getOwnPropSymbols$
|
|
160
|
-
for (var prop of __getOwnPropSymbols$
|
|
161
|
-
if (__propIsEnum$
|
|
162
|
-
__defNormalProp$
|
|
159
|
+
if (__hasOwnProp$g.call(b, prop))
|
|
160
|
+
__defNormalProp$g(a, prop, b[prop]);
|
|
161
|
+
if (__getOwnPropSymbols$g)
|
|
162
|
+
for (var prop of __getOwnPropSymbols$g(b)) {
|
|
163
|
+
if (__propIsEnum$g.call(b, prop))
|
|
164
|
+
__defNormalProp$g(a, prop, b[prop]);
|
|
163
165
|
}
|
|
164
166
|
return a;
|
|
165
167
|
};
|
|
166
|
-
var __spreadProps$
|
|
168
|
+
var __spreadProps$g = (a, b) => __defProps$g(a, __getOwnPropDescs$g(b));
|
|
167
169
|
function adaptDescribable(describable, linkGenerator) {
|
|
168
170
|
return {
|
|
169
171
|
description: describableToRenderableContent(describable, linkGenerator)
|
|
@@ -215,7 +217,7 @@ function adaptDocumentable(documentable, linkGenerator, subHeadingLevel) {
|
|
|
215
217
|
function extractCustomTags(type) {
|
|
216
218
|
var _a2, _b2;
|
|
217
219
|
const baseTags = ["description", "group", "author", "date", "see", "example", "throws", "exception"];
|
|
218
|
-
return (_b2 = (_a2 = type.docComment) == null ? void 0 : _a2.annotations.filter((currentAnnotation) => !baseTags.includes(currentAnnotation.name.toLowerCase())).map((currentAnnotation) => __spreadProps$
|
|
220
|
+
return (_b2 = (_a2 = type.docComment) == null ? void 0 : _a2.annotations.filter((currentAnnotation) => !baseTags.includes(currentAnnotation.name.toLowerCase())).map((currentAnnotation) => __spreadProps$g(__spreadValues$g({}, adaptDescribable(currentAnnotation.bodyLines, linkGenerator)), {
|
|
219
221
|
name: currentAnnotation.name
|
|
220
222
|
}))) != null ? _b2 : [];
|
|
221
223
|
}
|
|
@@ -229,7 +231,7 @@ function adaptDocumentable(documentable, linkGenerator, subHeadingLevel) {
|
|
|
229
231
|
var _a2, _b2;
|
|
230
232
|
return (_b2 = (_a2 = type.docComment) == null ? void 0 : _a2.annotations.filter((currentAnnotation) => currentAnnotation.name.toLowerCase() === "see").map((currentAnnotation) => currentAnnotation.body)) != null ? _b2 : [];
|
|
231
233
|
}
|
|
232
|
-
return __spreadProps$
|
|
234
|
+
return __spreadProps$g(__spreadValues$g({}, adaptDescribable((_a = documentable.docComment) == null ? void 0 : _a.descriptionLines, linkGenerator)), {
|
|
233
235
|
annotations: documentable.annotations.map((annotation) => annotation.type.toUpperCase()),
|
|
234
236
|
customTags: extractCustomTags(documentable),
|
|
235
237
|
example: {
|
|
@@ -244,25 +246,25 @@ function adaptDocumentable(documentable, linkGenerator, subHeadingLevel) {
|
|
|
244
246
|
});
|
|
245
247
|
}
|
|
246
248
|
|
|
247
|
-
var __defProp$
|
|
248
|
-
var __defProps$
|
|
249
|
-
var __getOwnPropDescs$
|
|
250
|
-
var __getOwnPropSymbols$
|
|
251
|
-
var __hasOwnProp$
|
|
252
|
-
var __propIsEnum$
|
|
253
|
-
var __defNormalProp$
|
|
254
|
-
var __spreadValues$
|
|
249
|
+
var __defProp$f = Object.defineProperty;
|
|
250
|
+
var __defProps$f = Object.defineProperties;
|
|
251
|
+
var __getOwnPropDescs$f = Object.getOwnPropertyDescriptors;
|
|
252
|
+
var __getOwnPropSymbols$f = Object.getOwnPropertySymbols;
|
|
253
|
+
var __hasOwnProp$f = Object.prototype.hasOwnProperty;
|
|
254
|
+
var __propIsEnum$f = Object.prototype.propertyIsEnumerable;
|
|
255
|
+
var __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
256
|
+
var __spreadValues$f = (a, b) => {
|
|
255
257
|
for (var prop in b || (b = {}))
|
|
256
|
-
if (__hasOwnProp$
|
|
257
|
-
__defNormalProp$
|
|
258
|
-
if (__getOwnPropSymbols$
|
|
259
|
-
for (var prop of __getOwnPropSymbols$
|
|
260
|
-
if (__propIsEnum$
|
|
261
|
-
__defNormalProp$
|
|
258
|
+
if (__hasOwnProp$f.call(b, prop))
|
|
259
|
+
__defNormalProp$f(a, prop, b[prop]);
|
|
260
|
+
if (__getOwnPropSymbols$f)
|
|
261
|
+
for (var prop of __getOwnPropSymbols$f(b)) {
|
|
262
|
+
if (__propIsEnum$f.call(b, prop))
|
|
263
|
+
__defNormalProp$f(a, prop, b[prop]);
|
|
262
264
|
}
|
|
263
265
|
return a;
|
|
264
266
|
};
|
|
265
|
-
var __spreadProps$
|
|
267
|
+
var __spreadProps$f = (a, b) => __defProps$f(a, __getOwnPropDescs$f(b));
|
|
266
268
|
function adaptMethod(method, linkGenerator, baseHeadingLevel) {
|
|
267
269
|
var _a, _b, _c;
|
|
268
270
|
function buildTitle(method2) {
|
|
@@ -292,7 +294,7 @@ function adaptMethod(method, linkGenerator, baseHeadingLevel) {
|
|
|
292
294
|
returnType: {
|
|
293
295
|
headingLevel: baseHeadingLevel + 1,
|
|
294
296
|
heading: "Return Type",
|
|
295
|
-
value: __spreadProps$
|
|
297
|
+
value: __spreadProps$f(__spreadValues$f({}, adaptDescribable((_b = (_a = method.docComment) == null ? void 0 : _a.returnAnnotation) == null ? void 0 : _b.bodyLines, linkGenerator)), {
|
|
296
298
|
type: linkGenerator(method.typeReference.rawDeclaration)
|
|
297
299
|
})
|
|
298
300
|
},
|
|
@@ -351,13 +353,13 @@ function mapParameters(documentable, param, linkGenerator) {
|
|
|
351
353
|
const paramAnnotation = (_a = documentable.docComment) == null ? void 0 : _a.paramAnnotations.find(
|
|
352
354
|
(pa) => pa.paramName.toLowerCase() === param.name.toLowerCase()
|
|
353
355
|
);
|
|
354
|
-
return __spreadProps$
|
|
356
|
+
return __spreadProps$f(__spreadValues$f({}, adaptDescribable(paramAnnotation == null ? void 0 : paramAnnotation.bodyLines, linkGenerator)), {
|
|
355
357
|
name: param.name,
|
|
356
358
|
type: linkGenerator(param.typeReference.rawDeclaration)
|
|
357
359
|
});
|
|
358
360
|
}
|
|
359
361
|
function mapThrows(thrown, linkGenerator) {
|
|
360
|
-
return __spreadProps$
|
|
362
|
+
return __spreadProps$f(__spreadValues$f({}, adaptDescribable(thrown.bodyLines, linkGenerator)), {
|
|
361
363
|
type: linkGenerator(thrown.exceptionName)
|
|
362
364
|
});
|
|
363
365
|
}
|
|
@@ -392,25 +394,25 @@ function adaptFieldOrProperty(field, linkGenerator, baseHeadingLevel) {
|
|
|
392
394
|
};
|
|
393
395
|
}
|
|
394
396
|
|
|
395
|
-
var __defProp$
|
|
396
|
-
var __defProps$
|
|
397
|
-
var __getOwnPropDescs$
|
|
398
|
-
var __getOwnPropSymbols$
|
|
399
|
-
var __hasOwnProp$
|
|
400
|
-
var __propIsEnum$
|
|
401
|
-
var __defNormalProp$
|
|
402
|
-
var __spreadValues$
|
|
397
|
+
var __defProp$e = Object.defineProperty;
|
|
398
|
+
var __defProps$e = Object.defineProperties;
|
|
399
|
+
var __getOwnPropDescs$e = Object.getOwnPropertyDescriptors;
|
|
400
|
+
var __getOwnPropSymbols$e = Object.getOwnPropertySymbols;
|
|
401
|
+
var __hasOwnProp$e = Object.prototype.hasOwnProperty;
|
|
402
|
+
var __propIsEnum$e = Object.prototype.propertyIsEnumerable;
|
|
403
|
+
var __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
404
|
+
var __spreadValues$e = (a, b) => {
|
|
403
405
|
for (var prop in b || (b = {}))
|
|
404
|
-
if (__hasOwnProp$
|
|
405
|
-
__defNormalProp$
|
|
406
|
-
if (__getOwnPropSymbols$
|
|
407
|
-
for (var prop of __getOwnPropSymbols$
|
|
408
|
-
if (__propIsEnum$
|
|
409
|
-
__defNormalProp$
|
|
406
|
+
if (__hasOwnProp$e.call(b, prop))
|
|
407
|
+
__defNormalProp$e(a, prop, b[prop]);
|
|
408
|
+
if (__getOwnPropSymbols$e)
|
|
409
|
+
for (var prop of __getOwnPropSymbols$e(b)) {
|
|
410
|
+
if (__propIsEnum$e.call(b, prop))
|
|
411
|
+
__defNormalProp$e(a, prop, b[prop]);
|
|
410
412
|
}
|
|
411
413
|
return a;
|
|
412
414
|
};
|
|
413
|
-
var __spreadProps$
|
|
415
|
+
var __spreadProps$e = (a, b) => __defProps$e(a, __getOwnPropDescs$e(b));
|
|
414
416
|
function typeToRenderable(parsedFile, linkGenerator, config) {
|
|
415
417
|
function getRenderable() {
|
|
416
418
|
const { type } = parsedFile;
|
|
@@ -423,7 +425,7 @@ function typeToRenderable(parsedFile, linkGenerator, config) {
|
|
|
423
425
|
return classTypeToClassSource(type, linkGenerator);
|
|
424
426
|
}
|
|
425
427
|
}
|
|
426
|
-
return __spreadProps$
|
|
428
|
+
return __spreadProps$e(__spreadValues$e({}, getRenderable()), {
|
|
427
429
|
filePath: parsedFile.source.filePath,
|
|
428
430
|
namespace: config.namespace
|
|
429
431
|
});
|
|
@@ -448,7 +450,7 @@ function baseTypeAdapter(type, linkGenerator, baseHeadingLevel) {
|
|
|
448
450
|
};
|
|
449
451
|
}
|
|
450
452
|
function enumTypeToEnumSource(enumType, linkGenerator, baseHeadingLevel = 1) {
|
|
451
|
-
return __spreadProps$
|
|
453
|
+
return __spreadProps$e(__spreadValues$e({
|
|
452
454
|
type: "enum"
|
|
453
455
|
}, baseTypeAdapter(enumType, linkGenerator, baseHeadingLevel)), {
|
|
454
456
|
values: {
|
|
@@ -456,7 +458,7 @@ function enumTypeToEnumSource(enumType, linkGenerator, baseHeadingLevel = 1) {
|
|
|
456
458
|
heading: "Values",
|
|
457
459
|
value: enumType.values.map((value) => {
|
|
458
460
|
var _a;
|
|
459
|
-
return __spreadProps$
|
|
461
|
+
return __spreadProps$e(__spreadValues$e({}, adaptDescribable((_a = value.docComment) == null ? void 0 : _a.descriptionLines, linkGenerator)), {
|
|
460
462
|
value: value.name
|
|
461
463
|
});
|
|
462
464
|
})
|
|
@@ -464,7 +466,7 @@ function enumTypeToEnumSource(enumType, linkGenerator, baseHeadingLevel = 1) {
|
|
|
464
466
|
});
|
|
465
467
|
}
|
|
466
468
|
function interfaceTypeToInterfaceSource(interfaceType, linkGenerator, baseHeadingLevel = 1) {
|
|
467
|
-
return __spreadProps$
|
|
469
|
+
return __spreadProps$e(__spreadValues$e({
|
|
468
470
|
type: "interface"
|
|
469
471
|
}, baseTypeAdapter(interfaceType, linkGenerator, baseHeadingLevel)), {
|
|
470
472
|
extends: interfaceType.extended_interfaces.map(linkGenerator),
|
|
@@ -476,7 +478,7 @@ function interfaceTypeToInterfaceSource(interfaceType, linkGenerator, baseHeadin
|
|
|
476
478
|
});
|
|
477
479
|
}
|
|
478
480
|
function classTypeToClassSource(classType, linkGenerator, baseHeadingLevel = 1) {
|
|
479
|
-
return __spreadProps$
|
|
481
|
+
return __spreadProps$e(__spreadValues$e({
|
|
480
482
|
type: "class"
|
|
481
483
|
}, baseTypeAdapter(classType, linkGenerator, baseHeadingLevel)), {
|
|
482
484
|
classModifier: classType.classModifier,
|
|
@@ -509,7 +511,7 @@ function classTypeToClassSource(classType, linkGenerator, baseHeadingLevel = 1)
|
|
|
509
511
|
headingLevel: baseHeadingLevel + 1,
|
|
510
512
|
heading: "Classes",
|
|
511
513
|
value: classType.classes.map(
|
|
512
|
-
(innerClass) => classTypeToClassSource(__spreadProps$
|
|
514
|
+
(innerClass) => classTypeToClassSource(__spreadProps$e(__spreadValues$e({}, innerClass), { inheritanceChain: [] }), linkGenerator, baseHeadingLevel + 2)
|
|
513
515
|
)
|
|
514
516
|
},
|
|
515
517
|
innerEnums: {
|
|
@@ -671,6 +673,45 @@ function parseApexMetadata(input) {
|
|
|
671
673
|
return map;
|
|
672
674
|
}
|
|
673
675
|
|
|
676
|
+
var __defProp$d = Object.defineProperty;
|
|
677
|
+
var __defProps$d = Object.defineProperties;
|
|
678
|
+
var __getOwnPropDescs$d = Object.getOwnPropertyDescriptors;
|
|
679
|
+
var __getOwnPropSymbols$d = Object.getOwnPropertySymbols;
|
|
680
|
+
var __hasOwnProp$d = Object.prototype.hasOwnProperty;
|
|
681
|
+
var __propIsEnum$d = Object.prototype.propertyIsEnumerable;
|
|
682
|
+
var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
683
|
+
var __spreadValues$d = (a, b) => {
|
|
684
|
+
for (var prop in b || (b = {}))
|
|
685
|
+
if (__hasOwnProp$d.call(b, prop))
|
|
686
|
+
__defNormalProp$d(a, prop, b[prop]);
|
|
687
|
+
if (__getOwnPropSymbols$d)
|
|
688
|
+
for (var prop of __getOwnPropSymbols$d(b)) {
|
|
689
|
+
if (__propIsEnum$d.call(b, prop))
|
|
690
|
+
__defNormalProp$d(a, prop, b[prop]);
|
|
691
|
+
}
|
|
692
|
+
return a;
|
|
693
|
+
};
|
|
694
|
+
var __spreadProps$d = (a, b) => __defProps$d(a, __getOwnPropDescs$d(b));
|
|
695
|
+
var __async$5 = (__this, __arguments, generator) => {
|
|
696
|
+
return new Promise((resolve, reject) => {
|
|
697
|
+
var fulfilled = (value) => {
|
|
698
|
+
try {
|
|
699
|
+
step(generator.next(value));
|
|
700
|
+
} catch (e) {
|
|
701
|
+
reject(e);
|
|
702
|
+
}
|
|
703
|
+
};
|
|
704
|
+
var rejected = (value) => {
|
|
705
|
+
try {
|
|
706
|
+
step(generator.throw(value));
|
|
707
|
+
} catch (e) {
|
|
708
|
+
reject(e);
|
|
709
|
+
}
|
|
710
|
+
};
|
|
711
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
712
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
713
|
+
});
|
|
714
|
+
};
|
|
674
715
|
class ReflectionErrors {
|
|
675
716
|
constructor(errors) {
|
|
676
717
|
this.errors = errors;
|
|
@@ -683,39 +724,51 @@ class ReflectionError {
|
|
|
683
724
|
this.message = message;
|
|
684
725
|
}
|
|
685
726
|
}
|
|
686
|
-
function
|
|
687
|
-
function
|
|
688
|
-
return
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
return
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
727
|
+
function reflectAsync(rawSource) {
|
|
728
|
+
return __async$5(this, null, function* () {
|
|
729
|
+
return new Promise((resolve, reject) => {
|
|
730
|
+
const result = apexReflection.reflect(rawSource);
|
|
731
|
+
if (result.typeMirror) {
|
|
732
|
+
return resolve(result.typeMirror);
|
|
733
|
+
} else if (result.error) {
|
|
734
|
+
return reject(result.error);
|
|
735
|
+
} else {
|
|
736
|
+
return reject(new Error("Unknown error"));
|
|
696
737
|
}
|
|
697
|
-
);
|
|
698
|
-
}
|
|
699
|
-
return _function.pipe(
|
|
700
|
-
reflectionResult,
|
|
701
|
-
reduceReflectionResultIntoSingleEither,
|
|
702
|
-
({ errors, parsedFiles }) => errors.length ? E__namespace.left(new ReflectionErrors(errors)) : E__namespace.right(parsedFiles)
|
|
703
|
-
);
|
|
738
|
+
});
|
|
739
|
+
});
|
|
704
740
|
}
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
741
|
+
function myPipeSeq(apexBundles) {
|
|
742
|
+
const semiGroupReflectionError = {
|
|
743
|
+
concat: (x, y) => new ReflectionErrors([...x.errors, ...y.errors])
|
|
744
|
+
};
|
|
745
|
+
const Ap = TE__namespace.getApplicativeTaskValidation(T__namespace.ApplyPar, semiGroupReflectionError);
|
|
746
|
+
return _function.pipe(apexBundles, A__namespace.traverse(Ap)(myPipe));
|
|
747
|
+
}
|
|
748
|
+
function myPipe(apexBundle) {
|
|
749
|
+
const convertToParsedFile = apply(toParsedFile, apexBundle.filePath);
|
|
750
|
+
const withMetadata = apply(addMetadata, apexBundle.metadataContent);
|
|
751
|
+
return _function.pipe(apexBundle, reflectAsTask, TE__namespace.map(convertToParsedFile), TE__namespace.map(withMetadata));
|
|
752
|
+
}
|
|
753
|
+
function reflectAsTask(apexBundle) {
|
|
754
|
+
return TE__namespace.tryCatch(
|
|
755
|
+
() => reflectAsync(apexBundle.content),
|
|
756
|
+
(error) => new ReflectionErrors([new ReflectionError(apexBundle.filePath, error.message)])
|
|
757
|
+
);
|
|
708
758
|
}
|
|
709
|
-
function
|
|
710
|
-
|
|
711
|
-
const result = apexReflection.reflect(input);
|
|
712
|
-
return result.error ? E__namespace.left(new ReflectionError(filePath, result.error.message)) : E__namespace.right({
|
|
759
|
+
function toParsedFile(filePath, typeMirror) {
|
|
760
|
+
return {
|
|
713
761
|
source: {
|
|
714
762
|
filePath,
|
|
715
|
-
name:
|
|
716
|
-
type:
|
|
763
|
+
name: typeMirror.name,
|
|
764
|
+
type: typeMirror.type_name
|
|
717
765
|
},
|
|
718
|
-
type:
|
|
766
|
+
type: typeMirror
|
|
767
|
+
};
|
|
768
|
+
}
|
|
769
|
+
function addMetadata(rawMetadataContent, parsedFile) {
|
|
770
|
+
return __spreadProps$d(__spreadValues$d({}, parsedFile), {
|
|
771
|
+
type: addFileMetadataToTypeAnnotation(parsedFile.type, rawMetadataContent)
|
|
719
772
|
});
|
|
720
773
|
}
|
|
721
774
|
function addFileMetadataToTypeAnnotation(type, metadata) {
|
|
@@ -1525,7 +1578,7 @@ var __spreadValues$7 = (a, b) => {
|
|
|
1525
1578
|
return a;
|
|
1526
1579
|
};
|
|
1527
1580
|
var __spreadProps$7 = (a, b) => __defProps$7(a, __getOwnPropDescs$7(b));
|
|
1528
|
-
var __async$
|
|
1581
|
+
var __async$4 = (__this, __arguments, generator) => {
|
|
1529
1582
|
return new Promise((resolve, reject) => {
|
|
1530
1583
|
var fulfilled = (value) => {
|
|
1531
1584
|
try {
|
|
@@ -1559,15 +1612,14 @@ function generateDocs(apexBundles, config) {
|
|
|
1559
1612
|
const sortTypeMembers = apply(sortMembers, config.sortMembersAlphabetically);
|
|
1560
1613
|
return _function.pipe(
|
|
1561
1614
|
apexBundles,
|
|
1562
|
-
|
|
1563
|
-
checkForReflectionErrors,
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
TE__namespace.fromEither,
|
|
1615
|
+
myPipeSeq,
|
|
1616
|
+
//checkForReflectionErrors,
|
|
1617
|
+
TE__namespace.map(filterOutOfScope),
|
|
1618
|
+
TE__namespace.map(addInheritedMembersToTypes),
|
|
1619
|
+
TE__namespace.map(addInheritanceChainToTypes),
|
|
1620
|
+
TE__namespace.map(sortTypeMembers),
|
|
1621
|
+
TE__namespace.bindTo("parsedFiles"),
|
|
1622
|
+
TE__namespace.bind("references", ({ parsedFiles }) => TE__namespace.right(convertToReferences(parsedFiles))),
|
|
1571
1623
|
TE__namespace.flatMap(({ parsedFiles, references }) => transformReferenceHook(config)({ references, parsedFiles })),
|
|
1572
1624
|
TE__namespace.map(({ parsedFiles, references }) => convertToRenderableBundle(parsedFiles, references)),
|
|
1573
1625
|
TE__namespace.map(convertToDocumentationBundleForTemplate),
|
|
@@ -1577,7 +1629,7 @@ function generateDocs(apexBundles, config) {
|
|
|
1577
1629
|
}
|
|
1578
1630
|
function transformReferenceHook(config) {
|
|
1579
1631
|
function _execute(references, parsedFiles, transformReference) {
|
|
1580
|
-
return __async$
|
|
1632
|
+
return __async$4(this, null, function* () {
|
|
1581
1633
|
return {
|
|
1582
1634
|
references: yield execTransformReferenceHook(Object.values(references), transformReference),
|
|
1583
1635
|
parsedFiles
|
|
@@ -1598,8 +1650,8 @@ function transformDocumentationBundleHook(config) {
|
|
|
1598
1650
|
function passThroughHook(value) {
|
|
1599
1651
|
return value;
|
|
1600
1652
|
}
|
|
1601
|
-
const execTransformReferenceHook = (_0, ..._1) => __async$
|
|
1602
|
-
const hooked = references.map((reference) => __async$
|
|
1653
|
+
const execTransformReferenceHook = (_0, ..._1) => __async$4(void 0, [_0, ..._1], function* (references, hook = passThroughHook) {
|
|
1654
|
+
const hooked = references.map((reference) => __async$4(void 0, null, function* () {
|
|
1603
1655
|
const hookedResult = yield hook(reference);
|
|
1604
1656
|
return __spreadValues$7(__spreadValues$7({}, reference), hookedResult);
|
|
1605
1657
|
}));
|
|
@@ -1609,24 +1661,24 @@ const execTransformReferenceHook = (_0, ..._1) => __async$2(void 0, [_0, ..._1],
|
|
|
1609
1661
|
return acc;
|
|
1610
1662
|
}, {});
|
|
1611
1663
|
});
|
|
1612
|
-
const documentationBundleHook = (bundle, config) => __async$
|
|
1664
|
+
const documentationBundleHook = (bundle, config) => __async$4(void 0, null, function* () {
|
|
1613
1665
|
return {
|
|
1614
1666
|
referenceGuide: yield transformReferenceGuide(bundle.referenceGuide, config.transformReferenceGuide),
|
|
1615
1667
|
docs: yield transformDocs(bundle.docs, config.transformDocs, config.transformDocPage)
|
|
1616
1668
|
};
|
|
1617
1669
|
});
|
|
1618
|
-
const transformReferenceGuide = (_0, ..._1) => __async$
|
|
1670
|
+
const transformReferenceGuide = (_0, ..._1) => __async$4(void 0, [_0, ..._1], function* (referenceGuide, hook = passThroughHook) {
|
|
1619
1671
|
const result = yield hook(referenceGuide);
|
|
1620
1672
|
if (isSkip(result)) {
|
|
1621
1673
|
return result;
|
|
1622
1674
|
}
|
|
1623
1675
|
return __spreadValues$7(__spreadValues$7({}, referenceGuide), yield hook(referenceGuide));
|
|
1624
1676
|
});
|
|
1625
|
-
const transformDocs = (_0, ..._1) => __async$
|
|
1677
|
+
const transformDocs = (_0, ..._1) => __async$4(void 0, [_0, ..._1], function* (docs, transformDocsHook = passThroughHook, transformDocPageHook = passThroughHook) {
|
|
1626
1678
|
const transformed = yield transformDocsHook(docs);
|
|
1627
1679
|
return Promise.all(transformed.map((doc) => transformDocPage(doc, transformDocPageHook)));
|
|
1628
1680
|
});
|
|
1629
|
-
const transformDocPage = (_0, ..._1) => __async$
|
|
1681
|
+
const transformDocPage = (_0, ..._1) => __async$4(void 0, [_0, ..._1], function* (doc, hook = passThroughHook) {
|
|
1630
1682
|
return __spreadValues$7(__spreadValues$7({}, doc), yield hook(doc));
|
|
1631
1683
|
});
|
|
1632
1684
|
function postHookCompile(bundle) {
|
|
@@ -2797,47 +2849,134 @@ function filterByScopes(manifest) {
|
|
|
2797
2849
|
return filteredTypes;
|
|
2798
2850
|
}
|
|
2799
2851
|
|
|
2852
|
+
var __async$3 = (__this, __arguments, generator) => {
|
|
2853
|
+
return new Promise((resolve, reject) => {
|
|
2854
|
+
var fulfilled = (value) => {
|
|
2855
|
+
try {
|
|
2856
|
+
step(generator.next(value));
|
|
2857
|
+
} catch (e) {
|
|
2858
|
+
reject(e);
|
|
2859
|
+
}
|
|
2860
|
+
};
|
|
2861
|
+
var rejected = (value) => {
|
|
2862
|
+
try {
|
|
2863
|
+
step(generator.throw(value));
|
|
2864
|
+
} catch (e) {
|
|
2865
|
+
reject(e);
|
|
2866
|
+
}
|
|
2867
|
+
};
|
|
2868
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
2869
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
2870
|
+
});
|
|
2871
|
+
};
|
|
2800
2872
|
const APEX_FILE_EXTENSION = ".cls";
|
|
2801
2873
|
class ApexFileReader {
|
|
2802
2874
|
/**
|
|
2803
2875
|
* Reads from .cls files and returns their raw body.
|
|
2804
2876
|
*/
|
|
2805
2877
|
static processFiles(fileSystem, rootPath, includeMetadata) {
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
const
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2878
|
+
return __async$3(this, null, function* () {
|
|
2879
|
+
const filePaths = yield this.getFilePaths(fileSystem, rootPath);
|
|
2880
|
+
const apexFilePaths = filePaths.filter((filePath) => this.isApexFile(filePath));
|
|
2881
|
+
const filePromises = apexFilePaths.map((filePath) => this.processFile(fileSystem, filePath, includeMetadata));
|
|
2882
|
+
return Promise.all(filePromises);
|
|
2883
|
+
});
|
|
2884
|
+
}
|
|
2885
|
+
static getFilePaths(fileSystem, rootPath) {
|
|
2886
|
+
return __async$3(this, null, function* () {
|
|
2887
|
+
const directoryContents = yield fileSystem.readDirectory(rootPath);
|
|
2888
|
+
const paths = [];
|
|
2889
|
+
for (const filePath of directoryContents) {
|
|
2890
|
+
const currentPath = fileSystem.joinPath(rootPath, filePath);
|
|
2891
|
+
if (yield fileSystem.isDirectory(currentPath)) {
|
|
2892
|
+
paths.push(...yield this.getFilePaths(fileSystem, currentPath));
|
|
2893
|
+
}
|
|
2894
|
+
paths.push(currentPath);
|
|
2815
2895
|
}
|
|
2816
|
-
|
|
2817
|
-
|
|
2896
|
+
return paths;
|
|
2897
|
+
});
|
|
2898
|
+
}
|
|
2899
|
+
static processFile(fileSystem, filePath, includeMetadata) {
|
|
2900
|
+
return __async$3(this, null, function* () {
|
|
2901
|
+
const rawTypeContent = yield fileSystem.readFile(filePath);
|
|
2902
|
+
const metadataPath = `${filePath}-meta.xml`;
|
|
2818
2903
|
let rawMetadataContent = null;
|
|
2819
2904
|
if (includeMetadata) {
|
|
2820
|
-
rawMetadataContent = fileSystem.exists(metadataPath) ? fileSystem.readFile(metadataPath) : null;
|
|
2905
|
+
rawMetadataContent = fileSystem.exists(metadataPath) ? yield fileSystem.readFile(metadataPath) : null;
|
|
2821
2906
|
}
|
|
2822
|
-
|
|
2907
|
+
return { filePath, content: rawTypeContent, metadataContent: rawMetadataContent };
|
|
2823
2908
|
});
|
|
2824
|
-
return bundles;
|
|
2825
2909
|
}
|
|
2826
2910
|
static isApexFile(currentFile) {
|
|
2827
2911
|
return currentFile.endsWith(APEX_FILE_EXTENSION);
|
|
2828
2912
|
}
|
|
2829
2913
|
}
|
|
2830
2914
|
|
|
2915
|
+
var __async$2 = (__this, __arguments, generator) => {
|
|
2916
|
+
return new Promise((resolve, reject) => {
|
|
2917
|
+
var fulfilled = (value) => {
|
|
2918
|
+
try {
|
|
2919
|
+
step(generator.next(value));
|
|
2920
|
+
} catch (e) {
|
|
2921
|
+
reject(e);
|
|
2922
|
+
}
|
|
2923
|
+
};
|
|
2924
|
+
var rejected = (value) => {
|
|
2925
|
+
try {
|
|
2926
|
+
step(generator.throw(value));
|
|
2927
|
+
} catch (e) {
|
|
2928
|
+
reject(e);
|
|
2929
|
+
}
|
|
2930
|
+
};
|
|
2931
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
2932
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
2933
|
+
});
|
|
2934
|
+
};
|
|
2935
|
+
function stat(path2) {
|
|
2936
|
+
return new Promise((resolve, reject) => {
|
|
2937
|
+
fs__namespace.stat(path2, (err, stats) => {
|
|
2938
|
+
if (err) {
|
|
2939
|
+
reject(err);
|
|
2940
|
+
} else {
|
|
2941
|
+
resolve(stats);
|
|
2942
|
+
}
|
|
2943
|
+
});
|
|
2944
|
+
});
|
|
2945
|
+
}
|
|
2946
|
+
function readdir(path2) {
|
|
2947
|
+
return new Promise((resolve, reject) => {
|
|
2948
|
+
fs__namespace.readdir(path2, (err, files) => {
|
|
2949
|
+
if (err) {
|
|
2950
|
+
reject(err);
|
|
2951
|
+
} else {
|
|
2952
|
+
resolve(files);
|
|
2953
|
+
}
|
|
2954
|
+
});
|
|
2955
|
+
});
|
|
2956
|
+
}
|
|
2957
|
+
function readFile(path2) {
|
|
2958
|
+
return new Promise((resolve, reject) => {
|
|
2959
|
+
fs__namespace.readFile(path2, (err, data) => {
|
|
2960
|
+
if (err) {
|
|
2961
|
+
reject(err);
|
|
2962
|
+
} else {
|
|
2963
|
+
resolve(data.toString());
|
|
2964
|
+
}
|
|
2965
|
+
});
|
|
2966
|
+
});
|
|
2967
|
+
}
|
|
2831
2968
|
class DefaultFileSystem {
|
|
2832
2969
|
isDirectory(pathToRead) {
|
|
2833
|
-
return
|
|
2970
|
+
return __async$2(this, null, function* () {
|
|
2971
|
+
const stats = yield stat(pathToRead);
|
|
2972
|
+
return stats.isDirectory();
|
|
2973
|
+
});
|
|
2834
2974
|
}
|
|
2835
2975
|
readDirectory(sourceDirectory) {
|
|
2836
|
-
return
|
|
2976
|
+
return readdir(sourceDirectory);
|
|
2837
2977
|
}
|
|
2838
2978
|
readFile(pathToRead) {
|
|
2839
|
-
|
|
2840
|
-
return rawFile.toString();
|
|
2979
|
+
return readFile(pathToRead);
|
|
2841
2980
|
}
|
|
2842
2981
|
joinPath(...paths) {
|
|
2843
2982
|
return path__namespace.join(...paths);
|
|
@@ -2875,7 +3014,11 @@ class Apexdocs {
|
|
|
2875
3014
|
return __async$1(this, null, function* () {
|
|
2876
3015
|
Logger.logSingle(`Generating ${config.targetGenerator} documentation...`);
|
|
2877
3016
|
try {
|
|
2878
|
-
const fileBodies = ApexFileReader.processFiles(
|
|
3017
|
+
const fileBodies = yield ApexFileReader.processFiles(
|
|
3018
|
+
new DefaultFileSystem(),
|
|
3019
|
+
config.sourceDir,
|
|
3020
|
+
config.includeMetadata
|
|
3021
|
+
);
|
|
2879
3022
|
switch (config.targetGenerator) {
|
|
2880
3023
|
case "markdown":
|
|
2881
3024
|
yield generate(fileBodies, config);
|
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.9",
|
|
4
4
|
"description": "Library with CLI capabilities to generate documentation for Salesforce Apex classes.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"apex",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
]
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@cparra/apex-reflection": "2.
|
|
61
|
+
"@cparra/apex-reflection": "2.12.1",
|
|
62
62
|
"@types/js-yaml": "^4.0.9",
|
|
63
63
|
"@types/yargs": "^17.0.32",
|
|
64
64
|
"chalk": "^4.1.2",
|
|
@@ -17,7 +17,11 @@ export class Apexdocs {
|
|
|
17
17
|
Logger.logSingle(`Generating ${config.targetGenerator} documentation...`);
|
|
18
18
|
|
|
19
19
|
try {
|
|
20
|
-
const fileBodies = ApexFileReader.processFiles(
|
|
20
|
+
const fileBodies = await ApexFileReader.processFiles(
|
|
21
|
+
new DefaultFileSystem(),
|
|
22
|
+
config.sourceDir,
|
|
23
|
+
config.includeMetadata,
|
|
24
|
+
);
|
|
21
25
|
|
|
22
26
|
switch (config.targetGenerator) {
|
|
23
27
|
case 'markdown':
|
|
@@ -18,24 +18,24 @@ describe('File Reader', () => {
|
|
|
18
18
|
} as SettingsConfig);
|
|
19
19
|
});
|
|
20
20
|
|
|
21
|
-
it('returns an empty list when there are no files in the directory', () => {
|
|
22
|
-
const result = ApexFileReader.processFiles(
|
|
21
|
+
it('returns an empty list when there are no files in the directory', async () => {
|
|
22
|
+
const result = await ApexFileReader.processFiles(
|
|
23
23
|
{
|
|
24
24
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
25
|
-
isDirectory(_: string): boolean {
|
|
26
|
-
return false;
|
|
25
|
+
isDirectory(_: string): Promise<boolean> {
|
|
26
|
+
return Promise.resolve(false);
|
|
27
27
|
},
|
|
28
28
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
29
29
|
joinPath(_: string): string {
|
|
30
30
|
return '';
|
|
31
31
|
},
|
|
32
32
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
33
|
-
readDirectory(_: string): string[] {
|
|
34
|
-
return [];
|
|
33
|
+
readDirectory(_: string): Promise<string[]> {
|
|
34
|
+
return Promise.resolve([]);
|
|
35
35
|
},
|
|
36
36
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
37
|
-
readFile(_: string): string {
|
|
38
|
-
return '';
|
|
37
|
+
readFile(_: string): Promise<string> {
|
|
38
|
+
return Promise.resolve('');
|
|
39
39
|
},
|
|
40
40
|
exists(): boolean {
|
|
41
41
|
return true;
|
|
@@ -47,20 +47,20 @@ describe('File Reader', () => {
|
|
|
47
47
|
expect(result.length).toBe(0);
|
|
48
48
|
});
|
|
49
49
|
|
|
50
|
-
it('returns an empty list when there are no Apex files in the directory', () => {
|
|
51
|
-
const result = ApexFileReader.processFiles(
|
|
50
|
+
it('returns an empty list when there are no Apex files in the directory', async () => {
|
|
51
|
+
const result = await ApexFileReader.processFiles(
|
|
52
52
|
{
|
|
53
|
-
isDirectory(): boolean {
|
|
54
|
-
return false;
|
|
53
|
+
isDirectory(): Promise<boolean> {
|
|
54
|
+
return Promise.resolve(false);
|
|
55
55
|
},
|
|
56
56
|
joinPath(): string {
|
|
57
57
|
return '';
|
|
58
58
|
},
|
|
59
|
-
readDirectory(): string[] {
|
|
60
|
-
return ['SomeFile.md'];
|
|
59
|
+
readDirectory(): Promise<string[]> {
|
|
60
|
+
return Promise.resolve(['SomeFile.md']);
|
|
61
61
|
},
|
|
62
|
-
readFile(): string {
|
|
63
|
-
return '';
|
|
62
|
+
readFile(): Promise<string> {
|
|
63
|
+
return Promise.resolve('');
|
|
64
64
|
},
|
|
65
65
|
exists(): boolean {
|
|
66
66
|
return true;
|
|
@@ -72,24 +72,24 @@ describe('File Reader', () => {
|
|
|
72
72
|
expect(result.length).toBe(0);
|
|
73
73
|
});
|
|
74
74
|
|
|
75
|
-
it('returns the file contents for an Apex file', () => {
|
|
76
|
-
const result = ApexFileReader.processFiles(
|
|
75
|
+
it('returns the file contents for an Apex file', async () => {
|
|
76
|
+
const result = await ApexFileReader.processFiles(
|
|
77
77
|
{
|
|
78
78
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
79
|
-
isDirectory(_: string): boolean {
|
|
80
|
-
return false;
|
|
79
|
+
isDirectory(_: string): Promise<boolean> {
|
|
80
|
+
return Promise.resolve(false);
|
|
81
81
|
},
|
|
82
82
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
83
83
|
joinPath(_: string): string {
|
|
84
|
-
return '';
|
|
84
|
+
return 'SomeApexFile.cls';
|
|
85
85
|
},
|
|
86
86
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
87
|
-
readDirectory(_: string): string[] {
|
|
88
|
-
return ['SomeApexFile.cls'];
|
|
87
|
+
readDirectory(_: string): Promise<string[]> {
|
|
88
|
+
return Promise.resolve(['SomeApexFile.cls']);
|
|
89
89
|
},
|
|
90
90
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
91
|
-
readFile(_: string): string {
|
|
92
|
-
return 'public class MyClass{}';
|
|
91
|
+
readFile(_: string): Promise<string> {
|
|
92
|
+
return Promise.resolve('public class MyClass{}');
|
|
93
93
|
},
|
|
94
94
|
exists(): boolean {
|
|
95
95
|
return true;
|
|
@@ -10,30 +10,43 @@ export class ApexFileReader {
|
|
|
10
10
|
/**
|
|
11
11
|
* Reads from .cls files and returns their raw body.
|
|
12
12
|
*/
|
|
13
|
-
static processFiles(
|
|
14
|
-
|
|
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
|
+
}
|
|
15
23
|
|
|
16
|
-
|
|
17
|
-
directoryContents.
|
|
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) {
|
|
18
28
|
const currentPath = fileSystem.joinPath(rootPath, filePath);
|
|
19
|
-
if (fileSystem.isDirectory(currentPath)) {
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (!this.isApexFile(filePath)) {
|
|
24
|
-
return;
|
|
29
|
+
if (await fileSystem.isDirectory(currentPath)) {
|
|
30
|
+
paths.push(...(await this.getFilePaths(fileSystem, currentPath)));
|
|
25
31
|
}
|
|
32
|
+
paths.push(currentPath);
|
|
33
|
+
}
|
|
34
|
+
return paths;
|
|
35
|
+
}
|
|
26
36
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
+
}
|
|
33
48
|
|
|
34
|
-
|
|
35
|
-
});
|
|
36
|
-
return bundles;
|
|
49
|
+
return { filePath, content: rawTypeContent, metadataContent: rawMetadataContent };
|
|
37
50
|
}
|
|
38
51
|
|
|
39
52
|
private static isApexFile(currentFile: string): boolean {
|
|
@@ -2,25 +2,61 @@ import * as fs from 'fs';
|
|
|
2
2
|
import * as path from 'path';
|
|
3
3
|
|
|
4
4
|
export interface FileSystem {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
readFile: (path: string) => string
|
|
5
|
+
isDirectory: (path: string) => Promise<boolean>;
|
|
6
|
+
readDirectory: (sourceDirectory: string) => Promise<string[]>;
|
|
7
|
+
readFile: (path: string) => Promise<string>;
|
|
8
8
|
joinPath: (...paths: string[]) => string;
|
|
9
9
|
exists: (path: string) => boolean;
|
|
10
10
|
}
|
|
11
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
|
+
|
|
12
48
|
export class DefaultFileSystem implements FileSystem {
|
|
13
|
-
isDirectory(pathToRead: string): boolean {
|
|
14
|
-
|
|
49
|
+
async isDirectory(pathToRead: string): Promise<boolean> {
|
|
50
|
+
const stats = await stat(pathToRead);
|
|
51
|
+
return stats.isDirectory();
|
|
15
52
|
}
|
|
16
53
|
|
|
17
|
-
readDirectory(sourceDirectory: string): string[] {
|
|
18
|
-
return
|
|
54
|
+
readDirectory(sourceDirectory: string): Promise<string[]> {
|
|
55
|
+
return readdir(sourceDirectory);
|
|
19
56
|
}
|
|
20
57
|
|
|
21
|
-
readFile(pathToRead: string): string {
|
|
22
|
-
|
|
23
|
-
return rawFile.toString();
|
|
58
|
+
readFile(pathToRead: string): Promise<string> {
|
|
59
|
+
return readFile(pathToRead);
|
|
24
60
|
}
|
|
25
61
|
|
|
26
62
|
joinPath(...paths: string[]): string {
|
|
@@ -8,10 +8,10 @@ import {
|
|
|
8
8
|
UnparsedSourceFile,
|
|
9
9
|
UserDefinedMarkdownConfig,
|
|
10
10
|
} from '../../core/shared/types';
|
|
11
|
-
import { ReflectionError } from '../../core/markdown/reflection/error-handling';
|
|
12
11
|
import { referenceGuideTemplate } from '../../core/markdown/templates/reference-guide';
|
|
13
12
|
import * as TE from 'fp-ts/TaskEither';
|
|
14
13
|
import { isSkip } from '../../core/shared/utils';
|
|
14
|
+
import { ReflectionError } from '../../core/markdown/reflection/reflect-source';
|
|
15
15
|
|
|
16
16
|
class FileWritingError {
|
|
17
17
|
readonly _tag = 'FileWritingError';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { pipe } from 'fp-ts/function';
|
|
2
|
-
import * as E from 'fp-ts/Either';
|
|
2
|
+
//import * as E from 'fp-ts/Either';
|
|
3
3
|
import * as TE from 'fp-ts/TaskEither';
|
|
4
4
|
import yaml from 'js-yaml';
|
|
5
5
|
|
|
@@ -20,8 +20,8 @@ import {
|
|
|
20
20
|
ParsedFile,
|
|
21
21
|
} from '../shared/types';
|
|
22
22
|
import { parsedFilesToRenderableBundle } from './adapters/renderable-bundle';
|
|
23
|
-
import { reflectSourceCode } from './reflection/reflect-source';
|
|
24
|
-
import { checkForReflectionErrors } from './reflection/error-handling';
|
|
23
|
+
import { myPipeSeq /*reflectSourceCode*/ } from './reflection/reflect-source';
|
|
24
|
+
//import { checkForReflectionErrors } from './reflection/error-handling';
|
|
25
25
|
import { addInheritanceChainToTypes } from './reflection/inheritance-chain-expanion';
|
|
26
26
|
import { addInheritedMembersToTypes } from './reflection/inherited-member-expansion';
|
|
27
27
|
import { convertToDocumentationBundle } from './adapters/renderable-to-page-data';
|
|
@@ -63,15 +63,14 @@ export function generateDocs(apexBundles: UnparsedSourceFile[], config: Markdown
|
|
|
63
63
|
|
|
64
64
|
return pipe(
|
|
65
65
|
apexBundles,
|
|
66
|
-
|
|
67
|
-
checkForReflectionErrors,
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
TE.fromEither,
|
|
66
|
+
myPipeSeq,
|
|
67
|
+
//checkForReflectionErrors,
|
|
68
|
+
TE.map(filterOutOfScope),
|
|
69
|
+
TE.map(addInheritedMembersToTypes),
|
|
70
|
+
TE.map(addInheritanceChainToTypes),
|
|
71
|
+
TE.map(sortTypeMembers),
|
|
72
|
+
TE.bindTo('parsedFiles'),
|
|
73
|
+
TE.bind('references', ({ parsedFiles }) => TE.right(convertToReferences(parsedFiles))),
|
|
75
74
|
TE.flatMap(({ parsedFiles, references }) => transformReferenceHook(config)({ references, parsedFiles })),
|
|
76
75
|
TE.map(({ parsedFiles, references }) => convertToRenderableBundle(parsedFiles, references)),
|
|
77
76
|
TE.map(convertToDocumentationBundleForTemplate),
|
|
@@ -1,34 +1,111 @@
|
|
|
1
1
|
import { ParsedFile, UnparsedSourceFile } from '../../shared/types';
|
|
2
|
-
import * as E from 'fp-ts/Either';
|
|
2
|
+
//import * as E from 'fp-ts/Either';
|
|
3
|
+
import * as TE from 'fp-ts/TaskEither';
|
|
4
|
+
import * as T from 'fp-ts/Task';
|
|
5
|
+
import * as A from 'fp-ts/lib/Array';
|
|
3
6
|
import { reflect as mirrorReflection, Type } from '@cparra/apex-reflection';
|
|
4
7
|
import { pipe } from 'fp-ts/function';
|
|
5
8
|
import * as O from 'fp-ts/Option';
|
|
6
9
|
import { parseApexMetadata } from '../../parse-apex-metadata';
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
10
|
+
import { ParsingError } from '@cparra/apex-reflection/index';
|
|
11
|
+
import { apply } from '#utils/fp';
|
|
12
|
+
import { Semigroup } from 'fp-ts/Semigroup';
|
|
13
|
+
|
|
14
|
+
export class ReflectionErrors {
|
|
15
|
+
readonly _tag = 'ReflectionErrors';
|
|
16
|
+
|
|
17
|
+
constructor(public errors: ReflectionError[]) {}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export class ReflectionError {
|
|
21
|
+
constructor(
|
|
22
|
+
public file: string,
|
|
23
|
+
public message: string,
|
|
24
|
+
) {}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function reflectAsync(rawSource: string): Promise<Type> {
|
|
28
|
+
return new Promise((resolve, reject) => {
|
|
29
|
+
const result = mirrorReflection(rawSource);
|
|
30
|
+
if (result.typeMirror) {
|
|
31
|
+
return resolve(result.typeMirror);
|
|
32
|
+
} else if (result.error) {
|
|
33
|
+
return reject(result.error);
|
|
34
|
+
} else {
|
|
35
|
+
return reject(new Error('Unknown error'));
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function myPipeSeq(apexBundles: UnparsedSourceFile[]) {
|
|
41
|
+
const semiGroupReflectionError: Semigroup<ReflectionErrors> = {
|
|
42
|
+
concat: (x, y) => new ReflectionErrors([...x.errors, ...y.errors]),
|
|
43
|
+
};
|
|
44
|
+
const Ap = TE.getApplicativeTaskValidation(T.ApplyPar, semiGroupReflectionError);
|
|
45
|
+
|
|
46
|
+
return pipe(apexBundles, A.traverse(Ap)(myPipe));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function myPipe(apexBundle: UnparsedSourceFile): TE.TaskEither<ReflectionErrors, ParsedFile> {
|
|
50
|
+
const convertToParsedFile: (typeMirror: Type) => ParsedFile = apply(toParsedFile, apexBundle.filePath);
|
|
51
|
+
const withMetadata: (parsedFile: ParsedFile) => ParsedFile = apply(addMetadata, apexBundle.metadataContent);
|
|
52
|
+
|
|
53
|
+
return pipe(apexBundle, reflectAsTask, TE.map(convertToParsedFile), TE.map(withMetadata));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function reflectAsTask(apexBundle: UnparsedSourceFile): TE.TaskEither<ReflectionErrors, Type> {
|
|
57
|
+
return TE.tryCatch(
|
|
58
|
+
() => reflectAsync(apexBundle.content),
|
|
59
|
+
(error) =>
|
|
60
|
+
new ReflectionErrors([new ReflectionError(apexBundle.filePath, (error as ParsingError | Error).message)]),
|
|
61
|
+
);
|
|
26
62
|
}
|
|
27
63
|
|
|
64
|
+
function toParsedFile(filePath: string, typeMirror: Type): ParsedFile {
|
|
65
|
+
return {
|
|
66
|
+
source: {
|
|
67
|
+
filePath: filePath,
|
|
68
|
+
name: typeMirror.name,
|
|
69
|
+
type: typeMirror.type_name,
|
|
70
|
+
},
|
|
71
|
+
type: typeMirror,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function addMetadata(rawMetadataContent: string | null, parsedFile: ParsedFile) {
|
|
76
|
+
return {
|
|
77
|
+
...parsedFile,
|
|
78
|
+
type: addFileMetadataToTypeAnnotation(parsedFile.type, rawMetadataContent),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// TODO: Not Async below
|
|
83
|
+
|
|
84
|
+
// export function reflectSourceCode(apexBundles: UnparsedSourceFile[]) {
|
|
85
|
+
// return apexBundles.map(reflectSourceBody);
|
|
86
|
+
// }
|
|
87
|
+
//
|
|
88
|
+
// function reflectSourceBody(apexBundle: UnparsedSourceFile): E.Either<ReflectionError, ParsedFile> {
|
|
89
|
+
// const { filePath, content: input, metadataContent: metadata } = apexBundle;
|
|
90
|
+
// const result = mirrorReflection(input);
|
|
91
|
+
// return result.error
|
|
92
|
+
// ? E.left(new ReflectionError(filePath, result.error.message))
|
|
93
|
+
// : E.right({
|
|
94
|
+
// source: {
|
|
95
|
+
// filePath,
|
|
96
|
+
// name: result.typeMirror!.name,
|
|
97
|
+
// type: result.typeMirror!.type_name,
|
|
98
|
+
// },
|
|
99
|
+
// type: addFileMetadataToTypeAnnotation(result.typeMirror!, metadata),
|
|
100
|
+
// });
|
|
101
|
+
// }
|
|
102
|
+
|
|
28
103
|
function addFileMetadataToTypeAnnotation(type: Type, metadata: string | null): Type {
|
|
29
104
|
return pipe(
|
|
30
105
|
O.fromNullable(metadata),
|
|
31
106
|
O.map((metadata) => {
|
|
107
|
+
// TODO: Do we need to error check this, as it is coming from an external library?
|
|
108
|
+
// Or maybe what we do is return the Either from the parse-apex-metadata function?
|
|
32
109
|
const metadataParams = parseApexMetadata(metadata);
|
|
33
110
|
metadataParams.forEach((value, key) => {
|
|
34
111
|
const declaration = `${key}: ${value}`;
|
|
@@ -1,13 +0,0 @@
|
|
|
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;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import * as E from 'fp-ts/Either';
|
|
2
|
-
import { ParsedFile } from '../../shared/types';
|
|
3
|
-
import { pipe } from 'fp-ts/function';
|
|
4
|
-
|
|
5
|
-
export class ReflectionErrors {
|
|
6
|
-
readonly _tag = 'ReflectionErrors';
|
|
7
|
-
constructor(public errors: ReflectionError[]) {}
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export class ReflectionError {
|
|
11
|
-
constructor(
|
|
12
|
-
public file: string,
|
|
13
|
-
public message: string,
|
|
14
|
-
) {}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function checkForReflectionErrors(reflectionResult: E.Either<ReflectionError, ParsedFile>[]) {
|
|
18
|
-
function reduceReflectionResultIntoSingleEither(results: E.Either<ReflectionError, ParsedFile>[]): {
|
|
19
|
-
errors: ReflectionError[];
|
|
20
|
-
parsedFiles: ParsedFile[];
|
|
21
|
-
} {
|
|
22
|
-
return results.reduce<{ errors: ReflectionError[]; parsedFiles: ParsedFile[] }>(
|
|
23
|
-
(acc, result) => {
|
|
24
|
-
E.isLeft(result) ? acc.errors.push(result.left) : acc.parsedFiles.push(result.right);
|
|
25
|
-
return acc;
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
errors: [],
|
|
29
|
-
parsedFiles: [],
|
|
30
|
-
},
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return pipe(reflectionResult, reduceReflectionResultIntoSingleEither, ({ errors, parsedFiles }) =>
|
|
35
|
-
errors.length ? E.left(new ReflectionErrors(errors)) : E.right(parsedFiles),
|
|
36
|
-
);
|
|
37
|
-
}
|