4
4
/**
5
5
6
6
*/
7
- import axios from "axios " ;
7
+ import { ManifestUtil , devPreview } from "@microsoft/teamsfx-api " ;
8
8
import fs from "fs" ;
9
9
import fse from "fs-extra" ;
10
10
import * as path from "path" ;
11
11
import * as unzip from "unzipper" ;
12
- import { ManifestUtil , devPreview } from "@microsoft/teamsfx-api" ;
13
12
import { manifestUtils } from "../../driver/teamsApp/utils/ManifestUtils" ;
14
13
15
14
const zipFile = "project.zip" ;
@@ -21,36 +20,28 @@ export class HelperMethods {
21
20
projectBranch ?: string
22
21
) : Promise < void > {
23
22
const projectTemplateZipFile = `${ projectRepo } /archive/${ projectBranch || "" } .zip` ;
24
- return axios
25
- . get ( projectTemplateZipFile , {
26
- responseType : "stream" ,
27
- } )
28
- . then ( ( response ) => {
29
- return new Promise < void > ( ( resolve , reject ) => {
30
- response . data
31
- . pipe ( fs . createWriteStream ( `${ projectFolder } /${ zipFile } ` ) )
32
- . on ( "error" , function ( err : unknown ) {
33
- reject (
34
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
35
- `Unable to download project zip file for "${ projectTemplateZipFile } ".\n${ err } `
36
- ) ;
37
- } )
38
- . on ( "close" , async ( ) => {
39
- await HelperMethods . unzipProjectTemplate ( projectFolder ) ;
40
- resolve ( ) ;
41
- } ) ;
42
- } ) ;
43
- } )
44
- . catch ( ( err ) => {
45
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
46
- console . log ( `Unable to download project zip file for "${ projectTemplateZipFile } ".\n${ err } ` ) ;
47
- } ) ;
23
+ const writeFileStream = fs . createWriteStream ( path . resolve ( projectFolder , zipFile ) ) ;
24
+ const response = await fetch ( projectTemplateZipFile , { method : "GET" } ) ;
25
+ const reader = response . body ?. getReader ( ) ;
26
+ if ( reader ) {
27
+ while ( true ) {
28
+ const res = await reader . read ( ) ;
29
+ if ( res . value ) {
30
+ writeFileStream . write ( res . value ) ;
31
+ }
32
+ if ( res . done ) {
33
+ break ;
34
+ }
35
+ }
36
+ writeFileStream . close ( ) ;
37
+ await HelperMethods . unzipProjectTemplate ( projectFolder ) ;
38
+ }
48
39
}
49
40
50
41
static async unzipProjectTemplate ( projectFolder : string ) : Promise < void > {
51
42
return new Promise ( ( resolve , reject ) => {
52
43
// TODO: Verify file exists
53
- const readStream = fs . createReadStream ( `${ projectFolder } /${ zipFile } ` ) ;
44
+ const readStream = fs . createReadStream ( path . resolve ( `${ projectFolder } /${ zipFile } ` ) ) ;
54
45
readStream
55
46
. pipe ( unzip . Extract ( { path : projectFolder } ) )
56
47
. on ( "error" , function ( err : unknown ) {
0 commit comments