smartarchive/ts/smartarchive.classes.smartarchive.ts

42 lines
1.3 KiB
TypeScript
Raw Normal View History

2020-03-13 20:22:56 +00:00
import * as plugins from './smartarchive.plugins';
2020-03-16 14:38:17 +00:00
import * as paths from './smartarchive.paths';
2020-03-13 20:22:56 +00:00
export class SmartArchive {
public archiveDirectory: string;
constructor() {}
2020-03-16 14:38:17 +00:00
/**
* 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) {
2020-03-13 20:22:56 +00:00
const parsedPath = plugins.path.parse(filePathArg);
switch (parsedPath.ext) {
2020-03-16 14:38:17 +00:00
case '.tgz':
console.log(`detected a .tgz archive`);
await plugins.tar.extract({
file: filePathArg,
cwd: targetDir
});
break;
2020-03-13 20:22:56 +00:00
}
2020-03-16 14:38:17 +00:00
}
}