Compare commits

..

8 Commits

Author SHA1 Message Date
4a11f50efe 10.0.2 2022-06-09 19:27:00 +02:00
0ddec29392 fix(core): update 2022-06-09 19:26:59 +02:00
df484d54e8 10.0.1 2022-06-07 15:50:48 +02:00
f637c20241 fix(core): update 2022-06-07 15:50:47 +02:00
ed0c1a9181 10.0.0 2022-06-07 15:43:28 +02:00
0e22999f69 BREAKING CHANGE(core): switch to esm 2022-06-07 15:43:28 +02:00
38f001ab23 9.0.7 2022-06-07 15:11:22 +02:00
d1429c5a41 fix(core): update 2022-06-07 15:11:21 +02:00
17 changed files with 3073 additions and 18735 deletions

4
.snyk
View File

@ -1,4 +0,0 @@
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
version: v1.13.1
ignore: {}
patch: {}

View File

View File

@ -1,8 +1,4 @@
{ {
"npmts": {
"mode": "default",
"coverageTreshold": 70
},
"npmdocker": {}, "npmdocker": {},
"npmci": { "npmci": {
"npmGlobalTools": [], "npmGlobalTools": [],

21589
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,13 +1,14 @@
{ {
"name": "@pushrocks/smartfile", "name": "@pushrocks/smartfile",
"private": false, "private": false,
"version": "9.0.6", "version": "10.0.2",
"description": "offers smart ways to work with files in nodejs", "description": "offers smart ways to work with files in nodejs",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts", "typings": "dist_ts/index.d.ts",
"type": "module",
"scripts": { "scripts": {
"test": "(tstest test/)", "test": "(tstest test/)",
"build": "(tsbuild --web)" "build": "(tsbuild --web --allowimplicitany)"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@ -24,31 +25,31 @@
}, },
"homepage": "https://gitlab.com/pushrocks/smartfile", "homepage": "https://gitlab.com/pushrocks/smartfile",
"dependencies": { "dependencies": {
"@pushrocks/lik": "^5.0.0", "@pushrocks/lik": "^6.0.0",
"@pushrocks/smartdelay": "^2.0.13", "@pushrocks/smartdelay": "^2.0.13",
"@pushrocks/smartfile-interfaces": "^1.0.7", "@pushrocks/smartfile-interfaces": "^1.0.7",
"@pushrocks/smarthash": "^2.1.10", "@pushrocks/smarthash": "^2.1.10",
"@pushrocks/smartjson": "^4.0.6", "@pushrocks/smartjson": "^4.0.6",
"@pushrocks/smartmime": "^1.0.5", "@pushrocks/smartmime": "^1.0.5",
"@pushrocks/smartpath": "^4.0.3", "@pushrocks/smartpath": "^5.0.5",
"@pushrocks/smartpromise": "^3.1.6", "@pushrocks/smartpromise": "^3.1.6",
"@pushrocks/smartrequest": "^1.1.52", "@pushrocks/smartrequest": "^1.1.56",
"@pushrocks/smartstream": "^2.0.3",
"@pushrocks/streamfunction": "^4.0.4",
"@types/fs-extra": "^9.0.13", "@types/fs-extra": "^9.0.13",
"@types/glob": "^7.2.0", "@types/glob": "^7.2.0",
"@types/js-yaml": "^4.0.5", "@types/js-yaml": "^4.0.5",
"fs-extra": "^10.0.0", "fs-extra": "^10.1.0",
"glob": "^7.2.0", "glob": "^8.0.3",
"js-yaml": "^4.1.0" "js-yaml": "^4.1.0"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.28", "@gitzone/tsbuild": "^2.1.63",
"@gitzone/tsrun": "^1.2.18", "@gitzone/tsrun": "^1.2.35",
"@gitzone/tstest": "^1.0.60", "@gitzone/tstest": "^1.0.71",
"@pushrocks/tapbundle": "^3.2.14", "@pushrocks/tapbundle": "^5.0.3",
"@types/node": "^16.11.11", "@types/node": "^17.0.41",
"gulp-function": "^2.2.14", "gulp-function": "^2.2.14"
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0"
}, },
"files": [ "files": [
"ts/**/*", "ts/**/*",

View File

@ -1,4 +1,4 @@
import * as smartfile from '../ts/index'; import * as smartfile from '../ts/index.js';
import * as path from 'path'; import * as path from 'path';
import { expect, tap } from '@pushrocks/tapbundle'; import { expect, tap } from '@pushrocks/tapbundle';
@ -9,47 +9,47 @@ import { expect, tap } from '@pushrocks/tapbundle';
tap.test('.fs.fileExistsSync -> should return an accurate boolean', async () => { tap.test('.fs.fileExistsSync -> should return an accurate boolean', async () => {
// tslint:disable-next-line: no-unused-expression // tslint:disable-next-line: no-unused-expression
expect(smartfile.fs.fileExistsSync('./test/testassets/mytest.json')).to.be.true; expect(smartfile.fs.fileExistsSync('./test/testassets/mytest.json')).toBeTrue();
// tslint:disable-next-line: no-unused-expression // tslint:disable-next-line: no-unused-expression
expect(smartfile.fs.fileExistsSync('./test/testassets/notthere.json')).be.false; expect(smartfile.fs.fileExistsSync('./test/testassets/notthere.json')).toBeFalse();
}); });
tap.test('.fs.fileExists -> should resolve or reject a promise', async () => { tap.test('.fs.fileExists -> should resolve or reject a promise', async () => {
expect(smartfile.fs.fileExists('./test/testassets/mytest.json')).to.be.instanceof(Promise); expect(smartfile.fs.fileExists('./test/testassets/mytest.json')).toBeInstanceOf(Promise);
await smartfile.fs.fileExists('./test/testassets/mytest.json'); await smartfile.fs.fileExists('./test/testassets/mytest.json');
await smartfile.fs.fileExists('./test/testassets/notthere.json').catch((err) => { await smartfile.fs.fileExists('./test/testassets/notthere.json').catch((err) => {
return expect(err.message).to.equal( return expect(err.message).toEqual(
"ENOENT: no such file or directory, access './test/testassets/notthere.json'" "ENOENT: no such file or directory, access './test/testassets/notthere.json'"
); );
}); });
}); });
tap.test('.fs.listFoldersSync() -> should get the file type from a string', async () => { tap.test('.fs.listFoldersSync() -> should get the file type from a string', async () => {
expect(smartfile.fs.listFoldersSync('./test/testassets/')).to.include('testfolder'); expect(smartfile.fs.listFoldersSync('./test/testassets/')).toContain('testfolder');
expect(smartfile.fs.listFoldersSync('./test/testassets/')).to.not.include('notExistentFolder'); expect(smartfile.fs.listFoldersSync('./test/testassets/')).not.toContain('notExistentFolder');
}); });
tap.test('.fs.listFolders() -> should get the file type from a string', async () => { tap.test('.fs.listFolders() -> should get the file type from a string', async () => {
const folderArrayArg = await smartfile.fs.listFolders('./test/testassets/'); const folderArrayArg = await smartfile.fs.listFolders('./test/testassets/');
expect(folderArrayArg).to.include('testfolder'); expect(folderArrayArg).toContain('testfolder');
expect(folderArrayArg).to.not.include('notExistentFolder'); expect(folderArrayArg).not.toContain('notExistentFolder');
}); });
tap.test('.fs.listFilesSync() -> should get the file type from a string', async () => { tap.test('.fs.listFilesSync() -> should get the file type from a string', async () => {
expect(smartfile.fs.listFilesSync('./test/testassets/')).to.include('mytest.json'); expect(smartfile.fs.listFilesSync('./test/testassets/')).toContain('mytest.json');
expect(smartfile.fs.listFilesSync('./test/testassets/')).to.not.include('notExistentFile'); expect(smartfile.fs.listFilesSync('./test/testassets/')).not.toContain('notExistentFile');
expect(smartfile.fs.listFilesSync('./test/testassets/', /mytest\.json/)).to.include( expect(smartfile.fs.listFilesSync('./test/testassets/', /mytest\.json/)).toContain(
'mytest.json' 'mytest.json'
); );
expect(smartfile.fs.listFilesSync('./test/testassets/', /mytests.json/)).to.not.include( expect(smartfile.fs.listFilesSync('./test/testassets/', /mytests.json/)).not.toContain(
'mytest.json' 'mytest.json'
); );
}); });
tap.test('.fs.listFiles() -> should get the file type from a string', async () => { tap.test('.fs.listFiles() -> should get the file type from a string', async () => {
const folderArrayArg = await smartfile.fs.listFiles('./test/testassets/'); const folderArrayArg = await smartfile.fs.listFiles('./test/testassets/');
expect(folderArrayArg).to.include('mytest.json'); expect(folderArrayArg).toContain('mytest.json');
expect(folderArrayArg).to.not.include('notExistentFile'); expect(folderArrayArg).not.toContain('notExistentFile');
}); });
tap.test('.fs.listFileTree() -> should get a file tree', async () => { tap.test('.fs.listFileTree() -> should get a file tree', async () => {
@ -57,8 +57,8 @@ tap.test('.fs.listFileTree() -> should get a file tree', async () => {
path.resolve('./test/testassets/'), path.resolve('./test/testassets/'),
'**/*.txt' '**/*.txt'
); );
expect(folderArrayArg).to.include('testfolder/testfile1.txt'); expect(folderArrayArg).toContain('testfolder/testfile1.txt');
expect(folderArrayArg).to.not.include('mytest.json'); expect(folderArrayArg).not.toContain('mytest.json');
}); });
tap.test('.fs.fileTreeToObject -> should read a file tree into an Object', async () => { tap.test('.fs.fileTreeToObject -> should read a file tree into an Object', async () => {
@ -66,8 +66,8 @@ tap.test('.fs.fileTreeToObject -> should read a file tree into an Object', async
path.resolve('./test/testassets/'), path.resolve('./test/testassets/'),
'**/*.txt' '**/*.txt'
); );
expect(fileArrayArg[0]).to.be.instanceof(smartfile.Smartfile); expect(fileArrayArg[0]).toBeInstanceOf(smartfile.Smartfile);
expect(fileArrayArg[0].contents.toString()).to.equal(fileArrayArg[0].contentBuffer.toString()); expect(fileArrayArg[0].contents.toString()).toEqual(fileArrayArg[0].contentBuffer.toString());
}); });
tap.test('.fs.copy() -> should copy a directory', async () => { tap.test('.fs.copy() -> should copy a directory', async () => {
@ -93,15 +93,15 @@ tap.test('.fs.remove -> should remove single files', async () => {
tap.test('.fs.removeSync -> should remove single files synchronouly', async () => { tap.test('.fs.removeSync -> should remove single files synchronouly', async () => {
smartfile.fs.removeSync('./test/testassets/temp/testfile1.txt'); smartfile.fs.removeSync('./test/testassets/temp/testfile1.txt');
expect(smartfile.fs.fileExistsSync('./test/testassets/temp/testfile1.txt')).to.be.false; expect(smartfile.fs.fileExistsSync('./test/testassets/temp/testfile1.txt')).toBeFalse();
}); });
tap.test('.fs.removeMany -> should remove and array of files', async () => { tap.test('.fs.removeMany -> should remove and array of files', async () => {
smartfile.fs smartfile.fs
.removeMany(['./test/testassets/temp/testfile1.txt', './test/testassets/temp/testfile2.txt']) .removeMany(['./test/testassets/temp/testfile1.txt', './test/testassets/temp/testfile2.txt'])
.then(() => { .then(() => {
expect(smartfile.fs.fileExistsSync('./test/testassets/temp/testfile1.txt')).to.be.false; expect(smartfile.fs.fileExistsSync('./test/testassets/temp/testfile1.txt')).toBeFalse();
expect(smartfile.fs.fileExistsSync('./test/testassets/temp/testfile2.txt')).to.be.false; expect(smartfile.fs.fileExistsSync('./test/testassets/temp/testfile2.txt')).toBeFalse();
}); });
}); });
@ -110,14 +110,14 @@ tap.test('.fs.removeManySync -> should remove and array of single files synchron
'./test/testassets/temp/testfile1.txt', './test/testassets/temp/testfile1.txt',
'./test/testassets/temp/testfile2.txt', './test/testassets/temp/testfile2.txt',
]); ]);
expect(smartfile.fs.fileExistsSync('./test/testassets/temp/testfile1.txt')).to.be.false; expect(smartfile.fs.fileExistsSync('./test/testassets/temp/testfile1.txt')).toBeFalse();
expect(smartfile.fs.fileExistsSync('./test/testassets/temp/testfile2.txt')).to.be.false; expect(smartfile.fs.fileExistsSync('./test/testassets/temp/testfile2.txt')).toBeFalse();
}); });
tap.test('.fs.toObjectSync() -> should read an ' + '.yaml' + ' file to an object', async () => { tap.test('.fs.toObjectSync() -> should read an .yaml file to an object', async () => {
const testData = smartfile.fs.toObjectSync('./test/testassets/mytest.yaml'); const testData = smartfile.fs.toObjectSync('./test/testassets/mytest.yaml');
expect(testData).to.include({ key1: 'this works' }); expect(testData.key1).toEqual('this works');
expect(testData).to.include({ key2: 'this works too' }); expect(testData.key2).toEqual('this works too');
}); });
tap.test( tap.test(
'.fs.toObjectSync() -> should state unknown file type for unknown file types', '.fs.toObjectSync() -> should state unknown file type for unknown file types',
@ -126,14 +126,14 @@ tap.test(
} }
); );
tap.test('.fs.toObjectSync() -> should read an ' + '.json' + ' file to an object', async () => { tap.test('.fs.toObjectSync() -> should read an .json file to an object', async () => {
const testData = smartfile.fs.toObjectSync('./test/testassets/mytest.json'); const testData = smartfile.fs.toObjectSync('./test/testassets/mytest.json');
expect(testData).to.include({ key1: 'this works' }); expect(testData.key1).toEqual('this works');
expect(testData).to.include({ key2: 'this works too' }); expect(testData.key2).toEqual('this works too');
}); });
tap.test('.fs.toStringSync() -> should read a file to a string', async () => { tap.test('.fs.toStringSync() -> should read a file to a string', async () => {
expect(smartfile.fs.toStringSync('./test/testassets/mytest.txt')).to.equal( expect(smartfile.fs.toStringSync('./test/testassets/mytest.txt')).toEqual(
'Some TestString &&%$' 'Some TestString &&%$'
); );
}); });
@ -143,7 +143,7 @@ tap.test('.fs.toStringSync() -> should read a file to a string', async () => {
// --------------------------- // ---------------------------
tap.test('.interpreter.filetype() -> should get the file type from a string', async () => { tap.test('.interpreter.filetype() -> should get the file type from a string', async () => {
expect(smartfile.interpreter.filetype('./somefolder/data.json')).equal('json'); expect(smartfile.interpreter.filetype('./somefolder/data.json')).toEqual('json');
}); });
// --------------------------- // ---------------------------
@ -179,14 +179,14 @@ tap.test('.Smartfile -> should produce vinyl compatible files', async () => {
'./test/testassets/testfolder/**/*' './test/testassets/testfolder/**/*'
); );
const localSmartfile = smartfileArray[0]; const localSmartfile = smartfileArray[0];
expect(localSmartfile).to.be.instanceof(smartfile.Smartfile); expect(localSmartfile).toBeInstanceOf(smartfile.Smartfile);
expect(localSmartfile.contents).to.be.instanceof(Buffer); expect(localSmartfile.contents).toBeInstanceOf(Buffer);
// tslint:disable-next-line:no-unused-expression // tslint:disable-next-line:no-unused-expression
expect(localSmartfile.isBuffer()).to.be.true; expect(localSmartfile.isBuffer()).toBeTrue();
// tslint:disable-next-line:no-unused-expression // tslint:disable-next-line:no-unused-expression
expect(localSmartfile.isDirectory()).to.be.false; expect(localSmartfile.isDirectory()).toBeFalse();
// tslint:disable-next-line:no-unused-expression // tslint:disable-next-line:no-unused-expression
expect(localSmartfile.isNull()).to.be.false; expect(localSmartfile.isNull()).toBeFalse();
}); });
tap.test('should output a smartfile array to disk', async () => { tap.test('should output a smartfile array to disk', async () => {
@ -210,7 +210,7 @@ tap.test('should create, store and retrieve valid smartfiles', async () => {
smartfileInstance.write(); smartfileInstance.write();
const smartfileInstance2 = await smartfile.Smartfile.fromFilePath(filePath); const smartfileInstance2 = await smartfile.Smartfile.fromFilePath(filePath);
const retrievedString = smartfileInstance.contents.toString(); const retrievedString = smartfileInstance.contents.toString();
expect(retrievedString).to.equal(fileString); expect(retrievedString).toEqual(fileString);
}); });
tap.test('should wait for file to be ready', async () => { tap.test('should wait for file to be ready', async () => {

View File

@ -1,10 +1,10 @@
import { tap, expect } from '@pushrocks/tapbundle'; import { tap, expect } from '@pushrocks/tapbundle';
import * as smartfile from '../ts'; import * as smartfile from '../ts/index.js';
tap.test('should create a virtualdirectory', async () => { tap.test('should create a virtualdirectory', async () => {
const virtualDir = await smartfile.VirtualDirectory.fromFsDirPath('./test/testassets/testfolder'); const virtualDir = await smartfile.VirtualDirectory.fromFsDirPath('./test/testassets/testfolder');
expect(virtualDir.smartfileArray.length).to.equal(4); expect(virtualDir.smartfileArray.length).toEqual(4);
}); });
tap.test('should write to a directory', async () => { tap.test('should write to a directory', async () => {

8
ts/00_commitinfo_data.ts Normal file
View File

@ -0,0 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
*/
export const commitinfo = {
name: '@pushrocks/smartfile',
version: '10.0.2',
description: 'offers smart ways to work with files in nodejs'
}

View File

@ -1,11 +1,13 @@
import * as plugins from './smartfile.plugins'; import * as plugins from './smartfile.plugins.js';
import * as fsMod from './smartfile.fs'; import * as fsMod from './smartfile.fs.js';
import * as interpreterMod from './smartfile.interpreter'; import * as fsStreamMod from './smartfile.fsstream.js';
import * as memoryMod from './smartfile.memory'; import * as interpreterMod from './smartfile.interpreter.js';
import * as memoryMod from './smartfile.memory.js';
export { Smartfile, ISmartfileConstructorOptions } from './smartfile.classes.smartfile'; export * from './smartfile.classes.smartfile.js';
export { VirtualDirectory } from './smartfile.classes.virtualdirectory'; export * from './smartfile.classes.virtualdirectory.js';
export let fs = fsMod; export const fs = fsMod;
export let interpreter = interpreterMod; export const fsStream = fsStreamMod;
export let memory = memoryMod; export const interpreter = interpreterMod;
export const memory = memoryMod;

View File

@ -1,6 +1,6 @@
import * as plugins from './smartfile.plugins'; import * as plugins from './smartfile.plugins.js';
import * as fs from './smartfile.fs'; import * as fs from './smartfile.fs.js';
import * as memory from './smartfile.memory'; import * as memory from './smartfile.memory.js';
export interface ISmartfileConstructorOptions { export interface ISmartfileConstructorOptions {
path: string; path: string;
@ -158,7 +158,7 @@ export class Smartfile extends plugins.smartjson.Smartjson {
* @returns * @returns
*/ */
public async writeToDir(dirPathArg: string) { public async writeToDir(dirPathArg: string) {
dirPathArg = plugins.smartpath.transform.toAbsolute(dirPathArg); dirPathArg = plugins.smartpath.transform.toAbsolute(dirPathArg) as string;
const filePath = plugins.path.join(dirPathArg, this.path); const filePath = plugins.path.join(dirPathArg, this.path);
await memory.toFs(this.contentBuffer, filePath); await memory.toFs(this.contentBuffer, filePath);
return filePath; return filePath;

View File

@ -1,6 +1,6 @@
import { Smartfile } from './smartfile.classes.smartfile'; import { Smartfile } from './smartfile.classes.smartfile.js';
import * as plugins from './smartfile.plugins'; import * as plugins from './smartfile.plugins.js';
import * as fs from './smartfile.fs'; import * as fs from './smartfile.fs.js';
/** /**
* a virtual directory exposes a fs api * a virtual directory exposes a fs api

View File

@ -1,9 +1,9 @@
import * as plugins from './smartfile.plugins'; import * as plugins from './smartfile.plugins.js';
import * as interpreter from './smartfile.interpreter'; import * as interpreter from './smartfile.interpreter.js';
import { Smartfile } from './smartfile.classes.smartfile'; import { Smartfile } from './smartfile.classes.smartfile.js';
import * as memory from './smartfile.memory'; import * as memory from './smartfile.memory.js';
/*=============================================================== /*===============================================================
============================ Checks ============================= ============================ Checks =============================
===============================================================*/ ===============================================================*/
@ -231,7 +231,7 @@ export const fileTreeToObject = async (dirPathArg: string, miniMatchFilter: stri
if (plugins.path.isAbsolute(miniMatchFilter)) { if (plugins.path.isAbsolute(miniMatchFilter)) {
dirPath = '/'; dirPath = '/';
} else { } else {
dirPath = plugins.smartpath.transform.toAbsolute(dirPathArg); dirPath = plugins.smartpath.transform.toAbsolute(dirPathArg) as string;
} }
const fileTree = await listFileTree(dirPath, miniMatchFilter); const fileTree = await listFileTree(dirPath, miniMatchFilter);

17
ts/smartfile.fsstream.ts Normal file
View File

@ -0,0 +1,17 @@
/*
This file contains logic for streaming things from and to the filesystem
*/
import * as plugins from './smartfile.plugins.js';
export const createReadStream = (pathArg: string) => {
return plugins.fs.createReadStream(pathArg);
};
export const createWriteStream = (pathArg: string) => {
return plugins.fs.createWriteStream(pathArg);
};
export const streamDirectory = async (dirPathArg: string) => {
}

View File

@ -1,4 +1,4 @@
import * as plugins from './smartfile.plugins'; import * as plugins from './smartfile.plugins.js';
export let filetype = (pathArg: string): string => { export let filetype = (pathArg: string): string => {
const extName = plugins.path.extname(pathArg); const extName = plugins.path.extname(pathArg);

View File

@ -1,7 +1,7 @@
import * as plugins from './smartfile.plugins'; import * as plugins from './smartfile.plugins.js';
import { Smartfile } from './smartfile.classes.smartfile'; import { Smartfile } from './smartfile.classes.smartfile.js';
import * as smartfileFs from './smartfile.fs'; import * as smartfileFs from './smartfile.fs.js';
import * as interpreter from './smartfile.interpreter'; import * as interpreter from './smartfile.interpreter.js';
/** /**
* converts file to Object * converts file to Object

View File

@ -14,6 +14,7 @@ import * as smartmime from '@pushrocks/smartmime';
import * as smartpath from '@pushrocks/smartpath'; import * as smartpath from '@pushrocks/smartpath';
import * as smartpromise from '@pushrocks/smartpromise'; import * as smartpromise from '@pushrocks/smartpromise';
import * as smartrequest from '@pushrocks/smartrequest'; import * as smartrequest from '@pushrocks/smartrequest';
import * as smartstream from '@pushrocks/smartstream';
export { export {
lik, lik,
@ -25,10 +26,11 @@ export {
smartpath, smartpath,
smartpromise, smartpromise,
smartrequest, smartrequest,
smartstream
}; };
// third party scope // third party scope
import * as fsExtra from 'fs-extra'; import fsExtra from 'fs-extra';
import glob from 'glob'; import glob from 'glob';
import yaml from 'js-yaml'; import yaml from 'js-yaml';

View File

@ -1,17 +0,0 @@
{
"extends": ["tslint:latest", "tslint-config-prettier"],
"rules": {
"semicolon": [true, "always"],
"no-console": false,
"ordered-imports": false,
"object-literal-sort-keys": false,
"member-ordering": {
"options":{
"order": [
"static-method"
]
}
}
},
"defaultSeverity": "warning"
}