@@ -100,4 +100,57 @@ async function generateDocs(forDevsite: boolean = false) {
100
100
[ command , 'markdown' , '--input' , 'temp' , '--output' , outputFolder ] ,
101
101
{ stdio : 'inherit' }
102
102
) ;
103
+
104
+ moveRulesUnitTestingDocs ( outputFolder , command ) ;
105
+ }
106
+
107
+ async function moveRulesUnitTestingDocs (
108
+ mainDocsFolder : string ,
109
+ command : string
110
+ ) {
111
+ const rulesOutputFolder = `${ projectRoot } /docs-rut` ;
112
+
113
+ // Generate from rules-unit-testing.api.json only, to get an index.md.
114
+ // Hide output warnings about being unable to link to external packages.
115
+ await spawn (
116
+ 'yarn' ,
117
+ [
118
+ command ,
119
+ 'markdown' ,
120
+ '--input' ,
121
+ 'packages/rules-unit-testing/temp' ,
122
+ '--output' ,
123
+ rulesOutputFolder
124
+ ] ,
125
+ { stdio : [ 'inherit' , 'ignore' , 'inherit' ] }
126
+ ) ;
127
+
128
+ const rulesDocPaths = await new Promise < string [ ] > ( resolve =>
129
+ glob ( `${ mainDocsFolder } /rules-unit-testing.*` , ( err , paths ) => {
130
+ if ( err ) throw err ;
131
+ resolve ( paths ) ;
132
+ } )
133
+ ) ;
134
+
135
+ // Overwrite non-index files with files generated from global docgen script,
136
+ // which have links to external packages.
137
+ // These paths also need to be adjusted to point to a sibling directory.
138
+ for ( const sourcePath of rulesDocPaths ) {
139
+ const destinationPath = sourcePath . replace (
140
+ mainDocsFolder ,
141
+ rulesOutputFolder
142
+ ) ;
143
+ const originalText = fs . readFileSync ( sourcePath , 'utf-8' ) ;
144
+ let alteredPathText = originalText . replace (
145
+ / \. \/ d a t a b a s e / g,
146
+ '../js/database'
147
+ ) ;
148
+ alteredPathText = alteredPathText . replace ( / \. \/ s t o r a g e / g, '../js/storage' ) ;
149
+ alteredPathText = alteredPathText . replace (
150
+ / \. \/ f i r e s t o r e / g,
151
+ '../js/firestore'
152
+ ) ;
153
+ fs . writeFileSync ( destinationPath , alteredPathText ) ;
154
+ fs . unlinkSync ( sourcePath ) ;
155
+ }
103
156
}
0 commit comments