@cparra/apexdocs 2.18.0 → 2.19.0-alpha.2

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
@@ -25,31 +25,6 @@ There are some key differences between ApexDocs and the Java based ApexDoc tool:
25
25
  Markdown like Github Pages or Netlify, and use site generators like Jekyll or Gatsby. This gives you the freedom to
26
26
  decide how to style your site to match your needs.
27
27
 
28
- ## Version 2.X
29
-
30
- Version shares almost* all the same functionality (and more) of 1.X , but is a rewrite from the ground up of the tool,
31
- so please be aware if migrating from a 1.X version.
32
-
33
- The Apex code parsing logic for the 1.X codebase was almost a one-to-one translation of the Java based ApexDoc tool to
34
- Javascript. With 2.X the parsing logic has been improved and extracted out of this codebase, and into its own standalone
35
- NPM module which is solely focused on Apex code reflection: https://www.npmjs.com/package/@cparra/apex-reflection
36
-
37
- This allows for an improved code quality of both code bases and an increased ease of introducing future improvements and
38
- fixing issues.
39
-
40
- ### Differences between the versions
41
-
42
- When migrating from 1.X please be aware of these changes between the major versions:
43
-
44
- #### Deprecated features
45
-
46
- * The `--group` CLI parameter has been deprecated. All files are grouped by default.
47
-
48
- #### Features from 1.X not supported in 2.X
49
-
50
- * The `--configPath` CLI parameter has been temporarily deprecated. We are planning on reintroducing it but the config
51
- file will use a different format.
52
-
53
28
  #### New features
54
29
 
55
30
  * All Apex annotations are now supported through the `--scope` CLI parameter, not just `namespaceaccessible`. This means
@@ -0,0 +1,9 @@
1
+ export default {
2
+ onBeforeFileWrite: (dir: string, fileName: string) => {
3
+ console.log('onBefore writing', fileName);
4
+ return { dir, fileName };
5
+ },
6
+ onAfterProcess: (files: { dir: string; fileName: string }[]) => {
7
+ console.log('onAfterProcess files', files);
8
+ },
9
+ };
@@ -30,9 +30,12 @@ class Apexdocs {
30
30
  const processor = factory_1.TypeTranspilerFactory.get(settings_1.Settings.getInstance().targetGenerator);
31
31
  transpiler_1.default.generate(filteredTypes, processor);
32
32
  const generatedFiles = processor.fileBuilder().files();
33
- file_writer_1.FileWriter.write(generatedFiles, (fileName) => {
34
- logger_1.Logger.logSingle(`${fileName} processed.`, false, 'green', false);
33
+ const generatedFilePaths = [];
34
+ file_writer_1.FileWriter.write(generatedFiles, (file) => {
35
+ logger_1.Logger.logSingle(`${file.fileName} processed.`, false, 'green', false);
36
+ generatedFilePaths.push(file);
35
37
  });
38
+ settings_1.Settings.getInstance().onAfterProcess(generatedFilePaths);
36
39
  // Error logging
37
40
  error_logger_1.default.logErrors(filteredTypes);
38
41
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Apexdocs.js","sourceRoot":"","sources":["../../src/application/Apexdocs.ts"],"names":[],"mappings":";;;AAAA,kEAA6D;AAC7D,wDAA2D;AAC3D,6DAA0E;AAC1E,2CAAwC;AACxC,kEAA6D;AAC7D,8CAAkD;AAClD,0CAAuC;AACvC,yDAAkD;AAClD,wDAAoD;AACpD,uDAA+C;AAG/C,gEAA4D;AAC5D,mDAA8D;AAE9D;;GAEG;AACH,MAAa,QAAQ;IACnB;;OAEG;IACH,MAAM,CAAC,QAAQ;QACb,eAAM,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;QAC9B,MAAM,UAAU,GAAG,iCAAc,CAAC,YAAY,CAAC,IAAI,+BAAiB,EAAE,CAAC,CAAC;QACxE,MAAM,QAAQ,GAAG,IAAA,iCAAc,EAAC,IAAI,sBAAa,CAAC,UAAU,CAAC,EAAE,IAAI,CAAC,qBAAqB,CAAC,CAAC;QAC3F,kCAAe,CAAC,WAAW,EAAE,CAAC,WAAW,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QAC1D,MAAM,aAAa,GAAG,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;QACpD,kCAAe,CAAC,WAAW,EAAE,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;QAC5D,MAAM,SAAS,GAAG,+BAAqB,CAAC,GAAG,CAAC,mBAAQ,CAAC,WAAW,EAAE,CAAC,eAAe,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C9D,cAAc;gBACd,YAAY;gBACZ,SAAS;gBACT,WAAW;gBACX,UAAU;gBACV,SAAS;aACV,CAAC,CAAC;YACH,kBAAkB,GAAG,YACnB,QAAQ,CAAC,KAAK,CAAC,MAAM,GAAG,aAAa,CAAC,MACxC,4DAA4D,CAAC;SAC9D;QACD,eAAM,CAAC,KAAK,EAAE,CAAC;QAEf,eAAM,CAAC,SAAS,CAAC,kBAAkB,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;QAC5D,eAAM,CAAC,SAAS,CAAC,8BAA8B,aAAa,CAAC,MAAM,UAAU,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;QACtG,OAAO,aAAa,CAAC;IACvB,CAAC;;AAvDH,4BAgEC;AAPQ,8BAAqB,GAAG,CAAC,UAAsB,EAAoB,EAAE;;IAC1E,MAAM,MAAM,GAAG,IAAA,yBAAO,EAAC,UAAU,CAAC,cAAc,CAAC,CAAC;IAClD,IAAI,MAAM,CAAC,KAAK,EAAE;QAChB,eAAM,CAAC,KAAK,CAAC,GAAG,UAAU,CAAC,QAAQ,oBAAoB,MAAA,MAAM,CAAC,KAAK,0CAAE,OAAO,EAAE,CAAC,CAAC;KACjF;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC"}
@@ -4,110 +4,120 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  const yargs = require("yargs");
5
5
  const settings_1 = require("../settings");
6
6
  const Apexdocs_1 = require("../application/Apexdocs");
7
- const argv = yargs.options({
8
- sourceDir: {
9
- type: 'string',
10
- alias: 's',
11
- demandOption: true,
12
- describe: 'The directory location which contains your apex .cls classes.',
13
- },
14
- targetDir: {
15
- type: 'string',
16
- alias: 't',
17
- default: './docs/',
18
- describe: 'The directory location where documentation will be generated to.',
19
- },
20
- recursive: {
21
- type: 'boolean',
22
- alias: 'r',
23
- default: true,
24
- describe: 'Whether .cls classes will be searched for recursively in the directory provided.',
25
- },
26
- scope: {
27
- type: 'array',
28
- alias: 'p',
29
- default: ['global'],
30
- describe: 'A list of scopes to document. Values should be separated by a space, e.g --scope global public namespaceaccessible. ' +
31
- 'Annotations are supported and should be passed lowercased and without the @ symbol, e.g. namespaceaccessible auraenabled. ' +
32
- 'Note that this setting is ignored if generating an OpenApi REST specification since that looks for classes annotated with @RestResource.',
33
- },
34
- targetGenerator: {
35
- type: 'string',
36
- alias: 'g',
37
- default: 'jekyll',
38
- choices: ['jekyll', 'docsify', 'plain-markdown', 'openapi'],
39
- describe: 'Define the static file generator for which the documents will be created. ' +
40
- 'Currently supports jekyll, docsify, plain markdown, and OpenAPI v3.1.0.',
41
- },
42
- indexOnly: {
43
- type: 'boolean',
44
- default: false,
45
- describe: 'Defines whether only the index file should be generated.',
46
- },
47
- defaultGroupName: {
48
- type: 'string',
49
- default: 'Miscellaneous',
50
- describe: 'Defines the @group name to be used when a file does not specify it.',
51
- },
52
- sanitizeHtml: {
53
- type: 'boolean',
54
- default: true,
55
- describe: 'When on, any special character within your ApexDocs is converted into its HTML code representation. ' +
56
- 'This is specially useful when generic objects are described within the docs, e.g. "List< Foo>", "Map<Foo, Bar>" ' +
57
- 'because otherwise the content within < and > would be treated as HTML tags and not shown in the output. ' +
58
- 'Content in @example blocks are never sanitized.',
59
- },
60
- openApiTitle: {
61
- type: 'string',
62
- default: 'Apex REST Api',
63
- describe: 'If using "openapi" as the target generator, this allows you to specify the OpenApi title value.',
64
- },
65
- title: {
66
- type: 'string',
67
- describe: "If this allows you to specify the title of the generated documentation's home file.",
68
- default: 'Classes',
69
- },
70
- namespace: {
71
- type: 'string',
72
- 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. ' +
73
- "If generating an OpenApi definition, it will be added to the file's Server Url.",
74
- },
75
- openApiFileName: {
76
- type: 'string',
77
- describe: 'If using "openapi" as the target generator, this allows you to specify the name of the output file.',
78
- default: 'openapi',
79
- },
80
- includeMetadata: {
81
- type: 'boolean',
82
- describe: "Whether to include the file's meta.xml information: Whether it is active and and the API version",
83
- default: false,
84
- },
85
- documentationRootDir: {
86
- type: 'string',
87
- describe: 'Allows you to specify the root documentation directory where the files are being generated. This can be helpful when embedding the generated docs into an existing site so that the links are generated correctly.',
88
- },
89
- }).argv;
90
- settings_1.Settings.build({
91
- sourceDirectory: argv.sourceDir,
92
- recursive: argv.recursive,
93
- scope: argv.scope,
94
- outputDir: argv.targetDir,
95
- targetGenerator: argv.targetGenerator,
96
- indexOnly: argv.indexOnly,
97
- defaultGroupName: argv.defaultGroupName,
98
- sanitizeHtml: argv.sanitizeHtml,
99
- openApiTitle: argv.openApiTitle,
100
- title: argv.title,
101
- namespace: argv.namespace,
102
- openApiFileName: argv.openApiFileName,
103
- includeMetadata: argv.includeMetadata,
104
- rootDir: argv.documentationRootDir,
7
+ const cosmiconfig_1 = require("cosmiconfig");
8
+ const result = (0, cosmiconfig_1.cosmiconfig)('apexdocs').search();
9
+ result.then((config) => {
10
+ var _a, _b;
11
+ let argv = yargs.options({
12
+ sourceDir: {
13
+ type: 'string',
14
+ alias: 's',
15
+ demandOption: true,
16
+ describe: 'The directory location which contains your apex .cls classes.',
17
+ },
18
+ targetDir: {
19
+ type: 'string',
20
+ alias: 't',
21
+ default: './docs/',
22
+ describe: 'The directory location where documentation will be generated to.',
23
+ },
24
+ recursive: {
25
+ type: 'boolean',
26
+ alias: 'r',
27
+ default: true,
28
+ describe: 'Whether .cls classes will be searched for recursively in the directory provided.',
29
+ },
30
+ scope: {
31
+ type: 'array',
32
+ alias: 'p',
33
+ default: ['global'],
34
+ describe: 'A list of scopes to document. Values should be separated by a space, e.g --scope global public namespaceaccessible. ' +
35
+ 'Annotations are supported and should be passed lowercased and without the @ symbol, e.g. namespaceaccessible auraenabled. ' +
36
+ 'Note that this setting is ignored if generating an OpenApi REST specification since that looks for classes annotated with @RestResource.',
37
+ },
38
+ targetGenerator: {
39
+ type: 'string',
40
+ alias: 'g',
41
+ default: 'jekyll',
42
+ choices: ['jekyll', 'docsify', 'plain-markdown', 'openapi'],
43
+ describe: 'Define the static file generator for which the documents will be created. ' +
44
+ 'Currently supports jekyll, docsify, plain markdown, and OpenAPI v3.1.0.',
45
+ },
46
+ indexOnly: {
47
+ type: 'boolean',
48
+ default: false,
49
+ describe: 'Defines whether only the index file should be generated.',
50
+ },
51
+ defaultGroupName: {
52
+ type: 'string',
53
+ default: 'Miscellaneous',
54
+ describe: 'Defines the @group name to be used when a file does not specify it.',
55
+ },
56
+ sanitizeHtml: {
57
+ type: 'boolean',
58
+ default: true,
59
+ describe: 'When on, any special character within your ApexDocs is converted into its HTML code representation. ' +
60
+ 'This is specially useful when generic objects are described within the docs, e.g. "List< Foo>", "Map<Foo, Bar>" ' +
61
+ 'because otherwise the content within < and > would be treated as HTML tags and not shown in the output. ' +
62
+ 'Content in @example blocks are never sanitized.',
63
+ },
64
+ openApiTitle: {
65
+ type: 'string',
66
+ default: 'Apex REST Api',
67
+ describe: 'If using "openapi" as the target generator, this allows you to specify the OpenApi title value.',
68
+ },
69
+ title: {
70
+ type: 'string',
71
+ describe: "If this allows you to specify the title of the generated documentation's home file.",
72
+ default: 'Classes',
73
+ },
74
+ namespace: {
75
+ type: 'string',
76
+ 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. ' +
77
+ "If generating an OpenApi definition, it will be added to the file's Server Url.",
78
+ },
79
+ openApiFileName: {
80
+ type: 'string',
81
+ describe: 'If using "openapi" as the target generator, this allows you to specify the name of the output file.',
82
+ default: 'openapi',
83
+ },
84
+ includeMetadata: {
85
+ type: 'boolean',
86
+ describe: "Whether to include the file's meta.xml information: Whether it is active and and the API version",
87
+ default: false,
88
+ },
89
+ documentationRootDir: {
90
+ type: 'string',
91
+ describe: 'Allows you to specify the root documentation directory where the files are being generated. This can be helpful when embedding the generated docs into an existing site so that the links are generated correctly.',
92
+ },
93
+ }).argv;
94
+ if (config) {
95
+ argv = Object.assign(Object.assign({}, config.config), argv);
96
+ }
97
+ settings_1.Settings.build({
98
+ sourceDirectory: argv.sourceDir,
99
+ recursive: argv.recursive,
100
+ scope: argv.scope,
101
+ outputDir: argv.targetDir,
102
+ targetGenerator: argv.targetGenerator,
103
+ indexOnly: argv.indexOnly,
104
+ defaultGroupName: argv.defaultGroupName,
105
+ sanitizeHtml: argv.sanitizeHtml,
106
+ openApiTitle: argv.openApiTitle,
107
+ title: argv.title,
108
+ namespace: argv.namespace,
109
+ openApiFileName: argv.openApiFileName,
110
+ includeMetadata: argv.includeMetadata,
111
+ rootDir: argv.documentationRootDir,
112
+ onAfterProcess: (_a = config === null || config === void 0 ? void 0 : config.config) === null || _a === void 0 ? void 0 : _a.onAfterProcess,
113
+ onBeforeFileWrite: (_b = config === null || config === void 0 ? void 0 : config.config) === null || _b === void 0 ? void 0 : _b.onBeforeFileWrite,
114
+ });
115
+ try {
116
+ Apexdocs_1.Apexdocs.generate();
117
+ }
118
+ catch (error) {
119
+ console.error(error);
120
+ process.exit(1);
121
+ }
105
122
  });
106
- try {
107
- Apexdocs_1.Apexdocs.generate();
108
- }
109
- catch (error) {
110
- console.error(error);
111
- process.exit(1);
112
- }
113
123
  //# sourceMappingURL=generate.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"generate.js","sourceRoot":"","sources":["../../src/cli/generate.ts"],"names":[],"mappings":";;;AACA,+BAA+B;AAE/B,0CAAuC;AACvC,sDAAmD;AAGnD,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC;IACzB,SAAS,EAAE;QACT,IAAI,EAAE,QAAQ;QACd,KAAK,EAAE,GAAG;QACV,YAAY,EAAE,IAAI;QAClB,QAAQ,EAAE,+DAA+D;KAC1E;IACD,SAAS,EAAE;QACT,IAAI,EAAE,QAAQ;QACd,KAAK,EAAE,GAAG;QACV,OAAO,EAAE,SAAS;QAClB,QAAQ,EAAE,kEAAkE;KAC7E;IACD,SAAS,EAAE;QACT,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,GAAG;QACV,OAAO,EAAE,IAAI;QACb,QAAQ,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ACrB;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACrB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACjB;AACH,CAAC,CAAC,CAAC"}
@@ -1,4 +1,10 @@
1
1
  import { OutputFile } from '../model/outputFile';
2
2
  export declare class FileWriter {
3
- static write(files: OutputFile[], onWriteCallback: (fileName: string) => void): void;
3
+ static write(files: OutputFile[], onWriteCallback: (file: TargetLocation) => void): void;
4
+ private static getTargetLocation;
4
5
  }
6
+ type TargetLocation = {
7
+ dir: string;
8
+ fileName: string;
9
+ };
10
+ export {};
@@ -6,21 +6,22 @@ const path = require("path");
6
6
  const settings_1 = require("../settings");
7
7
  class FileWriter {
8
8
  static write(files, onWriteCallback) {
9
- const outputDir = settings_1.Settings.getInstance().outputDir;
10
- if (!fs.existsSync(outputDir)) {
11
- fs.mkdirSync(outputDir);
12
- }
9
+ const onBeforeFileWrite = (outputDir, fileName) => settings_1.Settings.getInstance().onBeforeFileWrite(outputDir, fileName);
13
10
  files.forEach((file) => {
14
- const dirPath = path.join(outputDir, file.dir);
11
+ const { dir: dirPath, fileName } = this.getTargetLocation(file, onBeforeFileWrite);
15
12
  if (!fs.existsSync(dirPath)) {
16
- fs.mkdirSync(dirPath);
13
+ fs.mkdirSync(dirPath, { recursive: true });
17
14
  }
18
- const filePath = path.join(dirPath, `${file.fileName}${file.fileExtension()}`);
19
- fs.writeFile(filePath, file.body, 'utf8', () => {
20
- onWriteCallback(file.fileName);
21
- });
15
+ const filePath = path.join(dirPath, fileName);
16
+ fs.writeFileSync(filePath, file.body, 'utf8');
17
+ onWriteCallback({ dir: dirPath, fileName });
22
18
  });
23
19
  }
20
+ static getTargetLocation(file, onBeforeFileWrite) {
21
+ const outputDir = path.join(settings_1.Settings.getInstance().outputDir, file.dir);
22
+ const fileName = `${file.fileName}${file.fileExtension()}`;
23
+ return onBeforeFileWrite(outputDir, fileName);
24
+ }
24
25
  }
25
26
  exports.FileWriter = FileWriter;
26
27
  //# sourceMappingURL=file-writer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"file-writer.js","sourceRoot":"","sources":["../../src/service/file-writer.ts"],"names":[],"mappings":";;;AAAA,yBAAyB;AACzB,6BAA6B;AAE7B,0CAAuC;AAEvC,MAAa,UAAU;IACrB,MAAM,CAAC,KAAK,CAAC,KAAmB,EAAE,eAA2C;QAC3E,MAAM,SAAS,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC,SAAS,CAAC;QACnD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE;YAC7B,EAAE,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;SACzB;QAED,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YACrB,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;YAC/C,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE;gBAC3B,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;aACvB;YAED,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC;YAC/E,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE;gBAC7C,eAAe,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACjC,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAnBD,gCAmBC"}
1
+ {"version":3,"file":"file-writer.js","sourceRoot":"","sources":["../../src/service/file-writer.ts"],"names":[],"mappings":";;;AAAA,yBAAyB;AACzB,6BAA6B;AAE7B,0CAAuC;AAEvC,MAAa,UAAU;IACrB,MAAM,CAAC,KAAK,CAAC,KA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16
  rootDir?: string;
17
+ onAfterProcess?: (files: {
18
+ dir: string;
19
+ fileName: string;
20
+ }[]) => void;
21
+ onBeforeFileWrite?: (outputDir: string, fileName: string) => {
22
+ dir: string;
23
+ fileName: string;
24
+ };
17
25
  }
18
26
  export declare class Settings {
19
27
  config: SettingsConfig;
@@ -36,4 +44,12 @@ export declare class Settings {
36
44
  openApiFileName(): string;
37
45
  includeMetadata(): boolean;
38
46
  getRootDir(): string | undefined;
47
+ onAfterProcess(files: {
48
+ dir: string;
49
+ fileName: string;
50
+ }[]): void;
51
+ onBeforeFileWrite(outputDir: string, fileName: string): {
52
+ dir: string;
53
+ fileName: string;
54
+ };
39
55
  }
package/lib/settings.js CHANGED
@@ -63,6 +63,17 @@ class Settings {
63
63
  getRootDir() {
64
64
  return this.config.rootDir;
65
65
  }
66
+ onAfterProcess(files) {
67
+ if (this.config.onAfterProcess) {
68
+ this.config.onAfterProcess(files);
69
+ }
70
+ }
71
+ onBeforeFileWrite(outputDir, fileName) {
72
+ if (this.config.onBeforeFileWrite) {
73
+ return this.config.onBeforeFileWrite(outputDir, fileName);
74
+ }
75
+ return { dir: outputDir, fileName };
76
+ }
66
77
  }
67
78
  exports.Settings = Settings;
68
79
  //# sourceMappingURL=settings.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"settings.js","sourceRoot":"","sources":["../src/settings.ts"],"names":[],"mappings":";;;AAmBA,MAAa,QAAQ;IAGnB,YAA2B,MAAsB;QAAtB,WAAM,GAAN,MAAM,CAAgB;IAAG,CAAC;IAE9C,MAAM,CAAC,KAAK,CAAC,MAAsB;QACxC,QAAQ,CAAC,QAAQ,GAAG,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC3C,CAAC;IAEM,MAAM,CAAC,WAAW;QACvB,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE;YACtB,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;SACtD;QACD,OAAO,QAAQ,CAAC,QAAQ,CAAC;IAC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C;IACvD,CAAC;IAEM,QAAQ;QACb,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;IAC3B,CAAC;IAEM,YAAY;QACjB,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC;IAC/B,CAAC;IAEM,kBAAkB;QACvB,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE;YAC1B,OAAO,EAAE,CAAC;SACX;QACD,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,GAAG,CAAC;IACrC,CAAC;IAEM,eAAe;QACpB,OAAO,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC;IACrC,CAAC;IAEM,eAAe;QACpB,OAAO,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC;IACrC,CAAC;IAEM,UAAU;QACf,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;IAC7B,CAAC;IAEM,cAAc,CAAC,KAA0C;QAC9D,IAAI,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE;YAC9B,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;SACnC;IACH,CAAC;IAEM,iBAAiB,CAAC,SAAiB,EAAE,QAAgB;QAC1D,IAAI,IAAI,CAAC,MAAM,CAAC,iBAAiB,EAAE;YACjC,OAAO,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;SAC3D;QACD,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;IACtC,CAAC;CACF;AA3FD,4BA2FC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cparra/apexdocs",
3
- "version": "2.18.0",
3
+ "version": "2.19.0-alpha.2",
4
4
  "description": "Library with CLI capabilities to generate documentation for Salesforce Apex classes.",
5
5
  "keywords": [
6
6
  "apex",
@@ -68,6 +68,7 @@
68
68
  "dependencies": {
69
69
  "@cparra/apex-reflection": "2.5.0",
70
70
  "chalk": "^4.1.2",
71
+ "cosmiconfig": "^9.0.0",
71
72
  "fast-xml-parser": "^4.0.1",
72
73
  "js-yaml": "^4.1.0",
73
74
  "log-update": "4.0.0",
@@ -30,10 +30,15 @@ export class Apexdocs {
30
30
  const processor = TypeTranspilerFactory.get(Settings.getInstance().targetGenerator);
31
31
  Transpiler.generate(filteredTypes, processor);
32
32
  const generatedFiles = processor.fileBuilder().files();
33
- FileWriter.write(generatedFiles, (fileName: string) => {
34
- Logger.logSingle(`${fileName} processed.`, false, 'green', false);
33
+
34
+ const generatedFilePaths: { dir: string; fileName: string }[] = [];
35
+ FileWriter.write(generatedFiles, (file: { dir: string; fileName: string }) => {
36
+ Logger.logSingle(`${file.fileName} processed.`, false, 'green', false);
37
+ generatedFilePaths.push(file);
35
38
  });
36
39
 
40
+ Settings.getInstance().onAfterProcess(generatedFilePaths);
41
+
37
42
  // Error logging
38
43
  ErrorLogger.logErrors(filteredTypes);
39
44
  }
@@ -4,116 +4,126 @@ import * as yargs from 'yargs';
4
4
  import { Settings } from '../settings';
5
5
  import { Apexdocs } from '../application/Apexdocs';
6
6
  import { GeneratorChoices } from '../transpiler/generator-choices';
7
+ import { cosmiconfig } from 'cosmiconfig';
7
8
 
8
- const argv = yargs.options({
9
- sourceDir: {
10
- type: 'string',
11
- alias: 's',
12
- demandOption: true,
13
- describe: 'The directory location which contains your apex .cls classes.',
14
- },
15
- targetDir: {
16
- type: 'string',
17
- alias: 't',
18
- default: './docs/',
19
- describe: 'The directory location where documentation will be generated to.',
20
- },
21
- recursive: {
22
- type: 'boolean',
23
- alias: 'r',
24
- default: true,
25
- describe: 'Whether .cls classes will be searched for recursively in the directory provided.',
26
- },
27
- scope: {
28
- type: 'array',
29
- alias: 'p',
30
- default: ['global'],
31
- describe:
32
- 'A list of scopes to document. Values should be separated by a space, e.g --scope global public namespaceaccessible. ' +
33
- 'Annotations are supported and should be passed lowercased and without the @ symbol, e.g. namespaceaccessible auraenabled. ' +
34
- 'Note that this setting is ignored if generating an OpenApi REST specification since that looks for classes annotated with @RestResource.',
35
- },
36
- targetGenerator: {
37
- type: 'string',
38
- alias: 'g',
39
- default: 'jekyll',
40
- choices: ['jekyll', 'docsify', 'plain-markdown', 'openapi'],
41
- describe:
42
- 'Define the static file generator for which the documents will be created. ' +
43
- 'Currently supports jekyll, docsify, plain markdown, and OpenAPI v3.1.0.',
44
- },
45
- indexOnly: {
46
- type: 'boolean',
47
- default: false,
48
- describe: 'Defines whether only the index file should be generated.',
49
- },
50
- defaultGroupName: {
51
- type: 'string',
52
- default: 'Miscellaneous',
53
- describe: 'Defines the @group name to be used when a file does not specify it.',
54
- },
55
- sanitizeHtml: {
56
- type: 'boolean',
57
- default: true,
58
- describe:
59
- 'When on, any special character within your ApexDocs is converted into its HTML code representation. ' +
60
- 'This is specially useful when generic objects are described within the docs, e.g. "List< Foo>", "Map<Foo, Bar>" ' +
61
- 'because otherwise the content within < and > would be treated as HTML tags and not shown in the output. ' +
62
- 'Content in @example blocks are never sanitized.',
63
- },
64
- openApiTitle: {
65
- type: 'string',
66
- default: 'Apex REST Api',
67
- describe: 'If using "openapi" as the target generator, this allows you to specify the OpenApi title value.',
68
- },
69
- title: {
70
- type: 'string',
71
- describe: "If this allows you to specify the title of the generated documentation's home file.",
72
- default: 'Classes',
73
- },
74
- namespace: {
75
- type: 'string',
76
- describe:
77
- 'The package namespace, if any. If this value is provided the namespace will be added as a prefix to all of the parsed files. ' +
78
- "If generating an OpenApi definition, it will be added to the file's Server Url.",
79
- },
80
- openApiFileName: {
81
- type: 'string',
82
- describe: 'If using "openapi" as the target generator, this allows you to specify the name of the output file.',
83
- default: 'openapi',
84
- },
85
- includeMetadata: {
86
- type: 'boolean',
87
- describe: "Whether to include the file's meta.xml information: Whether it is active and and the API version",
88
- default: false,
89
- },
90
- documentationRootDir: {
91
- type: 'string',
92
- describe:
93
- 'Allows you to specify the root documentation directory where the files are being generated. This can be helpful when embedding the generated docs into an existing site so that the links are generated correctly.',
94
- },
95
- }).argv;
9
+ const result = cosmiconfig('apexdocs').search();
10
+ result.then((config) => {
11
+ let argv = yargs.options({
12
+ sourceDir: {
13
+ type: 'string',
14
+ alias: 's',
15
+ demandOption: true,
16
+ describe: 'The directory location which contains your apex .cls classes.',
17
+ },
18
+ targetDir: {
19
+ type: 'string',
20
+ alias: 't',
21
+ default: './docs/',
22
+ describe: 'The directory location where documentation will be generated to.',
23
+ },
24
+ recursive: {
25
+ type: 'boolean',
26
+ alias: 'r',
27
+ default: true,
28
+ describe: 'Whether .cls classes will be searched for recursively in the directory provided.',
29
+ },
30
+ scope: {
31
+ type: 'array',
32
+ alias: 'p',
33
+ default: ['global'],
34
+ describe:
35
+ 'A list of scopes to document. Values should be separated by a space, e.g --scope global public namespaceaccessible. ' +
36
+ 'Annotations are supported and should be passed lowercased and without the @ symbol, e.g. namespaceaccessible auraenabled. ' +
37
+ 'Note that this setting is ignored if generating an OpenApi REST specification since that looks for classes annotated with @RestResource.',
38
+ },
39
+ targetGenerator: {
40
+ type: 'string',
41
+ alias: 'g',
42
+ default: 'jekyll',
43
+ choices: ['jekyll', 'docsify', 'plain-markdown', 'openapi'],
44
+ describe:
45
+ 'Define the static file generator for which the documents will be created. ' +
46
+ 'Currently supports jekyll, docsify, plain markdown, and OpenAPI v3.1.0.',
47
+ },
48
+ indexOnly: {
49
+ type: 'boolean',
50
+ default: false,
51
+ describe: 'Defines whether only the index file should be generated.',
52
+ },
53
+ defaultGroupName: {
54
+ type: 'string',
55
+ default: 'Miscellaneous',
56
+ describe: 'Defines the @group name to be used when a file does not specify it.',
57
+ },
58
+ sanitizeHtml: {
59
+ type: 'boolean',
60
+ default: true,
61
+ describe:
62
+ 'When on, any special character within your ApexDocs is converted into its HTML code representation. ' +
63
+ 'This is specially useful when generic objects are described within the docs, e.g. "List< Foo>", "Map<Foo, Bar>" ' +
64
+ 'because otherwise the content within < and > would be treated as HTML tags and not shown in the output. ' +
65
+ 'Content in @example blocks are never sanitized.',
66
+ },
67
+ openApiTitle: {
68
+ type: 'string',
69
+ default: 'Apex REST Api',
70
+ describe: 'If using "openapi" as the target generator, this allows you to specify the OpenApi title value.',
71
+ },
72
+ title: {
73
+ type: 'string',
74
+ describe: "If this allows you to specify the title of the generated documentation's home file.",
75
+ default: 'Classes',
76
+ },
77
+ namespace: {
78
+ type: 'string',
79
+ describe:
80
+ 'The package namespace, if any. If this value is provided the namespace will be added as a prefix to all of the parsed files. ' +
81
+ "If generating an OpenApi definition, it will be added to the file's Server Url.",
82
+ },
83
+ openApiFileName: {
84
+ type: 'string',
85
+ describe: 'If using "openapi" as the target generator, this allows you to specify the name of the output file.',
86
+ default: 'openapi',
87
+ },
88
+ includeMetadata: {
89
+ type: 'boolean',
90
+ describe: "Whether to include the file's meta.xml information: Whether it is active and and the API version",
91
+ default: false,
92
+ },
93
+ documentationRootDir: {
94
+ type: 'string',
95
+ describe:
96
+ 'Allows you to specify the root documentation directory where the files are being generated. This can be helpful when embedding the generated docs into an existing site so that the links are generated correctly.',
97
+ },
98
+ }).argv;
96
99
 
97
- Settings.build({
98
- sourceDirectory: argv.sourceDir,
99
- recursive: argv.recursive,
100
- scope: argv.scope,
101
- outputDir: argv.targetDir,
102
- targetGenerator: argv.targetGenerator as GeneratorChoices,
103
- indexOnly: argv.indexOnly,
104
- defaultGroupName: argv.defaultGroupName,
105
- sanitizeHtml: argv.sanitizeHtml,
106
- openApiTitle: argv.openApiTitle,
107
- title: argv.title,
108
- namespace: argv.namespace,
109
- openApiFileName: argv.openApiFileName,
110
- includeMetadata: argv.includeMetadata,
111
- rootDir: argv.documentationRootDir,
112
- });
100
+ if (config) {
101
+ argv = { ...config.config, ...argv };
102
+ }
103
+
104
+ Settings.build({
105
+ sourceDirectory: argv.sourceDir,
106
+ recursive: argv.recursive,
107
+ scope: argv.scope,
108
+ outputDir: argv.targetDir,
109
+ targetGenerator: argv.targetGenerator as GeneratorChoices,
110
+ indexOnly: argv.indexOnly,
111
+ defaultGroupName: argv.defaultGroupName,
112
+ sanitizeHtml: argv.sanitizeHtml,
113
+ openApiTitle: argv.openApiTitle,
114
+ title: argv.title,
115
+ namespace: argv.namespace,
116
+ openApiFileName: argv.openApiFileName,
117
+ includeMetadata: argv.includeMetadata,
118
+ rootDir: argv.documentationRootDir,
119
+ onAfterProcess: config?.config?.onAfterProcess,
120
+ onBeforeFileWrite: config?.config?.onBeforeFileWrite,
121
+ });
113
122
 
114
- try {
115
- Apexdocs.generate();
116
- } catch (error) {
117
- console.error(error);
118
- process.exit(1);
119
- }
123
+ try {
124
+ Apexdocs.generate();
125
+ } catch (error) {
126
+ console.error(error);
127
+ process.exit(1);
128
+ }
129
+ });
@@ -4,22 +4,31 @@ import { OutputFile } from '../model/outputFile';
4
4
  import { Settings } from '../settings';
5
5
 
6
6
  export class FileWriter {
7
- static write(files: OutputFile[], onWriteCallback: (fileName: string) => void) {
8
- const outputDir = Settings.getInstance().outputDir;
9
- if (!fs.existsSync(outputDir)) {
10
- fs.mkdirSync(outputDir);
11
- }
12
-
7
+ static write(files: OutputFile[], onWriteCallback: (file: TargetLocation) => void) {
8
+ const onBeforeFileWrite = (outputDir: string, fileName: string) =>
9
+ Settings.getInstance().onBeforeFileWrite(outputDir, fileName);
13
10
  files.forEach((file) => {
14
- const dirPath = path.join(outputDir, file.dir);
11
+ const { dir: dirPath, fileName } = this.getTargetLocation(file, onBeforeFileWrite);
15
12
  if (!fs.existsSync(dirPath)) {
16
- fs.mkdirSync(dirPath);
13
+ fs.mkdirSync(dirPath, { recursive: true });
17
14
  }
18
15
 
19
- const filePath = path.join(dirPath, `${file.fileName}${file.fileExtension()}`);
20
- fs.writeFile(filePath, file.body, 'utf8', () => {
21
- onWriteCallback(file.fileName);
22
- });
16
+ const filePath = path.join(dirPath, fileName);
17
+ fs.writeFileSync(filePath, file.body, 'utf8');
18
+ onWriteCallback({ dir: dirPath, fileName });
23
19
  });
24
20
  }
21
+
22
+ private static getTargetLocation(file: OutputFile, onBeforeFileWrite: OnBeforeFileWrite): TargetLocation {
23
+ const outputDir = path.join(Settings.getInstance().outputDir, file.dir);
24
+ const fileName = `${file.fileName}${file.fileExtension()}`;
25
+ return onBeforeFileWrite(outputDir, fileName);
26
+ }
25
27
  }
28
+
29
+ type OnBeforeFileWrite = (outputDir: string, fileName: string) => TargetLocation;
30
+
31
+ type TargetLocation = {
32
+ dir: string;
33
+ fileName: string;
34
+ };
package/src/settings.ts CHANGED
@@ -15,6 +15,8 @@ export interface SettingsConfig {
15
15
  openApiFileName: string;
16
16
  includeMetadata: boolean;
17
17
  rootDir?: string;
18
+ onAfterProcess?: (files: { dir: string; fileName: string }[]) => void;
19
+ onBeforeFileWrite?: (outputDir: string, fileName: string) => { dir: string; fileName: string };
18
20
  }
19
21
 
20
22
  export class Settings {
@@ -95,4 +97,17 @@ export class Settings {
95
97
  public getRootDir(): string | undefined {
96
98
  return this.config.rootDir;
97
99
  }
100
+
101
+ public onAfterProcess(files: { dir: string; fileName: string }[]) {
102
+ if (this.config.onAfterProcess) {
103
+ this.config.onAfterProcess(files);
104
+ }
105
+ }
106
+
107
+ public onBeforeFileWrite(outputDir: string, fileName: string): { dir: string; fileName: string } {
108
+ if (this.config.onBeforeFileWrite) {
109
+ return this.config.onBeforeFileWrite(outputDir, fileName);
110
+ }
111
+ return { dir: outputDir, fileName };
112
+ }
98
113
  }