From c1b1cbfd64b35969fb433ea16e60d5a55ec6c941 Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Mon, 16 Mar 2020 14:38:17 +0000 Subject: [PATCH] fix(core): update --- package-lock.json | 34 ++++++++++------------- package.json | 9 ++++--- test/test.ts | 35 +++++++++++++++++++++--- ts/smartarchive.classes.smartarchive.ts | 36 ++++++++++++++++++++++--- ts/smartarchive.plugins.ts | 4 ++- 5 files changed, 85 insertions(+), 33 deletions(-) diff --git a/package-lock.json b/package-lock.json index cedcff3..b4f4f49 100644 --- a/package-lock.json +++ b/package-lock.json @@ -160,9 +160,9 @@ } }, "@pushrocks/smartfile": { - "version": "7.0.9", - "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartfile/-/smartfile-7.0.9.tgz", - "integrity": "sha512-DDRoHZxD8do4UVVYRBoGUdQXPQEFhgpZG7lCvr4FUYaBaU/R5zW23AUtUEgednW4SCbEESg4mBtKDyTpmlr/3g==", + "version": "7.0.10", + "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartfile/-/smartfile-7.0.10.tgz", + "integrity": "sha512-Gsm9PXFsmA50KsLDA9zdwFKZ84ZalEPDZ8Q1/fX/7PR8hIntp6qafoo3Unvl3/LFHEHxYB1VYWX1PviLND3xNw==", "requires": { "@pushrocks/smarthash": "^2.1.6", "@pushrocks/smartmime": "^1.0.3", @@ -307,7 +307,6 @@ "version": "3.0.3", "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartunique/-/smartunique-3.0.3.tgz", "integrity": "sha512-f+c3s2WzzjASoRHyYTLU0kHDVWREg4sZVdi5L42bTA3CTUWNrcGUC62h4wP4U4BiPl3bopTr3LPhClZHJ738oA==", - "dev": true, "requires": { "@types/shortid": "0.0.29", "@types/uuid": "^7.0.0", @@ -316,22 +315,22 @@ } }, "@pushrocks/tapbundle": { - "version": "3.2.0", - "resolved": "https://verdaccio.lossless.one/@pushrocks%2ftapbundle/-/tapbundle-3.2.0.tgz", - "integrity": "sha512-xnKIGe7NJqxWBaFeKIEXShDjV2wap1XJqmlp3m1MKqmIF62vRpZnkzpyE1ZAoNwiYQmIsXIpvP/PDv+iPevPfw==", + "version": "3.2.1", + "resolved": "https://verdaccio.lossless.one/@pushrocks%2ftapbundle/-/tapbundle-3.2.1.tgz", + "integrity": "sha512-D3o205SE+Viu8sukm+6CvGkXEwOiQiEEcga9eWyvjWS4vDx6FWwrO0pNZkQq6GqsKQ9xRpCmBtI7F3KsJR0+PA==", "dev": true, "requires": { "@pushrocks/early": "^3.0.3", "@pushrocks/smartdelay": "^2.0.3", - "@pushrocks/smartfile": "^7.0.6", + "@pushrocks/smartfile": "^7.0.9", "@pushrocks/smartpromise": "^3.0.2", "smartchai": "^2.0.1" } }, "@types/chai": { - "version": "4.2.10", - "resolved": "https://verdaccio.lossless.one/@types%2fchai/-/chai-4.2.10.tgz", - "integrity": "sha512-TlWWgb21+0LdkuFqEqfmy7NEgfB/7Jjux15fWQAh3P93gbmXuwTM/vxEdzW89APIcI2BgKR48yjeAkdeH+4qvQ==", + "version": "4.2.11", + "resolved": "https://verdaccio.lossless.one/@types%2fchai/-/chai-4.2.11.tgz", + "integrity": "sha512-t7uW6eFafjO+qJ3BIV2gGUyZs27egcNRkUdalkud+Qa3+kg//f129iuOFivHDXQ+vnU3fDXuwgv0cqMCbcE8sw==", "dev": true }, "@types/chai-as-promised": { @@ -431,8 +430,7 @@ "@types/shortid": { "version": "0.0.29", "resolved": "https://verdaccio.lossless.one/@types%2fshortid/-/shortid-0.0.29.tgz", - "integrity": "sha1-gJPuBBam4r8qpjOBCRFLP7/6Dps=", - "dev": true + "integrity": "sha1-gJPuBBam4r8qpjOBCRFLP7/6Dps=" }, "@types/tar": { "version": "4.0.3", @@ -454,8 +452,7 @@ "@types/uuid": { "version": "7.0.0", "resolved": "https://verdaccio.lossless.one/@types%2fuuid/-/uuid-7.0.0.tgz", - "integrity": "sha512-RiX1I0lK9WFLFqy2xOxke396f0wKIzk5sAll0tL4J4XDYJXURI7JOs96XQb3nP+2gEpQ/LutBb66jgiT5oQshQ==", - "dev": true + "integrity": "sha512-RiX1I0lK9WFLFqy2xOxke396f0wKIzk5sAll0tL4J4XDYJXURI7JOs96XQb3nP+2gEpQ/LutBb66jgiT5oQshQ==" }, "@types/which": { "version": "1.3.2", @@ -1032,8 +1029,7 @@ "nanoid": { "version": "2.1.11", "resolved": "https://verdaccio.lossless.one/nanoid/-/nanoid-2.1.11.tgz", - "integrity": "sha512-s/snB+WGm6uwi0WjsZdaVcuf3KJXlfGl2LcxgwkEwJF0D/BWzVWAZW/XY4bFaiR7s0Jk3FPvlnepg1H1b1UwlA==", - "dev": true + "integrity": "sha512-s/snB+WGm6uwi0WjsZdaVcuf3KJXlfGl2LcxgwkEwJF0D/BWzVWAZW/XY4bFaiR7s0Jk3FPvlnepg1H1b1UwlA==" }, "once": { "version": "1.4.0", @@ -1201,7 +1197,6 @@ "version": "2.2.15", "resolved": "https://verdaccio.lossless.one/shortid/-/shortid-2.2.15.tgz", "integrity": "sha512-5EaCy2mx2Jgc/Fdn9uuDuNIIfWBpzY4XIlhoqtXF6qsf+/+SGZ+FxDdX/ZsMZiWupIWNqAEmiNY4RC+LSmCeOw==", - "dev": true, "requires": { "nanoid": "^2.1.0" } @@ -1402,8 +1397,7 @@ "uuid": { "version": "7.0.2", "resolved": "https://verdaccio.lossless.one/uuid/-/uuid-7.0.2.tgz", - "integrity": "sha512-vy9V/+pKG+5ZTYKf+VcphF5Oc6EFiu3W8Nv3P3zIh0EqVI80ZxOzuPfe9EHjkFNvf8+xuTHVeei4Drydlx4zjw==", - "dev": true + "integrity": "sha512-vy9V/+pKG+5ZTYKf+VcphF5Oc6EFiu3W8Nv3P3zIh0EqVI80ZxOzuPfe9EHjkFNvf8+xuTHVeei4Drydlx4zjw==" }, "wcwidth": { "version": "1.0.1", diff --git a/package.json b/package.json index f53c1c6..0de3263 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "1.0.5", "description": "work with archives", "main": "dist_ts/index.js", - "typings": "dist/index.d.ts", + "typings": "dist_ts/index.d.ts", "scripts": { "test": "tstest test/", "build": "tsbuild" @@ -19,16 +19,17 @@ }, "homepage": "https://github.com/pushrocks/smartarchive#readme", "dependencies": { - "@pushrocks/smartfile": "^7.0.9", + "@pushrocks/smartfile": "^7.0.10", "@pushrocks/smartpath": "^4.0.1", + "@pushrocks/smartrequest": "^1.1.47", + "@pushrocks/smartunique": "^3.0.3", "@types/tar": "^4.0.3", "tar": "^6.0.1" }, "devDependencies": { "@gitzone/tsbuild": "^2.1.22", "@gitzone/tstest": "^1.0.28", - "@pushrocks/smartrequest": "^1.1.47", - "@pushrocks/tapbundle": "^3.2.0", + "@pushrocks/tapbundle": "^3.2.1", "tslint": "^6.1.0", "tslint-config-prettier": "^1.18.0" }, diff --git a/test/test.ts b/test/test.ts index 249bdeb..b5eed49 100644 --- a/test/test.ts +++ b/test/test.ts @@ -1,11 +1,38 @@ import { tap, expect } from '@pushrocks/tapbundle'; + +import * as path from 'path'; +import * as smartfile from '@pushrocks/smartfile'; import * as smartrequest from '@pushrocks/smartrequest'; -tap.test('should prepare downloads', async (tools) => { - const downLoadedFile: Buffer = (await smartrequest.getBinary('https://verdaccio.lossless.one/level/-/level-6.0.1.tgz')).body; - console.log(downLoadedFile); +const testPlugins = { + path, + smartfile, + smartrequest +}; + +const testPaths = { + nogitDir: testPlugins.path.join(process.cwd(), '.nogit/') +} + +import * as smartarchive from '../ts/index'; + +tap.preTask('should prepare .nogit dir', async () => { + await testPlugins.smartfile.fs.ensureDir(testPaths.nogitDir); }); -tap.test('should extract files on disk', async () => {}); +tap.preTask('should prepare downloads', async tools => { + const downloadedFile: Buffer = ( + await testPlugins.smartrequest.getBinary('https://verdaccio.lossless.one/@pushrocks%2fwebsetup/-/websetup-2.0.14.tgz') + ).body; + await testPlugins.smartfile.memory.toFs(downloadedFile, testPlugins.path.join(testPaths.nogitDir, 'test.tgz')); +}); + +tap.test('should extract files on disk', async () => { + const testSmartarchive = new smartarchive.SmartArchive(); + await testSmartarchive.extractArchiveFromFilePath( + testPlugins.path.join(testPaths.nogitDir, 'test.tgz'), + testPlugins.path.join(testPaths.nogitDir) + ); +}); tap.start(); diff --git a/ts/smartarchive.classes.smartarchive.ts b/ts/smartarchive.classes.smartarchive.ts index 23506bf..abb2cf0 100644 --- a/ts/smartarchive.classes.smartarchive.ts +++ b/ts/smartarchive.classes.smartarchive.ts @@ -1,13 +1,41 @@ import * as plugins from './smartarchive.plugins'; +import * as paths from './smartarchive.paths'; export class SmartArchive { public archiveDirectory: string; constructor() {} - public extractArchiveFromFilePath(filePathArg: string, targetDir: string) { + /** + * extracts an archive from a given url + */ + public async extractArchiveFromUrl(urlArg: string, targetDir: string) { + const parsedPath = plugins.path.parse(urlArg); + const uniqueFileName = plugins.smartunique.uni() + parsedPath.ext; + const downloadPath = plugins.path.join(paths.nogitDir, uniqueFileName); + const downloadedArchive = ( + await plugins.smartrequest.getBinary( + 'https://verdaccio.lossless.one/@pushrocks%2fwebsetup/-/websetup-2.0.14.tgz' + ) + ).body; + await plugins.smartfile.memory.toFs(downloadedArchive, downloadPath); + await this.extractArchiveFromFilePath(downloadPath, targetDir); + } + + /** + * extracts an archive from a given filePath on disk + * @param filePathArg + * @param targetDir + */ + public async extractArchiveFromFilePath(filePathArg: string, targetDir: string) { const parsedPath = plugins.path.parse(filePathArg); switch (parsedPath.ext) { - + case '.tgz': + console.log(`detected a .tgz archive`); + await plugins.tar.extract({ + file: filePathArg, + cwd: targetDir + }); + break; } - }; -} \ No newline at end of file + } +} diff --git a/ts/smartarchive.plugins.ts b/ts/smartarchive.plugins.ts index 2e4f800..a3eea02 100644 --- a/ts/smartarchive.plugins.ts +++ b/ts/smartarchive.plugins.ts @@ -6,8 +6,10 @@ export { path }; // @pushrocks scope import * as smartfile from '@pushrocks/smartfile'; import * as smartpath from '@pushrocks/smartpath'; +import * as smartrequest from '@pushrocks/smartrequest'; +import * as smartunique from '@pushrocks/smartunique'; -export { smartfile, smartpath }; +export { smartfile, smartpath, smartrequest, smartunique }; // third party scope import tar from 'tar';