1
0
mirror of https://github.com/0O0o0oOoO00/Alas.git synced 2026-05-14 22:19:26 +08:00
Files
Alas/webapp/packages/common/utils/copyFilesToDir.ts

36 lines
867 B
TypeScript
Raw Normal View History

2023-04-25 18:55:23 +08:00
import type {CopyOptions} from 'fs-extra';
import fsExtra from 'fs-extra';
import {join,sep,normalize} from 'path';
2023-04-25 18:55:23 +08:00
export interface CopyToDirOptions {
2023-04-25 18:55:23 +08:00
successCallback?: (pathStr: string) => void;
filedCallback?: (pathStr: string, error: any) => void;
fsExtraOptions?: CopyOptions;
}
/**
*
* @param pathList
* @param targetDirPath
* @param options
*/
export async function copyFilesToDir(
pathList: string[],
targetDirPath: string,
options?: CopyToDirOptions | undefined,
) {
const {fsExtraOptions, successCallback, filedCallback} = options || {};
for (const pathStr of pathList) {
try {
await fsExtra.copy(
pathStr,
join(normalize(targetDirPath) + sep + pathStr.split(sep).pop()),
2023-04-25 18:55:23 +08:00
fsExtraOptions,
);
successCallback?.(pathStr);
} catch (err) {
filedCallback?.(pathStr, err);
}
}
}