fix(core): update
This commit is contained in:
@ -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;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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';
|
||||
|
Reference in New Issue
Block a user