Skip to content

Commit

Permalink
feat(public/fs): allows copy, move, remove to take promises as src
Browse files Browse the repository at this point in the history
  • Loading branch information
rafamel committed May 18, 2019
1 parent 69e3d9a commit 3747dba
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
20 changes: 13 additions & 7 deletions src/public/fs/copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,24 @@ export type TCopyFilterFn =

export default expose(copy) as TExposedOverload<
typeof copy,
| [string | string[], string]
| [string | string[], string, IFsWriteOptions]
| [string | string[], string, TCopyFilterFn]
| [string | string[], string, IFsWriteOptions | undefined, TCopyFilterFn]
| [string | string[] | Promise<string | string[]>, string]
| [string | string[] | Promise<string | string[]>, string, IFsWriteOptions]
| [string | string[] | Promise<string | string[]>, string, TCopyFilterFn]
| [
string | string[] | Promise<string | string[]>,
string,
IFsWriteOptions | undefined,
TCopyFilterFn
]
>;

function copy(
src: string | string[],
src: string | string[] | Promise<string | string[]>,
dest: string,
filter?: TCopyFilterFn
): () => Promise<void>;
function copy(
src: string | string[],
src: string | string[] | Promise<string | string[]>,
dest: string,
options?: IFsWriteOptions,
filter?: TCopyFilterFn
Expand All @@ -36,11 +41,12 @@ function copy(
* @returns An asynchronous function -hence, calling `copy` won't have any effect until the returned function is called.
*/
function copy(
src: string | string[],
src: string | string[] | Promise<string | string[]>,
dest: string,
...args: any[]
): () => Promise<void> {
return async () => {
src = await src;
if (Array.isArray(src)) {
for (let source of src) {
await trunk(source, path.join(dest, path.parse(source).base), args);
Expand Down
3 changes: 2 additions & 1 deletion src/public/fs/move.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ export default expose(move);
* @returns An asynchronous function -hence, calling `move` won't have any effect until the returned function is called.
*/
function move(
src: string | string[],
src: string | string[] | Promise<string | string[]>,
dest: string,
options: IFsWriteOptions = {}
): () => Promise<void> {
return async () => {
src = await src;
if (Array.isArray(src)) {
for (let source of src) {
await trunk(source, path.join(dest, path.parse(source).base), options);
Expand Down
3 changes: 2 additions & 1 deletion src/public/fs/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ export default expose(remove);
* @returns An asynchronous function -hence, calling `remove` won't have any effect until the returned function is called.
*/
function remove(
paths: string | string[],
paths: string | string[] | Promise<string | string[]>,
options: IFsOptions = {}
): () => Promise<void> {
return async () => {
const cwd = process.cwd();
paths = await paths;
paths = Array.isArray(paths) ? paths : [paths];
paths = paths.map((path) => absolute({ path, cwd }));

Expand Down

0 comments on commit 3747dba

Please sign in to comment.