@naturalcycles/nodejs-lib 13.4.0 → 13.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/fs/del.js +8 -13
- package/dist/fs/fs2.d.ts +79 -0
- package/dist/fs/fs2.js +267 -0
- package/dist/fs/json2env.js +4 -4
- package/dist/fs/kpy.js +6 -6
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/secret/secrets-decrypt.util.js +2 -2
- package/dist/secret/secrets-encrypt.util.js +2 -2
- package/dist/stream/ndjson/pipelineToNDJsonFile.js +2 -2
- package/dist/util/buildInfo.util.js +3 -3
- package/dist/validation/ajv/ajv.util.js +1 -1
- package/dist/validation/ajv/ajvSchema.js +1 -1
- package/package.json +3 -1
- package/src/fs/del.ts +9 -20
- package/src/fs/fs2.ts +303 -0
- package/src/fs/json2env.ts +4 -4
- package/src/fs/kpy.ts +7 -15
- package/src/index.ts +1 -1
- package/src/secret/secrets-decrypt.util.ts +3 -3
- package/src/secret/secrets-encrypt.util.ts +3 -3
- package/src/slack/slack.service.ts +1 -1
- package/src/stream/ndjson/pipelineToNDJsonFile.ts +3 -3
- package/src/util/buildInfo.util.ts +3 -3
- package/src/validation/ajv/ajv.util.ts +2 -2
- package/src/validation/ajv/ajvSchema.ts +2 -2
- package/dist/fs/fs.util.d.ts +0 -182
- package/dist/fs/fs.util.js +0 -285
- package/src/fs/fs.util.ts +0 -285
package/dist/fs/fs.util.d.ts
DELETED
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
/// <reference types="node" />
|
|
4
|
-
import fs from 'node:fs';
|
|
5
|
-
/**
|
|
6
|
-
* fs2 conveniently groups filesystem functions together.
|
|
7
|
-
* Supposed to be almost a drop-in replacement for these things together:
|
|
8
|
-
*
|
|
9
|
-
* 1. node:fs
|
|
10
|
-
* 2. node:fs/promises
|
|
11
|
-
* 3. fs-extra
|
|
12
|
-
*/
|
|
13
|
-
export declare const fs2: {
|
|
14
|
-
readFile: typeof _readFile;
|
|
15
|
-
readFileSync: typeof _readFileSync;
|
|
16
|
-
readFileAsBuffer: typeof _readFileAsBuffer;
|
|
17
|
-
readFileAsBufferSync: typeof _readFileAsBufferSync;
|
|
18
|
-
readJson: typeof _readJson;
|
|
19
|
-
readJsonSync: typeof _readJsonSync;
|
|
20
|
-
writeFile: typeof _writeFile;
|
|
21
|
-
writeFileSync: typeof _writeFileSync;
|
|
22
|
-
outputJson: typeof _outputJson;
|
|
23
|
-
outputJsonSync: typeof _outputJsonSync;
|
|
24
|
-
writeJson: typeof _writeJson;
|
|
25
|
-
writeJsonSync: typeof _writeJsonSync;
|
|
26
|
-
outputFile: typeof _outputFile;
|
|
27
|
-
outputFileSync: typeof _outputFileSync;
|
|
28
|
-
pathExists: typeof _pathExists;
|
|
29
|
-
pathExistsSync: typeof _pathExistsSync;
|
|
30
|
-
ensureDir: typeof _ensureDir;
|
|
31
|
-
ensureDirSync: typeof _ensureDirSync;
|
|
32
|
-
ensureFile: typeof _ensureFile;
|
|
33
|
-
ensureFileSync: typeof _ensureFileSync;
|
|
34
|
-
removePath: typeof _removePath;
|
|
35
|
-
removePathSync: typeof _removePathSync;
|
|
36
|
-
emptyDir: typeof _emptyDir;
|
|
37
|
-
emptyDirSync: typeof _emptyDirSync;
|
|
38
|
-
copyPath: typeof _copyPath;
|
|
39
|
-
copyPathSync: typeof _copyPathSync;
|
|
40
|
-
movePath: typeof _movePath;
|
|
41
|
-
movePathSync: typeof _movePathSync;
|
|
42
|
-
link: typeof fs.link;
|
|
43
|
-
open: typeof fs.open;
|
|
44
|
-
truncate: typeof fs.truncate;
|
|
45
|
-
write: typeof fs.write;
|
|
46
|
-
close: typeof fs.close;
|
|
47
|
-
read: typeof fs.read;
|
|
48
|
-
rename: typeof fs.rename;
|
|
49
|
-
writev: typeof fs.writev;
|
|
50
|
-
renameSync: typeof fs.renameSync;
|
|
51
|
-
truncateSync: typeof fs.truncateSync;
|
|
52
|
-
ftruncate: typeof fs.ftruncate;
|
|
53
|
-
ftruncateSync: typeof fs.ftruncateSync;
|
|
54
|
-
chown: typeof fs.chown;
|
|
55
|
-
chownSync: typeof fs.chownSync;
|
|
56
|
-
fchown: typeof fs.fchown;
|
|
57
|
-
fchownSync: typeof fs.fchownSync;
|
|
58
|
-
lchown: typeof fs.lchown;
|
|
59
|
-
lchownSync: typeof fs.lchownSync;
|
|
60
|
-
lutimes: typeof fs.lutimes;
|
|
61
|
-
lutimesSync: typeof fs.lutimesSync;
|
|
62
|
-
chmod: typeof fs.chmod;
|
|
63
|
-
chmodSync: typeof fs.chmodSync;
|
|
64
|
-
fchmod: typeof fs.fchmod;
|
|
65
|
-
fchmodSync: typeof fs.fchmodSync;
|
|
66
|
-
lchmod: typeof fs.lchmod;
|
|
67
|
-
lchmodSync: typeof fs.lchmodSync;
|
|
68
|
-
stat: typeof fs.stat;
|
|
69
|
-
fstat: typeof fs.fstat;
|
|
70
|
-
fstatSync: typeof fs.fstatSync;
|
|
71
|
-
lstat: typeof fs.lstat;
|
|
72
|
-
statfs: typeof fs.statfs;
|
|
73
|
-
statfsSync: typeof fs.statfsSync;
|
|
74
|
-
linkSync: typeof fs.linkSync;
|
|
75
|
-
symlink: typeof fs.symlink;
|
|
76
|
-
symlinkSync: typeof fs.symlinkSync;
|
|
77
|
-
readlink: typeof fs.readlink;
|
|
78
|
-
readlinkSync: typeof fs.readlinkSync;
|
|
79
|
-
realpath: typeof fs.realpath;
|
|
80
|
-
realpathSync: typeof fs.realpathSync;
|
|
81
|
-
unlink: typeof fs.unlink;
|
|
82
|
-
unlinkSync: typeof fs.unlinkSync;
|
|
83
|
-
rmdir: typeof fs.rmdir;
|
|
84
|
-
rmdirSync: typeof fs.rmdirSync;
|
|
85
|
-
rm: typeof fs.rm;
|
|
86
|
-
rmSync: typeof fs.rmSync;
|
|
87
|
-
mkdir: typeof fs.mkdir;
|
|
88
|
-
mkdirSync: typeof fs.mkdirSync;
|
|
89
|
-
mkdtemp: typeof fs.mkdtemp;
|
|
90
|
-
mkdtempSync: typeof fs.mkdtempSync;
|
|
91
|
-
readdir: typeof fs.readdir;
|
|
92
|
-
readdirSync: typeof fs.readdirSync;
|
|
93
|
-
closeSync: typeof fs.closeSync;
|
|
94
|
-
openSync: typeof fs.openSync;
|
|
95
|
-
utimes: typeof fs.utimes;
|
|
96
|
-
utimesSync: typeof fs.utimesSync;
|
|
97
|
-
futimes: typeof fs.futimes;
|
|
98
|
-
futimesSync: typeof fs.futimesSync;
|
|
99
|
-
fsync: typeof fs.fsync;
|
|
100
|
-
fsyncSync: typeof fs.fsyncSync;
|
|
101
|
-
writeSync: typeof fs.writeSync;
|
|
102
|
-
readSync: typeof fs.readSync;
|
|
103
|
-
appendFile: typeof fs.appendFile;
|
|
104
|
-
appendFileSync: typeof fs.appendFileSync;
|
|
105
|
-
watchFile: typeof fs.watchFile;
|
|
106
|
-
unwatchFile: typeof fs.unwatchFile;
|
|
107
|
-
watch: typeof fs.watch;
|
|
108
|
-
exists: typeof fs.exists;
|
|
109
|
-
existsSync: typeof fs.existsSync;
|
|
110
|
-
access: typeof fs.access;
|
|
111
|
-
accessSync: typeof fs.accessSync;
|
|
112
|
-
createReadStream: typeof fs.createReadStream;
|
|
113
|
-
createWriteStream: typeof fs.createWriteStream;
|
|
114
|
-
fdatasync: typeof fs.fdatasync;
|
|
115
|
-
fdatasyncSync: typeof fs.fdatasyncSync;
|
|
116
|
-
copyFile: typeof fs.copyFile;
|
|
117
|
-
copyFileSync: typeof fs.copyFileSync;
|
|
118
|
-
writevSync: typeof fs.writevSync;
|
|
119
|
-
readv: typeof fs.readv;
|
|
120
|
-
readvSync: typeof fs.readvSync;
|
|
121
|
-
openAsBlob: typeof fs.openAsBlob;
|
|
122
|
-
opendirSync: typeof fs.opendirSync;
|
|
123
|
-
opendir: typeof fs.opendir;
|
|
124
|
-
cp: typeof fs.cp;
|
|
125
|
-
cpSync: typeof fs.cpSync;
|
|
126
|
-
promises: typeof fs.promises;
|
|
127
|
-
Stats: typeof fs.Stats;
|
|
128
|
-
StatsFs: typeof fs.StatsFs;
|
|
129
|
-
Dirent: typeof fs.Dirent;
|
|
130
|
-
Dir: typeof fs.Dir;
|
|
131
|
-
ReadStream: typeof fs.ReadStream;
|
|
132
|
-
WriteStream: typeof fs.WriteStream;
|
|
133
|
-
statSync: fs.StatSyncFn;
|
|
134
|
-
lstatSync: fs.StatSyncFn;
|
|
135
|
-
constants: typeof fs.constants;
|
|
136
|
-
};
|
|
137
|
-
export interface JsonOptions {
|
|
138
|
-
spaces?: number;
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Convenience wrapper that defaults to utf-8 string output.
|
|
142
|
-
*/
|
|
143
|
-
export declare function _readFile(filePath: string): Promise<string>;
|
|
144
|
-
export declare function _readFileAsBuffer(filePath: string): Promise<Buffer>;
|
|
145
|
-
/**
|
|
146
|
-
* Convenience wrapper that defaults to utf-8 string output.
|
|
147
|
-
*/
|
|
148
|
-
export declare function _readFileSync(filePath: string): string;
|
|
149
|
-
/**
|
|
150
|
-
* Convenience wrapper that defaults to utf-8 string output.
|
|
151
|
-
*/
|
|
152
|
-
export declare function _readFileAsBufferSync(filePath: string): Buffer;
|
|
153
|
-
export declare function _readJson<T = unknown>(filePath: string): Promise<T>;
|
|
154
|
-
export declare function _readJsonSync<T = unknown>(filePath: string): T;
|
|
155
|
-
export declare function _writeFile(filePath: string, data: string | Buffer): Promise<void>;
|
|
156
|
-
export declare function _writeFileSync(filePath: string, data: string | Buffer): void;
|
|
157
|
-
export declare function _outputFile(filePath: string, data: string | Buffer): Promise<void>;
|
|
158
|
-
export declare function _outputFileSync(filePath: string, data: string | Buffer): void;
|
|
159
|
-
export declare function _writeJson(filePath: string, data: any, opt?: JsonOptions): Promise<void>;
|
|
160
|
-
export declare function _writeJsonSync(filePath: string, data: any, opt?: JsonOptions): void;
|
|
161
|
-
export declare function _outputJson(filePath: string, data: any, opt?: JsonOptions): Promise<void>;
|
|
162
|
-
export declare function _outputJsonSync(filePath: string, data: any, opt?: JsonOptions): void;
|
|
163
|
-
export declare function _pathExists(filePath: string): Promise<boolean>;
|
|
164
|
-
export declare function _pathExistsSync(filePath: string): boolean;
|
|
165
|
-
export declare function _ensureDir(dirPath: string): Promise<void>;
|
|
166
|
-
export declare function _ensureDirSync(dirPath: string): void;
|
|
167
|
-
export declare function _ensureFile(filePath: string): Promise<void>;
|
|
168
|
-
export declare function _ensureFileSync(filePath: string): void;
|
|
169
|
-
export declare function _removePath(fileOrDirPath: string): Promise<void>;
|
|
170
|
-
export declare function _removePathSync(fileOrDirPath: string): void;
|
|
171
|
-
export declare function _emptyDir(dirPath: string): Promise<void>;
|
|
172
|
-
export declare function _emptyDirSync(dirPath: string): void;
|
|
173
|
-
/**
|
|
174
|
-
* Cautious, underlying Node function is currently Experimental.
|
|
175
|
-
*/
|
|
176
|
-
export declare function _copyPath(src: string, dest: string, opt?: fs.CopyOptions): Promise<void>;
|
|
177
|
-
/**
|
|
178
|
-
* Cautious, underlying Node function is currently Experimental.
|
|
179
|
-
*/
|
|
180
|
-
export declare function _copyPathSync(src: string, dest: string, opt?: fs.CopySyncOptions): void;
|
|
181
|
-
export declare function _movePath(src: string, dest: string, opt?: fs.CopyOptions): Promise<void>;
|
|
182
|
-
export declare function _movePathSync(src: string, dest: string, opt?: fs.CopySyncOptions): void;
|
package/dist/fs/fs.util.js
DELETED
|
@@ -1,285 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
|
|
4
|
-
Why?
|
|
5
|
-
|
|
6
|
-
Convenience re-export/re-implementation of most common fs functions from
|
|
7
|
-
node:fs, node:fs/promises and fs-extra
|
|
8
|
-
|
|
9
|
-
Defaults to string input/output, as it's used in 80% of time. For the rest - you can use native fs.
|
|
10
|
-
|
|
11
|
-
Allows to import it easier, so you don't have to choose between the 3 import locations.
|
|
12
|
-
That's why function names are slightly renamed, to avoid conflict.
|
|
13
|
-
|
|
14
|
-
Credit to: fs-extra (https://github.com/jprichardson/node-fs-extra)
|
|
15
|
-
|
|
16
|
-
*/
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports._movePathSync = exports._movePath = exports._copyPathSync = exports._copyPath = exports._emptyDirSync = exports._emptyDir = exports._removePathSync = exports._removePath = exports._ensureFileSync = exports._ensureFile = exports._ensureDirSync = exports._ensureDir = exports._pathExistsSync = exports._pathExists = exports._outputJsonSync = exports._outputJson = exports._writeJsonSync = exports._writeJson = exports._outputFileSync = exports._outputFile = exports._writeFileSync = exports._writeFile = exports._readJsonSync = exports._readJson = exports._readFileAsBufferSync = exports._readFileSync = exports._readFileAsBuffer = exports._readFile = exports.fs2 = void 0;
|
|
19
|
-
const tslib_1 = require("tslib");
|
|
20
|
-
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
21
|
-
const promises_1 = tslib_1.__importDefault(require("node:fs/promises"));
|
|
22
|
-
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
23
|
-
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
24
|
-
/**
|
|
25
|
-
* fs2 conveniently groups filesystem functions together.
|
|
26
|
-
* Supposed to be almost a drop-in replacement for these things together:
|
|
27
|
-
*
|
|
28
|
-
* 1. node:fs
|
|
29
|
-
* 2. node:fs/promises
|
|
30
|
-
* 3. fs-extra
|
|
31
|
-
*/
|
|
32
|
-
exports.fs2 = {
|
|
33
|
-
// "Omit" is here to workaround this TS error:
|
|
34
|
-
// Exported variable 'fs2' has or is using name 'StreamOptions' from external module "fs" but cannot be named.
|
|
35
|
-
...node_fs_1.default,
|
|
36
|
-
readFile: _readFile,
|
|
37
|
-
readFileSync: _readFileSync,
|
|
38
|
-
readFileAsBuffer: _readFileAsBuffer,
|
|
39
|
-
readFileAsBufferSync: _readFileAsBufferSync,
|
|
40
|
-
readJson: _readJson,
|
|
41
|
-
readJsonSync: _readJsonSync,
|
|
42
|
-
writeFile: _writeFile,
|
|
43
|
-
writeFileSync: _writeFileSync,
|
|
44
|
-
outputJson: _outputJson,
|
|
45
|
-
outputJsonSync: _outputJsonSync,
|
|
46
|
-
writeJson: _writeJson,
|
|
47
|
-
writeJsonSync: _writeJsonSync,
|
|
48
|
-
outputFile: _outputFile,
|
|
49
|
-
outputFileSync: _outputFileSync,
|
|
50
|
-
pathExists: _pathExists,
|
|
51
|
-
pathExistsSync: _pathExistsSync,
|
|
52
|
-
ensureDir: _ensureDir,
|
|
53
|
-
ensureDirSync: _ensureDirSync,
|
|
54
|
-
ensureFile: _ensureFile,
|
|
55
|
-
ensureFileSync: _ensureFileSync,
|
|
56
|
-
removePath: _removePath,
|
|
57
|
-
removePathSync: _removePathSync,
|
|
58
|
-
emptyDir: _emptyDir,
|
|
59
|
-
emptyDirSync: _emptyDirSync,
|
|
60
|
-
copyPath: _copyPath,
|
|
61
|
-
copyPathSync: _copyPathSync,
|
|
62
|
-
movePath: _movePath,
|
|
63
|
-
movePathSync: _movePathSync,
|
|
64
|
-
};
|
|
65
|
-
/**
|
|
66
|
-
* Convenience wrapper that defaults to utf-8 string output.
|
|
67
|
-
*/
|
|
68
|
-
async function _readFile(filePath) {
|
|
69
|
-
return await promises_1.default.readFile(filePath, 'utf8');
|
|
70
|
-
}
|
|
71
|
-
exports._readFile = _readFile;
|
|
72
|
-
async function _readFileAsBuffer(filePath) {
|
|
73
|
-
return await promises_1.default.readFile(filePath);
|
|
74
|
-
}
|
|
75
|
-
exports._readFileAsBuffer = _readFileAsBuffer;
|
|
76
|
-
/**
|
|
77
|
-
* Convenience wrapper that defaults to utf-8 string output.
|
|
78
|
-
*/
|
|
79
|
-
function _readFileSync(filePath) {
|
|
80
|
-
return node_fs_1.default.readFileSync(filePath, 'utf8');
|
|
81
|
-
}
|
|
82
|
-
exports._readFileSync = _readFileSync;
|
|
83
|
-
/**
|
|
84
|
-
* Convenience wrapper that defaults to utf-8 string output.
|
|
85
|
-
*/
|
|
86
|
-
function _readFileAsBufferSync(filePath) {
|
|
87
|
-
return node_fs_1.default.readFileSync(filePath);
|
|
88
|
-
}
|
|
89
|
-
exports._readFileAsBufferSync = _readFileAsBufferSync;
|
|
90
|
-
async function _readJson(filePath) {
|
|
91
|
-
const str = await promises_1.default.readFile(filePath, 'utf8');
|
|
92
|
-
return (0, js_lib_1._jsonParse)(str);
|
|
93
|
-
}
|
|
94
|
-
exports._readJson = _readJson;
|
|
95
|
-
function _readJsonSync(filePath) {
|
|
96
|
-
const str = node_fs_1.default.readFileSync(filePath, 'utf8');
|
|
97
|
-
return (0, js_lib_1._jsonParse)(str);
|
|
98
|
-
}
|
|
99
|
-
exports._readJsonSync = _readJsonSync;
|
|
100
|
-
async function _writeFile(filePath, data) {
|
|
101
|
-
await promises_1.default.writeFile(filePath, data);
|
|
102
|
-
}
|
|
103
|
-
exports._writeFile = _writeFile;
|
|
104
|
-
function _writeFileSync(filePath, data) {
|
|
105
|
-
node_fs_1.default.writeFileSync(filePath, data);
|
|
106
|
-
}
|
|
107
|
-
exports._writeFileSync = _writeFileSync;
|
|
108
|
-
async function _outputFile(filePath, data) {
|
|
109
|
-
const dirPath = node_path_1.default.dirname(filePath);
|
|
110
|
-
if (!(await _pathExists(dirPath))) {
|
|
111
|
-
await _ensureDir(dirPath);
|
|
112
|
-
}
|
|
113
|
-
await promises_1.default.writeFile(filePath, data);
|
|
114
|
-
}
|
|
115
|
-
exports._outputFile = _outputFile;
|
|
116
|
-
function _outputFileSync(filePath, data) {
|
|
117
|
-
const dirPath = node_path_1.default.dirname(filePath);
|
|
118
|
-
if (!node_fs_1.default.existsSync(dirPath)) {
|
|
119
|
-
_ensureDirSync(dirPath);
|
|
120
|
-
}
|
|
121
|
-
node_fs_1.default.writeFileSync(filePath, data);
|
|
122
|
-
}
|
|
123
|
-
exports._outputFileSync = _outputFileSync;
|
|
124
|
-
function stringify(data, opt) {
|
|
125
|
-
// If pretty-printing is enabled (spaces) - also add a newline at the end (to match our prettier config)
|
|
126
|
-
return JSON.stringify(data, null, opt?.spaces) + (opt?.spaces ? '\n' : '');
|
|
127
|
-
}
|
|
128
|
-
async function _writeJson(filePath, data, opt) {
|
|
129
|
-
const str = stringify(data, opt);
|
|
130
|
-
await promises_1.default.writeFile(filePath, str);
|
|
131
|
-
}
|
|
132
|
-
exports._writeJson = _writeJson;
|
|
133
|
-
function _writeJsonSync(filePath, data, opt) {
|
|
134
|
-
const str = stringify(data, opt);
|
|
135
|
-
node_fs_1.default.writeFileSync(filePath, str);
|
|
136
|
-
}
|
|
137
|
-
exports._writeJsonSync = _writeJsonSync;
|
|
138
|
-
async function _outputJson(filePath, data, opt) {
|
|
139
|
-
const str = stringify(data, opt);
|
|
140
|
-
await _outputFile(filePath, str);
|
|
141
|
-
}
|
|
142
|
-
exports._outputJson = _outputJson;
|
|
143
|
-
function _outputJsonSync(filePath, data, opt) {
|
|
144
|
-
const str = stringify(data, opt);
|
|
145
|
-
_outputFileSync(filePath, str);
|
|
146
|
-
}
|
|
147
|
-
exports._outputJsonSync = _outputJsonSync;
|
|
148
|
-
async function _pathExists(filePath) {
|
|
149
|
-
try {
|
|
150
|
-
await promises_1.default.access(filePath);
|
|
151
|
-
return true;
|
|
152
|
-
}
|
|
153
|
-
catch {
|
|
154
|
-
return false;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
exports._pathExists = _pathExists;
|
|
158
|
-
function _pathExistsSync(filePath) {
|
|
159
|
-
return node_fs_1.default.existsSync(filePath);
|
|
160
|
-
}
|
|
161
|
-
exports._pathExistsSync = _pathExistsSync;
|
|
162
|
-
async function _ensureDir(dirPath) {
|
|
163
|
-
await promises_1.default.mkdir(dirPath, {
|
|
164
|
-
mode: 0o777,
|
|
165
|
-
recursive: true,
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
exports._ensureDir = _ensureDir;
|
|
169
|
-
function _ensureDirSync(dirPath) {
|
|
170
|
-
node_fs_1.default.mkdirSync(dirPath, {
|
|
171
|
-
mode: 0o777,
|
|
172
|
-
recursive: true,
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
exports._ensureDirSync = _ensureDirSync;
|
|
176
|
-
async function _ensureFile(filePath) {
|
|
177
|
-
let stats;
|
|
178
|
-
try {
|
|
179
|
-
stats = await promises_1.default.stat(filePath);
|
|
180
|
-
}
|
|
181
|
-
catch { }
|
|
182
|
-
if (stats?.isFile())
|
|
183
|
-
return;
|
|
184
|
-
const dir = node_path_1.default.dirname(filePath);
|
|
185
|
-
try {
|
|
186
|
-
if (!(await promises_1.default.stat(dir)).isDirectory()) {
|
|
187
|
-
// parent is not a directory
|
|
188
|
-
// This is just to cause an internal ENOTDIR error to be thrown
|
|
189
|
-
await promises_1.default.readdir(dir);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
catch (err) {
|
|
193
|
-
// If the stat call above failed because the directory doesn't exist, create it
|
|
194
|
-
if (err?.code === 'ENOENT')
|
|
195
|
-
return await _ensureDir(dir);
|
|
196
|
-
throw err;
|
|
197
|
-
}
|
|
198
|
-
await promises_1.default.writeFile(filePath, '');
|
|
199
|
-
}
|
|
200
|
-
exports._ensureFile = _ensureFile;
|
|
201
|
-
function _ensureFileSync(filePath) {
|
|
202
|
-
let stats;
|
|
203
|
-
try {
|
|
204
|
-
stats = node_fs_1.default.statSync(filePath);
|
|
205
|
-
}
|
|
206
|
-
catch { }
|
|
207
|
-
if (stats?.isFile())
|
|
208
|
-
return;
|
|
209
|
-
const dir = node_path_1.default.dirname(filePath);
|
|
210
|
-
try {
|
|
211
|
-
if (!node_fs_1.default.statSync(dir).isDirectory()) {
|
|
212
|
-
// parent is not a directory
|
|
213
|
-
// This is just to cause an internal ENOTDIR error to be thrown
|
|
214
|
-
node_fs_1.default.readdirSync(dir);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
catch (err) {
|
|
218
|
-
// If the stat call above failed because the directory doesn't exist, create it
|
|
219
|
-
if (err?.code === 'ENOENT')
|
|
220
|
-
return _ensureDirSync(dir);
|
|
221
|
-
throw err;
|
|
222
|
-
}
|
|
223
|
-
node_fs_1.default.writeFileSync(filePath, '');
|
|
224
|
-
}
|
|
225
|
-
exports._ensureFileSync = _ensureFileSync;
|
|
226
|
-
async function _removePath(fileOrDirPath) {
|
|
227
|
-
await promises_1.default.rm(fileOrDirPath, { recursive: true, force: true });
|
|
228
|
-
}
|
|
229
|
-
exports._removePath = _removePath;
|
|
230
|
-
function _removePathSync(fileOrDirPath) {
|
|
231
|
-
node_fs_1.default.rmSync(fileOrDirPath, { recursive: true, force: true });
|
|
232
|
-
}
|
|
233
|
-
exports._removePathSync = _removePathSync;
|
|
234
|
-
async function _emptyDir(dirPath) {
|
|
235
|
-
let items;
|
|
236
|
-
try {
|
|
237
|
-
items = await promises_1.default.readdir(dirPath);
|
|
238
|
-
}
|
|
239
|
-
catch {
|
|
240
|
-
return await _ensureDir(dirPath);
|
|
241
|
-
}
|
|
242
|
-
await Promise.all(items.map(item => _removePath(node_path_1.default.join(dirPath, item))));
|
|
243
|
-
}
|
|
244
|
-
exports._emptyDir = _emptyDir;
|
|
245
|
-
function _emptyDirSync(dirPath) {
|
|
246
|
-
let items;
|
|
247
|
-
try {
|
|
248
|
-
items = node_fs_1.default.readdirSync(dirPath);
|
|
249
|
-
}
|
|
250
|
-
catch {
|
|
251
|
-
return _ensureDirSync(dirPath);
|
|
252
|
-
}
|
|
253
|
-
items.forEach(item => _removePathSync(node_path_1.default.join(dirPath, item)));
|
|
254
|
-
}
|
|
255
|
-
exports._emptyDirSync = _emptyDirSync;
|
|
256
|
-
/**
|
|
257
|
-
* Cautious, underlying Node function is currently Experimental.
|
|
258
|
-
*/
|
|
259
|
-
async function _copyPath(src, dest, opt) {
|
|
260
|
-
await promises_1.default.cp(src, dest, {
|
|
261
|
-
recursive: true,
|
|
262
|
-
...opt,
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
exports._copyPath = _copyPath;
|
|
266
|
-
/**
|
|
267
|
-
* Cautious, underlying Node function is currently Experimental.
|
|
268
|
-
*/
|
|
269
|
-
function _copyPathSync(src, dest, opt) {
|
|
270
|
-
node_fs_1.default.cpSync(src, dest, {
|
|
271
|
-
recursive: true,
|
|
272
|
-
...opt,
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
exports._copyPathSync = _copyPathSync;
|
|
276
|
-
async function _movePath(src, dest, opt) {
|
|
277
|
-
await _copyPath(src, dest, opt);
|
|
278
|
-
await _removePath(src);
|
|
279
|
-
}
|
|
280
|
-
exports._movePath = _movePath;
|
|
281
|
-
function _movePathSync(src, dest, opt) {
|
|
282
|
-
_copyPathSync(src, dest, opt);
|
|
283
|
-
_removePathSync(src);
|
|
284
|
-
}
|
|
285
|
-
exports._movePathSync = _movePathSync;
|