|
1 | 1 | import * as fs from "fs";
|
| 2 | +import * as http from "http"; |
2 | 3 | import {GenericContainer, StartedTestContainer} from "testcontainers";
|
| 4 | +import * as path from "path"; |
3 | 5 |
|
4 | 6 | const RegClient = require('npm-registry-client');
|
5 | 7 | const DEFAULT_NPM_PORT = 4873
|
@@ -49,6 +51,25 @@ export async function publishAsync(registryUrl: string, tgzPath: string, moduleN
|
49 | 51 | });
|
50 | 52 | }
|
51 | 53 |
|
| 54 | +export async function downloadTarball(registryUrl: string, moduleName: String, version: string, auth: any): Promise<string> { |
| 55 | + let moduleInfo:any = await getModuleInfo(registryUrl, moduleName, version, auth); |
| 56 | + const tarballUrl = moduleInfo.dist.tarball as string; |
| 57 | + const tempTgzPath: string = path.join(__dirname, `../.tmp/tmp-${Math.random()}.tgz`) |
| 58 | + await new Promise(resolve => { |
| 59 | + fs.mkdir(path.join(__dirname, `../.tmp/`), () => { |
| 60 | + resolve() |
| 61 | + }) |
| 62 | + }) |
| 63 | + const file = fs.createWriteStream(tempTgzPath); |
| 64 | + return await new Promise<string>(resolve => { |
| 65 | + const request = http.get(tarballUrl, function(response) { |
| 66 | + response.pipe(file); |
| 67 | + resolve(tempTgzPath) |
| 68 | + }); |
| 69 | + }) |
| 70 | + |
| 71 | +} |
| 72 | + |
52 | 73 | export async function getModuleInfo(registryUrl: string, moduleName: String, version: string, auth: any): Promise<unknown> {
|
53 | 74 | let regInfo: any = await new Promise((resolve: (value?: unknown) => void, reject: (reason?: any) => void) => {
|
54 | 75 | const regClient = new RegClient();
|
|
0 commit comments