@wocker/core 1.0.22 → 1.0.23-beta.1
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/lib/core/ApplicationContext.js +18 -17
- package/lib/core/ControllerWrapper.d.ts +0 -1
- package/lib/core/ControllerWrapper.js +1 -14
- package/lib/core/InstanceWrapper.d.ts +0 -1
- package/lib/core/InstanceWrapper.js +0 -1
- package/lib/decorators/Global.d.ts +0 -1
- package/lib/decorators/Global.js +0 -1
- package/lib/decorators/Injectable.d.ts +5 -1
- package/lib/decorators/Injectable.js +5 -1
- package/lib/exceptions/UsageException.d.ts +3 -0
- package/lib/exceptions/UsageException.js +10 -0
- package/lib/exceptions/index.d.ts +1 -0
- package/lib/exceptions/index.js +17 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/makes/AppConfig.d.ts +19 -30
- package/lib/makes/AppConfig.js +20 -20
- package/lib/makes/Config.d.ts +6 -0
- package/lib/makes/Config.js +4 -0
- package/lib/makes/ConfigCollection.d.ts +6 -0
- package/lib/makes/ConfigCollection.js +4 -0
- package/lib/makes/File.d.ts +32 -0
- package/lib/makes/File.js +140 -0
- package/lib/makes/FileSystem.d.ts +33 -13
- package/lib/makes/FileSystem.js +66 -51
- package/lib/makes/FileSystemManager.d.ts +7 -4
- package/lib/makes/FileSystemManager.js +20 -3
- package/lib/makes/Project.d.ts +9 -3
- package/lib/makes/Project.js +11 -3
- package/lib/makes/index.d.ts +0 -2
- package/lib/makes/index.js +0 -2
- package/lib/services/AppConfigService.d.ts +6 -1
- package/lib/services/AppConfigService.js +16 -5
- package/lib/services/DockerService.d.ts +3 -1
- package/lib/services/ModemService.d.ts +4 -0
- package/lib/services/ModemService.js +16 -0
- package/lib/services/index.d.ts +1 -0
- package/lib/services/index.js +1 -0
- package/lib/types/FileSystemDriver.d.ts +38 -0
- package/lib/types/FileSystemDriver.js +2 -0
- package/lib/types/PluginRef.d.ts +4 -0
- package/lib/types/PluginRef.js +2 -0
- package/lib/types/PresetRef.d.ts +6 -0
- package/lib/types/PresetRef.js +2 -0
- package/lib/types/ProjectRef.d.ts +16 -0
- package/lib/types/ProjectRef.js +2 -0
- package/lib/types/Provider.d.ts +1 -1
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.js +1 -0
- package/package.json +8 -4
- package/lib/makes/FS.d.ts +0 -19
- package/lib/makes/FS.js +0 -170
- package/lib/makes/FSManager.d.ts +0 -14
- package/lib/makes/FSManager.js +0 -122
|
@@ -31,27 +31,28 @@ class ApplicationContext {
|
|
|
31
31
|
return __awaiter(this, void 0, void 0, function* () {
|
|
32
32
|
const cli = this.get(cli_1.Cli);
|
|
33
33
|
cli.command("").action(() => {
|
|
34
|
-
const module
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
console.info(`${container.description}:`);
|
|
40
|
-
const spaceLength = container.commands.reduce((space, route) => {
|
|
41
|
-
return route.commandNames.reduce((space, command) => {
|
|
42
|
-
return Math.max(space, command.length + 2);
|
|
43
|
-
}, space);
|
|
44
|
-
}, 0);
|
|
45
|
-
for (const route of container.commands) {
|
|
46
|
-
if (!route.description) {
|
|
34
|
+
for (const [, module] of this.container.modules) {
|
|
35
|
+
for (const [, container] of module.controllers) {
|
|
36
|
+
if (!container.description) {
|
|
47
37
|
continue;
|
|
48
38
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
39
|
+
console.info(`${container.description}:`);
|
|
40
|
+
const spaceLength = container.commands.reduce((space, route) => {
|
|
41
|
+
return route.commandNames.reduce((space, command) => {
|
|
42
|
+
return Math.max(space, command.length + 2);
|
|
43
|
+
}, space);
|
|
44
|
+
}, 0);
|
|
45
|
+
for (const route of container.commands) {
|
|
46
|
+
if (!route.description) {
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
for (const commandName of route.commandNames) {
|
|
50
|
+
const space = " ".repeat(Math.max(0, spaceLength - commandName.length));
|
|
51
|
+
console.info(` ${commandName} ${space} ${route.description}`);
|
|
52
|
+
}
|
|
52
53
|
}
|
|
54
|
+
console.info("");
|
|
53
55
|
}
|
|
54
|
-
console.info("");
|
|
55
56
|
}
|
|
56
57
|
});
|
|
57
58
|
return cli.run(args);
|
|
@@ -10,7 +10,6 @@ export declare class ControllerWrapper<TInput = any> extends InstanceWrapper {
|
|
|
10
10
|
commands: Route[];
|
|
11
11
|
completions: Route[];
|
|
12
12
|
constructor(module: Module, type: Type<TInput>);
|
|
13
|
-
getRoutes(): Route[];
|
|
14
13
|
getCompletionCommands(name: string, command: string): Route[];
|
|
15
14
|
run(route: Route, input: CommandInput): any;
|
|
16
15
|
}
|
|
@@ -27,19 +27,6 @@ class ControllerWrapper extends InstanceWrapper_1.InstanceWrapper {
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
getRoutes() {
|
|
31
|
-
const routes = [];
|
|
32
|
-
if (!this.type) {
|
|
33
|
-
return [];
|
|
34
|
-
}
|
|
35
|
-
for (const method of Object.getOwnPropertyNames(this.type.prototype)) {
|
|
36
|
-
const route = new Route_1.Route(this.type, method);
|
|
37
|
-
if (route.isCommand || route.isCompletion) {
|
|
38
|
-
routes.push(route);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return routes;
|
|
42
|
-
}
|
|
43
30
|
getCompletionCommands(name, command) {
|
|
44
31
|
const completions = this.completions.filter((route) => {
|
|
45
32
|
return route.completions.filter((completion) => {
|
|
@@ -52,7 +39,7 @@ class ControllerWrapper extends InstanceWrapper_1.InstanceWrapper {
|
|
|
52
39
|
return this.completions.filter((route) => {
|
|
53
40
|
return route.completions.filter((completion) => {
|
|
54
41
|
return completion.name === name && !completion.command;
|
|
55
|
-
});
|
|
42
|
+
}).length > 0;
|
|
56
43
|
});
|
|
57
44
|
}
|
|
58
45
|
run(route, input) {
|
package/lib/decorators/Global.js
CHANGED
|
@@ -2,9 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Injectable = void 0;
|
|
4
4
|
const env_1 = require("../env");
|
|
5
|
-
const Injectable = (
|
|
5
|
+
const Injectable = (tokenOrOptions) => {
|
|
6
6
|
return (target) => {
|
|
7
7
|
Reflect.defineMetadata(env_1.INJECTABLE_WATERMARK, true, target);
|
|
8
|
+
if (!tokenOrOptions) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const { token } = typeof tokenOrOptions === "string" ? { token: tokenOrOptions } : tokenOrOptions;
|
|
8
12
|
if (token) {
|
|
9
13
|
Reflect.defineMetadata(env_1.INJECT_TOKEN_METADATA, token, target);
|
|
10
14
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UsageException = void 0;
|
|
4
|
+
class UsageException extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = "UsageException";
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.UsageException = UsageException;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./UsageException";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./UsageException"), exports);
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -21,6 +21,7 @@ Object.defineProperty(exports, "Cli", { enumerable: true, get: function () { ret
|
|
|
21
21
|
Object.defineProperty(exports, "CommandNotFoundError", { enumerable: true, get: function () { return cli_1.CommandNotFoundError; } });
|
|
22
22
|
__exportStar(require("./core"), exports);
|
|
23
23
|
__exportStar(require("./decorators"), exports);
|
|
24
|
+
__exportStar(require("./exceptions"), exports);
|
|
24
25
|
__exportStar(require("./makes"), exports);
|
|
25
26
|
__exportStar(require("./services"), exports);
|
|
26
27
|
__exportStar(require("./types"), exports);
|
package/lib/makes/AppConfig.d.ts
CHANGED
|
@@ -1,50 +1,37 @@
|
|
|
1
1
|
import { EnvConfig } from "../types";
|
|
2
|
+
import { PluginRef } from "../types/PluginRef";
|
|
3
|
+
import { PresetRef } from "../types/PresetRef";
|
|
4
|
+
import { ProjectRef, ProjectOldRef } from "../types/ProjectRef";
|
|
2
5
|
import { PresetSource } from "./Preset";
|
|
3
|
-
type ProjectData = {
|
|
4
|
-
id: string;
|
|
5
|
-
name?: string;
|
|
6
|
-
path?: string;
|
|
7
|
-
/** @deprecated */
|
|
8
|
-
src?: string;
|
|
9
|
-
};
|
|
10
|
-
type PluginData = {
|
|
11
|
-
name: string;
|
|
12
|
-
env: "latest" | "beta";
|
|
13
|
-
};
|
|
14
|
-
type PresetData = {
|
|
15
|
-
name: string;
|
|
16
|
-
source: PresetSource;
|
|
17
|
-
path?: string;
|
|
18
|
-
};
|
|
19
6
|
export type AppConfigProperties = {
|
|
20
7
|
debug?: boolean;
|
|
21
8
|
keystore?: string;
|
|
22
9
|
logLevel?: "off" | "info" | "warn" | "error";
|
|
23
|
-
plugins?:
|
|
24
|
-
presets?:
|
|
25
|
-
projects?:
|
|
10
|
+
plugins?: PluginRef[];
|
|
11
|
+
presets?: PresetRef[];
|
|
12
|
+
projects?: ProjectOldRef[];
|
|
26
13
|
meta?: EnvConfig;
|
|
27
14
|
env?: EnvConfig;
|
|
28
15
|
};
|
|
29
|
-
export declare
|
|
16
|
+
export declare class AppConfig {
|
|
30
17
|
debug?: boolean;
|
|
31
18
|
keystore?: string;
|
|
32
19
|
logLevel: "off" | "info" | "warn" | "error";
|
|
33
|
-
plugins:
|
|
34
|
-
presets:
|
|
35
|
-
projects:
|
|
20
|
+
plugins: PluginRef[];
|
|
21
|
+
presets: PresetRef[];
|
|
22
|
+
projects: ProjectRef[];
|
|
36
23
|
meta?: EnvConfig;
|
|
37
24
|
env?: EnvConfig;
|
|
38
|
-
|
|
39
|
-
addPlugin(name: string, env?:
|
|
25
|
+
constructor(data: AppConfigProperties);
|
|
26
|
+
addPlugin(name: string, env?: PluginRef["env"]): void;
|
|
40
27
|
removePlugin(name: string): void;
|
|
41
|
-
getProject(
|
|
28
|
+
getProject(name: string): ProjectRef | undefined;
|
|
42
29
|
addProject(id: string, name: string, path: string): void;
|
|
43
|
-
removeProject(
|
|
30
|
+
removeProject(name: string): void;
|
|
44
31
|
registerPreset(name: string, source: PresetSource, path?: string): void;
|
|
45
32
|
unregisterPreset(name: string): void;
|
|
46
33
|
hasMeta(name: string): boolean;
|
|
47
|
-
getMeta(name: string): string | undefined;
|
|
34
|
+
getMeta(name: string, defaultValue?: string): string | undefined;
|
|
48
35
|
getMeta(name: string, defaultValue: string): string;
|
|
49
36
|
setMeta(name: string, value: string): void;
|
|
50
37
|
unsetMeta(name: string): void;
|
|
@@ -52,7 +39,10 @@ export declare abstract class AppConfig {
|
|
|
52
39
|
getEnv(name: string, defaultValue: string): string;
|
|
53
40
|
setEnv(name: string, value: string): void;
|
|
54
41
|
unsetEnv(name: string): void;
|
|
55
|
-
|
|
42
|
+
/**
|
|
43
|
+
* @deprecated
|
|
44
|
+
*/
|
|
45
|
+
save(): void;
|
|
56
46
|
/**
|
|
57
47
|
* @deprecated
|
|
58
48
|
*/
|
|
@@ -61,4 +51,3 @@ export declare abstract class AppConfig {
|
|
|
61
51
|
toJsString(): string;
|
|
62
52
|
toString(): string;
|
|
63
53
|
}
|
|
64
|
-
export {};
|
package/lib/makes/AppConfig.js
CHANGED
|
@@ -28,7 +28,13 @@ class AppConfig {
|
|
|
28
28
|
return plugin;
|
|
29
29
|
});
|
|
30
30
|
this.presets = presets;
|
|
31
|
-
this.projects = projects
|
|
31
|
+
this.projects = projects.map((ref) => {
|
|
32
|
+
const { id, name, path, src } = ref;
|
|
33
|
+
return {
|
|
34
|
+
name: (name || id),
|
|
35
|
+
path: (path || src)
|
|
36
|
+
};
|
|
37
|
+
});
|
|
32
38
|
}
|
|
33
39
|
addPlugin(name, env = "latest") {
|
|
34
40
|
const plugin = this.plugins.find((plugin) => plugin.name === name);
|
|
@@ -48,42 +54,32 @@ class AppConfig {
|
|
|
48
54
|
}
|
|
49
55
|
this.plugins = this.plugins.filter((plugin) => plugin.name !== name);
|
|
50
56
|
}
|
|
51
|
-
getProject(
|
|
57
|
+
getProject(name) {
|
|
52
58
|
if (!this.projects) {
|
|
53
59
|
return;
|
|
54
60
|
}
|
|
55
61
|
return this.projects.find((projectData) => {
|
|
56
|
-
return projectData.
|
|
62
|
+
return projectData.name === name;
|
|
57
63
|
});
|
|
58
64
|
}
|
|
59
65
|
addProject(id, name, path) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
let projectData = this.projects.find((projectData) => {
|
|
64
|
-
return projectData.id === id;
|
|
65
|
-
});
|
|
66
|
-
if (!projectData) {
|
|
66
|
+
let projectRef = this.getProject(name);
|
|
67
|
+
if (!projectRef) {
|
|
67
68
|
this.projects.push({
|
|
68
|
-
id,
|
|
69
69
|
name,
|
|
70
|
-
path
|
|
70
|
+
path
|
|
71
71
|
});
|
|
72
72
|
return;
|
|
73
73
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
delete projectData.src;
|
|
77
|
-
}
|
|
78
|
-
projectData.name = name;
|
|
79
|
-
projectData.path = path;
|
|
74
|
+
projectRef.name = name;
|
|
75
|
+
projectRef.path = path;
|
|
80
76
|
}
|
|
81
|
-
removeProject(
|
|
77
|
+
removeProject(name) {
|
|
82
78
|
if (this.projects.length === 0) {
|
|
83
79
|
return;
|
|
84
80
|
}
|
|
85
81
|
this.projects = this.projects.filter((projectData) => {
|
|
86
|
-
return projectData.
|
|
82
|
+
return projectData.name !== name;
|
|
87
83
|
});
|
|
88
84
|
}
|
|
89
85
|
registerPreset(name, source, path) {
|
|
@@ -167,6 +163,10 @@ class AppConfig {
|
|
|
167
163
|
delete this.env;
|
|
168
164
|
}
|
|
169
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* @deprecated
|
|
168
|
+
*/
|
|
169
|
+
save() { }
|
|
170
170
|
/**
|
|
171
171
|
* @deprecated
|
|
172
172
|
*/
|
package/lib/makes/Config.d.ts
CHANGED
package/lib/makes/Config.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { Config, ConfigProperties } from "./Config";
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated
|
|
4
|
+
*/
|
|
2
5
|
interface Constructible<P extends ConfigProperties, C extends Config<P>> {
|
|
3
6
|
new (props: P): C;
|
|
4
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* @deprecated
|
|
10
|
+
*/
|
|
5
11
|
export declare class ConfigCollection<C extends Config<P>, P extends ConfigProperties> {
|
|
6
12
|
protected ConfigClass: Constructible<P, C>;
|
|
7
13
|
items: C[];
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ConfigCollection = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated
|
|
6
|
+
*/
|
|
7
|
+
/* istanbul ignore next */
|
|
4
8
|
class ConfigCollection {
|
|
5
9
|
constructor(ConfigClass, items) {
|
|
6
10
|
this.ConfigClass = ConfigClass;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import FS from "fs";
|
|
2
|
+
import { Readable } from "stream";
|
|
3
|
+
import { FileSystemDriver } from "../types";
|
|
4
|
+
type ReadStreamOptions = {
|
|
5
|
+
start?: number;
|
|
6
|
+
end?: number;
|
|
7
|
+
encoding?: BufferEncoding;
|
|
8
|
+
};
|
|
9
|
+
type ReadlineStreamOptions = {
|
|
10
|
+
start?: number;
|
|
11
|
+
end?: number;
|
|
12
|
+
encoding?: ReadStreamOptions["encoding"];
|
|
13
|
+
};
|
|
14
|
+
export declare class File {
|
|
15
|
+
readonly path: string;
|
|
16
|
+
readonly flags: FS.OpenMode;
|
|
17
|
+
readonly mode: FS.Mode | null | undefined;
|
|
18
|
+
protected readonly driver: FileSystemDriver;
|
|
19
|
+
protected _fd: number;
|
|
20
|
+
protected _closed: boolean;
|
|
21
|
+
constructor(path: string, flags: FS.OpenMode | undefined, mode: FS.Mode | null | undefined, driver?: FileSystemDriver);
|
|
22
|
+
get fd(): number;
|
|
23
|
+
get closed(): boolean;
|
|
24
|
+
open(): void;
|
|
25
|
+
stat(): FS.Stats;
|
|
26
|
+
close(): void;
|
|
27
|
+
createReadStream(options?: ReadStreamOptions): FS.ReadStream;
|
|
28
|
+
createReadlineStream(options?: ReadlineStreamOptions): Readable;
|
|
29
|
+
readBytes(position?: number, size?: number): Buffer<ArrayBuffer>;
|
|
30
|
+
getLinePosition(line: number): number;
|
|
31
|
+
}
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.File = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const stream_1 = require("stream");
|
|
9
|
+
const readline_1 = require("readline");
|
|
10
|
+
class File {
|
|
11
|
+
constructor(path, flags = "r", mode, driver = fs_1.default) {
|
|
12
|
+
this.path = path;
|
|
13
|
+
this.flags = flags;
|
|
14
|
+
this.mode = mode;
|
|
15
|
+
this.driver = driver;
|
|
16
|
+
this._closed = true;
|
|
17
|
+
this.open();
|
|
18
|
+
}
|
|
19
|
+
get fd() {
|
|
20
|
+
return this._fd;
|
|
21
|
+
}
|
|
22
|
+
get closed() {
|
|
23
|
+
return this._closed;
|
|
24
|
+
}
|
|
25
|
+
open() {
|
|
26
|
+
if (!this.closed) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
this._fd = this.driver.openSync(this.path, this.flags, this.mode);
|
|
30
|
+
this._closed = false;
|
|
31
|
+
}
|
|
32
|
+
stat() {
|
|
33
|
+
return this.driver.fstatSync(this.fd);
|
|
34
|
+
}
|
|
35
|
+
close() {
|
|
36
|
+
if (this.closed) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
this.driver.closeSync(this.fd);
|
|
40
|
+
this._closed = true;
|
|
41
|
+
}
|
|
42
|
+
createReadStream(options) {
|
|
43
|
+
const stream = this.driver.createReadStream(this.path, Object.assign(Object.assign({}, options || {}), { fd: this.fd, autoClose: false, emitClose: false }));
|
|
44
|
+
stream.on("close", () => {
|
|
45
|
+
this._closed = true;
|
|
46
|
+
});
|
|
47
|
+
return stream;
|
|
48
|
+
}
|
|
49
|
+
createReadlineStream(options) {
|
|
50
|
+
let { start, end, encoding } = options || {};
|
|
51
|
+
const startLine = typeof start !== "undefined"
|
|
52
|
+
? this.getLinePosition(start)
|
|
53
|
+
: undefined;
|
|
54
|
+
const endLine = typeof end !== "undefined"
|
|
55
|
+
? this.getLinePosition(end)
|
|
56
|
+
: undefined;
|
|
57
|
+
const stream = this.createReadStream({
|
|
58
|
+
encoding: encoding,
|
|
59
|
+
start: startLine,
|
|
60
|
+
end: endLine
|
|
61
|
+
});
|
|
62
|
+
const outputStream = new stream_1.Readable({
|
|
63
|
+
objectMode: true,
|
|
64
|
+
read() { }
|
|
65
|
+
});
|
|
66
|
+
const readline = (0, readline_1.createInterface)({
|
|
67
|
+
input: stream,
|
|
68
|
+
crlfDelay: Infinity
|
|
69
|
+
});
|
|
70
|
+
readline.on("line", (line) => {
|
|
71
|
+
outputStream.push(line);
|
|
72
|
+
});
|
|
73
|
+
readline.on("close", () => {
|
|
74
|
+
outputStream.push(null);
|
|
75
|
+
});
|
|
76
|
+
readline.on("error", (err) => {
|
|
77
|
+
outputStream.emit("error", err);
|
|
78
|
+
});
|
|
79
|
+
stream.on("error", (err) => {
|
|
80
|
+
outputStream.emit("error", err);
|
|
81
|
+
});
|
|
82
|
+
return outputStream;
|
|
83
|
+
}
|
|
84
|
+
readBytes(position = 0, size) {
|
|
85
|
+
const stats = this.stat();
|
|
86
|
+
if (position < 0 && typeof size === "undefined") {
|
|
87
|
+
size = position * -1;
|
|
88
|
+
position = stats.size - size;
|
|
89
|
+
}
|
|
90
|
+
else if (typeof size === "undefined") {
|
|
91
|
+
size = stats.size - position;
|
|
92
|
+
}
|
|
93
|
+
if (size <= 0) {
|
|
94
|
+
return Buffer.alloc(0);
|
|
95
|
+
}
|
|
96
|
+
const buffer = Buffer.alloc(size);
|
|
97
|
+
this.driver.readSync(this.fd, buffer, 0, size, position);
|
|
98
|
+
return buffer;
|
|
99
|
+
}
|
|
100
|
+
getLinePosition(line) {
|
|
101
|
+
var _a, _b;
|
|
102
|
+
if (line === 0) {
|
|
103
|
+
throw new Error("Line number must be a non-zero");
|
|
104
|
+
}
|
|
105
|
+
const bufferSize = 1024, isForward = line > 0, targetLine = Math.abs(line), stats = this.stat();
|
|
106
|
+
let position = isForward ? 0 : stats.size, currentLine = 0, currentOffset = isForward ? 0 : stats.size + 1, stump = "";
|
|
107
|
+
while (isForward ? position < stats.size : position > 0) {
|
|
108
|
+
const readSize = isForward
|
|
109
|
+
? Math.min(bufferSize, stats.size - position)
|
|
110
|
+
: Math.min(bufferSize, position);
|
|
111
|
+
if (!isForward) {
|
|
112
|
+
position -= readSize;
|
|
113
|
+
}
|
|
114
|
+
const chunk = this.readBytes(position, readSize).toString(), lines = (isForward ? stump + chunk : chunk + stump).split("\n");
|
|
115
|
+
if (isForward) {
|
|
116
|
+
position += readSize;
|
|
117
|
+
}
|
|
118
|
+
if (isForward ? position === stats.size : position === 0) {
|
|
119
|
+
stump = "";
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
stump = isForward
|
|
123
|
+
? (_a = lines.pop()) !== null && _a !== void 0 ? _a : ""
|
|
124
|
+
: (_b = lines.shift()) !== null && _b !== void 0 ? _b : "";
|
|
125
|
+
}
|
|
126
|
+
for (let i = isForward ? 0 : lines.length - 1; isForward ? i < lines.length : i >= 0; isForward ? i++ : i--) {
|
|
127
|
+
const lineLength = Buffer.byteLength(`${lines[i]}\n`);
|
|
128
|
+
currentLine++;
|
|
129
|
+
if (currentLine === targetLine) {
|
|
130
|
+
return isForward ? currentOffset : currentOffset - lineLength;
|
|
131
|
+
}
|
|
132
|
+
currentOffset += isForward ? lineLength : -lineLength;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return isForward
|
|
136
|
+
? Math.min(currentOffset, stats.size)
|
|
137
|
+
: Math.max(currentOffset, 0);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
exports.File = File;
|
|
@@ -1,24 +1,44 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import FS from "fs";
|
|
2
|
+
import { Readable } from "stream";
|
|
3
|
+
import { FileSystemDriver, ReadStreamOptions, WriteStreamOptions } from "../types";
|
|
4
|
+
import { File } from "./File";
|
|
5
|
+
type ReaddirOptions = FS.ObjectEncodingOptions & {
|
|
3
6
|
recursive?: boolean | undefined;
|
|
4
7
|
};
|
|
8
|
+
type ReadlineOptions = {
|
|
9
|
+
encoding?: BufferEncoding;
|
|
10
|
+
start?: number;
|
|
11
|
+
end?: number;
|
|
12
|
+
};
|
|
5
13
|
export declare class FileSystem {
|
|
6
14
|
protected readonly source: string;
|
|
7
|
-
|
|
15
|
+
protected readonly driver: FileSystemDriver;
|
|
16
|
+
constructor(source: string, driver?: FileSystemDriver);
|
|
8
17
|
path(...parts: string[]): string;
|
|
18
|
+
cd(path: string): FileSystem;
|
|
19
|
+
readBytes(path: string, position?: number, size?: number): Buffer<ArrayBuffer>;
|
|
20
|
+
open(path: string, flags: FS.OpenMode, mode?: FS.Mode | null): File;
|
|
9
21
|
basename(...parts: string[]): string;
|
|
10
22
|
exists(...parts: string[]): boolean;
|
|
11
|
-
stat(...parts: string[]): Stats;
|
|
12
|
-
mkdir(path?: string, options?: MakeDirectoryOptions): void;
|
|
13
|
-
readdir(path
|
|
23
|
+
stat(...parts: string[]): FS.Stats;
|
|
24
|
+
mkdir(path?: string, options?: FS.MakeDirectoryOptions): void;
|
|
25
|
+
readdir(path?: string, options?: {
|
|
26
|
+
recursive?: boolean;
|
|
27
|
+
}): string[];
|
|
28
|
+
/**
|
|
29
|
+
* @deprecated
|
|
30
|
+
*/
|
|
14
31
|
readdirFiles(path?: string, options?: ReaddirOptions): Promise<string[]>;
|
|
15
|
-
readFile(path: string): Buffer;
|
|
32
|
+
readFile(path: string): string | Buffer;
|
|
16
33
|
readJSON(...paths: string[]): any;
|
|
17
|
-
writeFile(path: string, data: string | Buffer | NodeJS.ArrayBufferView, options?:
|
|
18
|
-
writeJSON(path: string, data: any, options?: WriteFileOptions): void;
|
|
19
|
-
appendFile(path: string, data: string | Uint8Array, options?: WriteFileOptions): void;
|
|
20
|
-
rm(path: string, options?: RmOptions): void;
|
|
21
|
-
createWriteStream(path: string, options?:
|
|
22
|
-
createReadStream(path: string, options?:
|
|
34
|
+
writeFile(path: string, data: string | Buffer | NodeJS.ArrayBufferView, options?: FS.WriteFileOptions): void;
|
|
35
|
+
writeJSON(path: string, data: any, options?: FS.WriteFileOptions): void;
|
|
36
|
+
appendFile(path: string, data: string | Uint8Array, options?: FS.WriteFileOptions): void;
|
|
37
|
+
rm(path: string, options?: FS.RmOptions): void;
|
|
38
|
+
createWriteStream(path: string, options?: WriteStreamOptions): FS.WriteStream;
|
|
39
|
+
createReadStream(path: string, options?: ReadStreamOptions): FS.ReadStream;
|
|
40
|
+
createReadlineStream(path: string, options?: ReadlineOptions): Readable;
|
|
41
|
+
getLinePosition(path: string, line: number): number;
|
|
42
|
+
watch(path: string, options?: FS.WatchOptions): FS.FSWatcher;
|
|
23
43
|
}
|
|
24
44
|
export {};
|