@@ -20,12 +20,12 @@ export interface DocsCacheDefaults {
2020 mode : CacheMode ;
2121 include : string [ ] ;
2222 targetMode ?: "symlink" | "copy" ;
23- depth : number ;
2423 required : boolean ;
2524 maxBytes : number ;
2625 maxFiles ?: number ;
2726 allowHosts : string [ ] ;
2827 toc ?: boolean | TocFormat ;
28+ unwrapSingleRootDir ?: boolean ;
2929}
3030
3131export interface DocsCacheSource {
@@ -35,14 +35,14 @@ export interface DocsCacheSource {
3535 targetMode ?: "symlink" | "copy" ;
3636 ref ?: string ;
3737 mode ?: CacheMode ;
38- depth ?: number ;
3938 include ?: string [ ] ;
4039 exclude ?: string [ ] ;
4140 required ?: boolean ;
4241 maxBytes ?: number ;
4342 maxFiles ?: number ;
4443 integrity ?: DocsCacheIntegrity ;
4544 toc ?: boolean | TocFormat ;
45+ unwrapSingleRootDir ?: boolean ;
4646}
4747
4848export interface DocsCacheConfig {
@@ -60,14 +60,14 @@ export interface DocsCacheResolvedSource {
6060 targetMode ?: "symlink" | "copy" ;
6161 ref : string ;
6262 mode : CacheMode ;
63- depth : number ;
6463 include ?: string [ ] ;
6564 exclude ?: string [ ] ;
6665 required : boolean ;
6766 maxBytes : number ;
6867 maxFiles ?: number ;
6968 integrity ?: DocsCacheIntegrity ;
7069 toc ?: boolean | TocFormat ;
70+ unwrapSingleRootDir ?: boolean ;
7171}
7272
7373export const DEFAULT_CONFIG_FILENAME = "docs.config.json" ;
@@ -81,11 +81,11 @@ export const DEFAULT_CONFIG: DocsCacheConfig = {
8181 mode : "materialize" ,
8282 include : [ "**/*.{md,mdx,markdown,mkd,txt,rst,adoc,asciidoc}" ] ,
8383 targetMode : DEFAULT_TARGET_MODE ,
84- depth : 1 ,
8584 required : true ,
8685 maxBytes : 200000000 ,
8786 allowHosts : [ "github.com" , "gitlab.com" ] ,
8887 toc : true ,
88+ unwrapSingleRootDir : false ,
8989 } ,
9090 sources : [ ] ,
9191} ;
@@ -246,15 +246,16 @@ export const validateConfig = (input: unknown): DocsCacheConfig => {
246246 . join ( "; " ) ;
247247 throw new Error ( `Config does not match schema: ${ details } .` ) ;
248248 }
249+ const configInput = parsed . data ;
249250
250- const cacheDir = input . cacheDir
251- ? assertString ( input . cacheDir , "cacheDir" )
251+ const cacheDir = configInput . cacheDir
252+ ? assertString ( configInput . cacheDir , "cacheDir" )
252253 : DEFAULT_CACHE_DIR ;
253254
254- const defaultsInput = input . defaults ;
255+ const defaultsInput = configInput . defaults ;
255256 const targetModeOverride =
256- input . targetMode !== undefined
257- ? assertTargetMode ( input . targetMode , "targetMode" )
257+ configInput . targetMode !== undefined
258+ ? assertTargetMode ( configInput . targetMode , "targetMode" )
258259 : undefined ;
259260 const defaultValues = DEFAULT_CONFIG . defaults as DocsCacheDefaults ;
260261 let defaults : DocsCacheDefaults = defaultValues ;
@@ -280,10 +281,6 @@ export const validateConfig = (input: unknown): DocsCacheConfig => {
280281 defaultsInput . targetMode !== undefined
281282 ? assertTargetMode ( defaultsInput . targetMode , "defaults.targetMode" )
282283 : ( targetModeOverride ?? defaultValues . targetMode ) ,
283- depth :
284- defaultsInput . depth !== undefined
285- ? assertPositiveNumber ( defaultsInput . depth , "defaults.depth" )
286- : defaultValues . depth ,
287284 required :
288285 defaultsInput . required !== undefined
289286 ? assertBoolean ( defaultsInput . required , "defaults.required" )
@@ -304,6 +301,13 @@ export const validateConfig = (input: unknown): DocsCacheConfig => {
304301 defaultsInput . toc !== undefined
305302 ? ( defaultsInput . toc as boolean | TocFormat )
306303 : defaultValues . toc ,
304+ unwrapSingleRootDir :
305+ defaultsInput . unwrapSingleRootDir !== undefined
306+ ? assertBoolean (
307+ defaultsInput . unwrapSingleRootDir ,
308+ "defaults.unwrapSingleRootDir" ,
309+ )
310+ : defaultValues . unwrapSingleRootDir ,
307311 } ;
308312 } else if ( targetModeOverride !== undefined ) {
309313 defaults = {
@@ -312,11 +316,7 @@ export const validateConfig = (input: unknown): DocsCacheConfig => {
312316 } ;
313317 }
314318
315- if ( ! Array . isArray ( input . sources ) ) {
316- throw new Error ( "sources must be an array." ) ;
317- }
318-
319- const sources = input . sources . map ( ( entry , index ) => {
319+ const sources = configInput . sources . map ( ( entry , index ) => {
320320 if ( ! isRecord ( entry ) ) {
321321 throw new Error ( `sources[${ index } ] must be an object.` ) ;
322322 }
@@ -348,12 +348,6 @@ export const validateConfig = (input: unknown): DocsCacheConfig => {
348348 if ( entry . mode !== undefined ) {
349349 source . mode = assertMode ( entry . mode , `sources[${ index } ].mode` ) ;
350350 }
351- if ( entry . depth !== undefined ) {
352- source . depth = assertPositiveNumber (
353- entry . depth ,
354- `sources[${ index } ].depth` ,
355- ) ;
356- }
357351 if ( entry . include !== undefined ) {
358352 source . include = assertStringArray (
359353 entry . include ,
@@ -394,6 +388,12 @@ export const validateConfig = (input: unknown): DocsCacheConfig => {
394388 if ( entry . toc !== undefined ) {
395389 source . toc = entry . toc as boolean | TocFormat ;
396390 }
391+ if ( entry . unwrapSingleRootDir !== undefined ) {
392+ source . unwrapSingleRootDir = assertBoolean (
393+ entry . unwrapSingleRootDir ,
394+ `sources[${ index } ].unwrapSingleRootDir` ,
395+ ) ;
396+ }
397397
398398 return source ;
399399 } ) ;
@@ -433,14 +433,15 @@ export const resolveSources = (
433433 targetMode : source . targetMode ?? defaults . targetMode ,
434434 ref : source . ref ?? defaults . ref ,
435435 mode : source . mode ?? defaults . mode ,
436- depth : source . depth ?? defaults . depth ,
437436 include : source . include ?? defaults . include ,
438437 exclude : source . exclude ,
439438 required : source . required ?? defaults . required ,
440439 maxBytes : source . maxBytes ?? defaults . maxBytes ,
441440 maxFiles : source . maxFiles ?? defaults . maxFiles ,
442441 integrity : source . integrity ,
443442 toc : source . toc ?? defaults . toc ,
443+ unwrapSingleRootDir :
444+ source . unwrapSingleRootDir ?? defaults . unwrapSingleRootDir ,
444445 } ) ) ;
445446} ;
446447
0 commit comments