@platform/fs
Advanced tools
Comparing version 0.1.0 to 0.1.1
/// <reference types="node" /> | ||
import { File } from '../file'; | ||
import * as fsExtra from 'fs-extra'; | ||
import * as path from 'path'; | ||
import { Zipper } from '../zip'; | ||
import { File } from '../file'; | ||
import { glob } from '../glob'; | ||
import { is } from '../is'; | ||
import { merge } from '../merge'; | ||
import { is } from '../is'; | ||
import { folderSize } from './helpers'; | ||
import { unzip, zip } from '../zip'; | ||
export declare const fs: { | ||
size: { | ||
toString(bytes: number, options?: import("../size").IFileSizeStringOptions | undefined): string; | ||
file(path: string): Promise<import("../size").IFileSize>; | ||
dir(path: string): Promise<{ | ||
path: string; | ||
bytes: number; | ||
files: import("../size").IFileSize[]; | ||
toString(options?: import("../size").IFileSizeStringOptions | undefined): string; | ||
}>; | ||
}; | ||
glob: typeof glob; | ||
@@ -15,5 +24,4 @@ file: typeof File; | ||
is: typeof is; | ||
folderSize: typeof folderSize; | ||
zip: Zipper; | ||
unzip: typeof Zipper.unzip; | ||
zip: typeof zip; | ||
unzip: typeof unzip; | ||
path: typeof path; | ||
@@ -85,6 +93,6 @@ join: typeof path.join; | ||
ensureLinkSync(src: string, dest: string): void; | ||
ensureSymlink(src: string, dest: string, type?: "dir" | "file" | undefined): Promise<void>; | ||
ensureSymlink(src: string, dest: string, type?: "file" | "dir" | undefined): Promise<void>; | ||
ensureSymlink(src: string, dest: string, type: fsExtra.SymlinkType, callback: (err: Error) => void): void; | ||
ensureSymlink(src: string, dest: string, callback: (err: Error) => void): void; | ||
ensureSymlinkSync(src: string, dest: string, type?: "dir" | "file" | undefined): void; | ||
ensureSymlinkSync(src: string, dest: string, type?: "file" | "dir" | undefined): void; | ||
emptyDir(path: string): Promise<void>; | ||
@@ -180,5 +188,5 @@ emptyDir(path: string, callback: (err: Error) => void): void; | ||
stat(path: string | Buffer): Promise<fsExtra.Stats>; | ||
symlink(srcpath: string | Buffer, dstpath: string | Buffer, type: "dir" | "file" | "junction" | undefined, callback: (err: NodeJS.ErrnoException) => void): void; | ||
symlink(srcpath: string | Buffer, dstpath: string | Buffer, type: "file" | "dir" | "junction" | undefined, callback: (err: NodeJS.ErrnoException) => void): void; | ||
symlink(srcpath: string | Buffer, dstpath: string | Buffer, callback: (err: NodeJS.ErrnoException) => void): void; | ||
symlink(srcpath: string | Buffer, dstpath: string | Buffer, type?: "dir" | "file" | "junction" | undefined): Promise<void>; | ||
symlink(srcpath: string | Buffer, dstpath: string | Buffer, type?: "file" | "dir" | "junction" | undefined): Promise<void>; | ||
truncate(path: string | Buffer, callback: (err: NodeJS.ErrnoException) => void): void; | ||
@@ -219,3 +227,3 @@ truncate(path: string | Buffer, len: number, callback: (err: NodeJS.ErrnoException) => void): void; | ||
linkSync(existingPath: fsExtra.PathLike, newPath: fsExtra.PathLike): void; | ||
symlinkSync(target: fsExtra.PathLike, path: fsExtra.PathLike, type?: "dir" | "file" | "junction" | null | undefined): void; | ||
symlinkSync(target: fsExtra.PathLike, path: fsExtra.PathLike, type?: "file" | "dir" | "junction" | null | undefined): void; | ||
readlinkSync(path: fsExtra.PathLike, options?: "utf-8" | "utf8" | { | ||
@@ -222,0 +230,0 @@ encoding?: "utf-8" | "utf8" | "ascii" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex" | null | undefined; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var file_1 = require("../file"); | ||
var fsExtra = require("fs-extra"); | ||
var path = require("path"); | ||
var zip_1 = require("../zip"); | ||
var file_1 = require("../file"); | ||
var glob_1 = require("../glob"); | ||
var is_1 = require("../is"); | ||
var merge_1 = require("../merge"); | ||
var is_1 = require("../is"); | ||
var helpers_1 = require("./helpers"); | ||
exports.fs = tslib_1.__assign({}, fsExtra, { glob: glob_1.glob, file: file_1.File, merge: merge_1.merge, | ||
var size_1 = require("../size"); | ||
var zip_1 = require("../zip"); | ||
exports.fs = tslib_1.__assign({}, fsExtra, { size: size_1.size, | ||
glob: glob_1.glob, file: file_1.File, merge: merge_1.merge, | ||
is: is_1.is, | ||
folderSize: helpers_1.folderSize, | ||
get zip() { | ||
return new zip_1.Zipper(); | ||
}, unzip: zip_1.Zipper.unzip, path: path, join: path.join, resolve: path.resolve, dirname: path.dirname, basename: path.basename, extname: path.extname }); | ||
zip: zip_1.zip, | ||
unzip: zip_1.unzip, | ||
path: path, join: path.join, resolve: path.resolve, dirname: path.dirname, basename: path.basename, extname: path.extname }); |
@@ -7,29 +7,32 @@ "use strict"; | ||
var _1 = require("."); | ||
describe('fs', function () { | ||
it('reads file', function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
var path, txt; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
path = _1.fs.resolve('./test/sample/my-file.md'); | ||
return [4, _1.fs.readFile(path, 'utf8')]; | ||
case 1: | ||
txt = _a.sent(); | ||
chai_1.expect(txt).to.include('# Hello'); | ||
return [2]; | ||
} | ||
}); | ||
}); }); | ||
it('has path helpers', function () { | ||
chai_1.expect(_1.fs.path.join).to.be.an.instanceof(Function); | ||
chai_1.expect(_1.fs.join).to.be.an.instanceof(Function); | ||
chai_1.expect(_1.fs.resolve).to.be.an.instanceof(Function); | ||
chai_1.expect(_1.fs.dirname).to.be.an.instanceof(Function); | ||
chai_1.expect(_1.fs.basename).to.be.an.instanceof(Function); | ||
chai_1.expect(_1.fs.extname).to.be.an.instanceof(Function); | ||
describe('size', function () { | ||
describe('file', function () { | ||
it('calculates the size of single file', function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
var res; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4, _1.fs.size.file('./src/index.ts')]; | ||
case 1: | ||
res = _a.sent(); | ||
chai_1.expect(res.bytes).to.greaterThan(30); | ||
chai_1.expect(res.path).to.eql('./src/index.ts'); | ||
return [2]; | ||
} | ||
}); | ||
}); }); | ||
it('toString', function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
var res; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4, _1.fs.size.file('./test/file/foo.json')]; | ||
case 1: | ||
res = _a.sent(); | ||
chai_1.expect(res.toString()).to.eql('20 B'); | ||
chai_1.expect(res.toString({ spacer: '' })).to.eql('20B'); | ||
return [2]; | ||
} | ||
}); | ||
}); }); | ||
}); | ||
it('has glob helper', function () { | ||
chai_1.expect(_1.fs.glob.find).to.be.an.instanceof(Function); | ||
}); | ||
describe('folderSize', function () { | ||
describe('dir', function () { | ||
it('calculates the size of a directory', function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
@@ -39,3 +42,3 @@ var res; | ||
switch (_a.label) { | ||
case 0: return [4, _1.fs.folderSize('./src')]; | ||
case 0: return [4, _1.fs.size.dir('./src')]; | ||
case 1: | ||
@@ -45,2 +48,3 @@ res = _a.sent(); | ||
chai_1.expect(res.bytes).to.greaterThan(1000); | ||
chai_1.expect(res.path).to.eql('./src'); | ||
return [2]; | ||
@@ -50,2 +54,14 @@ } | ||
}); }); | ||
it('toString', function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
var res; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4, _1.fs.size.dir('./test/file')]; | ||
case 1: | ||
res = _a.sent(); | ||
chai_1.expect(res.toString()).to.eql('826 B'); | ||
return [2]; | ||
} | ||
}); | ||
}); }); | ||
it('nothing when path does not exist', function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
@@ -55,3 +71,3 @@ var res; | ||
switch (_a.label) { | ||
case 0: return [4, _1.fs.folderSize('./NO_EXIST')]; | ||
case 0: return [4, _1.fs.size.dir('./NO_EXIST')]; | ||
case 1: | ||
@@ -66,2 +82,11 @@ res = _a.sent(); | ||
}); | ||
describe('size.toString( bytes )', function () { | ||
it('converts to human readable size', function () { | ||
chai_1.expect(_1.fs.size.toString(123)).to.eql('123 B'); | ||
chai_1.expect(_1.fs.size.toString(9999)).to.eql('9.76 KB'); | ||
chai_1.expect(_1.fs.size.toString(9999, { spacer: '' })).to.eql('9.76KB'); | ||
chai_1.expect(_1.fs.size.toString(9999, { round: 1 })).to.eql('9.8 KB'); | ||
chai_1.expect(_1.fs.size.toString(9999, { round: 0 })).to.eql('10 KB'); | ||
}); | ||
}); | ||
}); |
export * from './Zipper'; | ||
export * from './unzip'; |
@@ -5,1 +5,2 @@ "use strict"; | ||
tslib_1.__exportStar(require("./Zipper"), exports); | ||
tslib_1.__exportStar(require("./unzip"), exports); |
@@ -7,3 +7,3 @@ "use strict"; | ||
var __1 = require(".."); | ||
var Zipper_1 = require("./Zipper"); | ||
var _1 = require("."); | ||
var TMP = __1.fs.resolve('./tmp'); | ||
@@ -41,3 +41,3 @@ var exepectFiles = function (paths) { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
case 0: | ||
zip = new Zipper_1.Zipper(); | ||
zip = new _1.Zipper(); | ||
zip | ||
@@ -50,3 +50,3 @@ .add('./test/file/foo.yaml') | ||
chai_1.expect(res.bytes).to.greaterThan(140); | ||
return [4, Zipper_1.Zipper.unzip('./tmp/foo.zip', './tmp/unzipped')]; | ||
return [4, _1.unzip('./tmp/foo.zip', './tmp/unzipped')]; | ||
case 2: | ||
@@ -66,7 +66,7 @@ _a.sent(); | ||
case 0: | ||
zip = new Zipper_1.Zipper().add('./test/file'); | ||
zip = new _1.Zipper().add('./test/file'); | ||
return [4, zip.save('./tmp/foo.zip')]; | ||
case 1: | ||
_a.sent(); | ||
return [4, Zipper_1.Zipper.unzip('./tmp/foo.zip', './tmp/unzipped')]; | ||
return [4, _1.unzip('./tmp/foo.zip', './tmp/unzipped')]; | ||
case 2: | ||
@@ -93,3 +93,3 @@ _a.sent(); | ||
switch (_a.label) { | ||
case 0: return [4, __1.fs.zip.add('./test/file', 'stuff').save('./tmp/foo.zip')]; | ||
case 0: return [4, __1.fs.zip('./test/file', 'stuff').save('./tmp/foo.zip')]; | ||
case 1: | ||
@@ -121,3 +121,3 @@ _a.sent(); | ||
case 0: | ||
zip = new Zipper_1.Zipper().add('./test/file'); | ||
zip = new _1.Zipper().add('./test/file'); | ||
events = []; | ||
@@ -124,0 +124,0 @@ return [4, zip.save('./tmp/foo.zip', { onProgress: function (e) { return events.push(e); } })]; |
@@ -19,4 +19,4 @@ export declare type IZipperArgs = { | ||
}; | ||
export declare function zip(source: string, dest?: string): Zipper; | ||
export declare class Zipper { | ||
static unzip(source: string, target: string): Promise<{}>; | ||
private items; | ||
@@ -23,0 +23,0 @@ add(source: string, target?: string): this; |
@@ -7,3 +7,6 @@ "use strict"; | ||
var fsPath = require("path"); | ||
var extract = require("extract-zip"); | ||
function zip(source, dest) { | ||
return new Zipper().add(source, dest); | ||
} | ||
exports.zip = zip; | ||
var Zipper = (function () { | ||
@@ -13,16 +16,4 @@ function Zipper() { | ||
} | ||
Zipper.unzip = function (source, target) { | ||
return new Promise(function (resolve, reject) { | ||
extract(fsPath.resolve(source), { dir: fsPath.resolve(target) }, function (err) { | ||
if (err) { | ||
reject(err); | ||
} | ||
else { | ||
resolve(); | ||
} | ||
}); | ||
}); | ||
}; | ||
Zipper.prototype.add = function (source, target) { | ||
this.items = this.items.concat([{ source: source, target: target }]); | ||
this.items = this.items.concat([{ source: source, dest: target }]); | ||
return this; | ||
@@ -84,7 +75,7 @@ }; | ||
if (stat.isDirectory()) { | ||
archive.directory(source, item.target || ''); | ||
archive.directory(source, item.dest || ''); | ||
} | ||
else { | ||
name_1 = fsPath.basename(source); | ||
name_1 = item.target ? fsPath.join(item.target, name_1) : name_1; | ||
name_1 = item.dest ? fsPath.join(item.dest, name_1) : name_1; | ||
archive.file(source, { name: name_1 }); | ||
@@ -91,0 +82,0 @@ } |
{ | ||
"name": "@platform/fs", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "File system tools.", | ||
@@ -15,15 +15,17 @@ "main": "lib/index", | ||
"dependencies": { | ||
"@types/fs-extra": "5.1.0", | ||
"@types/fs-extra": "7.0.0", | ||
"@types/js-yaml": "3.12.1", | ||
"archiver": "3.0.0", | ||
"extract-zip": "1.6.7", | ||
"fast-glob": "2.2.6", | ||
"fs-extra": "7.0.1", | ||
"fast-glob": "2.2.7", | ||
"filesize": "^4.1.2", | ||
"fs-extra": "8.0.1", | ||
"js-yaml": "3.13.1" | ||
}, | ||
"devDependencies": { | ||
"@platform/test": "0.0.53", | ||
"@platform/ts.libs": "3.4.15", | ||
"@platform/test": "0.0.54", | ||
"@platform/ts.libs": "3.4.16", | ||
"@types/archiver": "3.0.0", | ||
"@types/extract-zip": "1.6.2" | ||
"@types/extract-zip": "1.6.2", | ||
"@types/filesize": "^4.1.0" | ||
}, | ||
@@ -30,0 +32,0 @@ "files": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
93859
56
1962
8
5
6
+ Addedfilesize@^4.1.2
+ Added@types/fs-extra@7.0.0(transitive)
+ Addedfast-glob@2.2.7(transitive)
+ Addedfilesize@4.2.1(transitive)
+ Addedfs-extra@8.0.1(transitive)
- Removed@types/fs-extra@5.1.0(transitive)
- Removedfast-glob@2.2.6(transitive)
- Removedfs-extra@7.0.1(transitive)
Updated@types/fs-extra@7.0.0
Updatedfast-glob@2.2.7
Updatedfs-extra@8.0.1