@wocker/ws 1.0.2 → 1.0.4
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/README.md +1 -1
- package/lib/App.d.ts +4 -3
- package/lib/App.js +98 -77
- package/lib/controllers/ImageController.d.ts +2 -2
- package/lib/controllers/ImageController.js +27 -27
- package/lib/controllers/PluginController.d.ts +2 -2
- package/lib/controllers/PluginController.js +78 -56
- package/lib/controllers/PresetController.d.ts +3 -1
- package/lib/controllers/PresetController.js +155 -136
- package/lib/controllers/ProjectController.d.ts +5 -5
- package/lib/controllers/ProjectController.js +653 -603
- package/lib/controllers/ProxyController.d.ts +4 -1
- package/lib/controllers/ProxyController.js +269 -245
- package/lib/controllers/index.js +19 -58
- package/lib/decorators/Inject.d.ts +1 -0
- package/lib/decorators/Inject.js +8 -0
- package/lib/decorators/Injectable.d.ts +4 -0
- package/lib/decorators/Injectable.js +17 -0
- package/lib/decorators/index.d.ts +1 -0
- package/lib/decorators/index.js +17 -0
- package/lib/env.js +33 -15
- package/lib/index.d.ts +3 -0
- package/lib/index.js +31 -16
- package/lib/makes/Controller.js +4 -8
- package/lib/makes/DI.d.ts +7 -0
- package/lib/makes/DI.js +27 -0
- package/lib/makes/Docker.js +298 -382
- package/lib/makes/FS.d.ts +3 -9
- package/lib/makes/FS.js +277 -305
- package/lib/makes/LineConvertStream.js +37 -40
- package/lib/makes/Logger.d.ts +9 -1
- package/lib/makes/Logger.js +22 -11
- package/lib/makes/Model.js +8 -12
- package/lib/makes/MySQL.js +6 -27
- package/lib/makes/Plugin.d.ts +1 -1
- package/lib/makes/Plugin.js +55 -37
- package/lib/makes/Preset.d.ts +46 -0
- package/lib/makes/Preset.js +33 -0
- package/lib/makes/Project.d.ts +45 -0
- package/lib/makes/Project.js +127 -0
- package/lib/makes/Repository.js +18 -21
- package/lib/makes/index.d.ts +3 -0
- package/lib/makes/index.js +23 -69
- package/lib/plugins/ElasticSearchPlugin.d.ts +3 -1
- package/lib/plugins/ElasticSearchPlugin.js +66 -66
- package/lib/plugins/LocaltunnelPlugin.d.ts +2 -2
- package/lib/plugins/LocaltunnelPlugin.js +256 -257
- package/lib/plugins/MaildevPlugin.d.ts +2 -2
- package/lib/plugins/MaildevPlugin.js +45 -44
- package/lib/plugins/MongodbPlugin.d.ts +2 -2
- package/lib/plugins/MongodbPlugin.js +303 -248
- package/lib/plugins/NgrokPlugin.d.ts +2 -2
- package/lib/plugins/NgrokPlugin.js +221 -231
- package/lib/plugins/PageKitePlugin.d.ts +2 -2
- package/lib/plugins/PageKitePlugin.js +150 -149
- package/lib/plugins/PostgresPlugin.d.ts +1 -1
- package/lib/plugins/PostgresPlugin.js +115 -89
- package/lib/plugins/ProxmoxPlugin.d.ts +1 -1
- package/lib/plugins/ProxmoxPlugin.js +50 -38
- package/lib/plugins/RedisPlugin.d.ts +3 -1
- package/lib/plugins/RedisPlugin.js +73 -72
- package/lib/plugins/index.js +25 -103
- package/lib/services/AppConfigService.d.ts +3 -3
- package/lib/services/AppConfigService.js +162 -157
- package/lib/services/AppEventsService.js +26 -24
- package/lib/services/DockerService.d.ts +37 -2
- package/lib/services/DockerService.js +185 -205
- package/lib/services/LogService.d.ts +3 -2
- package/lib/services/LogService.js +33 -34
- package/lib/services/PluginService.d.ts +2 -1
- package/lib/services/PluginService.js +11 -14
- package/lib/services/PresetService.d.ts +8 -3
- package/lib/services/PresetService.js +60 -59
- package/lib/services/ProjectService.d.ts +11 -4
- package/lib/services/ProjectService.js +140 -129
- package/lib/services/index.js +21 -80
- package/lib/types/Config.d.ts +4 -3
- package/lib/types/Config.js +1 -4
- package/lib/types/EnvConfig.js +1 -4
- package/lib/types/index.js +16 -25
- package/lib/utils/buildOptions.js +5 -8
- package/lib/utils/demuxOutput.js +16 -20
- package/lib/utils/escapeRegExp.js +4 -7
- package/lib/utils/exec.js +38 -39
- package/lib/utils/fetch.js +46 -30
- package/lib/utils/followProgress.js +66 -77
- package/lib/utils/format-size-units.js +16 -16
- package/lib/utils/get-config.d.ts +1 -1
- package/lib/utils/get-config.js +13 -16
- package/lib/utils/get-cursor-position.js +22 -29
- package/lib/utils/image-build.js +35 -23
- package/lib/utils/index.js +32 -191
- package/lib/utils/injectVariables.js +10 -13
- package/lib/utils/parse-table.js +20 -23
- package/lib/utils/set-config.d.ts +1 -1
- package/lib/utils/set-config.js +12 -15
- package/lib/utils/spawn.js +17 -20
- package/lib/utils/tty.js +2 -6
- package/lib/utils/volumeFormat.js +5 -12
- package/lib/utils/volumeParse.js +10 -13
- package/package.json +13 -39
- package/presets/bun/Dockerfile +11 -0
- package/presets/bun/config.json +3 -0
- package/presets/node/Dockerfile +4 -2
- package/presets/php-apache/Dockerfile +3 -2
- package/.github/workflows/publish.yml +0 -31
- package/plugins/mariadb/admin/conf/config.user.inc.php +0 -9
package/lib/makes/FS.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
|
-
|
|
3
|
+
import { FS as CoreFS } from "@wocker/core";
|
|
4
4
|
import * as fs from "fs";
|
|
5
|
-
import { Stats, BigIntStats, PathLike, PathOrFileDescriptor, WriteFileOptions, MakeDirectoryOptions
|
|
5
|
+
import { Stats, BigIntStats, PathLike, PathOrFileDescriptor, WriteFileOptions, MakeDirectoryOptions } from "fs";
|
|
6
6
|
import { PassThrough } from "readable-stream";
|
|
7
7
|
type ReaddirFilesOptions = {
|
|
8
8
|
recursive?: boolean;
|
|
9
9
|
};
|
|
10
|
-
declare class FS {
|
|
10
|
+
declare class FS extends CoreFS {
|
|
11
11
|
static access(path: PathLike): Promise<any>;
|
|
12
12
|
static exists(path: PathLike): Promise<boolean>;
|
|
13
13
|
static existsSync(path: PathLike): boolean;
|
|
@@ -17,21 +17,15 @@ declare class FS {
|
|
|
17
17
|
static readdirFiles(path: string, options?: ReaddirFilesOptions): Promise<string[]>;
|
|
18
18
|
static appendFile(path: PathOrFileDescriptor, data: any, options?: WriteFileOptions): Promise<unknown>;
|
|
19
19
|
static appendFileSync(path: PathOrFileDescriptor, data: any, options?: WriteFileOptions): void;
|
|
20
|
-
static read(): void;
|
|
21
20
|
static readBytes(filePath: PathLike, position?: number | bigint, size?: number | bigint): Promise<Buffer>;
|
|
22
|
-
static readFile(filePath: PathLike | number): Promise<Buffer>;
|
|
23
21
|
static readFileSync(filePath: PathLike): Buffer;
|
|
24
|
-
static writeFile(filePath: PathOrFileDescriptor, data: string | NodeJS.ArrayBufferView, options?: WriteFileOptions): Promise<void>;
|
|
25
22
|
static writeFileSync(path: PathLike, data: any, options?: WriteFileOptions): void;
|
|
26
23
|
static createWriteStream(path: PathLike): fs.WriteStream;
|
|
27
|
-
static readJSON(...paths: string[]): Promise<any>;
|
|
28
|
-
static writeJSON(filePath: PathLike | number, data: any): Promise<void>;
|
|
29
24
|
static unlink(filePath: PathLike): Promise<void>;
|
|
30
25
|
static watch(filename: PathLike, options?: any): fs.FSWatcher;
|
|
31
26
|
static stat(filename: PathLike, options?: Parameters<typeof fs.stat>[1]): Promise<Stats | BigIntStats>;
|
|
32
27
|
static createReadStream(path: PathLike, options?: Parameters<typeof fs.createReadStream>[1]): fs.ReadStream;
|
|
33
28
|
static createReadLinesStream(path: PathLike, count?: number): PassThrough;
|
|
34
29
|
static copyFile(src: PathLike, dest: PathLike): Promise<void>;
|
|
35
|
-
static rm(path: PathLike, options?: RmOptions): Promise<unknown>;
|
|
36
30
|
}
|
|
37
31
|
export { FS };
|
package/lib/makes/FS.js
CHANGED
|
@@ -1,320 +1,292 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
5
17
|
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
26
|
exports.FS = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Asynchronously tests whether or not the given path exists by checking with the file system.
|
|
27
|
-
* @param path path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
|
|
28
|
-
*/
|
|
29
|
-
static async exists(path) {
|
|
30
|
-
return new Promise(resolve => {
|
|
31
|
-
fs.exists(path, exists => {
|
|
32
|
-
resolve(exists);
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
static existsSync(path) {
|
|
37
|
-
return fs.existsSync(path);
|
|
38
|
-
}
|
|
39
|
-
static async mkdir(dirPath, options = {}) {
|
|
40
|
-
return new Promise((resolve, reject) => {
|
|
41
|
-
fs.mkdir(dirPath, options, err => {
|
|
42
|
-
if (!err) {
|
|
43
|
-
resolve();
|
|
44
|
-
} else {
|
|
45
|
-
reject(err);
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
static mkdirSync(path, options) {
|
|
51
|
-
return fs.mkdirSync(path, options);
|
|
52
|
-
}
|
|
53
|
-
static async readdir(path) {
|
|
54
|
-
return new Promise((resolve, reject) => {
|
|
55
|
-
fs.readdir(path, (err, files) => {
|
|
56
|
-
if (!err) {
|
|
57
|
-
resolve(files);
|
|
58
|
-
} else {
|
|
59
|
-
reject(err);
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
static async readdirFiles(path, options) {
|
|
65
|
-
const {
|
|
66
|
-
recursive = false
|
|
67
|
-
} = options || {};
|
|
68
|
-
if (recursive) {
|
|
69
|
-
const names = await FS.readdir(path);
|
|
70
|
-
let res = [];
|
|
71
|
-
for (const name of names) {
|
|
72
|
-
const filePath = Path.join(path, name);
|
|
73
|
-
let sub = [name];
|
|
74
|
-
const stats = await FS.stat(filePath);
|
|
75
|
-
if (stats.isDirectory()) {
|
|
76
|
-
sub = (await FS.readdirFiles(filePath, {
|
|
77
|
-
recursive: true
|
|
78
|
-
})).map(subName => {
|
|
79
|
-
return Path.join(name, subName);
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
res = [...res, ...sub];
|
|
83
|
-
}
|
|
84
|
-
return res;
|
|
27
|
+
const core_1 = require("@wocker/core");
|
|
28
|
+
const fs = __importStar(require("fs"));
|
|
29
|
+
const Path = __importStar(require("path"));
|
|
30
|
+
const readable_stream_1 = require("readable-stream");
|
|
31
|
+
class FS extends core_1.FS {
|
|
32
|
+
static async access(path) {
|
|
33
|
+
return new Promise((resolve, reject) => {
|
|
34
|
+
fs.access(path, (err) => {
|
|
35
|
+
if (!err) {
|
|
36
|
+
resolve(null);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
reject(err);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
});
|
|
85
43
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return reject(err);
|
|
92
|
-
}
|
|
93
|
-
const names = files.filter(dirent => {
|
|
94
|
-
return dirent.isFile();
|
|
95
|
-
}).map(dirent => {
|
|
96
|
-
return dirent.name;
|
|
44
|
+
static async exists(path) {
|
|
45
|
+
return new Promise((resolve) => {
|
|
46
|
+
fs.exists(path, (exists) => {
|
|
47
|
+
resolve(exists);
|
|
48
|
+
});
|
|
97
49
|
});
|
|
98
|
-
resolve(names);
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
static async appendFile(path, data, options) {
|
|
103
|
-
return new Promise((resolve, reject) => {
|
|
104
|
-
fs.appendFile(path, data, options, (error, data) => {
|
|
105
|
-
if (error) {
|
|
106
|
-
reject(error);
|
|
107
|
-
} else {
|
|
108
|
-
resolve(data);
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
static appendFileSync(path, data, options) {
|
|
114
|
-
return fs.appendFileSync(path, data, options);
|
|
115
|
-
}
|
|
116
|
-
static read() {
|
|
117
|
-
//
|
|
118
|
-
}
|
|
119
|
-
static async readBytes(filePath, position = 0, size) {
|
|
120
|
-
if (position < 0 && typeof size === "undefined") {
|
|
121
|
-
const stats = await FS.stat(filePath);
|
|
122
|
-
size = BigInt(position) * -1n;
|
|
123
|
-
position = BigInt(stats.size) - size;
|
|
124
|
-
if (position < 0n) {
|
|
125
|
-
position = 0;
|
|
126
|
-
}
|
|
127
|
-
} else if (typeof size === "undefined") {
|
|
128
|
-
const stats = await FS.stat(filePath);
|
|
129
|
-
if (typeof stats.size !== "bigint" && typeof position !== "bigint") {
|
|
130
|
-
size = stats.size - position;
|
|
131
|
-
} else {
|
|
132
|
-
size = BigInt(stats.size) - BigInt(position);
|
|
133
|
-
}
|
|
134
50
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
return Buffer.alloc(0);
|
|
51
|
+
static existsSync(path) {
|
|
52
|
+
return fs.existsSync(path);
|
|
139
53
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
resolve(buffer);
|
|
54
|
+
static async mkdir(dirPath, options = {}) {
|
|
55
|
+
return new Promise((resolve, reject) => {
|
|
56
|
+
fs.mkdir(dirPath, options, (err) => {
|
|
57
|
+
if (!err) {
|
|
58
|
+
resolve();
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
reject(err);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
153
64
|
});
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
const filePath = Path.join(...paths);
|
|
191
|
-
fs.readFile(filePath, (err, data) => {
|
|
192
|
-
if (err) {
|
|
193
|
-
reject(err);
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
resolve(data);
|
|
197
|
-
});
|
|
198
|
-
});
|
|
199
|
-
return JSON.parse(res.toString());
|
|
200
|
-
}
|
|
201
|
-
static async writeJSON(filePath, data) {
|
|
202
|
-
const json = JSON.stringify(data, null, 4);
|
|
203
|
-
return FS.writeFile(filePath, json);
|
|
204
|
-
}
|
|
205
|
-
static async unlink(filePath) {
|
|
206
|
-
return new Promise((resolve, reject) => {
|
|
207
|
-
fs.unlink(filePath, err => {
|
|
208
|
-
if (!err) {
|
|
209
|
-
resolve();
|
|
210
|
-
} else {
|
|
211
|
-
reject(err);
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
static watch(filename, options) {
|
|
217
|
-
return fs.watch(filename, options);
|
|
218
|
-
}
|
|
219
|
-
static stat(filename, options) {
|
|
220
|
-
return new Promise((resolve, reject) => {
|
|
221
|
-
fs.stat(filename, options, (err, stats) => {
|
|
222
|
-
if (err) {
|
|
223
|
-
reject(err);
|
|
224
|
-
} else {
|
|
225
|
-
resolve(stats);
|
|
226
|
-
}
|
|
227
|
-
});
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
static createReadStream(path, options) {
|
|
231
|
-
return fs.createReadStream(path, options);
|
|
232
|
-
}
|
|
233
|
-
static createReadLinesStream(path, count) {
|
|
234
|
-
const write = new _readableStream.PassThrough();
|
|
235
|
-
(async () => {
|
|
236
|
-
if (typeof count === "undefined" || count > 0) {
|
|
237
|
-
const stats = await FS.stat(path);
|
|
238
|
-
const resLines = [""];
|
|
239
|
-
let position = 0n;
|
|
240
|
-
while (position < stats.size) {
|
|
241
|
-
let size = BigInt(count ? 64 * count : 255);
|
|
242
|
-
if (position + size > stats.size) {
|
|
243
|
-
size = BigInt(stats.size) - position;
|
|
244
|
-
}
|
|
245
|
-
const buffer = await FS.readBytes(path, position, size);
|
|
246
|
-
const lines = buffer.toString("utf-8").split("\n");
|
|
247
|
-
position += size;
|
|
248
|
-
for (let i = 0; i < lines.length; i++) {
|
|
249
|
-
const line = lines[i];
|
|
250
|
-
if (i === 0) {
|
|
251
|
-
resLines[resLines.length - 1] = (resLines[resLines.length - 1] || "") + line;
|
|
252
|
-
} else {
|
|
253
|
-
resLines.push(line);
|
|
65
|
+
}
|
|
66
|
+
static mkdirSync(path, options) {
|
|
67
|
+
return fs.mkdirSync(path, options);
|
|
68
|
+
}
|
|
69
|
+
static async readdir(path) {
|
|
70
|
+
return new Promise((resolve, reject) => {
|
|
71
|
+
fs.readdir(path, (err, files) => {
|
|
72
|
+
if (!err) {
|
|
73
|
+
resolve(files);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
reject(err);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
static async readdirFiles(path, options) {
|
|
82
|
+
const { recursive = false } = options || {};
|
|
83
|
+
if (recursive) {
|
|
84
|
+
const names = await FS.readdir(path);
|
|
85
|
+
let res = [];
|
|
86
|
+
for (const name of names) {
|
|
87
|
+
const filePath = Path.join(path, name);
|
|
88
|
+
let sub = [
|
|
89
|
+
name
|
|
90
|
+
];
|
|
91
|
+
const stats = await FS.stat(filePath);
|
|
92
|
+
if (stats.isDirectory()) {
|
|
93
|
+
sub = (await FS.readdirFiles(filePath, { recursive: true })).map((subName) => {
|
|
94
|
+
return Path.join(name, subName);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
res = [
|
|
98
|
+
...res,
|
|
99
|
+
...sub
|
|
100
|
+
];
|
|
254
101
|
}
|
|
255
|
-
|
|
256
|
-
if (resLines.length > count + 1) {
|
|
257
|
-
break;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
for (let i = 0; i < (count || resLines.length); i++) {
|
|
261
|
-
write.write(resLines[i]);
|
|
102
|
+
return res;
|
|
262
103
|
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
104
|
+
return new Promise((resolve, reject) => {
|
|
105
|
+
fs.readdir(path, {
|
|
106
|
+
withFileTypes: true
|
|
107
|
+
}, (err, files) => {
|
|
108
|
+
if (err) {
|
|
109
|
+
return reject(err);
|
|
110
|
+
}
|
|
111
|
+
const names = files.filter((dirent) => {
|
|
112
|
+
return dirent.isFile();
|
|
113
|
+
}).map((dirent) => {
|
|
114
|
+
return dirent.name;
|
|
115
|
+
});
|
|
116
|
+
resolve(names);
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
static async appendFile(path, data, options) {
|
|
121
|
+
return new Promise((resolve, reject) => {
|
|
122
|
+
fs.appendFile(path, data, options, (error, data) => {
|
|
123
|
+
if (error) {
|
|
124
|
+
reject(error);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
resolve(data);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
static appendFileSync(path, data, options) {
|
|
133
|
+
return fs.appendFileSync(path, data, options);
|
|
134
|
+
}
|
|
135
|
+
static async readBytes(filePath, position = 0, size) {
|
|
136
|
+
if (position < 0 && typeof size === "undefined") {
|
|
137
|
+
const stats = await FS.stat(filePath);
|
|
138
|
+
size = BigInt(position) * -1n;
|
|
139
|
+
position = BigInt(stats.size) - size;
|
|
140
|
+
if (position < 0n) {
|
|
141
|
+
position = 0;
|
|
283
142
|
}
|
|
284
|
-
}
|
|
285
|
-
if (resLines.length > count * -1 + 1) {
|
|
286
|
-
break;
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
const lines = resLines.slice(count - 1);
|
|
290
|
-
for (let i = 0; i < lines.length; i++) {
|
|
291
|
-
write.write(lines[i]);
|
|
292
143
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
if (!err) {
|
|
302
|
-
resolve(undefined);
|
|
303
|
-
} else {
|
|
304
|
-
reject(err);
|
|
144
|
+
else if (typeof size === "undefined") {
|
|
145
|
+
const stats = await FS.stat(filePath);
|
|
146
|
+
if (typeof stats.size !== "bigint" && typeof position !== "bigint") {
|
|
147
|
+
size = stats.size - position;
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
size = BigInt(stats.size) - BigInt(position);
|
|
151
|
+
}
|
|
305
152
|
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
}
|
|
309
|
-
static async rm(path, options) {
|
|
310
|
-
return new Promise((resolve, reject) => {
|
|
311
|
-
fs.rm(path, options, err => {
|
|
312
|
-
if (err) {
|
|
313
|
-
return reject(err);
|
|
153
|
+
if (size < 0n) {
|
|
154
|
+
return Buffer.alloc(0);
|
|
314
155
|
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
156
|
+
const buffer = Buffer.alloc(Number(size));
|
|
157
|
+
return new Promise((resolve, reject) => {
|
|
158
|
+
fs.open(filePath, (err, file) => {
|
|
159
|
+
if (err) {
|
|
160
|
+
reject(err);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
fs.read(file, buffer, 0, buffer.length, position, (err, bytesRead, buffer) => {
|
|
164
|
+
if (err) {
|
|
165
|
+
reject(err);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
resolve(buffer);
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
static readFileSync(filePath) {
|
|
174
|
+
return fs.readFileSync(filePath);
|
|
175
|
+
}
|
|
176
|
+
static writeFileSync(path, data, options) {
|
|
177
|
+
return fs.writeFileSync(path, data, options);
|
|
178
|
+
}
|
|
179
|
+
static createWriteStream(path) {
|
|
180
|
+
return fs.createWriteStream(path);
|
|
181
|
+
}
|
|
182
|
+
static async unlink(filePath) {
|
|
183
|
+
return new Promise((resolve, reject) => {
|
|
184
|
+
fs.unlink(filePath, (err) => {
|
|
185
|
+
if (!err) {
|
|
186
|
+
resolve();
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
reject(err);
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
static watch(filename, options) {
|
|
195
|
+
return fs.watch(filename, options);
|
|
196
|
+
}
|
|
197
|
+
static stat(filename, options) {
|
|
198
|
+
return new Promise((resolve, reject) => {
|
|
199
|
+
fs.stat(filename, options, (err, stats) => {
|
|
200
|
+
if (err) {
|
|
201
|
+
reject(err);
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
resolve(stats);
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
static createReadStream(path, options) {
|
|
210
|
+
return fs.createReadStream(path, options);
|
|
211
|
+
}
|
|
212
|
+
static createReadLinesStream(path, count) {
|
|
213
|
+
const write = new readable_stream_1.PassThrough();
|
|
214
|
+
(async () => {
|
|
215
|
+
if (typeof count === "undefined" || count > 0) {
|
|
216
|
+
const stats = await FS.stat(path);
|
|
217
|
+
const resLines = [""];
|
|
218
|
+
let position = 0n;
|
|
219
|
+
while (position < stats.size) {
|
|
220
|
+
let size = BigInt(count ? 64 * count : 255);
|
|
221
|
+
if (position + size > stats.size) {
|
|
222
|
+
size = BigInt(stats.size) - position;
|
|
223
|
+
}
|
|
224
|
+
const buffer = await FS.readBytes(path, position, size);
|
|
225
|
+
const lines = buffer.toString("utf-8").split("\n");
|
|
226
|
+
position += size;
|
|
227
|
+
for (let i = 0; i < lines.length; i++) {
|
|
228
|
+
const line = lines[i];
|
|
229
|
+
if (i === 0) {
|
|
230
|
+
resLines[resLines.length - 1] = (resLines[resLines.length - 1] || "") + line;
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
resLines.push(line);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
if (resLines.length > count + 1) {
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
for (let i = 0; i < (count || resLines.length); i++) {
|
|
241
|
+
write.write(resLines[i]);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
else if (count < 0) {
|
|
245
|
+
const stats = await FS.stat(path);
|
|
246
|
+
const resLines = [""];
|
|
247
|
+
let position = BigInt(stats.size);
|
|
248
|
+
while (position > 0n) {
|
|
249
|
+
let size = BigInt(2 * count * -1);
|
|
250
|
+
position -= size;
|
|
251
|
+
if (position < 0) {
|
|
252
|
+
size = position + size;
|
|
253
|
+
position = 0n;
|
|
254
|
+
}
|
|
255
|
+
const buffer = await FS.readBytes(path, position, size);
|
|
256
|
+
const lines = buffer.toString("utf-8").split("\n").reverse();
|
|
257
|
+
for (let i = 0; i < lines.length; i++) {
|
|
258
|
+
const line = lines[i];
|
|
259
|
+
if (i === 0) {
|
|
260
|
+
resLines[0] = line + (resLines[0] || "");
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
resLines.unshift(line);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
if (resLines.length > count * -1 + 1) {
|
|
267
|
+
break;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
const lines = resLines.slice(count - 1);
|
|
271
|
+
for (let i = 0; i < lines.length; i++) {
|
|
272
|
+
write.write(lines[i]);
|
|
273
|
+
}
|
|
274
|
+
write.end();
|
|
275
|
+
}
|
|
276
|
+
})();
|
|
277
|
+
return write;
|
|
278
|
+
}
|
|
279
|
+
static async copyFile(src, dest) {
|
|
280
|
+
new Promise((resolve, reject) => {
|
|
281
|
+
fs.copyFile(src, dest, (err) => {
|
|
282
|
+
if (!err) {
|
|
283
|
+
resolve(undefined);
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
reject(err);
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
}
|
|
319
291
|
}
|
|
320
|
-
exports.FS = FS;
|
|
292
|
+
exports.FS = FS;
|