@satisfactory-dev/docdown 0.1.0 → 0.1.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/bin-lib/help.js +21 -0
- package/bin-lib/options.js +58 -0
- package/package.json +2 -1
package/bin-lib/help.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates the help text for the docdown cli tool
|
|
3
|
+
*
|
|
4
|
+
* @return {string} The help text for the docdown cli tool
|
|
5
|
+
*/
|
|
6
|
+
function help() {
|
|
7
|
+
return [
|
|
8
|
+
'Usage:',
|
|
9
|
+
' docdown inputFile.js outputFile.md [options]',
|
|
10
|
+
'Options:',
|
|
11
|
+
' lang="js" The language indicator for code blocks.',
|
|
12
|
+
' sort=true|false Specify whether entries are sorted.',
|
|
13
|
+
' style="default|github" The hash style for links.',
|
|
14
|
+
' title="title" The documentation title.',
|
|
15
|
+
' toc="categories|properties" The table of contents organization style.',
|
|
16
|
+
' url="url" The source URL.',
|
|
17
|
+
' --force Force the docs to be written to if writing would only leave commit hash-related changes',
|
|
18
|
+
].join('\n');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export default help;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* docdown
|
|
3
|
+
* Copyright 2011-2016 John-David Dalton
|
|
4
|
+
* Copyright 2026 SignpostMarv
|
|
5
|
+
* Available under MIT license
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/*----------------------------------------------------------------------------*/
|
|
9
|
+
|
|
10
|
+
/** @typedef {'lang'|'sort'|'style'|'title'|'toc'|'url'|'--force'} OptionName */
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Wraps functions in a context provider to enable testing without relying on process.argv
|
|
14
|
+
*
|
|
15
|
+
* @param {string[]} context
|
|
16
|
+
*/
|
|
17
|
+
function fromContext(context) {
|
|
18
|
+
/**
|
|
19
|
+
* Gets the value for the given option name. If no value is available the
|
|
20
|
+
* `defaultValue` is returned.
|
|
21
|
+
*
|
|
22
|
+
* @param {OptionName} name The name of the option.
|
|
23
|
+
* @param {string|boolean|undefined} defaultValue The default option value.
|
|
24
|
+
* @returns {string|boolean|undefined} Returns the option value.
|
|
25
|
+
*/
|
|
26
|
+
function getOption(name, defaultValue) {
|
|
27
|
+
return context.reduce(function(result, value) {
|
|
28
|
+
value = optionToValue(name, value);
|
|
29
|
+
|
|
30
|
+
return value == null ? result : value;
|
|
31
|
+
}, defaultValue);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return getOption;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Extracts the option value from an option string.
|
|
39
|
+
*
|
|
40
|
+
* @param {OptionName} name The name of the option to inspect.
|
|
41
|
+
* @param {string} string The options string.
|
|
42
|
+
* @returns {string|boolean|undefined} Returns the option value, else `undefined`.
|
|
43
|
+
*/
|
|
44
|
+
function optionToValue(name, string) {
|
|
45
|
+
/** @type {string|undefined} */
|
|
46
|
+
let result = undefined;
|
|
47
|
+
const match = string.match(RegExp('^' + name + '(?:=([\\s\\S]+))?$'));
|
|
48
|
+
if (match) {
|
|
49
|
+
[, result] = match;
|
|
50
|
+
result = result ? result.trim() : true;
|
|
51
|
+
}
|
|
52
|
+
if (result === 'false') {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
return result || undefined;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export default fromContext;
|