forked from cometchat/cometchat-sample-app-angular
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostinstall.js
More file actions
Latest commit
70 lines (50 loc) · 1.81 KB
/
Copy pathpostinstall.js
File metadata and controls
70 lines (50 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
constfs=require('fs-extra');
constrequest=require('request');
constextract=require('extract-zip')
constrimraf=require("rimraf");
constfileName="cometchat-pro-angular-ui-kit";
constfilePath=__dirname+"/src/"+fileName;
constzipFileName="cometchat-pro-angular-ui-kit-master";
constzipName=zipFileName+".zip";
constsource=__dirname+"/"+zipFileName;
constdestination=filePath;//__dirname + "/src/cometchat-pro-angular-ui-kit";
constdownloadUrl="https://github.com/cometchat-pro/cometchat-pro-angular-ui-kit/archive/master.zip";
constdownload=(uri,filename,callback)=>{
request.head(uri,(err,res,body)=>{
console.log('content-type:',res.headers['content-type']);
console.log('content-length:',res.headers['content-length']);
request(uri).pipe(fs.createWriteStream(filename)).on('close',callback);
});
};
constcheckIfFolderExists=(path)=>{
if(fs.existsSync(path)){
console.log("File exists",path);
returntrue;
}
returnfalse;
}
constdeleteFileFolder=(target)=>{
console.log("deleting file",target);
rimraf.sync(target);
}
if(checkIfFolderExists(filePath)){
deleteFileFolder(filePath);
}
download(downloadUrl,zipName,(props)=>{
try{
extract(zipName,{dir: __dirname}).then(response=>{
fs.move(source,destination,error=>{
if(error){
returnconsole.error('move file error!',error);
}
console.log('move file success!');
});
constzipFile=__dirname+"/"+zipName;
if(checkIfFolderExists(zipFile)){
deleteFileFolder(zipFile);
}
});
}catch(error){
console.log("File extraction error",zipName);
}
});