@appium/docutils 0.4.12 → 1.0.1
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/base-mkdocs.yml +45 -5
- package/build/lib/builder/deploy.d.ts +4 -4
- package/build/lib/builder/deploy.d.ts.map +1 -1
- package/build/lib/builder/deploy.js +5 -4
- package/build/lib/builder/deploy.js.map +1 -1
- package/build/lib/builder/index.d.ts +0 -2
- package/build/lib/builder/index.d.ts.map +1 -1
- package/build/lib/builder/index.js +0 -2
- package/build/lib/builder/index.js.map +1 -1
- package/build/lib/builder/site.d.ts +2 -2
- package/build/lib/builder/site.js +2 -2
- package/build/lib/cli/command/build.d.ts +8 -45
- package/build/lib/cli/command/build.d.ts.map +1 -1
- package/build/lib/cli/command/build.js +11 -56
- package/build/lib/cli/command/build.js.map +1 -1
- package/build/lib/cli/command/init.d.ts +0 -27
- package/build/lib/cli/command/init.d.ts.map +1 -1
- package/build/lib/cli/command/init.js +0 -27
- package/build/lib/cli/command/init.js.map +1 -1
- package/build/lib/cli/command/validate.d.ts +0 -24
- package/build/lib/cli/command/validate.d.ts.map +1 -1
- package/build/lib/cli/command/validate.js +2 -26
- package/build/lib/cli/command/validate.js.map +1 -1
- package/build/lib/constants.d.ts +3 -14
- package/build/lib/constants.d.ts.map +1 -1
- package/build/lib/constants.js +4 -15
- package/build/lib/constants.js.map +1 -1
- package/build/lib/fs.d.ts +0 -29
- package/build/lib/fs.d.ts.map +1 -1
- package/build/lib/fs.js +4 -57
- package/build/lib/fs.js.map +1 -1
- package/build/lib/index.d.ts +0 -1
- package/build/lib/index.d.ts.map +1 -1
- package/build/lib/index.js +0 -1
- package/build/lib/index.js.map +1 -1
- package/build/lib/init.d.ts +7 -131
- package/build/lib/init.d.ts.map +1 -1
- package/build/lib/init.js +2 -55
- package/build/lib/init.js.map +1 -1
- package/build/lib/model.d.ts +0 -11
- package/build/lib/model.d.ts.map +1 -1
- package/build/lib/validate.d.ts +2 -30
- package/build/lib/validate.d.ts.map +1 -1
- package/build/lib/validate.js +2 -93
- package/build/lib/validate.js.map +1 -1
- package/lib/builder/deploy.ts +17 -15
- package/lib/builder/index.ts +0 -2
- package/lib/builder/site.ts +6 -6
- package/lib/cli/command/build.ts +12 -59
- package/lib/cli/command/init.ts +0 -27
- package/lib/cli/command/validate.ts +3 -27
- package/lib/constants.ts +4 -17
- package/lib/fs.ts +16 -84
- package/lib/index.ts +0 -1
- package/lib/init.ts +9 -106
- package/lib/model.ts +0 -14
- package/lib/validate.ts +23 -172
- package/package.json +7 -13
- package/requirements.txt +4 -3
- package/tsconfig.json +1 -0
- package/build/lib/builder/nav.d.ts +0 -81
- package/build/lib/builder/nav.d.ts.map +0 -1
- package/build/lib/builder/nav.js +0 -288
- package/build/lib/builder/nav.js.map +0 -1
- package/build/lib/builder/reference.d.ts +0 -57
- package/build/lib/builder/reference.d.ts.map +0 -1
- package/build/lib/builder/reference.js +0 -111
- package/build/lib/builder/reference.js.map +0 -1
- package/build/lib/mike.d.ts +0 -81
- package/build/lib/mike.d.ts.map +0 -1
- package/build/lib/mike.js +0 -146
- package/build/lib/mike.js.map +0 -1
- package/lib/builder/nav.ts +0 -402
- package/lib/builder/reference.ts +0 -171
- package/lib/mike.js +0 -153
package/lib/cli/command/build.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import path from 'node:path';
|
|
7
7
|
import type {CommandModule, InferredOptionTypes, Options} from 'yargs';
|
|
8
|
-
import {
|
|
8
|
+
import {buildSite, deploy} from '../../builder';
|
|
9
9
|
import {NAME_BIN} from '../../constants';
|
|
10
10
|
import {getLogger} from '../../logger';
|
|
11
11
|
import {stopwatch} from '../../util';
|
|
@@ -21,12 +21,6 @@ enum BuildCommandGroup {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
const opts = {
|
|
24
|
-
reference: {
|
|
25
|
-
describe: 'Run TypeDoc command API reference build (Markdown)',
|
|
26
|
-
group: BuildCommandGroup.Build,
|
|
27
|
-
type: 'boolean',
|
|
28
|
-
default: true,
|
|
29
|
-
},
|
|
30
24
|
site: {
|
|
31
25
|
describe: 'Run MkDocs build (HTML)',
|
|
32
26
|
group: BuildCommandGroup.Build,
|
|
@@ -55,24 +49,6 @@ const opts = {
|
|
|
55
49
|
requiresArg: true,
|
|
56
50
|
type: 'string',
|
|
57
51
|
},
|
|
58
|
-
title: {
|
|
59
|
-
defaultDescription: '(extension package name)',
|
|
60
|
-
describe: 'Title of the API reference',
|
|
61
|
-
group: BuildCommandGroup.Build,
|
|
62
|
-
nargs: 1,
|
|
63
|
-
requiresArg: true,
|
|
64
|
-
type: 'string',
|
|
65
|
-
},
|
|
66
|
-
'tsconfig-json': {
|
|
67
|
-
defaultDescription: './tsconfig.json',
|
|
68
|
-
describe: 'Path to tsconfig.json',
|
|
69
|
-
group: BuildCommandGroup.BuildPaths,
|
|
70
|
-
nargs: 1,
|
|
71
|
-
normalize: true,
|
|
72
|
-
requiresArg: true,
|
|
73
|
-
coerce: path.resolve,
|
|
74
|
-
type: 'string',
|
|
75
|
-
},
|
|
76
52
|
'mkdocs-yml': {
|
|
77
53
|
defaultDescription: './mkdocs.yml',
|
|
78
54
|
description: 'Path to mkdocs.yml',
|
|
@@ -83,22 +59,6 @@ const opts = {
|
|
|
83
59
|
coerce: path.resolve,
|
|
84
60
|
type: 'string',
|
|
85
61
|
},
|
|
86
|
-
'typedoc-json': {
|
|
87
|
-
defaultDescription: './typedoc.json',
|
|
88
|
-
describe: 'Path to typedoc.json',
|
|
89
|
-
group: BuildCommandGroup.BuildPaths,
|
|
90
|
-
nargs: 1,
|
|
91
|
-
normalize: true,
|
|
92
|
-
requiresArg: true,
|
|
93
|
-
coerce: path.resolve,
|
|
94
|
-
type: 'string',
|
|
95
|
-
},
|
|
96
|
-
all: {
|
|
97
|
-
describe: 'Output all reference docs (not just Appium comands)',
|
|
98
|
-
group: BuildCommandGroup.Build,
|
|
99
|
-
implies: 'site',
|
|
100
|
-
type: 'boolean',
|
|
101
|
-
},
|
|
102
62
|
deploy: {
|
|
103
63
|
describe: 'Commit HTML output to a branch using mike',
|
|
104
64
|
group: BuildCommandGroup.Deploy,
|
|
@@ -131,7 +91,7 @@ const opts = {
|
|
|
131
91
|
nargs: 1,
|
|
132
92
|
defaultDescription: 'origin',
|
|
133
93
|
},
|
|
134
|
-
prefix: {
|
|
94
|
+
'deploy-prefix': {
|
|
135
95
|
describe: 'Subdirectory within <branch> to commit to',
|
|
136
96
|
implies: 'branch',
|
|
137
97
|
group: BuildCommandGroup.Deploy,
|
|
@@ -166,12 +126,15 @@ const opts = {
|
|
|
166
126
|
requiresArg: true,
|
|
167
127
|
defaultDescription: 'latest',
|
|
168
128
|
},
|
|
169
|
-
|
|
170
|
-
describe: '
|
|
129
|
+
'alias-type': {
|
|
130
|
+
describe: 'Alias creation strategy',
|
|
171
131
|
implies: 'deploy',
|
|
172
132
|
group: BuildCommandGroup.Deploy,
|
|
173
|
-
type: '
|
|
174
|
-
|
|
133
|
+
type: 'string',
|
|
134
|
+
nargs: 1,
|
|
135
|
+
requiresArg: true,
|
|
136
|
+
choices: ['symlink', 'redirect', 'copy'],
|
|
137
|
+
defaultDescription: 'redirect',
|
|
175
138
|
},
|
|
176
139
|
serve: {
|
|
177
140
|
describe: 'Start development server',
|
|
@@ -204,37 +167,27 @@ type BuildOptions = InferredOptionTypes<typeof opts>;
|
|
|
204
167
|
|
|
205
168
|
export default {
|
|
206
169
|
command: 'build',
|
|
207
|
-
describe: 'Build Appium extension documentation using
|
|
170
|
+
describe: 'Build Appium extension documentation using MkDocs',
|
|
208
171
|
builder(yargs) {
|
|
209
172
|
return yargs
|
|
210
173
|
.options(opts)
|
|
211
174
|
.check(async (argv) => {
|
|
212
175
|
// either this method doesn't provide camel-cased props, or the types are wrong.
|
|
213
176
|
if (argv.deploy === true && argv['site-dir']) {
|
|
214
|
-
return `--site-dir is unsupported when running "${NAME_BIN} deploy"; use --prefix if needed, but remember that the default behavior is to deploy to the root of the branch (${argv.branch}) instead of a subdirectory`;
|
|
177
|
+
return `--site-dir is unsupported when running "${NAME_BIN} deploy"; use --deploy-prefix if needed, but remember that the default behavior is to deploy to the root of the branch (${argv.branch}) instead of a subdirectory`;
|
|
215
178
|
}
|
|
216
179
|
|
|
217
180
|
return await checkMissingPaths(opts, BuildCommandGroup.BuildPaths, argv);
|
|
218
181
|
})
|
|
219
182
|
.epilog(
|
|
220
|
-
'For help with further configuration, see:\n - MkDocs: https://www.mkdocs.org\n -
|
|
183
|
+
'For help with further configuration, see:\n - MkDocs: https://www.mkdocs.org\n - Mike: https://github.com/jimporter/mike',
|
|
221
184
|
);
|
|
222
185
|
},
|
|
223
186
|
async handler(args) {
|
|
224
187
|
log.info('Building docs...');
|
|
225
188
|
const stop = stopwatch('build');
|
|
226
189
|
log.debug('Build command called with args: %O', args);
|
|
227
|
-
if (!args.site && !args.reference) {
|
|
228
|
-
// specifically not a DocUtils error
|
|
229
|
-
throw new Error(
|
|
230
|
-
'Cannot use both --no-site (--site=false) and --no-reference (--reference=false)'
|
|
231
|
-
);
|
|
232
|
-
}
|
|
233
|
-
if (args.reference) {
|
|
234
|
-
await buildReferenceDocs(args);
|
|
235
|
-
}
|
|
236
190
|
if (args.site) {
|
|
237
|
-
await updateNav(args);
|
|
238
191
|
if (args.deploy) {
|
|
239
192
|
await deploy(args);
|
|
240
193
|
} else {
|
package/lib/cli/command/init.ts
CHANGED
|
@@ -149,33 +149,6 @@ const opts = {
|
|
|
149
149
|
type: 'string',
|
|
150
150
|
implies: 'typescript',
|
|
151
151
|
},
|
|
152
|
-
typedoc: {
|
|
153
|
-
default: true,
|
|
154
|
-
description: 'Create typedoc.json if needed',
|
|
155
|
-
group: InitCommandGroup.Behavior,
|
|
156
|
-
type: 'boolean',
|
|
157
|
-
implies: 'entry-point',
|
|
158
|
-
},
|
|
159
|
-
'typedoc-json': {
|
|
160
|
-
defaultDescription: './typedoc.json',
|
|
161
|
-
describe: 'Path to new or existing typedoc.json',
|
|
162
|
-
group: InitCommandGroup.Behavior,
|
|
163
|
-
nargs: 1,
|
|
164
|
-
normalize: true,
|
|
165
|
-
requiresArg: true,
|
|
166
|
-
type: 'string',
|
|
167
|
-
implies: 'typedoc',
|
|
168
|
-
},
|
|
169
|
-
'entry-point': {
|
|
170
|
-
alias: 'e',
|
|
171
|
-
describe: 'Source entry point of extension',
|
|
172
|
-
group: InitCommandGroup.Paths,
|
|
173
|
-
nargs: 1,
|
|
174
|
-
normalize: false,
|
|
175
|
-
requiresArg: true,
|
|
176
|
-
type: 'string',
|
|
177
|
-
implies: 'typedoc',
|
|
178
|
-
},
|
|
179
152
|
typescript: {
|
|
180
153
|
default: true,
|
|
181
154
|
description: 'Create tsconfig.json if needed',
|
|
@@ -66,30 +66,6 @@ const opts = {
|
|
|
66
66
|
requiresArg: true,
|
|
67
67
|
type: 'string',
|
|
68
68
|
},
|
|
69
|
-
typedoc: {
|
|
70
|
-
default: true,
|
|
71
|
-
description: 'Validate TypoDoc environment',
|
|
72
|
-
group: ValidateCommandGroup.Behavior,
|
|
73
|
-
type: 'boolean',
|
|
74
|
-
},
|
|
75
|
-
'typedoc-json': {
|
|
76
|
-
defaultDescription: './typedoc.json',
|
|
77
|
-
describe: 'Path to typedoc.json',
|
|
78
|
-
group: ValidateCommandGroup.Paths,
|
|
79
|
-
nargs: 1,
|
|
80
|
-
normalize: true,
|
|
81
|
-
requiresArg: true,
|
|
82
|
-
type: 'string',
|
|
83
|
-
},
|
|
84
|
-
'typedoc-path': {
|
|
85
|
-
defaultDescription: '(derived from shell)',
|
|
86
|
-
description: 'Path to typedoc executable',
|
|
87
|
-
group: ValidateCommandGroup.Paths,
|
|
88
|
-
nargs: 1,
|
|
89
|
-
normalize: true,
|
|
90
|
-
requiresArg: true,
|
|
91
|
-
type: 'string',
|
|
92
|
-
},
|
|
93
69
|
typescript: {
|
|
94
70
|
default: true,
|
|
95
71
|
description: 'Validate TypeScript environment',
|
|
@@ -105,8 +81,8 @@ export default {
|
|
|
105
81
|
describe: 'Validate Environment',
|
|
106
82
|
builder(yargs) {
|
|
107
83
|
return yargs.options(opts).check(async (argv) => {
|
|
108
|
-
if (!argv.python && !argv.
|
|
109
|
-
return 'No validation targets specified; one or more of --python, --typescript
|
|
84
|
+
if (!argv.python && !argv.typescript && !argv.mkdocs) {
|
|
85
|
+
return 'No validation targets specified; one or more of --python, --typescript or --mkdocs must be provided';
|
|
110
86
|
}
|
|
111
87
|
return checkMissingPaths(opts, ValidateCommandGroup.Paths, argv);
|
|
112
88
|
});
|
|
@@ -131,7 +107,7 @@ export default {
|
|
|
131
107
|
|
|
132
108
|
if (errorCount) {
|
|
133
109
|
throw new DocutilsError(
|
|
134
|
-
`Validation failed with ${errorCount} ${util.pluralize('error', errorCount)}
|
|
110
|
+
`Validation failed with ${errorCount} ${util.pluralize('error', errorCount)}`,
|
|
135
111
|
);
|
|
136
112
|
}
|
|
137
113
|
},
|
package/lib/constants.ts
CHANGED
|
@@ -26,10 +26,6 @@ export const NAME_TSCONFIG_JSON = 'tsconfig.json';
|
|
|
26
26
|
* `python` executable
|
|
27
27
|
*/
|
|
28
28
|
export const NAME_PYTHON = 'python';
|
|
29
|
-
/**
|
|
30
|
-
* Default name of the `typedoc.json` config file
|
|
31
|
-
*/
|
|
32
|
-
export const NAME_TYPEDOC_JSON = 'typedoc.json';
|
|
33
29
|
/**
|
|
34
30
|
* It's `package.json`!
|
|
35
31
|
*/
|
|
@@ -53,11 +49,6 @@ export const NAME_MKDOCS = 'mkdocs';
|
|
|
53
49
|
*/
|
|
54
50
|
export const NAME_MIKE = 'mike';
|
|
55
51
|
|
|
56
|
-
/**
|
|
57
|
-
* Name of the `typedoc` executable
|
|
58
|
-
*/
|
|
59
|
-
export const NAME_TYPEDOC = 'typedoc';
|
|
60
|
-
|
|
61
52
|
/**
|
|
62
53
|
* Name of the `pip` module.
|
|
63
54
|
*
|
|
@@ -104,7 +95,7 @@ export const PKG_ROOT_DIR = fs.findRoot(__dirname);
|
|
|
104
95
|
*/
|
|
105
96
|
|
|
106
97
|
export const DOCUTILS_PKG: PackageJson = JSON.parse(
|
|
107
|
-
readFileSync(path.join(PKG_ROOT_DIR, NAME_PACKAGE_JSON), 'utf8')
|
|
98
|
+
readFileSync(path.join(PKG_ROOT_DIR, NAME_PACKAGE_JSON), 'utf8'),
|
|
108
99
|
);
|
|
109
100
|
|
|
110
101
|
/**
|
|
@@ -114,9 +105,10 @@ export const DOCUTILS_PKG: PackageJson = JSON.parse(
|
|
|
114
105
|
export const REQUIREMENTS_TXT_PATH = path.join(PKG_ROOT_DIR, NAME_REQUIREMENTS_TXT);
|
|
115
106
|
|
|
116
107
|
/**
|
|
117
|
-
* The default
|
|
108
|
+
* The default alias creation strategy to pass to `mike` when deploying
|
|
109
|
+
* (`symlink`, `redirect` or `copy`)
|
|
118
110
|
*/
|
|
119
|
-
export const
|
|
111
|
+
export const DEFAULT_DEPLOY_ALIAS_TYPE = 'redirect';
|
|
120
112
|
|
|
121
113
|
/**
|
|
122
114
|
* The default branch to deploy to
|
|
@@ -149,11 +141,6 @@ export const LogLevelMap = {
|
|
|
149
141
|
debug: LogLevel.Debug,
|
|
150
142
|
} as const;
|
|
151
143
|
|
|
152
|
-
/**
|
|
153
|
-
* Default site nav header text
|
|
154
|
-
*/
|
|
155
|
-
export const DEFAULT_NAV_HEADER = 'Reference';
|
|
156
|
-
|
|
157
144
|
/**
|
|
158
145
|
* If the user does not specify a site directory _and_ the `mkdocs.yml` doesn't either, use this dir.
|
|
159
146
|
*/
|
package/lib/fs.ts
CHANGED
|
@@ -4,28 +4,18 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import {fs} from '@appium/support';
|
|
7
|
-
import findUp from 'find-up';
|
|
8
7
|
import * as JSON5 from 'json5';
|
|
9
8
|
import _ from 'lodash';
|
|
10
9
|
import path from 'node:path';
|
|
11
10
|
import _pkgDir from 'pkg-dir';
|
|
12
11
|
import readPkg, {NormalizedPackageJson, PackageJson} from 'read-pkg';
|
|
13
12
|
import {JsonValue} from 'type-fest';
|
|
14
|
-
import {Application, TypeDocReader} from 'typedoc';
|
|
15
13
|
import YAML from 'yaml';
|
|
16
|
-
import {
|
|
17
|
-
NAME_MIKE,
|
|
18
|
-
NAME_MKDOCS_YML,
|
|
19
|
-
NAME_NPM,
|
|
20
|
-
NAME_PACKAGE_JSON,
|
|
21
|
-
NAME_PYTHON,
|
|
22
|
-
NAME_TYPEDOC,
|
|
23
|
-
NAME_TYPEDOC_JSON,
|
|
24
|
-
} from './constants';
|
|
14
|
+
import {NAME_MIKE, NAME_MKDOCS_YML, NAME_NPM, NAME_PACKAGE_JSON, NAME_PYTHON} from './constants';
|
|
25
15
|
import {DocutilsError} from './error';
|
|
26
16
|
import {getLogger} from './logger';
|
|
27
17
|
import {MkDocsYml} from './model';
|
|
28
|
-
import {
|
|
18
|
+
import {exec} from 'teen_process';
|
|
29
19
|
|
|
30
20
|
const log = getLogger('fs');
|
|
31
21
|
|
|
@@ -44,7 +34,7 @@ export const findPkgDir = _.memoize(_pkgDir);
|
|
|
44
34
|
export const stringifyYaml: (value: JsonValue) => string = _.partialRight(
|
|
45
35
|
YAML.stringify,
|
|
46
36
|
{indent: 2},
|
|
47
|
-
undefined
|
|
37
|
+
undefined,
|
|
48
38
|
);
|
|
49
39
|
|
|
50
40
|
/**
|
|
@@ -65,17 +55,17 @@ export const stringifyJson5: (value: JsonValue) => string = _.partialRight(JSON5
|
|
|
65
55
|
export const stringifyJson: (value: JsonValue) => string = _.partialRight(
|
|
66
56
|
JSON.stringify,
|
|
67
57
|
2,
|
|
68
|
-
undefined
|
|
58
|
+
undefined,
|
|
69
59
|
);
|
|
70
60
|
|
|
71
61
|
/**
|
|
72
62
|
* Reads a YAML file, parses it and caches the result
|
|
73
63
|
*/
|
|
74
|
-
|
|
64
|
+
const readYaml = _.memoize(async (filepath: string) =>
|
|
75
65
|
YAML.parse(await fs.readFile(filepath, 'utf8'), {
|
|
76
66
|
prettyErrors: false,
|
|
77
67
|
logLevel: 'silent',
|
|
78
|
-
})
|
|
68
|
+
}),
|
|
79
69
|
);
|
|
80
70
|
|
|
81
71
|
/**
|
|
@@ -87,7 +77,7 @@ export const readYaml = _.memoize(async (filepath: string) =>
|
|
|
87
77
|
*/
|
|
88
78
|
export async function findInPkgDir(
|
|
89
79
|
filename: string,
|
|
90
|
-
cwd = process.cwd()
|
|
80
|
+
cwd = process.cwd(),
|
|
91
81
|
): Promise<string | undefined> {
|
|
92
82
|
const pkgDir = await findPkgDir(cwd);
|
|
93
83
|
if (!pkgDir) {
|
|
@@ -96,19 +86,6 @@ export async function findInPkgDir(
|
|
|
96
86
|
return path.join(pkgDir, filename);
|
|
97
87
|
}
|
|
98
88
|
|
|
99
|
-
/**
|
|
100
|
-
* Finds a `typedoc.json`, expected to be a sibling of `package.json`
|
|
101
|
-
*
|
|
102
|
-
* Caches the result.
|
|
103
|
-
* @param cwd - Current working directory
|
|
104
|
-
* @returns Path to `typedoc.json`
|
|
105
|
-
*/
|
|
106
|
-
export const findTypeDocJsonPath = _.memoize(async (cwd = process.cwd()) => {
|
|
107
|
-
const filepath = await findUp(NAME_TYPEDOC_JSON, {cwd, type: 'file'});
|
|
108
|
-
log.debug('Found `typedoc.json` at %s', filepath);
|
|
109
|
-
return filepath;
|
|
110
|
-
});
|
|
111
|
-
|
|
112
89
|
/**
|
|
113
90
|
* Finds an `mkdocs.yml`, expected to be a sibling of `package.json`
|
|
114
91
|
*
|
|
@@ -126,20 +103,20 @@ export const findMkDocsYml = _.memoize(_.partial(findInPkgDir, NAME_MKDOCS_YML))
|
|
|
126
103
|
*/
|
|
127
104
|
async function _readPkgJson(
|
|
128
105
|
cwd: string,
|
|
129
|
-
normalize: true
|
|
106
|
+
normalize: true,
|
|
130
107
|
): Promise<{pkgPath: string; pkg: NormalizedPackageJson}>;
|
|
131
108
|
async function _readPkgJson(
|
|
132
109
|
cwd: string,
|
|
133
|
-
normalize?: false
|
|
110
|
+
normalize?: false,
|
|
134
111
|
): Promise<{pkgPath: string; pkg: PackageJson}>;
|
|
135
112
|
async function _readPkgJson(
|
|
136
113
|
cwd: string,
|
|
137
|
-
normalize?: boolean
|
|
114
|
+
normalize?: boolean,
|
|
138
115
|
): Promise<{pkgPath: string; pkg: PackageJson | NormalizedPackageJson}> {
|
|
139
116
|
const pkgDir = await findPkgDir(cwd);
|
|
140
117
|
if (!pkgDir) {
|
|
141
118
|
throw new DocutilsError(
|
|
142
|
-
`Could not find a ${NAME_PACKAGE_JSON} near ${cwd}; please create it before using this utility
|
|
119
|
+
`Could not find a ${NAME_PACKAGE_JSON} near ${cwd}; please create it before using this utility`,
|
|
143
120
|
);
|
|
144
121
|
}
|
|
145
122
|
const pkgPath = path.join(pkgDir, NAME_PACKAGE_JSON);
|
|
@@ -158,27 +135,12 @@ async function _readPkgJson(
|
|
|
158
135
|
*/
|
|
159
136
|
export const readPackageJson = _.memoize(_readPkgJson);
|
|
160
137
|
|
|
161
|
-
/**
|
|
162
|
-
* Reads a `typedoc.json` file and returns its parsed contents.
|
|
163
|
-
*
|
|
164
|
-
* TypeDoc expands the "extends" field, which is why we use its facilities. It, unfortunately, is a
|
|
165
|
-
* blocking operation.
|
|
166
|
-
*/
|
|
167
|
-
export const readTypedocJson = _.memoize((typedocJsonPath: string) => {
|
|
168
|
-
const app = new Application();
|
|
169
|
-
app.options.setValue('plugin', 'none');
|
|
170
|
-
app.options.setValue('logger', 'none');
|
|
171
|
-
app.options.addReader(new TypeDocReader());
|
|
172
|
-
app.bootstrap({options: path.dirname(typedocJsonPath)});
|
|
173
|
-
return app.options.getRawValues();
|
|
174
|
-
});
|
|
175
|
-
|
|
176
138
|
/**
|
|
177
139
|
* Reads a JSON5 file and parses it
|
|
178
140
|
*/
|
|
179
141
|
export const readJson5 = _.memoize(
|
|
180
142
|
async <T extends JsonValue>(filepath: string): Promise<T> =>
|
|
181
|
-
JSON5.parse(await fs.readFile(filepath, 'utf8'))
|
|
143
|
+
JSON5.parse(await fs.readFile(filepath, 'utf8')),
|
|
182
144
|
);
|
|
183
145
|
|
|
184
146
|
/**
|
|
@@ -186,7 +148,7 @@ export const readJson5 = _.memoize(
|
|
|
186
148
|
*/
|
|
187
149
|
export const readJson = _.memoize(
|
|
188
150
|
async <T extends JsonValue>(filepath: string): Promise<T> =>
|
|
189
|
-
JSON.parse(await fs.readFile(filepath, 'utf8'))
|
|
151
|
+
JSON.parse(await fs.readFile(filepath, 'utf8')),
|
|
190
152
|
);
|
|
191
153
|
|
|
192
154
|
/**
|
|
@@ -225,11 +187,6 @@ const whichPython = _.partial(cachedWhich, NAME_PYTHON, {nothrow: true});
|
|
|
225
187
|
*/
|
|
226
188
|
const whichPython3 = _.partial(cachedWhich, `${NAME_PYTHON}3`, {nothrow: true});
|
|
227
189
|
|
|
228
|
-
/**
|
|
229
|
-
* Finds `typedoc` executable
|
|
230
|
-
*/
|
|
231
|
-
const whichTypeDoc = _.partial(cachedWhich, NAME_TYPEDOC, {nothrow: true});
|
|
232
|
-
|
|
233
190
|
/**
|
|
234
191
|
* `mike` cannot be invoked via `python -m`, so we need to find the script.
|
|
235
192
|
*/
|
|
@@ -254,21 +211,7 @@ export const findMike = _.partial(async () => {
|
|
|
254
211
|
return mikePath;
|
|
255
212
|
}
|
|
256
213
|
}
|
|
257
|
-
}
|
|
258
|
-
catch {}
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* Finds the `typedoc` executable.
|
|
263
|
-
*
|
|
264
|
-
* Looks in the `node_modules/.bin` dir from the current working directory, and if this fails, in the `node_modules` dir for the file which `.bin/typedoc` should be a symlink of, and if _that_ fails, try the `PATH`.
|
|
265
|
-
*/
|
|
266
|
-
export const findTypeDoc = _.memoize(async (cwd = process.cwd()): Promise<string | undefined> => {
|
|
267
|
-
// .cmd is for win32, of course. note that glob _always_ uses posix dir separators.
|
|
268
|
-
const globResult =
|
|
269
|
-
(await fs.glob('node_modules/.bin/typedoc?(.cmd)', {cwd, nodir: true})) ??
|
|
270
|
-
(await fs.glob('node_modules/**/typedoc/bin/typedoc', {cwd, nodir: true, follow: true}));
|
|
271
|
-
return _.first(globResult) ?? (await whichTypeDoc());
|
|
214
|
+
} catch {}
|
|
272
215
|
});
|
|
273
216
|
|
|
274
217
|
/**
|
|
@@ -277,7 +220,7 @@ export const findTypeDoc = _.memoize(async (cwd = process.cwd()): Promise<string
|
|
|
277
220
|
* `python3` is preferred over `python`, since the latter could be Python 2.
|
|
278
221
|
*/
|
|
279
222
|
export const findPython = _.memoize(
|
|
280
|
-
async (): Promise<string | undefined> => (await whichPython3()) ?? (await whichPython())
|
|
223
|
+
async (): Promise<string | undefined> => (await whichPython3()) ?? (await whichPython()),
|
|
281
224
|
);
|
|
282
225
|
|
|
283
226
|
/**
|
|
@@ -313,16 +256,5 @@ export const readMkDocsYml = _.memoize(
|
|
|
313
256
|
}
|
|
314
257
|
}
|
|
315
258
|
return mkDocsYml;
|
|
316
|
-
}
|
|
259
|
+
},
|
|
317
260
|
);
|
|
318
|
-
|
|
319
|
-
/**
|
|
320
|
-
* Given an abs path to a directory, return a list of all abs paths of all directories in it
|
|
321
|
-
*/
|
|
322
|
-
export const findDirsIn = _.memoize(async (dirpath: string): Promise<string[]> => {
|
|
323
|
-
if (!path.isAbsolute(dirpath)) {
|
|
324
|
-
throw new DocutilsError(`Expected absolute path, got '${dirpath}'`);
|
|
325
|
-
}
|
|
326
|
-
const dirEnts = await fs.readdir(dirpath, {withFileTypes: true});
|
|
327
|
-
return dirEnts.filter((ent) => ent.isDirectory()).map((ent) => path.join(dirpath, ent.name));
|
|
328
|
-
});
|