@appium/docutils 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (201) hide show
  1. package/LICENSE +1 -1
  2. package/build/lib/builder/deploy.d.ts.map +1 -1
  3. package/build/lib/builder/deploy.js +6 -2
  4. package/build/lib/builder/deploy.js.map +1 -1
  5. package/build/lib/builder/index.d.ts +4 -0
  6. package/build/lib/builder/index.d.ts.map +1 -1
  7. package/build/lib/builder/index.js +4 -0
  8. package/build/lib/builder/index.js.map +1 -1
  9. package/build/lib/builder/nav.d.ts +1 -1
  10. package/build/lib/builder/nav.d.ts.map +1 -1
  11. package/build/lib/builder/nav.js +3 -3
  12. package/build/lib/builder/nav.js.map +1 -1
  13. package/build/lib/builder/reference.d.ts +1 -1
  14. package/build/lib/builder/reference.d.ts.map +1 -1
  15. package/build/lib/builder/reference.js +1 -19
  16. package/build/lib/builder/reference.js.map +1 -1
  17. package/build/lib/builder/site.d.ts.map +1 -1
  18. package/build/lib/builder/site.js +4 -3
  19. package/build/lib/builder/site.js.map +1 -1
  20. package/build/lib/cli/check.d.ts +19 -0
  21. package/build/lib/cli/check.d.ts.map +1 -0
  22. package/build/lib/cli/check.js +58 -0
  23. package/build/lib/cli/check.js.map +1 -0
  24. package/build/lib/cli/command/build.d.ts +42 -29
  25. package/build/lib/cli/command/build.d.ts.map +1 -1
  26. package/build/lib/cli/command/build.js +55 -39
  27. package/build/lib/cli/command/build.js.map +1 -1
  28. package/build/lib/cli/command/index.d.ts +4 -0
  29. package/build/lib/cli/command/index.d.ts.map +1 -1
  30. package/build/lib/cli/command/index.js +4 -0
  31. package/build/lib/cli/command/index.js.map +1 -1
  32. package/build/lib/cli/command/init.d.ts +42 -27
  33. package/build/lib/cli/command/init.d.ts.map +1 -1
  34. package/build/lib/cli/command/init.js +51 -28
  35. package/build/lib/cli/command/init.js.map +1 -1
  36. package/build/lib/cli/command/validate.d.ts +21 -15
  37. package/build/lib/cli/command/validate.d.ts.map +1 -1
  38. package/build/lib/cli/command/validate.js +30 -21
  39. package/build/lib/cli/command/validate.js.map +1 -1
  40. package/build/lib/cli/config.js +1 -1
  41. package/build/lib/cli/config.js.map +1 -1
  42. package/build/lib/cli/index.d.ts.map +1 -1
  43. package/build/lib/cli/index.js +29 -12
  44. package/build/lib/cli/index.js.map +1 -1
  45. package/build/lib/constants.d.ts +4 -0
  46. package/build/lib/constants.d.ts.map +1 -1
  47. package/build/lib/constants.js +5 -1
  48. package/build/lib/constants.js.map +1 -1
  49. package/build/lib/error.d.ts +5 -0
  50. package/build/lib/error.d.ts.map +1 -1
  51. package/build/lib/error.js +5 -0
  52. package/build/lib/error.js.map +1 -1
  53. package/build/lib/fs.d.ts +1 -1
  54. package/build/lib/fs.d.ts.map +1 -1
  55. package/build/lib/fs.js +2 -2
  56. package/build/lib/fs.js.map +1 -1
  57. package/build/lib/index.d.ts +4 -0
  58. package/build/lib/index.d.ts.map +1 -1
  59. package/build/lib/index.js +4 -0
  60. package/build/lib/index.js.map +1 -1
  61. package/build/lib/init.d.ts +24 -26
  62. package/build/lib/init.d.ts.map +1 -1
  63. package/build/lib/init.js +12 -7
  64. package/build/lib/init.js.map +1 -1
  65. package/build/lib/logger.js +0 -4
  66. package/build/lib/logger.js.map +1 -1
  67. package/build/lib/mike.d.ts.map +1 -1
  68. package/build/lib/mike.js +4 -0
  69. package/build/lib/mike.js.map +1 -1
  70. package/build/lib/model.d.ts +6 -10
  71. package/build/lib/model.d.ts.map +1 -1
  72. package/build/lib/scaffold.d.ts +5 -5
  73. package/build/lib/scaffold.d.ts.map +1 -1
  74. package/build/lib/util.d.ts +6 -3
  75. package/build/lib/util.d.ts.map +1 -1
  76. package/build/lib/util.js.map +1 -1
  77. package/build/lib/validate.d.ts +5 -2
  78. package/build/lib/validate.d.ts.map +1 -1
  79. package/build/lib/validate.js +9 -7
  80. package/build/lib/validate.js.map +1 -1
  81. package/lib/builder/deploy.ts +9 -3
  82. package/lib/builder/index.ts +5 -0
  83. package/lib/builder/nav.ts +2 -3
  84. package/lib/builder/reference.ts +2 -22
  85. package/lib/builder/site.ts +6 -5
  86. package/lib/cli/check.ts +87 -0
  87. package/lib/cli/command/build.ts +61 -46
  88. package/lib/cli/command/index.ts +5 -0
  89. package/lib/cli/command/init.ts +54 -32
  90. package/lib/cli/command/validate.ts +35 -28
  91. package/lib/cli/index.ts +23 -4
  92. package/lib/constants.ts +5 -0
  93. package/lib/error.ts +6 -0
  94. package/lib/fs.ts +6 -3
  95. package/lib/index.ts +5 -0
  96. package/lib/init.ts +23 -6
  97. package/lib/logger.ts +6 -11
  98. package/lib/mike.js +5 -0
  99. package/lib/model.ts +3 -9
  100. package/lib/util.ts +4 -1
  101. package/lib/validate.ts +10 -9
  102. package/package.json +10 -12
  103. package/requirements.txt +1 -1
  104. package/build/lib/build/mkdocs.d.ts +0 -58
  105. package/build/lib/build/mkdocs.d.ts.map +0 -1
  106. package/build/lib/build/mkdocs.js +0 -80
  107. package/build/lib/build/mkdocs.js.map +0 -1
  108. package/build/lib/build/typedoc.d.ts +0 -55
  109. package/build/lib/build/typedoc.d.ts.map +0 -1
  110. package/build/lib/build/typedoc.js +0 -120
  111. package/build/lib/build/typedoc.js.map +0 -1
  112. package/build/lib/build-api.d.ts +0 -18
  113. package/build/lib/build-api.d.ts.map +0 -1
  114. package/build/lib/build-api.js +0 -75
  115. package/build/lib/build-api.js.map +0 -1
  116. package/build/lib/build.d.ts +0 -21
  117. package/build/lib/build.d.ts.map +0 -1
  118. package/build/lib/build.js +0 -71
  119. package/build/lib/build.js.map +0 -1
  120. package/build/lib/cli/command/deploy.d.ts +0 -1
  121. package/build/lib/cli/command/deploy.d.ts.map +0 -1
  122. package/build/lib/cli/command/deploy.js +0 -2
  123. package/build/lib/cli/command/deploy.js.map +0 -1
  124. package/build/lib/cli/command-init.d.ts +0 -143
  125. package/build/lib/cli/command-init.d.ts.map +0 -1
  126. package/build/lib/cli/command-init.js +0 -164
  127. package/build/lib/cli/command-init.js.map +0 -1
  128. package/build/lib/cli/command-validate.d.ts +0 -52
  129. package/build/lib/cli/command-validate.d.ts.map +0 -1
  130. package/build/lib/cli/command-validate.js +0 -66
  131. package/build/lib/cli/command-validate.js.map +0 -1
  132. package/build/lib/cli/init.d.ts +0 -143
  133. package/build/lib/cli/init.d.ts.map +0 -1
  134. package/build/lib/cli/init.js +0 -164
  135. package/build/lib/cli/init.js.map +0 -1
  136. package/build/lib/cli/options.d.ts +0 -1
  137. package/build/lib/cli/options.d.ts.map +0 -1
  138. package/build/lib/cli/options.js +0 -2
  139. package/build/lib/cli/options.js.map +0 -1
  140. package/build/lib/cli/validate.d.ts +0 -1
  141. package/build/lib/cli/validate.d.ts.map +0 -1
  142. package/build/lib/cli/validate.js +0 -2
  143. package/build/lib/cli/validate.js.map +0 -1
  144. package/build/lib/cli.d.ts +0 -10
  145. package/build/lib/cli.d.ts.map +0 -1
  146. package/build/lib/cli.js +0 -328
  147. package/build/lib/cli.js.map +0 -1
  148. package/build/lib/init-task.d.ts +0 -49
  149. package/build/lib/init-task.d.ts.map +0 -1
  150. package/build/lib/init-task.js +0 -95
  151. package/build/lib/init-task.js.map +0 -1
  152. package/build/lib/io.d.ts +0 -1
  153. package/build/lib/io.d.ts.map +0 -1
  154. package/build/lib/io.js +0 -2
  155. package/build/lib/io.js.map +0 -1
  156. package/build/lib/mkdocs.d.ts +0 -58
  157. package/build/lib/mkdocs.d.ts.map +0 -1
  158. package/build/lib/mkdocs.js +0 -77
  159. package/build/lib/mkdocs.js.map +0 -1
  160. package/build/lib/nav.d.ts +0 -47
  161. package/build/lib/nav.d.ts.map +0 -1
  162. package/build/lib/nav.js +0 -132
  163. package/build/lib/nav.js.map +0 -1
  164. package/build/lib/test.d.ts +0 -9
  165. package/build/lib/test.d.ts.map +0 -1
  166. package/build/lib/test.js +0 -2
  167. package/build/lib/test.js.map +0 -1
  168. package/build/lib/typedoc.d.ts +0 -55
  169. package/build/lib/typedoc.d.ts.map +0 -1
  170. package/build/lib/typedoc.js +0 -122
  171. package/build/lib/typedoc.js.map +0 -1
  172. package/build/lib/types.d.ts +0 -52
  173. package/build/lib/types.d.ts.map +0 -1
  174. package/build/lib/types.js +0 -7
  175. package/build/lib/types.js.map +0 -1
  176. package/build/lib/validation/base-validator.d.ts +0 -218
  177. package/build/lib/validation/base-validator.d.ts.map +0 -1
  178. package/build/lib/validation/base-validator.js +0 -453
  179. package/build/lib/validation/base-validator.js.map +0 -1
  180. package/build/lib/validation/mkdocs-validator.d.ts +0 -5
  181. package/build/lib/validation/mkdocs-validator.d.ts.map +0 -1
  182. package/build/lib/validation/mkdocs-validator.js +0 -54
  183. package/build/lib/validation/mkdocs-validator.js.map +0 -1
  184. package/build/lib/validation/python-validator.d.ts +0 -1
  185. package/build/lib/validation/python-validator.d.ts.map +0 -1
  186. package/build/lib/validation/python-validator.js +0 -2
  187. package/build/lib/validation/python-validator.js.map +0 -1
  188. package/build/lib/validation/python.d.ts +0 -1
  189. package/build/lib/validation/python.d.ts.map +0 -1
  190. package/build/lib/validation/python.js +0 -2
  191. package/build/lib/validation/python.js.map +0 -1
  192. package/build/lib/validation/validate.d.ts +0 -221
  193. package/build/lib/validation/validate.d.ts.map +0 -1
  194. package/build/lib/validation/validate.js +0 -508
  195. package/build/lib/validation/validate.js.map +0 -1
  196. package/build/lib/validation/validator.d.ts +0 -220
  197. package/build/lib/validation/validator.d.ts.map +0 -1
  198. package/build/lib/validation/validator.js +0 -470
  199. package/build/lib/validation/validator.js.map +0 -1
  200. package/build/test/unit/mike.spec.js +0 -17
  201. package/build/test/unit/mike.spec.js.map +0 -1
@@ -1,218 +0,0 @@
1
- /// <reference types="node" />
2
- import 'type-fest';
3
- import { EventEmitter } from 'node:events';
4
- import { NAME_MKDOCS, NAME_NPM, NAME_PYTHON, NAME_TYPEDOC, NAME_TYPESCRIPT } from '../constants';
5
- import { DocutilsError } from '../error';
6
- import { PipPackage } from '../model';
7
- /**
8
- * The "kinds" of validation which were requested to be performed
9
- */
10
- export declare type ValidationKind = typeof NAME_PYTHON | typeof NAME_TYPESCRIPT | typeof NAME_TYPEDOC | typeof NAME_NPM | typeof NAME_MKDOCS;
11
- /**
12
- * This class is designed to run _all_ validation checks (as requested by the user), and emit events for
13
- * each failure encountered.
14
- *
15
- * Whenever a method _rejects or throws_, this is considered an "unexpected" error, and the validation
16
- * will abort.
17
- *
18
- * @todo Use [`strict-event-emitter-types`](https://npm.im/strict-event-emitter-types)
19
- */
20
- export declare abstract class BaseValidator extends EventEmitter {
21
- protected requirementsTxt: PipPackage[] | undefined;
22
- /**
23
- * Current working directory. Defaults to `process.cwd()`
24
- * @todo This cannot yet be overriden by user
25
- */
26
- protected readonly cwd: string;
27
- /**
28
- * Path to `npm` executable.
29
- */
30
- protected readonly npmPath: string | undefined;
31
- /**
32
- * Path to `python` executable.
33
- */
34
- protected readonly pythonPath: string | undefined;
35
- /**
36
- * List of validations to perform
37
- */
38
- protected readonly _validations: Set<ValidationKind>;
39
- /**
40
- * Mapping of error messages to errors.
41
- *
42
- * Used to prevent duplicate emission of errors and track error count; if non-empty, the validation
43
- * process should be considered to have failed.
44
- *
45
- * Reset after {@linkcode BaseValidator.validate validate} completes.
46
- */
47
- protected emittedErrors: Map<string, DocutilsError>;
48
- /**
49
- * Path to `mkdocs.yml`. If not provided, will be lazily resolved.
50
- */
51
- protected mkDocsYmlPath: string | undefined;
52
- /**
53
- * Path to `package.json`. If not provided, will be lazily resolved.
54
- */
55
- protected packageJsonPath: string | undefined;
56
- /**
57
- * Path to the package directory. If not provided, will be lazily resolved.
58
- */
59
- protected pkgDir: string | undefined;
60
- /**
61
- * Path to `tsconfig.json`. If not provided, will be lazily resolved.
62
- */
63
- protected tsconfigJsonPath: string | undefined;
64
- /**
65
- * Path to `typedoc.json`. If not provided, will be lazily resolved.
66
- */
67
- protected typeDocJsonPath: string | undefined;
68
- /**
69
- * Emitted when validation begins with a list of validation kinds to be performed
70
- * @event
71
- */
72
- static readonly BEGIN = "begin";
73
- /**
74
- * Emitted when validation ends with an error count
75
- * @event
76
- */
77
- static readonly END = "end";
78
- /**
79
- * Emitted when a validation fails, with the associated {@linkcode DocutilsError}
80
- * @event
81
- */
82
- static readonly FAILURE = "fail";
83
- /**
84
- * Emitted when a validation succeeds
85
- * @event
86
- */
87
- static readonly SUCCESS = "ok";
88
- readonly opts: DocutilsValidatorOpts;
89
- /**
90
- * Creates a listener to track errors emitted
91
- */
92
- constructor(opts?: Partial<DocutilsValidatorOpts>);
93
- get errorCount(): number;
94
- /**
95
- * Runs the configured validations, then resets internal state upon completion or rejection.
96
- */
97
- validate(): Promise<void>;
98
- /**
99
- * If a thing like `err` has not already been emitted, emit
100
- * {@linkcode BaseValidator.FAILURE}.
101
- * @param err A validation error
102
- * @returns
103
- */
104
- protected fail(err: DocutilsError | string): void;
105
- /**
106
- * Resolves with a the parent directory of `package.json`, if we can find it.
107
- */
108
- protected findPkgDir(): Promise<string | undefined>;
109
- /**
110
- * Emits a {@linkcode BaseValidator.SUCCESS} event
111
- * @param message Success message
112
- */
113
- protected ok(message: string): void;
114
- /**
115
- * Parses a `requirements.txt` file and returns an array of packages
116
- *
117
- * Caches the result.
118
- * @returns List of package data w/ name and version
119
- */
120
- protected parseRequirementsTxt(): Promise<PipPackage[]>;
121
- /**
122
- * Resets the cache of emitted errors
123
- */
124
- protected reset(): void;
125
- /**
126
- * Validates (sort of) an `mkdocs.yml` config file.
127
- *
128
- * It checks if the file exists, if it can be parsed as YAML, and if it has a `site_name` property.
129
- */
130
- protected validateMkDocsConfig(mkDocsYmlPath?: string): Promise<void>;
131
- /**
132
- * Validates that the version of `npm` matches what's described in this package's `engines` field.
133
- *
134
- * This is required because other validators need `npm exec` to work, which is only available in npm 7+.
135
- */
136
- protected validateNpmVersion(): Promise<void>;
137
- /**
138
- * Asserts that the dependencies as listed in `requirements.txt` are installed.
139
- *
140
- * @privateRemarks This lists all installed packages with `pip` and then compares them to the
141
- * contents of our `requirements.txt`. Versions _must_ match exactly.
142
- */
143
- protected validatePythonDeps(): Promise<void>;
144
- /**
145
- * Asserts that the Python version is 3.x
146
- */
147
- protected validatePythonVersion(): Promise<void>;
148
- /**
149
- * Asserts TypeDoc is installed, runnable, the correct version, and that the config file is readable
150
- * and constaints required options
151
- */
152
- protected validateTypeDoc(): Promise<void>;
153
- /**
154
- * Validates the `typedoc.json` file
155
- */
156
- protected validateTypeDocConfig(): Promise<void>;
157
- /**
158
- * Asserts that TypeScript is installed, runnable, the correct version, and a parseable `tsconfig.json` exists.
159
- */
160
- protected validateTypeScript(): Promise<void>;
161
- /**
162
- * Validates a `tsconfig.json` file
163
- */
164
- protected validateTypeScriptConfig(): Promise<void>;
165
- }
166
- /**
167
- * Options for {@linkcode BaseValidator} constructor
168
- */
169
- export interface DocutilsValidatorOpts {
170
- /**
171
- * Current working directory
172
- */
173
- cwd: string;
174
- /**
175
- * If `true`, run MkDocs validation
176
- */
177
- mkdocs?: boolean;
178
- /**
179
- * Path to `mkdocs.yml`
180
- */
181
- mkdocsYml?: string;
182
- /**
183
- * Path to `npm` executable
184
- */
185
- npm?: string;
186
- /**
187
- * Path to `package.json`
188
- */
189
- packageJson?: string;
190
- /**
191
- * If `true`, run Python validation
192
- */
193
- python?: boolean;
194
- /**
195
- * Path to `python` executable
196
- */
197
- pythonPath?: string;
198
- /**
199
- * Path to `tsconfig.json`
200
- */
201
- tsconfigJson?: string;
202
- /**
203
- * If `true`, run TypeDoc validation
204
- */
205
- typedoc?: boolean;
206
- /**
207
- * Path to `typedoc.json`
208
- */
209
- typedocJson?: string;
210
- /**
211
- * If `true`, run TypeScript validation
212
- */
213
- typescript?: boolean;
214
- }
215
- export interface IDocutilsValidator {
216
- validate(): Promise<void>;
217
- }
218
- //# sourceMappingURL=base-validator.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"base-validator.d.ts","sourceRoot":"","sources":["../../../lib/validation/base-validator.ts"],"names":[],"mappings":";AAAA,OAAO,WAAW,CAAC;AAUnB,OAAO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AM,CAAC;IACtB;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3B"}
@@ -1,453 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.BaseValidator = void 0;
7
- require("type-fest");
8
- /**
9
- * Validates an environment for building documentation
10
- *
11
- * @module
12
- */
13
- const support_1 = require("@appium/support");
14
- const chalk_1 = __importDefault(require("chalk"));
15
- const lodash_1 = __importDefault(require("lodash"));
16
- const node_events_1 = require("node:events");
17
- const node_path_1 = __importDefault(require("node:path"));
18
- const pluralize_1 = __importDefault(require("pluralize"));
19
- const semver_1 = require("semver");
20
- const teen_process_1 = require("teen_process");
21
- const constants_1 = require("../constants");
22
- const error_1 = require("../error");
23
- const fs_1 = require("../fs");
24
- const logger_1 = __importDefault(require("../logger"));
25
- const util_1 = require("../util");
26
- /**
27
- * Matches the Python version string from `python --version`
28
- */
29
- const PYTHON_VER_STR = 'Python 3.';
30
- /**
31
- * Matches the TypeScript version string from `tsc --version`
32
- */
33
- const TYPESCRIPT_VERSION_REGEX = /Version\s(\d+\.\d+\..+)/;
34
- /**
35
- * Matches the TypeDoc version string from `typedoc --version`
36
- */
37
- const TYPEDOC_VERSION_REGEX = /TypeDoc\s(\d+\.\d+\..+)/;
38
- const log = logger_1.default.withTag('validate');
39
- /**
40
- * This class is designed to run _all_ validation checks (as requested by the user), and emit events for
41
- * each failure encountered.
42
- *
43
- * Whenever a method _rejects or throws_, this is considered an "unexpected" error, and the validation
44
- * will abort.
45
- *
46
- * @todo Use [`strict-event-emitter-types`](https://npm.im/strict-event-emitter-types)
47
- */
48
- class BaseValidator extends node_events_1.EventEmitter {
49
- /**
50
- * Creates a listener to track errors emitted
51
- */
52
- constructor(opts = {}) {
53
- super();
54
- /**
55
- * List of validations to perform
56
- */
57
- this._validations = new Set();
58
- /**
59
- * Mapping of error messages to errors.
60
- *
61
- * Used to prevent duplicate emission of errors and track error count; if non-empty, the validation
62
- * process should be considered to have failed.
63
- *
64
- * Reset after {@linkcode BaseValidator.validate validate} completes.
65
- */
66
- this.emittedErrors = new Map();
67
- this.opts = Object.freeze(lodash_1.default.defaultsDeep(opts, { cwd: process.cwd() }));
68
- this.packageJsonPath = this.opts.packageJson;
69
- this.pythonPath = this.opts.pythonPath;
70
- this.cwd = this.opts.cwd;
71
- this.tsconfigJsonPath = this.opts.tsconfigJson;
72
- this.typeDocJsonPath = this.opts.typedocJson;
73
- this.npmPath = this.opts.npm;
74
- this.mkDocsYmlPath = this.opts.mkdocsYml;
75
- // this just tracks the emitted errors
76
- this.on(BaseValidator.FAILURE, (err) => {
77
- this.emittedErrors.set(err.message, err);
78
- });
79
- }
80
- get errorCount() {
81
- return this.emittedErrors.size;
82
- }
83
- /**
84
- * Runs the configured validations, then resets internal state upon completion or rejection.
85
- */
86
- async validate() {
87
- try {
88
- this.emit(BaseValidator.BEGIN, [...this._validations]);
89
- if (this._validations.has(constants_1.NAME_PYTHON)) {
90
- await this.validatePythonVersion();
91
- await this.validatePythonDeps();
92
- }
93
- if (this._validations.has(constants_1.NAME_MKDOCS)) {
94
- // await this.validateMkDocs();
95
- await this.validateMkDocsConfig();
96
- }
97
- if (this._validations.has(constants_1.NAME_NPM)) {
98
- await this.validateNpmVersion();
99
- }
100
- if (this._validations.has(constants_1.NAME_TYPESCRIPT)) {
101
- await this.validateTypeScript();
102
- await this.validateTypeScriptConfig();
103
- }
104
- if (this._validations.has(constants_1.NAME_TYPEDOC)) {
105
- await this.validateTypeDoc();
106
- await this.validateTypeDocConfig();
107
- }
108
- this.emit(BaseValidator.END, this.emittedErrors.size);
109
- }
110
- finally {
111
- this.reset();
112
- }
113
- }
114
- /**
115
- * If a thing like `err` has not already been emitted, emit
116
- * {@linkcode BaseValidator.FAILURE}.
117
- * @param err A validation error
118
- * @returns
119
- */
120
- fail(err) {
121
- const dErr = lodash_1.default.isString(err) ? new error_1.DocutilsError(err) : err;
122
- if (!this.emittedErrors.has(dErr.message)) {
123
- this.emit(BaseValidator.FAILURE, dErr);
124
- }
125
- }
126
- /**
127
- * Resolves with a the parent directory of `package.json`, if we can find it.
128
- */
129
- async findPkgDir() {
130
- return (this.pkgDir ??
131
- (this.pkgDir = this.packageJsonPath
132
- ? node_path_1.default.dirname(this.packageJsonPath)
133
- : await (0, fs_1.findPkgDir)(this.cwd)));
134
- }
135
- /**
136
- * Emits a {@linkcode BaseValidator.SUCCESS} event
137
- * @param message Success message
138
- */
139
- ok(message) {
140
- this.emit(BaseValidator.SUCCESS, message);
141
- }
142
- /**
143
- * Parses a `requirements.txt` file and returns an array of packages
144
- *
145
- * Caches the result.
146
- * @returns List of package data w/ name and version
147
- */
148
- async parseRequirementsTxt() {
149
- if (this.requirementsTxt) {
150
- return this.requirementsTxt;
151
- }
152
- let requiredPackages = [];
153
- try {
154
- let requirementsTxt = await support_1.fs.readFile(constants_1.REQUIREMENTS_TXT_PATH, 'utf8');
155
- requirementsTxt = requirementsTxt.trim();
156
- log.debug('Raw %s: %s', constants_1.NAME_REQUIREMENTS_TXT, requirementsTxt);
157
- for (const line of requirementsTxt.split(/\r?\n/)) {
158
- const [name, version] = line.trim().split('==');
159
- requiredPackages.push({ name, version });
160
- }
161
- log.debug('Parsed %s: %O', constants_1.NAME_REQUIREMENTS_TXT, requiredPackages);
162
- }
163
- catch {
164
- throw new error_1.DocutilsError(`Could not find ${constants_1.REQUIREMENTS_TXT_PATH}. This is a bug`);
165
- }
166
- return (this.requirementsTxt = requiredPackages);
167
- }
168
- /**
169
- * Resets the cache of emitted errors
170
- */
171
- reset() {
172
- this.emittedErrors.clear();
173
- }
174
- /**
175
- * Validates (sort of) an `mkdocs.yml` config file.
176
- *
177
- * It checks if the file exists, if it can be parsed as YAML, and if it has a `site_name` property.
178
- */
179
- async validateMkDocsConfig(mkDocsYmlPath) {
180
- mkDocsYmlPath = mkDocsYmlPath ?? this.mkDocsYmlPath ?? (await (0, fs_1.findMkDocsYml)(this.cwd));
181
- if (!mkDocsYmlPath) {
182
- return this.fail(`Could not find ${constants_1.NAME_MKDOCS_YML} from ${this.cwd}. Run "${constants_1.NAME_BIN} init" to create it`);
183
- }
184
- let mkDocsYml;
185
- try {
186
- mkDocsYml = await (0, fs_1.readMkDocsYml)(mkDocsYmlPath);
187
- }
188
- catch (e) {
189
- const err = e;
190
- if (err.code === constants_1.NAME_ERR_ENOENT) {
191
- return this.fail(`Could not find ${constants_1.NAME_MKDOCS_YML} at ${mkDocsYmlPath}. Use --mkdocs-yml to specify a different path.`);
192
- }
193
- return this.fail(`Could not parse ${mkDocsYmlPath}: ${err}`);
194
- }
195
- if (!mkDocsYml.site_name) {
196
- return this.fail(`Could not find required property "site_name" in ${mkDocsYmlPath}`);
197
- }
198
- this.ok(`MkDocs config at ${mkDocsYmlPath} OK`);
199
- }
200
- /**
201
- * Validates that the version of `npm` matches what's described in this package's `engines` field.
202
- *
203
- * This is required because other validators need `npm exec` to work, which is only available in npm 7+.
204
- */
205
- async validateNpmVersion() {
206
- const npmEngineRange = constants_1.DOCUTILS_PKG.engines?.npm;
207
- if (!npmEngineRange) {
208
- throw new error_1.DocutilsError('Could not find property engines.npm in package.json. This is a bug');
209
- }
210
- try {
211
- const npmPath = this.npmPath ?? (await (0, fs_1.whichNpm)());
212
- if (!npmPath) {
213
- throw new error_1.DocutilsError(`Could not find ${constants_1.NAME_NPM} in PATH. That seems weird, doesn't it?`);
214
- }
215
- const { stdout: npmVersion } = await (0, teen_process_1.exec)(npmPath, ['-v']);
216
- if (!(0, semver_1.satisfies)(npmVersion.trim(), npmEngineRange)) {
217
- this.fail(`${constants_1.NAME_NPM} is version ${npmVersion}, but ${npmEngineRange} is required`);
218
- return;
219
- }
220
- }
221
- catch {
222
- return this.fail(`Could not find ${this.npmPath} in PATH. Is it installed?`);
223
- }
224
- this.ok(`${constants_1.NAME_NPM} version OK`);
225
- }
226
- /**
227
- * Asserts that the dependencies as listed in `requirements.txt` are installed.
228
- *
229
- * @privateRemarks This lists all installed packages with `pip` and then compares them to the
230
- * contents of our `requirements.txt`. Versions _must_ match exactly.
231
- */
232
- async validatePythonDeps() {
233
- let pipListOutput;
234
- const pythonPath = this.pythonPath ?? (await (0, fs_1.whichPython)());
235
- if (!pythonPath) {
236
- return this.fail(`Could not find ${constants_1.NAME_PYTHON} in PATH. Is it installed?`);
237
- }
238
- try {
239
- ({ stdout: pipListOutput } = await (0, teen_process_1.exec)(pythonPath, [
240
- '-m',
241
- constants_1.NAME_PIP,
242
- 'list',
243
- '--format',
244
- 'json',
245
- ]));
246
- }
247
- catch {
248
- return this.fail(`Could not find ${constants_1.NAME_PIP} in PATH. Is it installed?`);
249
- }
250
- let installedPkgs;
251
- try {
252
- installedPkgs = JSON.parse(pipListOutput);
253
- }
254
- catch {
255
- throw new error_1.DocutilsError(`Could not parse output of "${constants_1.NAME_PIP} list" as JSON: ${pipListOutput}`);
256
- }
257
- const pkgsByName = lodash_1.default.mapValues(lodash_1.default.keyBy(installedPkgs, 'name'), 'version');
258
- log.debug('Installed Python packages: %O', pkgsByName);
259
- const requiredPackages = await this.parseRequirementsTxt();
260
- const missingPackages = [];
261
- const invalidVersionPackages = [];
262
- for (const reqdPkg of requiredPackages) {
263
- const version = pkgsByName[reqdPkg.name];
264
- if (!version) {
265
- missingPackages.push(reqdPkg);
266
- }
267
- if (version !== reqdPkg.version) {
268
- invalidVersionPackages.push([reqdPkg, { name: reqdPkg.name, version }]);
269
- }
270
- }
271
- const msgParts = [];
272
- if (missingPackages.length) {
273
- msgParts.push(`The following required ${(0, pluralize_1.default)('package', missingPackages.length)} could not be found:\n${missingPackages
274
- .map((p) => (0, chalk_1.default) `- {yellow ${p.name}} @ {yellow ${p.version}}`)
275
- .join('\n')}`);
276
- }
277
- if (invalidVersionPackages.length) {
278
- msgParts.push(`The following required ${(0, pluralize_1.default)('package', invalidVersionPackages.length)} are installed, but at the wrong version:\n${invalidVersionPackages
279
- .map(([expected, actual]) => (0, chalk_1.default) `- {yellow ${expected.name}} @ {yellow ${expected.version}} (found {red ${actual.version}})`)
280
- .join('\n')}`);
281
- }
282
- if (msgParts.length) {
283
- return this.fail(`Required Python dependency validation failed:\n\n${msgParts.join('\n\n')}`);
284
- }
285
- this.ok('Python dependencies OK');
286
- }
287
- /**
288
- * Asserts that the Python version is 3.x
289
- */
290
- async validatePythonVersion() {
291
- const pythonPath = this.pythonPath ?? (await (0, fs_1.whichPython)());
292
- if (!pythonPath) {
293
- return this.fail(`Could not find ${constants_1.NAME_PYTHON} in PATH. Is it installed?`);
294
- }
295
- try {
296
- const { stdout } = await (0, teen_process_1.exec)(pythonPath, ['--version']);
297
- if (!stdout.includes(PYTHON_VER_STR)) {
298
- return this.fail(`Could not find Python 3.x in PATH; found ${stdout}. Please use --python-path`);
299
- }
300
- }
301
- catch {
302
- return this.fail(`Could not find Python 3.x in PATH.`);
303
- }
304
- this.ok('Python version OK');
305
- }
306
- /**
307
- * Asserts TypeDoc is installed, runnable, the correct version, and that the config file is readable
308
- * and constaints required options
309
- */
310
- async validateTypeDoc() {
311
- const pkgDir = await this.findPkgDir();
312
- let rawTypeDocVersion;
313
- let typeDocVersion;
314
- try {
315
- ({ stdout: rawTypeDocVersion } = await (0, teen_process_1.exec)('npm', ['exec', constants_1.NAME_TYPEDOC, '--', '--version'], {
316
- cwd: pkgDir,
317
- }));
318
- }
319
- catch {
320
- return this.fail(`Could not find ${constants_1.NAME_TYPEDOC} executable from ${pkgDir}`);
321
- }
322
- if (rawTypeDocVersion) {
323
- let match = rawTypeDocVersion.match(TYPEDOC_VERSION_REGEX);
324
- if (match) {
325
- typeDocVersion = match[1];
326
- }
327
- else {
328
- throw new error_1.DocutilsError(`Could not parse TypeDoc version from "typedoc --version"; output was:\n ${rawTypeDocVersion}`);
329
- }
330
- const reqdTypeDocVersion = constants_1.DOCUTILS_PKG.dependencies.typedoc;
331
- if (!(0, semver_1.satisfies)(typeDocVersion, reqdTypeDocVersion)) {
332
- return this.fail(`Found TypeDoc version ${typeDocVersion}, but ${reqdTypeDocVersion} is required`);
333
- }
334
- this.ok('TypeDoc install OK');
335
- }
336
- }
337
- /**
338
- * Validates the `typedoc.json` file
339
- */
340
- async validateTypeDocConfig() {
341
- const pkgDir = await this.findPkgDir();
342
- if (!pkgDir) {
343
- return this.fail(new error_1.DocutilsError(`Could not find package.json in ${this.cwd}`));
344
- }
345
- const typeDocJsonPath = (this.typeDocJsonPath =
346
- this.typeDocJsonPath ?? node_path_1.default.join(pkgDir, constants_1.NAME_TYPEDOC_JSON));
347
- const relTypeDocJsonPath = (0, util_1.relative)(this.cwd, typeDocJsonPath);
348
- let typeDocJson;
349
- // handle the case where the user passes a JS file as the typedoc config
350
- // (which is allowed by TypeDoc)
351
- if (typeDocJsonPath.endsWith('.js')) {
352
- try {
353
- typeDocJson = require(typeDocJsonPath);
354
- }
355
- catch (err) {
356
- throw new error_1.DocutilsError(`TypeDoc config at ${relTypeDocJsonPath} threw an exception: ${err}`);
357
- }
358
- }
359
- else {
360
- try {
361
- typeDocJson = (0, fs_1.readTypedocJson)(typeDocJsonPath);
362
- }
363
- catch (e) {
364
- if (e instanceof SyntaxError) {
365
- return this.fail(new error_1.DocutilsError(`Unparseable ${constants_1.NAME_TYPEDOC_JSON} at ${relTypeDocJsonPath}: ${e}`));
366
- }
367
- return this.fail(new error_1.DocutilsError(`Missing ${constants_1.NAME_TYPEDOC_JSON} at ${relTypeDocJsonPath}; "${constants_1.NAME_BIN} init" can help`));
368
- }
369
- }
370
- if (!typeDocJson.out) {
371
- return this.fail(new error_1.DocutilsError(`Missing "out" property in ${relTypeDocJsonPath}; path "${constants_1.DEFAULT_REL_TYPEDOC_OUT_PATH} is recommended`));
372
- }
373
- this.ok('TypeDoc config OK');
374
- }
375
- /**
376
- * Asserts that TypeScript is installed, runnable, the correct version, and a parseable `tsconfig.json` exists.
377
- */
378
- async validateTypeScript() {
379
- const pkgDir = await this.findPkgDir();
380
- if (!pkgDir) {
381
- return this.fail(`Could not find package.json in ${this.cwd}`);
382
- }
383
- let typeScriptVersion;
384
- let rawTypeScriptVersion;
385
- try {
386
- ({ stdout: rawTypeScriptVersion } = await (0, teen_process_1.exec)(constants_1.NAME_NPM, ['exec', 'tsc', '--', '--version'], {
387
- cwd: pkgDir,
388
- }));
389
- }
390
- catch {
391
- return this.fail(`Could not find TypeScript compiler ("tsc") from ${pkgDir}`);
392
- }
393
- let match = rawTypeScriptVersion.match(TYPESCRIPT_VERSION_REGEX);
394
- if (match) {
395
- typeScriptVersion = match[1];
396
- }
397
- else {
398
- return this.fail(`Could not parse TypeScript version from "tsc --version"; output was:\n ${rawTypeScriptVersion}`);
399
- }
400
- const reqdTypeScriptVersion = constants_1.DOCUTILS_PKG.dependencies?.typescript;
401
- if (!reqdTypeScriptVersion) {
402
- throw new error_1.DocutilsError(`Could not find a dep for ${constants_1.NAME_TYPESCRIPT} in ${constants_1.NAME_PACKAGE_JSON}. This is a bug.`);
403
- }
404
- if (!(0, semver_1.satisfies)(typeScriptVersion, reqdTypeScriptVersion)) {
405
- return this.fail(`Found TypeScript version ${typeScriptVersion}, but ${reqdTypeScriptVersion} is required`);
406
- }
407
- this.ok('TypeScript install OK');
408
- }
409
- /**
410
- * Validates a `tsconfig.json` file
411
- */
412
- async validateTypeScriptConfig() {
413
- const pkgDir = await this.findPkgDir();
414
- if (!pkgDir) {
415
- return this.fail(new error_1.DocutilsError(`Could not find package.json in ${this.cwd}`));
416
- }
417
- const tsconfigJsonPath = (this.tsconfigJsonPath =
418
- this.tsconfigJsonPath ?? node_path_1.default.join(pkgDir, constants_1.NAME_TSCONFIG_JSON));
419
- const relTsconfigJsonPath = (0, util_1.relative)(this.cwd, tsconfigJsonPath);
420
- try {
421
- await (0, fs_1.readJson5)(tsconfigJsonPath);
422
- }
423
- catch (e) {
424
- if (e instanceof SyntaxError) {
425
- return this.fail(new error_1.DocutilsError(`Unparseable ${constants_1.NAME_TSCONFIG_JSON} at ${relTsconfigJsonPath}: ${e}`));
426
- }
427
- return this.fail(new error_1.DocutilsError(`Missing ${constants_1.NAME_TSCONFIG_JSON} at ${relTsconfigJsonPath}; "${constants_1.NAME_BIN} init" can help`));
428
- }
429
- this.ok('TypeScript config OK');
430
- }
431
- }
432
- exports.BaseValidator = BaseValidator;
433
- /**
434
- * Emitted when validation begins with a list of validation kinds to be performed
435
- * @event
436
- */
437
- BaseValidator.BEGIN = 'begin';
438
- /**
439
- * Emitted when validation ends with an error count
440
- * @event
441
- */
442
- BaseValidator.END = 'end';
443
- /**
444
- * Emitted when a validation fails, with the associated {@linkcode DocutilsError}
445
- * @event
446
- */
447
- BaseValidator.FAILURE = 'fail';
448
- /**
449
- * Emitted when a validation succeeds
450
- * @event
451
- */
452
- BaseValidator.SUCCESS = 'ok';
453
- //# sourceMappingURL=base-validator.js.map