@@ -6,7 +6,6 @@ const require = createRequire(import.meta.url);
66const componentDocsConfig = require ( '../component-docs.config' ) ;
77
88const rootDir = path . resolve ( path . dirname ( new URL ( import . meta. url ) . pathname ) , '..' ) ;
9- const versionedDocsDir = path . join ( rootDir , 'versioned_docs' ) ;
109const sourcePagesDir = path . join ( rootDir , 'src' , 'pages' ) ;
1110const staticDir = path . join ( rootDir , 'static' ) ;
1211const publicDir = path . join ( rootDir , 'public' ) ;
@@ -85,6 +84,8 @@ const copyFile = (sourcePath, targetPath, transform) => {
8584 fs . writeFileSync ( targetPath , transform ( source ) ) ;
8685} ;
8786
87+ const getVersionDocsDir = ( version ) => path . join ( rootDir , version , 'docs' ) ;
88+
8889const createNav = ( version ) => {
8990 const activePrefix =
9091 version === '6.x' ? '^/(?:6\\.x/)?docs' : '^/docs' ;
@@ -148,12 +149,7 @@ const getComponentChildOrder = (version, dirName) => {
148149 return Object . keys ( configEntry ) ;
149150 }
150151
151- const dirPath = path . join (
152- versionedDocsDir ,
153- `version-${ version } ` ,
154- 'components' ,
155- dirName
156- ) ;
152+ const dirPath = path . join ( getVersionDocsDir ( version ) , 'components' , dirName ) ;
157153
158154 return fs
159155 . readdirSync ( dirPath , { withFileTypes : true } )
@@ -162,71 +158,25 @@ const getComponentChildOrder = (version, dirName) => {
162158} ;
163159
164160const createGuidesMeta = ( version ) => {
165- const guidesDir = path . join ( versionedDocsDir , `version-${ version } ` , 'guides' ) ;
161+ const guidesDir = path . join ( getVersionDocsDir ( version ) , 'guides' ) ;
162+ const metaPath = path . join ( guidesDir , '_meta.json' ) ;
163+ const existingOrder = fs . existsSync ( metaPath )
164+ ? JSON . parse ( fs . readFileSync ( metaPath , 'utf8' ) )
165+ : [ ] ;
166166
167- return fs
167+ const currentEntries = fs
168168 . readdirSync ( guidesDir , { withFileTypes : true } )
169169 . filter ( ( entry ) => entry . isFile ( ) && / \. ( m d | m d x ) $ / . test ( entry . name ) )
170- . sort ( ( left , right ) => left . name . localeCompare ( right . name , undefined , { numeric : true } ) )
171170 . map ( ( entry ) => stripNumericPrefix ( entry . name ) ) ;
172- } ;
173-
174- const createComponentMeta = ( version ) => {
175- return getVersionComponentOrder ( version ) ;
176- } ;
177171
178- const copyGuides = ( version , targetVersionDir ) => {
179- const guidesDir = path . join ( versionedDocsDir , `version-${ version } ` , 'guides' ) ;
180- const targetGuidesDir = path . join ( targetVersionDir , 'docs' , 'guides' ) ;
172+ const knownEntries = existingOrder . filter ( ( entry ) => currentEntries . includes ( entry ) ) ;
173+ const newEntries = currentEntries . filter ( ( entry ) => ! existingOrder . includes ( entry ) ) ;
181174
182- for ( const entry of fs . readdirSync ( guidesDir , { withFileTypes : true } ) ) {
183- if ( ! entry . isFile ( ) || ! / \. ( m d | m d x ) $ / . test ( entry . name ) ) {
184- continue ;
185- }
186-
187- const sourcePath = path . join ( guidesDir , entry . name ) ;
188- const cleanName = `${ stripNumericPrefix ( entry . name ) } ${ path . extname ( entry . name ) } ` ;
189- copyFile ( sourcePath , path . join ( targetGuidesDir , cleanName ) , ( content ) =>
190- transformSharedContent ( content , version )
191- ) ;
192- }
175+ return [ ...knownEntries , ...newEntries ] ;
193176} ;
194177
195- const copyComponentDocs = ( version , targetVersionDir ) => {
196- const componentsDir = path . join (
197- versionedDocsDir ,
198- `version-${ version } ` ,
199- 'components'
200- ) ;
201- const targetComponentsDir = path . join ( targetVersionDir , 'docs' , 'components' ) ;
202-
203- const walk = ( sourceDir , outputDir ) => {
204- ensureDir ( outputDir ) ;
205-
206- for ( const entry of fs . readdirSync ( sourceDir , { withFileTypes : true } ) ) {
207- if ( entry . name === '_category_.json' ) {
208- continue ;
209- }
210-
211- const sourcePath = path . join ( sourceDir , entry . name ) ;
212- const targetPath = path . join ( outputDir , entry . name ) ;
213-
214- if ( entry . isDirectory ( ) ) {
215- walk ( sourcePath , targetPath ) ;
216- continue ;
217- }
218-
219- if ( ! / \. ( m d | m d x ) $ / . test ( entry . name ) ) {
220- continue ;
221- }
222-
223- copyFile ( sourcePath , targetPath , ( content ) =>
224- transformSharedContent ( content , version )
225- ) ;
226- }
227- } ;
228-
229- walk ( componentsDir , targetComponentsDir ) ;
178+ const createComponentMeta = ( version ) => {
179+ return getVersionComponentOrder ( version ) ;
230180} ;
231181
232182const writeMetaFiles = ( version , targetVersionDir ) => {
@@ -277,14 +227,6 @@ const writeIndexPage = (targetVersionDir) => {
277227 ) ;
278228} ;
279229
280- const writeShowcasePage = ( version , targetVersionDir ) => {
281- copyFile (
282- path . join ( versionedDocsDir , `version-${ version } ` , 'showcase.mdx' ) ,
283- path . join ( targetVersionDir , 'docs' , 'showcase.mdx' ) ,
284- ( content ) => transformSharedContent ( content , version )
285- ) ;
286- } ;
287-
288230const copyStaticAssets = ( ) => {
289231 fs . cpSync ( staticDir , publicDir , { recursive : true , force : true } ) ;
290232 fs . cpSync ( staticDir , path . join ( publicDir , 'react-native-paper' ) , {
@@ -295,14 +237,10 @@ const copyStaticAssets = () => {
295237
296238const prepareVersionDir = ( version ) => {
297239 const targetVersionDir = path . join ( rootDir , version ) ;
298- fs . rmSync ( targetVersionDir , { recursive : true , force : true } ) ;
299240 ensureDir ( targetVersionDir ) ;
300241
301242 writeJson ( path . join ( targetVersionDir , '_nav.json' ) , createNav ( version ) ) ;
302243 writeIndexPage ( targetVersionDir ) ;
303- writeShowcasePage ( version , targetVersionDir ) ;
304- copyGuides ( version , targetVersionDir ) ;
305- copyComponentDocs ( version , targetVersionDir ) ;
306244 writeMetaFiles ( version , targetVersionDir ) ;
307245} ;
308246
0 commit comments