1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.copyFile = exports.exists = exports.rmdir = exports.stat = exports.mkdir = exports.access = exports.writeFile = exports.readFile = void 0;
|
4 | const util_1 = require("util");
|
5 | const fs = require("fs");
|
6 | const path_1 = require("path");
|
7 | exports.readFile = fs.promises.readFile;
|
8 | exports.writeFile = fs.promises.writeFile;
|
9 | exports.access = fs.promises.access;
|
10 | exports.mkdir = fs.promises.mkdir;
|
11 | exports.stat = fs.promises.stat;
|
12 | exports.rmdir = fs.promises.rmdir;
|
13 | async function exists(path) {
|
14 | try {
|
15 | await exports.access(path, fs.constants.F_OK);
|
16 | return true;
|
17 | }
|
18 | catch {
|
19 | return false;
|
20 | }
|
21 | }
|
22 | exports.exists = exists;
|
23 | const cpFile = util_1.promisify(fs.copyFile);
|
24 | async function copyFile(src, dest) {
|
25 | const dir = path_1.dirname(dest);
|
26 | if (!(await exists(dir))) {
|
27 | await exports.mkdir(dir, { recursive: true });
|
28 | }
|
29 | await cpFile(src, dest, fs.constants.COPYFILE_FICLONE);
|
30 | }
|
31 | exports.copyFile = copyFile;
|
32 |
|
\ | No newline at end of file |