@@ -41,8 +41,15 @@ export interface CopyFilesOptions {
4141 error ? : ( error :Error , { source, target} :{ source : string , target : string } ) => void | typeof ABORT // 复制出错的回调
4242 templateOptions ?: Record < string , any > | ( ( file : string ) => Record < string , any > | Promise < Record < string , any > > ) ;
4343}
44-
45- export async function copyFiles ( pattern : string , targetDir : string , options ?: CopyFilesOptions ) {
44+ /**
45+ * 拷贝满足条件的文件到目标文件夹
46+ *
47+ * @param pattern
48+ * @param targetDir
49+ * @param options
50+ * @returns 返回实际拷贝的文件列表
51+ */
52+ export async function copyFiles ( pattern : string , targetDir : string , options ?: CopyFilesOptions ) :Promise < string [ ] > {
4653
4754 const opts = assignObject ( {
4855 ignore : [ ] ,
@@ -62,8 +69,10 @@ export async function copyFiles( pattern: string, targetDir: string, options?: C
6269 if ( opts . clean ) {
6370 try { await cleanDir ( targetDir ) } catch { }
6471 }
72+
73+ const copyedFiles :string [ ] = [ ]
6574
66- return new Promise < void > ( ( resolve , reject ) => {
75+ return new Promise < string [ ] > ( ( resolve , reject ) => {
6776 glob ( pattern , {
6877 ignore,
6978 cwd :srcDir ,
@@ -92,6 +101,7 @@ export async function copyFiles( pattern: string, targetDir: string, options?: C
92101 }
93102 try {
94103 await copyFile ( fromFile , toFile , opts ) ;
104+ copyedFiles . push ( toFile )
95105 if ( typeof options ?. after == "function" ) {
96106 if ( options . after ( fileInfo ) === ABORT ) {
97107 break
@@ -105,7 +115,7 @@ export async function copyFiles( pattern: string, targetDir: string, options?: C
105115 }
106116 }
107117 }
108- resolve ( ) ;
118+ resolve ( copyedFiles ) ;
109119 } ) . catch ( reject ) ;
110120 } ) ;
111121}
0 commit comments