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