fix(core): update

This commit is contained in:
2020-03-16 14:38:17 +00:00
parent 39b718fc41
commit c1b1cbfd64
5 changed files with 85 additions and 33 deletions

View File

@ -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;
}
};
}
}
}

View File

@ -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';