@@ -41,15 +41,23 @@ const DesignDocumentSchema = Type.Object({
4141
4242type DesignDocument = Static < typeof DesignDocumentSchema >
4343
44- export default async function ( src : string , opts : { destination : string ; format : string } ) {
44+ export default async function (
45+ src : string ,
46+ opts : { destination : string ; format : string ; noVerbose ?: boolean } ,
47+ ) {
4548 const methods = new Map < string , string > ( )
4649 try {
4750 if ( ! FORMATS . includes ( opts . format ) ) {
4851 throw Error ( `Wrong destination format provided ${ opts . format } , must be one of ${ FORMATS } ` )
4952 }
5053 const srcPath = path . resolve ( src )
5154 const dbBackup = ( await readFIle ( srcPath ) ) . toString ( )
52- console . log ( `> ${ chalk . bgBlueBright ( chalk . black ( ' ddoc extract src ' ) ) } ${ chalk . cyan ( srcPath ) } ` )
55+
56+ if ( ! opts . noVerbose ) {
57+ console . log (
58+ `> ${ chalk . bgBlueBright ( chalk . black ( ' ddoc extract src ' ) ) } ${ chalk . cyan ( srcPath ) } ` ,
59+ )
60+ }
5361
5462 const main = JSON . parse ( dbBackup . replace ( / \] \n \[ / g, ',' ) ) as any [ ]
5563 const designDocuments = main . filter ( doc => doc . _id . startsWith ( '_design/' ) ) as DesignDocument [ ]
@@ -78,13 +86,17 @@ export default async function(src: string, opts: { destination: string; format:
7886 const filename = `${ path . basename ( src , path . extname ( src ) ) } -designs.${ opts . format } `
7987 const dest = path . resolve ( path . join ( opts . destination , filename ) )
8088
81- console . log ( `> ${ chalk . bgBlueBright ( chalk . black ( ' ddoc extract designs found ' ) ) } ` )
82- console . table ( stats )
89+ if ( ! opts . noVerbose ) {
90+ console . log ( `> ${ chalk . bgBlueBright ( chalk . black ( ' ddoc extract designs found ' ) ) } ` )
91+ console . table ( stats )
92+ }
8393 await mkdirp ( path . dirname ( dest ) )
8494
85- console . log (
86- `> ${ chalk . bgGreenBright ( chalk . black ( ' ddoc extract destination ' ) ) } ${ chalk . cyan ( dest ) } ` ,
87- )
95+ if ( ! opts . noVerbose ) {
96+ console . log (
97+ `> ${ chalk . bgGreenBright ( chalk . black ( ' ddoc extract destination ' ) ) } ${ chalk . cyan ( dest ) } ` ,
98+ )
99+ }
88100
89101 await writeFile ( dest , JSON . stringify ( designDocuments , null , 1 ) )
90102 } else {
@@ -153,11 +165,13 @@ export default async function(src: string, opts: { destination: string; format:
153165 }
154166 }
155167
156- console . log (
157- `> ${ chalk . bgBlueBright (
158- chalk . black ( ' ddoc extract designs creating destination folder ' ) ,
159- ) } `,
160- )
168+ if ( ! opts . noVerbose ) {
169+ console . log (
170+ `> ${ chalk . bgBlueBright (
171+ chalk . black ( ' ddoc extract designs creating destination folder ' ) ,
172+ ) } `,
173+ )
174+ }
161175
162176 const destFolder = path . resolve (
163177 path . join ( opts . destination , `${ path . basename ( src , path . extname ( src ) ) } -designs` ) ,
@@ -169,9 +183,12 @@ export default async function(src: string, opts: { destination: string; format:
169183 const filename = `${ doc . _id ?. split ( '_design/' ) [ 1 ] } -${ doc . _rev } .${
170184 opts . format === 'js' ? 'js' : 'ts'
171185 } `
172- console . log (
173- `> ${ chalk . bgBlueBright ( chalk . black ( ` ddoc extract designs creating ${ filename } ` ) ) } ` ,
174- )
186+
187+ if ( ! opts . noVerbose ) {
188+ console . log (
189+ `> ${ chalk . bgBlueBright ( chalk . black ( ` ddoc extract designs creating ${ filename } ` ) ) } ` ,
190+ )
191+ }
175192 const dest = path . resolve ( path . join ( destFolder , filename ) )
176193
177194 let docString =
@@ -185,8 +202,10 @@ export default async function(src: string, opts: { destination: string; format:
185202 await writeFile ( dest , docString )
186203 }
187204
188- console . log ( `> ${ chalk . bgGreenBright ( chalk . black ( ' ddoc extract designs done ' ) ) } ` )
189- console . table ( stats )
205+ if ( ! opts . noVerbose ) {
206+ console . log ( `> ${ chalk . bgGreenBright ( chalk . black ( ' ddoc extract designs done ' ) ) } ` )
207+ console . table ( stats )
208+ }
190209 }
191210 } catch ( err ) {
192211 console . error ( chalk . bgRed ( chalk . white ( ` ${ err . message } ` ) ) )
0 commit comments