@@ -28,8 +28,7 @@ const pAll = async (obj) => {
28
28
} , { } )
29
29
}
30
30
31
- const run = async ( params ) => {
32
- const { content, template, nav, man, html, md } = params
31
+ const run = async ( { content, template, nav, man, html, md } ) => {
33
32
await rmAll ( man , html , md )
34
33
const [ contentPaths , navFile , options ] = await Promise . all ( [
35
34
readDocs ( content ) ,
@@ -92,37 +91,47 @@ const run = async (params) => {
92
91
...( fullName === 'using-npm/config'
93
92
? [ transform . shorthands , transform . config ]
94
93
: [ ] ) ,
95
- ] ) ;
96
-
97
- [ 'man' , 'html' , 'md' ] . forEach ( ( type ) => {
98
- const isMan = type === 'man'
99
- const DUPLICATED_FOLDER_PATH = 'configuring-npm/'
100
- const FOLDER_PREFIX = isMan ? '' : DUPLICATED_FOLDER_PATH
101
- const trs = [ transform [ type ] ]
102
-
103
- let paths = [
104
- isMan ? name : fullName ,
105
- fullName === `${ DUPLICATED_FOLDER_PATH } package-json` && `${ FOLDER_PREFIX } npm-json` ,
106
- fullName === `${ DUPLICATED_FOLDER_PATH } folders` && `${ FOLDER_PREFIX } npm-global` ,
107
- ] . filter ( Boolean )
108
-
109
- if ( isMan && data . section ) {
110
- paths = paths . map ( p => applyTransforms ( p , [ transform . manPath ] ) )
111
- trs . unshift ( transform . helpLinks )
112
- const manSrc = applyTransforms ( transformedSrc , trs )
113
- acc . man . push ( ...paths . map ( ( manPath ) => ( {
94
+ ] )
95
+
96
+ const aliases = [
97
+ fullName === 'configuring-npm/package-json' && 'configuring-npm/npm-json' ,
98
+ fullName === 'configuring-npm/folders' && 'configuring-npm/npm-global' ,
99
+ ] . filter ( Boolean )
100
+
101
+ if ( data . section ) {
102
+ const manSource = applyTransforms ( transformedSrc , [
103
+ transform . helpLinks ,
104
+ transform . man ,
105
+ ] )
106
+ // Man page aliases are only the basename since the man pages have no hierarchy
107
+ acc . man . push ( ...[ name , ...aliases . map ( a => basename ( a ) ) ]
108
+ . map ( ( p ) => applyTransforms ( p , [ transform . manPath ] ) )
109
+ . map ( ( manPath ) => ( {
114
110
path : manPath ,
115
111
fullPath : join ( man , manPath ) ,
116
- src : manSrc ,
117
- } ) ) )
118
- } else {
119
- acc [ type ] . push ( ...paths . map ( ( path ) => ( {
120
- path : `${ path } .${ type } ` ,
121
- fullPath : join ( params [ type ] , `${ path } .${ type } ` ) ,
122
- src : applyTransforms ( transformedSrc , trs ) ,
123
- } ) ) )
124
- }
112
+ src : manSource ,
113
+ } ) )
114
+ )
115
+ }
116
+
117
+ // html docs are used for npm help on Windows
118
+ const htmlSource = applyTransforms ( transformedSrc , [ transform . html ] )
119
+ acc . html . push ( ...[ fullName , ...aliases ] . map ( ( htmlPath ) => ( {
120
+ path : `${ htmlPath } .html` ,
121
+ fullPath : join ( html , `${ htmlPath } .html` ) ,
122
+ src : htmlSource ,
123
+ } ) ) )
124
+
125
+ // Markdown pages don't get aliases here. These are used to build the website so any redirects
126
+ // for these pages are applied in npm/documentation. Not ideal but there are also many more
127
+ // redirects that we would never apply to man or html docs pages
128
+ const mdSource = applyTransforms ( transformedSrc , [ transform . md ] )
129
+ acc . md . push ( {
130
+ path : childPath ,
131
+ fullPath : join ( md , childPath ) ,
132
+ src : mdSource ,
125
133
} )
134
+
126
135
return acc
127
136
} , { man : [ ] , html : [ ] , md : [ ] } )
128
137
0 commit comments