1
1
const marked = require ( 'marked-man' )
2
2
const { join } = require ( 'path' )
3
- const TAGS = require ( './tags' )
4
3
const NPM = require ( './npm.js' )
5
4
const transformHTML = require ( './transform-html.js' )
6
5
6
+ const TAGS = {
7
+ CONFIG : '<!-- AUTOGENERATED CONFIG DESCRIPTIONS -->' ,
8
+ USAGE : '<!-- AUTOGENERATED USAGE DESCRIPTIONS -->' ,
9
+ SHORTHANDS : '<!-- AUTOGENERATED CONFIG SHORTHANDS -->' ,
10
+ }
11
+
7
12
const assertPlaceholder = ( src , path , type ) => {
8
- const placeholder = TAGS [ type ] . REPLACE
13
+ const placeholder = TAGS [ type ]
9
14
if ( ! src . includes ( placeholder ) ) {
10
15
throw new Error (
11
16
`Cannot replace ${ type } in ${ path } due to missing placeholder`
@@ -20,15 +25,9 @@ const removePlaceholders = (src) => src.replace(/^<!--.*-->$/gm, '')
20
25
21
26
const replaceUsage = ( src , { path, docExt } ) => {
22
27
const replacer = assertPlaceholder ( src , path , 'USAGE' )
23
- const { usage, name, srcName } = NPM . getCommandByDoc ( path , docExt )
28
+ const { usage, name } = NPM . getCommandByDoc ( path , docExt )
24
29
25
- const synopsis = [
26
- TAGS . USAGE . START ,
27
- TAGS . USAGE . SEP ( srcName ) ,
28
- '' ,
29
- '```bash' ,
30
- usage ,
31
- ]
30
+ const synopsis = [ '```bash' , usage ]
32
31
33
32
const cmdAliases = Object . keys ( NPM . aliases ) . reduce ( ( p , c ) => {
34
33
if ( NPM . aliases [ c ] === name ) {
@@ -45,7 +44,7 @@ const replaceUsage = (src, { path, docExt }) => {
45
44
synopsis . push ( `aliases: ${ cmdAliases . join ( ', ' ) } ` )
46
45
}
47
46
48
- synopsis . push ( '```' , '' , TAGS . USAGE . SEP ( srcName ) , '' , TAGS . USAGE . END )
47
+ synopsis . push ( '```' )
49
48
50
49
return src . replace ( replacer , synopsis . join ( '\n' ) )
51
50
}
@@ -58,38 +57,18 @@ const replaceParams = (src, { path, docExt }) => {
58
57
return src
59
58
}
60
59
61
- const config = [
62
- TAGS . CONFIG . START ,
63
- TAGS . CONFIG . SEP ( ) ,
64
- NPM . describeParams ( params ) . join ( '\n\n' + TAGS . CONFIG . SEP ( ) + '\n\n' ) ,
65
- '' ,
66
- TAGS . CONFIG . SEP ( ) ,
67
- '' ,
68
- TAGS . CONFIG . END ,
69
- ] . join ( '\n' )
70
-
71
- return src . replace ( replacer , config )
60
+ return src . replace ( replacer , NPM . describeParams ( params ) . join ( '\n\n' ) )
72
61
}
73
62
74
63
const replaceConfig = ( src , { path } ) => {
75
64
const replacer = assertPlaceholder ( src , path , 'CONFIG' )
76
-
77
- const config = [
78
- TAGS . CONFIG . START ,
79
- TAGS . CONFIG . SEP ( ) ,
80
- NPM . describeAll ( ) ,
81
- '' ,
82
- TAGS . CONFIG . SEP ( ) ,
83
- TAGS . CONFIG . END ,
84
- ] . join ( '\n' )
85
-
86
- return src . replace ( replacer , config )
65
+ return src . replace ( replacer , NPM . describeAll ( ) )
87
66
}
88
67
89
68
const replaceShorthands = ( src , { path } ) => {
90
69
const replacer = assertPlaceholder ( src , path , 'SHORTHANDS' )
91
70
92
- const sh = Object . entries ( NPM . shorthands )
71
+ const shorthands = Object . entries ( NPM . shorthands )
93
72
. sort ( ( [ shorta , expansiona ] , [ shortb , expansionb ] ) => {
94
73
// sort by what they're short FOR
95
74
return expansiona . join ( ' ' ) . localeCompare ( expansionb . join ( ' ' ) , 'en' ) ||
@@ -98,16 +77,9 @@ const replaceShorthands = (src, { path }) => {
98
77
. map ( ( [ short , expansion ] ) => {
99
78
const dash = short . length === 1 ? '-' : '--'
100
79
return `* \`${ dash } ${ short } \`: \`${ expansion . join ( ' ' ) } \``
101
- } ) . join ( '\n' )
102
-
103
- return src . replace ( replacer , [
104
- TAGS . SHORTHANDS . START ,
105
- TAGS . SHORTHANDS . SEP ( ) ,
106
- sh ,
107
- '' ,
108
- TAGS . SHORTHANDS . SEP ( ) ,
109
- TAGS . SHORTHANDS . END ,
110
- ] . join ( '\n' ) )
80
+ } )
81
+
82
+ return src . replace ( replacer , shorthands . join ( '\n' ) )
111
83
}
112
84
113
85
const replaceHelpLinks = ( src ) => {
0 commit comments