-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
46 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import path from 'path' | ||
import { promises as fs } from 'fs' | ||
|
||
export async function exists(path: string) { | ||
try { | ||
await fs.stat(path) | ||
return true | ||
} catch (e) { | ||
return false | ||
} | ||
} | ||
|
||
export async function copyDir(from: string, to: string) { | ||
if (exists(to)) { | ||
await fs.rmdir(to, { recursive: true }) | ||
} | ||
await fs.mkdir(to, { recursive: true }) | ||
const content = await fs.readdir(from) | ||
for (const entry of content) { | ||
const fromPath = path.join(from, entry) | ||
const toPath = path.join(to, entry) | ||
const stat = await fs.stat(fromPath) | ||
if (stat.isFile()) { | ||
await fs.copyFile(fromPath, toPath) | ||
} else if (stat.isDirectory()) { | ||
await copyDir(fromPath, toPath) | ||
} | ||
} | ||
} |