fsd 0.14.0 → 0.15.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/LICENSE +1 -1
- package/README.md +748 -2
- package/index.d.ts +1083 -71
- package/lib/file.js +13 -12
- package/lib/fsd.js +2 -1
- package/package.json +8 -4
package/lib/file.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
5
|
+
const slash_1 = tslib_1.__importDefault(require("slash"));
|
|
6
|
+
const debug_1 = tslib_1.__importDefault(require("debug"));
|
|
7
|
+
const is_stream_1 = tslib_1.__importDefault(require("is-stream"));
|
|
7
8
|
const stream_1 = require("stream");
|
|
8
|
-
const debug =
|
|
9
|
+
const debug = (0, debug_1.default)('fsd');
|
|
9
10
|
class FSDFile {
|
|
10
11
|
constructor(pathOrFile, adapter, metadata) {
|
|
11
12
|
if (!pathOrFile)
|
|
@@ -19,7 +20,7 @@ class FSDFile {
|
|
|
19
20
|
this._adapter = adapter;
|
|
20
21
|
this.needEnsureDir = adapter.needEnsureDir;
|
|
21
22
|
this.path = path;
|
|
22
|
-
let info =
|
|
23
|
+
let info = path_1.default.parse(path);
|
|
23
24
|
this.dir = info.dir;
|
|
24
25
|
if (this.dir !== '/') {
|
|
25
26
|
this.dir += '/';
|
|
@@ -82,7 +83,7 @@ class FSDFile {
|
|
|
82
83
|
this._lastModified = null;
|
|
83
84
|
let stream = await this._adapter.createWriteStream(this.path);
|
|
84
85
|
if (stream.promise) {
|
|
85
|
-
if (
|
|
86
|
+
if (is_stream_1.default.readable(data)) {
|
|
86
87
|
data.pipe(stream);
|
|
87
88
|
}
|
|
88
89
|
else {
|
|
@@ -94,7 +95,7 @@ class FSDFile {
|
|
|
94
95
|
await new Promise((resolve, reject) => {
|
|
95
96
|
stream.on('error', reject);
|
|
96
97
|
stream.on('finish', resolve);
|
|
97
|
-
if (
|
|
98
|
+
if (is_stream_1.default.readable(data)) {
|
|
98
99
|
data.pipe(stream);
|
|
99
100
|
}
|
|
100
101
|
else {
|
|
@@ -140,7 +141,7 @@ class FSDFile {
|
|
|
140
141
|
}
|
|
141
142
|
let files = await this._adapter.readdir(this.path, recursion);
|
|
142
143
|
return files.map(({ name, metadata }) => {
|
|
143
|
-
let path =
|
|
144
|
+
let path = (0, slash_1.default)(path_1.default.join(this.path, name));
|
|
144
145
|
return new FSDFile(path, this._adapter, metadata);
|
|
145
146
|
});
|
|
146
147
|
}
|
|
@@ -150,8 +151,8 @@ class FSDFile {
|
|
|
150
151
|
}
|
|
151
152
|
async copy(dest) {
|
|
152
153
|
debug('copy %s to %s', this.path, dest);
|
|
153
|
-
if (!
|
|
154
|
-
dest =
|
|
154
|
+
if (!path_1.default.isAbsolute(dest)) {
|
|
155
|
+
dest = (0, slash_1.default)(path_1.default.join(path_1.default.dirname(this.path), dest));
|
|
155
156
|
}
|
|
156
157
|
if (dest === this.path) {
|
|
157
158
|
throw new Error('copy failed, dest path should not equal to source path');
|
|
@@ -227,7 +228,7 @@ class FSDFile {
|
|
|
227
228
|
if (!task.startsWith('task:'))
|
|
228
229
|
throw new Error('Invalid task link');
|
|
229
230
|
let stream;
|
|
230
|
-
if (
|
|
231
|
+
if (is_stream_1.default.readable(data)) {
|
|
231
232
|
stream = data;
|
|
232
233
|
}
|
|
233
234
|
else {
|
package/lib/fsd.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = FSD;
|
|
4
|
-
const
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const file_1 = tslib_1.__importDefault(require("./file"));
|
|
5
6
|
function FSD(options) {
|
|
6
7
|
function fsd(path) {
|
|
7
8
|
return new file_1.default(path, options.adapter);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fsd",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"description": "General file system driver for Node.js",
|
|
5
5
|
"main": "lib/fsd.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -9,12 +9,16 @@
|
|
|
9
9
|
"prepublish": "npm run build"
|
|
10
10
|
},
|
|
11
11
|
"repository": "https://github.com/liangxingchen/fsd/tree/master/packages/fsd",
|
|
12
|
-
"author":
|
|
12
|
+
"author": {
|
|
13
|
+
"name": "Liang",
|
|
14
|
+
"email": "liang@miaomo.cn",
|
|
15
|
+
"url": "https://github.com/liangxingchen"
|
|
16
|
+
},
|
|
13
17
|
"license": "MIT",
|
|
14
18
|
"dependencies": {
|
|
15
|
-
"debug": "^4.4.
|
|
19
|
+
"debug": "^4.4.3",
|
|
16
20
|
"is-stream": "^2.0.1",
|
|
17
21
|
"slash": "^3.0.0"
|
|
18
22
|
},
|
|
19
|
-
"gitHead": "
|
|
23
|
+
"gitHead": "ea754919fb95b49deffd529b5c01c66da0dc08f9"
|
|
20
24
|
}
|