@appium/docutils 0.3.13 → 0.4.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.
Files changed (45) hide show
  1. package/bin/appium-docs.js +2 -0
  2. package/build/lib/builder/deploy.d.ts.map +1 -1
  3. package/build/lib/builder/deploy.js +15 -11
  4. package/build/lib/builder/deploy.js.map +1 -1
  5. package/build/lib/builder/nav.d.ts.map +1 -1
  6. package/build/lib/builder/nav.js +11 -5
  7. package/build/lib/builder/nav.js.map +1 -1
  8. package/build/lib/cli/check.d.ts.map +1 -1
  9. package/build/lib/cli/check.js +1 -1
  10. package/build/lib/cli/check.js.map +1 -1
  11. package/build/lib/cli/command/build.d.ts +4 -3
  12. package/build/lib/cli/command/build.d.ts.map +1 -1
  13. package/build/lib/cli/command/build.js +4 -3
  14. package/build/lib/cli/command/build.js.map +1 -1
  15. package/build/lib/cli/command/init.d.ts +22 -0
  16. package/build/lib/cli/command/init.d.ts.map +1 -1
  17. package/build/lib/cli/command/init.js +22 -0
  18. package/build/lib/cli/command/init.js.map +1 -1
  19. package/build/lib/cli/index.d.ts +2 -2
  20. package/build/lib/cli/index.d.ts.map +1 -1
  21. package/build/lib/cli/index.js +22 -3
  22. package/build/lib/cli/index.js.map +1 -1
  23. package/build/lib/fs.d.ts +4 -0
  24. package/build/lib/fs.d.ts.map +1 -1
  25. package/build/lib/fs.js +29 -1
  26. package/build/lib/fs.js.map +1 -1
  27. package/build/lib/init.d.ts +24 -10
  28. package/build/lib/init.d.ts.map +1 -1
  29. package/build/lib/init.js +31 -2
  30. package/build/lib/init.js.map +1 -1
  31. package/build/lib/scaffold.d.ts +1 -1
  32. package/build/lib/scaffold.d.ts.map +1 -1
  33. package/build/lib/scaffold.js +11 -3
  34. package/build/lib/scaffold.js.map +1 -1
  35. package/lib/builder/deploy.ts +17 -12
  36. package/lib/builder/nav.ts +11 -9
  37. package/lib/cli/check.ts +4 -1
  38. package/lib/cli/command/build.ts +4 -3
  39. package/lib/cli/command/init.ts +22 -0
  40. package/lib/cli/index.ts +27 -4
  41. package/lib/fs.ts +30 -0
  42. package/lib/init.ts +49 -2
  43. package/lib/scaffold.ts +11 -4
  44. package/package.json +7 -7
  45. package/requirements.txt +1 -1
@@ -30,6 +30,7 @@ const opts = {
30
30
  nargs: 1,
31
31
  requiresArg: true,
32
32
  type: 'string',
33
+ implies: 'mkdocs',
33
34
  },
34
35
  dir: {
35
36
  default: '.',
@@ -59,6 +60,7 @@ const opts = {
59
60
  group: InitCommandGroup.MkDocs,
60
61
  requiresArg: true,
61
62
  type: 'string',
63
+ implies: 'mkdocs',
62
64
  },
63
65
  mkdocs: {
64
66
  default: true,
@@ -74,6 +76,7 @@ const opts = {
74
76
  normalize: true,
75
77
  requiresArg: true,
76
78
  type: 'string',
79
+ implies: 'mkdocs',
77
80
  },
78
81
  'package-json': {
79
82
  defaultDescription: './package.json',
@@ -98,6 +101,7 @@ const opts = {
98
101
  normalize: true,
99
102
  requiresArg: true,
100
103
  type: 'string',
104
+ implies: 'python',
101
105
  },
102
106
  'repo-name': {
103
107
  defaultDescription: '(derived from --repo-url)',
@@ -106,6 +110,7 @@ const opts = {
106
110
  nargs: 1,
107
111
  requiresArg: true,
108
112
  type: 'string',
113
+ implies: 'mkdocs',
109
114
  },
110
115
  'repo-url': {
111
116
  defaultDescription: '(from package.json)',
@@ -114,6 +119,7 @@ const opts = {
114
119
  nargs: 1,
115
120
  requiresArg: true,
116
121
  type: 'string',
122
+ implies: 'mkdocs',
117
123
  },
118
124
  'site-description': {
119
125
  defaultDescription: '(from package.json)',
@@ -122,6 +128,7 @@ const opts = {
122
128
  nargs: 1,
123
129
  requiresArg: true,
124
130
  type: 'string',
131
+ implies: 'mkdocs',
125
132
  },
126
133
  'site-name': {
127
134
  defaultDescription: '(extension package name)',
@@ -130,6 +137,7 @@ const opts = {
130
137
  nargs: 1,
131
138
  requiresArg: true,
132
139
  type: 'string',
140
+ implies: 'mkdocs',
133
141
  },
134
142
  'tsconfig-json': {
135
143
  defaultDescription: './tsconfig.json',
@@ -139,12 +147,14 @@ const opts = {
139
147
  normalize: true,
140
148
  requiresArg: true,
141
149
  type: 'string',
150
+ implies: 'typescript',
142
151
  },
143
152
  typedoc: {
144
153
  default: true,
145
154
  description: 'Create typedoc.json if needed',
146
155
  group: InitCommandGroup.Behavior,
147
156
  type: 'boolean',
157
+ implies: 'entry-point',
148
158
  },
149
159
  'typedoc-json': {
150
160
  defaultDescription: './typedoc.json',
@@ -154,6 +164,17 @@ const opts = {
154
164
  normalize: true,
155
165
  requiresArg: true,
156
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',
157
178
  },
158
179
  typescript: {
159
180
  default: true,
@@ -167,6 +188,7 @@ const opts = {
167
188
  group: InitCommandGroup.Behavior,
168
189
  type: 'boolean',
169
190
  conflicts: 'force',
191
+ implies: 'python',
170
192
  },
171
193
  } as const satisfies Record<string, Options>;
172
194
 
package/lib/cli/index.ts CHANGED
@@ -8,19 +8,20 @@
8
8
 
9
9
  import {getLogger} from '../logger';
10
10
 
11
+ import {fs} from '@appium/support';
11
12
  import _ from 'lodash';
13
+ import {sync as readPkg} from 'read-pkg';
12
14
  import {hideBin} from 'yargs/helpers';
13
15
  import yargs from 'yargs/yargs';
14
16
  import {DEFAULT_LOG_LEVEL, LogLevelMap, NAME_BIN} from '../constants';
15
17
  import {DocutilsError} from '../error';
16
18
  import {build, init, validate} from './command';
17
19
  import {findConfig} from './config';
18
- import {fs} from '@appium/support';
19
- import {sync as readPkg} from 'read-pkg';
20
20
 
21
21
  const pkg = readPkg({cwd: fs.findRoot(__dirname)});
22
-
23
22
  const log = getLogger('cli');
23
+ const IMPLICATIONS_FAILED_REGEX = /implications\s+failed:\n\s*(.+)\s->\s(.+)$/i;
24
+
24
25
  export async function main(argv = hideBin(process.argv)) {
25
26
  const config = await findConfig(argv);
26
27
 
@@ -70,12 +71,34 @@ export async function main(argv = hideBin(process.argv)) {
70
71
  * Custom failure handler so we can log nicely.
71
72
  */
72
73
  (msg: string | null, error) => {
74
+ /**
75
+ * yargs' default output if an "implication" fails (e.g., arg _A_ requires arg _B_) leaves much to be desired.
76
+ *
77
+ * @remarks Unfortunately, we do not have access to the parsed arguments object, since it may have failed parsing.
78
+ * @param msg Implication failure message
79
+ * @returns Whether the message was an implication failure
80
+ */
81
+ const handleImplicationFailure = (msg: string | null): boolean => {
82
+ let match: RegExpMatchArray | null | undefined;
83
+ if (!(match = msg?.match(IMPLICATIONS_FAILED_REGEX))) {
84
+ return false;
85
+ }
86
+ const [, arg, missingArg] = match;
87
+ log.error(
88
+ `Argument "--${arg}" requires "--${missingArg}"; note that "--${arg}" may be enabled by default`
89
+ );
90
+ return true;
91
+ };
92
+
73
93
  // if it is a DocutilsError, it has nothing to do with the CLI
74
94
  if (error instanceof DocutilsError) {
75
95
  log.error(error.message);
76
96
  } else {
77
97
  y.showHelp();
78
- log.error(`\n\n${msg ?? error.message}`);
98
+
99
+ if (!handleImplicationFailure(msg)) {
100
+ log.error(`\n\n${msg ?? error.message}`);
101
+ }
79
102
  }
80
103
  y.exit(1, error);
81
104
  }
package/lib/fs.ts CHANGED
@@ -14,6 +14,7 @@ import {JsonValue} from 'type-fest';
14
14
  import {Application, TypeDocReader} from 'typedoc';
15
15
  import YAML from 'yaml';
16
16
  import {
17
+ NAME_MIKE,
17
18
  NAME_MKDOCS_YML,
18
19
  NAME_NPM,
19
20
  NAME_PACKAGE_JSON,
@@ -24,6 +25,7 @@ import {
24
25
  import {DocutilsError} from './error';
25
26
  import {getLogger} from './logger';
26
27
  import {MkDocsYml} from './model';
28
+ import { exec } from 'teen_process';
27
29
 
28
30
  const log = getLogger('fs');
29
31
 
@@ -228,6 +230,34 @@ const whichPython3 = _.partial(cachedWhich, `${NAME_PYTHON}3`, {nothrow: true});
228
230
  */
229
231
  const whichTypeDoc = _.partial(cachedWhich, NAME_TYPEDOC, {nothrow: true});
230
232
 
233
+ /**
234
+ * `mike` cannot be invoked via `python -m`, so we need to find the script.
235
+ */
236
+ export const findMike = _.partial(async () => {
237
+ // see if it's in PATH
238
+ let mikePath = await cachedWhich(NAME_MIKE, {nothrow: true});
239
+ if (mikePath) {
240
+ return mikePath;
241
+ }
242
+ // if it isn't, it may be in a user dir
243
+ const pythonPath = await findPython();
244
+ if (!pythonPath) {
245
+ return;
246
+ }
247
+ try {
248
+ // the user dir can be found this way.
249
+ // usually it's something like ~/.local
250
+ const {stdout} = await exec(pythonPath, ['-m', 'site', '--user-base']);
251
+ if (stdout) {
252
+ mikePath = path.join(stdout.trim(), 'bin', 'mike');
253
+ if (await fs.isExecutable(mikePath)) {
254
+ return mikePath;
255
+ }
256
+ }
257
+ }
258
+ catch {}
259
+ });
260
+
231
261
  /**
232
262
  * Finds the `typedoc` executable.
233
263
  *
package/lib/init.ts CHANGED
@@ -11,10 +11,11 @@ import {
11
11
  NAME_PYTHON,
12
12
  REQUIREMENTS_TXT_PATH,
13
13
  NAME_TYPEDOC_JSON,
14
+ NAME_PACKAGE_JSON,
14
15
  } from './constants';
15
16
  import YAML from 'yaml';
16
17
  import {exec} from 'teen_process';
17
- import {Simplify} from 'type-fest';
18
+ import {PackageJson, Simplify} from 'type-fest';
18
19
  import {DocutilsError} from './error';
19
20
  import {createScaffoldTask, ScaffoldTaskOptions} from './scaffold';
20
21
  import {getLogger} from './logger';
@@ -54,9 +55,19 @@ const BASE_TSCONFIG_JSON: Readonly<TsConfigJson> = Object.freeze({
54
55
  },
55
56
  });
56
57
 
58
+ /**
59
+ * Data for the base `package.json` file.
60
+ * We expect `package.json` to exist, and we are not in the business of creating it.
61
+ * However, we will need to add a `typedoc.entryPoint` prop to it.
62
+ */
63
+ const BASE_PACKAGE_JSON: Readonly<PackageJson> = Object.freeze({});
64
+
57
65
  const log = getLogger('init');
58
66
  const dryRunLog = getLogger('dry-run', log);
59
67
 
68
+ /**
69
+ * Files included, by default, in `tsconfig.json`
70
+ */
60
71
  const DEFAULT_INCLUDE = ['lib', 'test', 'index.js'];
61
72
  /**
62
73
  * Function which scaffolds a `tsconfig.json` file
@@ -97,6 +108,26 @@ export const initTypeDocJson = createScaffoldTask<InitTypeDocOptions, TypeDocJso
97
108
  'TypeDoc configuration'
98
109
  );
99
110
 
111
+ /**
112
+ * Function which scaffolds a `package.json` file
113
+ *
114
+ * This only amends prop `typedoc.entryPoint` to the `package.json` file.
115
+ *
116
+ * If, strangely, `package.json` did not exist, then it will now contain _only_ that prop.
117
+ */
118
+ export const initTypeDocPkgJson = createScaffoldTask<InitTypeDocOptions, PackageJson>(
119
+ NAME_PACKAGE_JSON,
120
+ BASE_PACKAGE_JSON,
121
+ 'Package configuration for TypeDoc',
122
+ {
123
+ transform: (content, opts) =>
124
+ ({
125
+ ...content,
126
+ typedoc: {entryPoint: opts.typeDocEntryPoint},
127
+ } as PackageJson),
128
+ }
129
+ );
130
+
100
131
  /**
101
132
  * Function which scaffolds an `mkdocs.yml` file
102
133
  */
@@ -224,6 +255,7 @@ export async function init({
224
255
  pythonPath,
225
256
  upgrade,
226
257
  typedocJson: typeDocJsonPath,
258
+ entryPoint: typeDocEntryPoint,
227
259
  }: InitOptions = {}): Promise<void> {
228
260
  if (!typescript && typedoc) {
229
261
  log.warn(
@@ -250,6 +282,13 @@ export async function init({
250
282
  dryRun,
251
283
  cwd,
252
284
  });
285
+ await initTypeDocPkgJson({
286
+ packageJson: packageJsonPath,
287
+ overwrite: true, // <-- always overwrite
288
+ dryRun,
289
+ cwd,
290
+ typeDocEntryPoint,
291
+ });
253
292
  }
254
293
 
255
294
  if (python) {
@@ -271,7 +310,10 @@ export async function init({
271
310
  }
272
311
  }
273
312
 
274
- export type InitTypeDocOptions = ScaffoldTaskOptions;
313
+ export interface InitTypeDocOptions extends ScaffoldTaskOptions {
314
+ typeDocEntryPoint?: string;
315
+ }
316
+
275
317
  export interface InitTsConfigOptions extends ScaffoldTaskOptions {
276
318
  /**
277
319
  * List of source files (globs supported); typically `src` or `lib`
@@ -334,5 +376,10 @@ export type InitOptions = Simplify<
334
376
  * If `true`, upgrade only
335
377
  */
336
378
  upgrade?: boolean;
379
+
380
+ /**
381
+ * Path to entry point of extension (source; not "main" field)
382
+ */
383
+ entryPoint?: string;
337
384
  }
338
385
  >;
package/lib/scaffold.ts CHANGED
@@ -92,6 +92,7 @@ export function createScaffoldTask<Opts extends ScaffoldTaskOptions, T extends J
92
92
  const relativeDest = relativePath(dest);
93
93
  log.debug('Initializing %s', relativeDest);
94
94
  let shouldWriteDest = false;
95
+ let isNew = false;
95
96
  let destContent: T;
96
97
  let result: ScaffoldTaskResult<T>;
97
98
  try {
@@ -105,6 +106,7 @@ export function createScaffoldTask<Opts extends ScaffoldTaskOptions, T extends J
105
106
  shouldWriteDest = true;
106
107
  log.debug('Creating new file %s', relativeDest);
107
108
  destContent = {} as T;
109
+ isNew = true;
108
110
  }
109
111
 
110
112
  const defaults: T = transform(defaultContent, opts, pkg);
@@ -113,7 +115,7 @@ export function createScaffoldTask<Opts extends ScaffoldTaskOptions, T extends J
113
115
  shouldWriteDest = shouldWriteDest || !_.isEqual(destContent, finalDestContent);
114
116
 
115
117
  if (shouldWriteDest) {
116
- log.info('Changes needed to %s', relativeDest);
118
+ log.info('Changes needed in %s', relativeDest);
117
119
  log.debug('Original %s: %O', relativeDest, destContent);
118
120
  log.debug('Final %s: %O', relativeDest, finalDestContent);
119
121
  const patch = makePatch(dest, destContent, finalDestContent, serialize);
@@ -126,6 +128,11 @@ export function createScaffoldTask<Opts extends ScaffoldTaskOptions, T extends J
126
128
 
127
129
  try {
128
130
  await safeWriteFile(dest, finalDestContent, overwrite);
131
+ if (isNew) {
132
+ log.success('Initialized %s', description);
133
+ } else {
134
+ log.success('Updated %s', description);
135
+ }
129
136
  } catch (e) {
130
137
  const err = e as NodeJS.ErrnoException;
131
138
  // this should only be thrown if `force` is false
@@ -139,9 +146,9 @@ export function createScaffoldTask<Opts extends ScaffoldTaskOptions, T extends J
139
146
  }
140
147
  }
141
148
  } else {
142
- log.info('No changes to %s', relativeDest);
149
+ log.info('No changes necessary for %s', relativeDest);
143
150
  }
144
- log.success('Initialized %s', description);
151
+ log.success(`${description}: done`);
145
152
  return {path: dest, content: finalDestContent};
146
153
  };
147
154
  }
@@ -153,7 +160,7 @@ export function createScaffoldTask<Opts extends ScaffoldTaskOptions, T extends J
153
160
  export type ScaffoldTaskTransformer<Opts extends ScaffoldTaskOptions, T extends JsonValue> = (
154
161
  content: Readonly<T>,
155
162
  opts: TaskSpecificOpts<Opts>,
156
- pkg: NormalizedPackageJson
163
+ pkg: Readonly<NormalizedPackageJson>
157
164
  ) => T;
158
165
 
159
166
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appium/docutils",
3
- "version": "0.3.13",
3
+ "version": "0.4.1",
4
4
  "description": "Documentation generation utilities for Appium and related projects",
5
5
  "keywords": [
6
6
  "automation",
@@ -49,9 +49,9 @@
49
49
  "start": "node ./build/lib/cli/index.js"
50
50
  },
51
51
  "dependencies": {
52
- "@appium/support": "^4.0.1",
52
+ "@appium/support": "^4.0.3",
53
53
  "@appium/tsconfig": "^0.3.0",
54
- "@appium/typedoc-plugin-appium": "^0.6.4",
54
+ "@appium/typedoc-plugin-appium": "^0.6.5",
55
55
  "@sliphua/lilconfig-ts-loader": "3.2.2",
56
56
  "@types/which": "3.0.0",
57
57
  "chalk": "4.1.2",
@@ -65,15 +65,15 @@
65
65
  "log-symbols": "4.1.0",
66
66
  "pkg-dir": "5.0.0",
67
67
  "read-pkg": "5.2.0",
68
- "semver": "7.5.0",
68
+ "semver": "7.5.1",
69
69
  "source-map-support": "0.5.21",
70
70
  "teen_process": "2.0.2",
71
- "type-fest": "3.10.0",
71
+ "type-fest": "3.11.1",
72
72
  "typedoc": "0.23.28",
73
73
  "typedoc-plugin-markdown": "3.14.0",
74
74
  "typedoc-plugin-resolve-crossmodule-references": "0.3.3",
75
75
  "typescript": "4.9.5",
76
- "yaml": "2.2.2",
76
+ "yaml": "2.3.1",
77
77
  "yargs": "17.7.2",
78
78
  "yargs-parser": "21.1.1"
79
79
  },
@@ -84,5 +84,5 @@
84
84
  "publishConfig": {
85
85
  "access": "public"
86
86
  },
87
- "gitHead": "922725b4f12c579ebf4afbd00e6e8b5eb7ed9016"
87
+ "gitHead": "af066eb5c3542338eec821b81d6aa4bcf2d81188"
88
88
  }
package/requirements.txt CHANGED
@@ -1,4 +1,4 @@
1
1
  mkdocs==1.4.3
2
- mkdocs-material==9.1.9
2
+ mkdocs-material==9.1.15
3
3
  mkdocs-material-extensions==1.1.1
4
4
  mike==1.1.2