forked from ionic-team/ionic-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
44 lines (40 loc) · 1.14 KB
/
utils.js
File metadata and controls
44 lines (40 loc) · 1.14 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
var transformCookies = function transformCookies(jar) {
return jar.map(function(c) {
return c.key + "=" + encodeURIComponent(c.value);
}).join("; ");
}
var retrieveCsrfToken = function retrieveCsrfToken(jar) {
// console.log('retrieveCsrfToken', jar)
if(!jar || typeof jar == 'undefined' || jar.length == 0) {
// console.log('no jar folks')
return '';
}
var csrftoken = '';
for (var i = 0; i < jar.length; i++) {
if (jar[i].key == 'csrftoken') {
csrftoken = jar[i].value;
break;
}
}
return csrftoken;
}
var deleteFolderRecursive = function(removePath) {
var fs = require('fs'),
path = require('path')
if( fs.existsSync(removePath) ) {
fs.readdirSync(removePath).forEach(function(file,index){
var curPath = path.join(removePath, file);
if(fs.lstatSync(curPath).isDirectory()) { // recurse
deleteFolderRecursive(curPath);
} else { // delete file
fs.unlinkSync(curPath);
}
});
fs.rmdirSync(removePath);
}
};
module.exports = {
deleteFolderRecursive: deleteFolderRecursive,
retrieveCsrfToken: retrieveCsrfToken,
transformCookies: transformCookies
}