File tree Expand file tree Collapse file tree 2 files changed +53
-0
lines changed Expand file tree Collapse file tree 2 files changed +53
-0
lines changed Original file line number Diff line number Diff line change 1
1
.idea /*
2
+ node_modules /*
Original file line number Diff line number Diff line change
1
+ var url = require ( 'url' ) ;
2
+
3
+
4
+ const AUTHOR = 1 ;
5
+ const REPOSITORY = 2 ;
6
+ const BRANCH = 4 ;
7
+
8
+
9
+ var parameters = {
10
+ url : "https://github.com/reduxjs/redux/tree/master/examples/async" ,
11
+ fileName : undefined ,
12
+ rootDirectory : undefined
13
+ } ;
14
+
15
+
16
+ function parseInfo ( parameters ) {
17
+ var repoPath = url . parse ( parameters . url , true ) . pathname ;
18
+ var splitPath = repoPath . split ( "/" ) ;
19
+ var info = { } ;
20
+
21
+ info . author = splitPath [ AUTHOR ] ;
22
+ info . repository = splitPath [ REPOSITORY ] ;
23
+ info . branch = splitPath [ BRANCH ] ;
24
+
25
+ info . rootName = splitPath [ splitPath . length - 1 ] ;
26
+ if ( ! ! splitPath [ BRANCH ] ) {
27
+ info . resPath = repoPath . substring (
28
+ repoPath . indexOf ( splitPath [ BRANCH ] ) + splitPath [ BRANCH ] . length + 1
29
+ ) ;
30
+ }
31
+
32
+ info . urlPrefix = "https://api.github.com/repos/" + info . author + "/" + info . repository + "/contents/" ;
33
+ info . urlPostfix = "?ref=" + info . branch ;
34
+
35
+ if ( ! parameters . fileName || parameters . fileName == "" ) {
36
+ info . downloadFileName = info . rootName ;
37
+ } else {
38
+ info . downloadFileName = parameters . fileName ;
39
+ }
40
+
41
+ if ( parameters . rootDirectory == "false" ) {
42
+ info . rootDirectoryName = "" ;
43
+ } else if ( ! parameters . rootDirectory || parameters . rootDirectory == "" ||
44
+ parameters . rootDirectory == "true" ) {
45
+ info . rootDirectoryName = info . rootName + "/" ;
46
+ } else {
47
+ info . rootDirectoryName = parameters . rootDirectory + "/" ;
48
+ }
49
+
50
+ return info ;
51
+ }
52
+
You can’t perform that action at this time.
0 commit comments