@@ -3,31 +3,35 @@ import fse from 'fs-extra';
33import fg from 'fast-glob' ;
44
55const defaultOptions = {
6+ flat : false ,
67 cwd : process . cwd ( ) ,
78} ;
89
9- const destPath = ( pattern , file , cwd ) => {
10+ const destPath = ( pattern , file , options = defaultOptions ) => {
11+ if ( options . flat ) {
12+ return path . posix . basename ( file ) ;
13+ }
14+
1015 const pathArr = pattern . split ( '/' ) ;
1116 const globIndex = pathArr . findIndex ( ( item ) => ( item ? fg . isDynamicPattern ( item ) : false ) ) ;
1217 const normalized = pathArr . slice ( 0 , globIndex ) . join ( '/' ) ;
1318
14- const absolutePath = path . isAbsolute ( normalized ) ? normalized : path . posix . join ( cwd , normalized ) ;
19+ const absolutePath = path . isAbsolute ( normalized ) ? normalized : path . posix . join ( options . cwd , normalized ) ;
1520
1621 return path . relative ( absolutePath , file ) ;
1722} ;
1823
19- const globCopy = async ( pattern , destination , options = defaultOptions ) => {
24+ const globCopy = async ( pattern , destination , options = defaultOptions , globOptions = { } ) => {
2025 await fse . ensureDir ( destination ) ;
2126
22- const matches = await fg ( pattern , { dot : true , absolute : true , cwd : options . cwd } ) ;
27+ const matches = await fg ( pattern , { dot : true , ... globOptions , absolute : true , cwd : options . cwd } ) ;
2328
2429 const entries = matches . map ( ( file ) => {
2530 const destDir = path . isAbsolute ( destination ) ? destination : path . posix . join ( options . cwd , destination ) ;
26- const destFileName = destPath ( pattern , file , options . cwd ) ;
31+ const destFileName = destPath ( pattern , file , options ) ;
2732
2833 return {
2934 from : file ,
30-
3135 destDir,
3236 destFileName,
3337 to : path . posix . join ( destDir , destFileName ) ,
0 commit comments