Compare commits

..

8 Commits

Author SHA1 Message Date
0ca38c109e 10.0.6 2023-01-09 15:32:37 +01:00
4e2321e1ee fix(core): update 2023-01-09 15:32:37 +01:00
a640ab3d7b 10.0.5 2022-09-05 00:21:43 +02:00
37d6d56287 fix(core): update 2022-09-05 00:21:42 +02:00
443a026502 10.0.4 2022-07-24 23:11:41 +02:00
9644c5b7e3 fix(core): update 2022-07-24 23:11:41 +02:00
25faa8c697 10.0.3 2022-07-24 23:04:52 +02:00
982387aaa3 fix(core): update 2022-07-24 23:04:51 +02:00
10 changed files with 4458 additions and 11378 deletions

View File

@ -13,43 +13,34 @@ stages:
- metadata - metadata
before_script: before_script:
- npm install -g @shipzone/npmci - pnpm install -g pnpm
- pnpm install -g @shipzone/pnpm
- npmci npm prepare
# ==================== # ====================
# security stage # security stage
# ==================== # ====================
mirror: # ====================
stage: security # security stage
script: # ====================
- npmci git mirror
only:
- tags
tags:
- lossless
- docker
- notpriv
auditProductionDependencies: auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security stage: security
script: script:
- npmci npm prepare - npmci command npm config set registry https://registry.npmjs.org
- npmci command npm install --production --ignore-scripts - npmci command pnpm audit --audit-level=high --prod
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=prod --production
tags: tags:
- lossless
- docker - docker
allow_failure: true
auditDevDependencies: auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security stage: security
script: script:
- npmci npm prepare
- npmci command npm install --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org - npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=dev - npmci command pnpm audit --audit-level=high --dev
tags: tags:
- lossless
- docker - docker
allow_failure: true allow_failure: true
@ -60,7 +51,6 @@ auditDevDependencies:
testStable: testStable:
stage: test stage: test
script: script:
- npmci npm prepare
- npmci node install stable - npmci node install stable
- npmci npm install - npmci npm install
- npmci npm test - npmci npm test
@ -71,7 +61,6 @@ testStable:
testBuild: testBuild:
stage: test stage: test
script: script:
- npmci npm prepare
- npmci node install stable - npmci node install stable
- npmci npm install - npmci npm install
- npmci command npm run build - npmci command npm run build
@ -100,10 +89,9 @@ codequality:
only: only:
- tags - tags
script: script:
- npmci command npm install -g tslint typescript - npmci command npm install -g typescript
- npmci npm prepare - npmci npm prepare
- npmci npm install - npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags: tags:
- lossless - lossless
- docker - docker
@ -123,11 +111,9 @@ trigger:
pages: pages:
stage: metadata stage: metadata
script: script:
- npmci node install lts - npmci node install stable
- npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare
- npmci npm install - npmci npm install
- npmci command tsdoc - npmci command npm run buildDocs
tags: tags:
- lossless - lossless
- docker - docker

11323
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,14 +1,15 @@
{ {
"name": "@pushrocks/smartfile", "name": "@pushrocks/smartfile",
"private": false, "private": false,
"version": "10.0.2", "version": "10.0.6",
"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", "type": "module",
"scripts": { "scripts": {
"test": "(tstest test/)", "test": "(tstest test/)",
"build": "(tsbuild --web --allowimplicitany)" "build": "(tsbuild --web --allowimplicitany)",
"buildDocs": "tsdoc"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@ -28,28 +29,27 @@
"@pushrocks/lik": "^6.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": "^3.0.1",
"@pushrocks/smartjson": "^4.0.6", "@pushrocks/smartjson": "^5.0.5",
"@pushrocks/smartmime": "^1.0.5", "@pushrocks/smartmime": "^1.0.5",
"@pushrocks/smartpath": "^5.0.5", "@pushrocks/smartpath": "^5.0.5",
"@pushrocks/smartpromise": "^3.1.6", "@pushrocks/smartpromise": "^3.1.6",
"@pushrocks/smartrequest": "^1.1.56", "@pushrocks/smartrequest": "^2.0.11",
"@pushrocks/smartstream": "^2.0.3", "@pushrocks/smartstream": "^2.0.3",
"@pushrocks/streamfunction": "^4.0.4", "@pushrocks/streamfunction": "^4.0.4",
"@types/fs-extra": "^9.0.13", "@types/fs-extra": "^11.0.0",
"@types/glob": "^7.2.0", "@types/glob": "^8.0.0",
"@types/js-yaml": "^4.0.5", "@types/js-yaml": "^4.0.5",
"fs-extra": "^10.1.0", "fs-extra": "^11.1.0",
"glob": "^8.0.3", "glob": "^8.0.3",
"js-yaml": "^4.1.0" "js-yaml": "^4.1.0"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.63", "@gitzone/tsbuild": "^2.1.65",
"@gitzone/tsrun": "^1.2.35", "@gitzone/tsrun": "^1.2.39",
"@gitzone/tstest": "^1.0.71", "@gitzone/tstest": "^1.0.74",
"@pushrocks/tapbundle": "^5.0.3", "@pushrocks/tapbundle": "^5.0.4",
"@types/node": "^17.0.41", "@types/node": "^18.11.18"
"gulp-function": "^2.2.14"
}, },
"files": [ "files": [
"ts/**/*", "ts/**/*",

4396
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -38,9 +38,7 @@ tap.test('.fs.listFolders() -> should get the file type from a string', async ()
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/')).toContain('mytest.json'); expect(smartfile.fs.listFilesSync('./test/testassets/')).toContain('mytest.json');
expect(smartfile.fs.listFilesSync('./test/testassets/')).not.toContain('notExistentFile'); expect(smartfile.fs.listFilesSync('./test/testassets/')).not.toContain('notExistentFile');
expect(smartfile.fs.listFilesSync('./test/testassets/', /mytest\.json/)).toContain( expect(smartfile.fs.listFilesSync('./test/testassets/', /mytest\.json/)).toContain('mytest.json');
'mytest.json'
);
expect(smartfile.fs.listFilesSync('./test/testassets/', /mytests.json/)).not.toContain( expect(smartfile.fs.listFilesSync('./test/testassets/', /mytests.json/)).not.toContain(
'mytest.json' 'mytest.json'
); );
@ -133,9 +131,7 @@ tap.test('.fs.toObjectSync() -> should read an .json file to an object', async (
}); });
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')).toEqual( expect(smartfile.fs.toStringSync('./test/testassets/mytest.txt')).toEqual('Some TestString &&%$');
'Some TestString &&%$'
);
}); });
// --------------------------- // ---------------------------
@ -213,6 +209,14 @@ tap.test('should create, store and retrieve valid smartfiles', async () => {
expect(retrievedString).toEqual(fileString); expect(retrievedString).toEqual(fileString);
}); });
tap.test('should get a hash', async () => {
const fileString = 'hi there';
const filePath = './test/testassets/utf8.txt';
const smartfileInstance = await smartfile.Smartfile.fromString(filePath, fileString, 'utf8');
const hash = await smartfileInstance.getHash();
console.log(hash);
});
tap.test('should wait for file to be ready', async () => { tap.test('should wait for file to be ready', async () => {
await smartfile.fs.waitForFileToBeReady('./test/testassets/mytest.json'); await smartfile.fs.waitForFileToBeReady('./test/testassets/mytest.json');
}); });

View File

@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@pushrocks/smartfile', name: '@pushrocks/smartfile',
version: '10.0.2', version: '10.0.6',
description: 'offers smart ways to work with files in nodejs' description: 'offers smart ways to work with files in nodejs'
} }

View File

@ -237,9 +237,29 @@ export class Smartfile extends plugins.smartjson.Smartjson {
return false; return false;
} }
public async getHash(typeArg: 'path' | 'content' | 'all' = 'all') {
const pathHash = await plugins.smarthash.sha256FromString(this.path);
const contentHash = await plugins.smarthash.sha256FromBuffer(this.contentBuffer);
const combinedHash = await plugins.smarthash.sha256FromString(pathHash + contentHash);
switch(typeArg) {
case 'path':
return pathHash;
case 'content':
return contentHash;
case 'all':
default:
return combinedHash;
}
}
// update things // update things
public updateFileName(fileNameArg: string) { public updateFileName(fileNameArg: string) {
const oldFileName = this.parsedPath.base; const oldFileName = this.parsedPath.base;
this.path = this.path.replace(new RegExp(oldFileName + '$'), fileNameArg); this.path = this.path.replace(new RegExp(oldFileName + '$'), fileNameArg);
} }
public async editContentAsString(editFuncArg: (fileStringArg: string) => Promise<string>) {
const newFileString = await editFuncArg(this.contentBuffer.toString());
this.contentBuffer = Buffer.from(newFileString);
}
} }

View File

@ -214,7 +214,7 @@ export const fileTreeToHash = async (dirPathArg: string, miniMatchFilter: string
const fileTreeObject = await fileTreeToObject(dirPathArg, miniMatchFilter); const fileTreeObject = await fileTreeToObject(dirPathArg, miniMatchFilter);
let combinedString = ''; let combinedString = '';
for (const smartfile of fileTreeObject) { for (const smartfile of fileTreeObject) {
combinedString += smartfile.contentBuffer.toString(); combinedString += await smartfile.getHash();
} }
const hash = await plugins.smarthash.sha256FromString(combinedString); const hash = await plugins.smarthash.sha256FromString(combinedString);
return hash; return hash;

View File

@ -11,7 +11,4 @@ export const createWriteStream = (pathArg: string) => {
return plugins.fs.createWriteStream(pathArg); return plugins.fs.createWriteStream(pathArg);
}; };
export const streamDirectory = async (dirPathArg: string) => {};
export const streamDirectory = async (dirPathArg: string) => {
}

View File

@ -26,7 +26,7 @@ export {
smartpath, smartpath,
smartpromise, smartpromise,
smartrequest, smartrequest,
smartstream smartstream,
}; };
// third party scope // third party scope